1 // Copyright 2013 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 5 #ifndef GPU_IPC_COMMON_GPU_MEMORY_BUFFER_IMPL_IO_SURFACE_H_ 6 #define GPU_IPC_COMMON_GPU_MEMORY_BUFFER_IMPL_IO_SURFACE_H_ 7 8 #include <IOSurface/IOSurface.h> 9 #include <stddef.h> 10 #include <stdint.h> 11 12 #include <memory> 13 14 #include "base/mac/scoped_cftyperef.h" 15 #include "base/macros.h" 16 #include "gpu/gpu_export.h" 17 #include "gpu/ipc/common/gpu_memory_buffer_impl.h" 18 #include "ui/gfx/color_space.h" 19 20 namespace gpu { 21 22 // Implementation of GPU memory buffer based on IO surfaces. 23 class GPU_EXPORT GpuMemoryBufferImplIOSurface : public GpuMemoryBufferImpl { 24 public: 25 ~GpuMemoryBufferImplIOSurface() override; 26 27 static constexpr gfx::GpuMemoryBufferType kBufferType = 28 gfx::IO_SURFACE_BUFFER; 29 30 static std::unique_ptr<GpuMemoryBufferImplIOSurface> CreateFromHandle( 31 const gfx::GpuMemoryBufferHandle& handle, 32 const gfx::Size& size, 33 gfx::BufferFormat format, 34 gfx::BufferUsage usage, 35 DestructionCallback callback); 36 37 static base::OnceClosure AllocateForTesting( 38 const gfx::Size& size, 39 gfx::BufferFormat format, 40 gfx::BufferUsage usage, 41 gfx::GpuMemoryBufferHandle* handle); 42 43 // Overridden from gfx::GpuMemoryBuffer: 44 bool Map() override; 45 void* memory(size_t plane) override; 46 void Unmap() override; 47 int stride(size_t plane) const override; 48 void SetColorSpace(const gfx::ColorSpace& color_space) override; 49 gfx::GpuMemoryBufferType GetType() const override; 50 gfx::GpuMemoryBufferHandle CloneHandle() const override; 51 52 private: 53 GpuMemoryBufferImplIOSurface(gfx::GpuMemoryBufferId id, 54 const gfx::Size& size, 55 gfx::BufferFormat format, 56 DestructionCallback callback, 57 IOSurfaceRef io_surface, 58 uint32_t lock_flags); 59 60 base::ScopedCFTypeRef<IOSurfaceRef> io_surface_; 61 uint32_t lock_flags_; 62 // Cache the color space, because re-assigning the same value can be 63 // expensive. 64 gfx::ColorSpace color_space_; 65 66 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImplIOSurface); 67 }; 68 69 } // namespace gpu 70 71 #endif // GPU_IPC_COMMON_GPU_MEMORY_BUFFER_IMPL_IO_SURFACE_H_ 72