gpu_memory_buffer_factory_native_pixmap.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_NATIVE_PIXMAP_H_
  5. #define GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_NATIVE_PIXMAP_H_
  6. #include <vulkan/vulkan_core.h>
  7. #include <unordered_map>
  8. #include <utility>
  9. #include "base/hash/hash.h"
  10. #include "base/synchronization/lock.h"
  11. #include "gpu/command_buffer/service/image_factory.h"
  12. #include "gpu/ipc/service/gpu_ipc_service_export.h"
  13. #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
  14. #include "ui/gfx/native_pixmap.h"
  15. namespace gl {
  16. class GLImage;
  17. }
  18. namespace gpu {
  19. class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactoryNativePixmap
  20. : public GpuMemoryBufferFactory,
  21. public ImageFactory {
  22. public:
  23. GpuMemoryBufferFactoryNativePixmap();
  24. explicit GpuMemoryBufferFactoryNativePixmap(
  25. viz::VulkanContextProvider* vulkan_context_provider);
  26. GpuMemoryBufferFactoryNativePixmap(
  27. const GpuMemoryBufferFactoryNativePixmap&) = delete;
  28. GpuMemoryBufferFactoryNativePixmap& operator=(
  29. const GpuMemoryBufferFactoryNativePixmap&) = delete;
  30. ~GpuMemoryBufferFactoryNativePixmap() override;
  31. // Overridden from GpuMemoryBufferFactory:
  32. gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
  33. gfx::GpuMemoryBufferId id,
  34. const gfx::Size& size,
  35. const gfx::Size& framebuffer_size,
  36. gfx::BufferFormat format,
  37. gfx::BufferUsage usage,
  38. int client_id,
  39. SurfaceHandle surface_handle) override;
  40. void CreateGpuMemoryBufferAsync(
  41. gfx::GpuMemoryBufferId id,
  42. const gfx::Size& size,
  43. gfx::BufferFormat format,
  44. gfx::BufferUsage usage,
  45. int client_id,
  46. SurfaceHandle surface_handle,
  47. CreateGpuMemoryBufferAsyncCallback callback) override;
  48. void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
  49. int client_id) override;
  50. bool FillSharedMemoryRegionWithBufferContents(
  51. gfx::GpuMemoryBufferHandle buffer_handle,
  52. base::UnsafeSharedMemoryRegion shared_memory) override;
  53. ImageFactory* AsImageFactory() override;
  54. // Overridden from ImageFactory:
  55. scoped_refptr<gl::GLImage> CreateImageForGpuMemoryBuffer(
  56. gfx::GpuMemoryBufferHandle handle,
  57. const gfx::Size& size,
  58. gfx::BufferFormat format,
  59. const gfx::ColorSpace& color_space,
  60. gfx::BufferPlane plane,
  61. int client_id,
  62. SurfaceHandle surface_handle) override;
  63. bool SupportsCreateAnonymousImage() const override;
  64. scoped_refptr<gl::GLImage> CreateAnonymousImage(const gfx::Size& size,
  65. gfx::BufferFormat format,
  66. gfx::BufferUsage usage,
  67. SurfaceHandle surface_handle,
  68. bool* is_cleared) override;
  69. unsigned RequiredTextureType() override;
  70. private:
  71. using NativePixmapMapKey = std::pair<int, int>;
  72. using NativePixmapMapKeyHash = base::IntPairHash<NativePixmapMapKey>;
  73. using NativePixmapMap = std::unordered_map<NativePixmapMapKey,
  74. scoped_refptr<gfx::NativePixmap>,
  75. NativePixmapMapKeyHash>;
  76. static void OnNativePixmapCreated(
  77. gfx::GpuMemoryBufferId id,
  78. const gfx::Size& size,
  79. gfx::BufferFormat format,
  80. gfx::BufferUsage usage,
  81. int client_id,
  82. CreateGpuMemoryBufferAsyncCallback callback,
  83. base::WeakPtr<GpuMemoryBufferFactoryNativePixmap> weak_ptr,
  84. scoped_refptr<gfx::NativePixmap> pixmap);
  85. gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromNativePixmap(
  86. gfx::GpuMemoryBufferId id,
  87. const gfx::Size& size,
  88. gfx::BufferFormat format,
  89. gfx::BufferUsage usage,
  90. int client_id,
  91. scoped_refptr<gfx::NativePixmap> pixmap);
  92. VkDevice GetVulkanDevice();
  93. scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider_;
  94. NativePixmapMap native_pixmaps_;
  95. base::Lock native_pixmaps_lock_;
  96. base::WeakPtrFactory<GpuMemoryBufferFactoryNativePixmap> weak_factory_{this};
  97. };
  98. } // namespace gpu
  99. #endif // GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_NATIVE_PIXMAP_H_