gpu_memory_buffer_factory.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_H_
  5. #define GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/memory/ref_counted.h"
  9. #include "base/memory/unsafe_shared_memory_region.h"
  10. #include "gpu/ipc/common/surface_handle.h"
  11. #include "gpu/ipc/service/gpu_ipc_service_export.h"
  12. #include "ui/gfx/geometry/size.h"
  13. #include "ui/gfx/gpu_memory_buffer.h"
  14. namespace viz {
  15. class VulkanContextProvider;
  16. } // namespace viz
  17. namespace gpu {
  18. class ImageFactory;
  19. class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactory {
  20. public:
  21. GpuMemoryBufferFactory(const GpuMemoryBufferFactory&) = delete;
  22. GpuMemoryBufferFactory& operator=(const GpuMemoryBufferFactory&) = delete;
  23. virtual ~GpuMemoryBufferFactory() = default;
  24. // Creates a new factory instance for native GPU memory buffers. Returns null
  25. // if native buffers are not supported.
  26. static std::unique_ptr<GpuMemoryBufferFactory> CreateNativeType(
  27. viz::VulkanContextProvider* vulkan_context_provider);
  28. // Creates a new GPU memory buffer instance. A valid handle is returned on
  29. // success. This method is thread-safe but it should not be called on the IO
  30. // thread as it can lead to deadlocks (see https://crbug.com/981721). Instead
  31. // use the asynchronous version on the IO thread. |framebuffer_size| specifies
  32. // the size used to create a framebuffer when the |usage| requires it and the
  33. // particular GpuMemoryBufferFactory implementation supports it (for example,
  34. // when creating a buffer for scanout using the Ozone/DRM backend).
  35. virtual gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
  36. gfx::GpuMemoryBufferId id,
  37. const gfx::Size& size,
  38. const gfx::Size& framebuffer_size,
  39. gfx::BufferFormat format,
  40. gfx::BufferUsage usage,
  41. int client_id,
  42. SurfaceHandle surface_handle) = 0;
  43. // Same as above, but returns the result asynchrounously. Safe to use on the
  44. // IO thread. |callback| will be called on the same thread that calls this
  45. // method, and it might be called on the same call stack.
  46. using CreateGpuMemoryBufferAsyncCallback =
  47. base::OnceCallback<void(gfx::GpuMemoryBufferHandle)>;
  48. virtual void CreateGpuMemoryBufferAsync(
  49. gfx::GpuMemoryBufferId id,
  50. const gfx::Size& size,
  51. gfx::BufferFormat format,
  52. gfx::BufferUsage usage,
  53. int client_id,
  54. SurfaceHandle surface_handle,
  55. CreateGpuMemoryBufferAsyncCallback callback);
  56. // Destroys GPU memory buffer identified by |id|. It can be called on any
  57. // thread.
  58. virtual void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
  59. int client_id) = 0;
  60. // Fills |shared_memory| with the contents of the provided |buffer_handle|
  61. virtual bool FillSharedMemoryRegionWithBufferContents(
  62. gfx::GpuMemoryBufferHandle buffer_handle,
  63. base::UnsafeSharedMemoryRegion shared_memory) = 0;
  64. // Type-checking downcast routine.
  65. virtual ImageFactory* AsImageFactory() = 0;
  66. protected:
  67. GpuMemoryBufferFactory() = default;
  68. };
  69. } // namespace gpu
  70. #endif // GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_H_