gpu_memory_buffer_factory_io_surface.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_IO_SURFACE_H_
  5. #define GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_
  6. #include <unordered_map>
  7. #include <utility>
  8. #include <IOSurface/IOSurface.h>
  9. #include "base/mac/scoped_cftyperef.h"
  10. #include "base/memory/ref_counted.h"
  11. #include "base/synchronization/lock.h"
  12. #include "gpu/command_buffer/service/image_factory.h"
  13. #include "gpu/ipc/service/gpu_ipc_service_export.h"
  14. #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
  15. #include "ui/gfx/geometry/size.h"
  16. #include "ui/gfx/gpu_memory_buffer.h"
  17. #include "ui/gfx/mac/io_surface.h"
  18. namespace gl {
  19. class GLImage;
  20. }
  21. namespace gpu {
  22. class GPU_IPC_SERVICE_EXPORT GpuMemoryBufferFactoryIOSurface
  23. : public GpuMemoryBufferFactory,
  24. public ImageFactory {
  25. public:
  26. GpuMemoryBufferFactoryIOSurface();
  27. GpuMemoryBufferFactoryIOSurface(const GpuMemoryBufferFactoryIOSurface&) =
  28. delete;
  29. GpuMemoryBufferFactoryIOSurface& operator=(
  30. const GpuMemoryBufferFactoryIOSurface&) = delete;
  31. ~GpuMemoryBufferFactoryIOSurface() override;
  32. // Overridden from GpuMemoryBufferFactory:
  33. gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
  34. gfx::GpuMemoryBufferId id,
  35. const gfx::Size& size,
  36. const gfx::Size& framebuffer_size,
  37. gfx::BufferFormat format,
  38. gfx::BufferUsage usage,
  39. int client_id,
  40. SurfaceHandle surface_handle) override;
  41. void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
  42. int client_id) override;
  43. bool FillSharedMemoryRegionWithBufferContents(
  44. gfx::GpuMemoryBufferHandle buffer_handle,
  45. base::UnsafeSharedMemoryRegion shared_memory) override;
  46. ImageFactory* AsImageFactory() override;
  47. // Overridden from ImageFactory:
  48. scoped_refptr<gl::GLImage> CreateImageForGpuMemoryBuffer(
  49. gfx::GpuMemoryBufferHandle handle,
  50. const gfx::Size& size,
  51. gfx::BufferFormat format,
  52. const gfx::ColorSpace& color_space,
  53. gfx::BufferPlane plane,
  54. int client_id,
  55. SurfaceHandle surface_handle) override;
  56. bool SupportsCreateAnonymousImage() const override;
  57. scoped_refptr<gl::GLImage> CreateAnonymousImage(const gfx::Size& size,
  58. gfx::BufferFormat format,
  59. gfx::BufferUsage usage,
  60. SurfaceHandle surface_handle,
  61. bool* is_cleared) override;
  62. unsigned RequiredTextureType() override;
  63. bool SupportsFormatRGB() override;
  64. private:
  65. typedef std::pair<gfx::IOSurfaceId, int> IOSurfaceMapKey;
  66. typedef std::unordered_map<IOSurfaceMapKey,
  67. base::ScopedCFTypeRef<IOSurfaceRef>>
  68. IOSurfaceMap;
  69. IOSurfaceMap io_surfaces_;
  70. base::Lock io_surfaces_lock_;
  71. };
  72. } // namespace gpu
  73. #endif // GPU_IPC_SERVICE_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_