OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" | 8 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" |
9 #include "ui/gfx/buffer_format_util.h" | 9 #include "ui/gfx/buffer_format_util.h" |
10 #include "ui/gfx/mac/io_surface_manager.h" | 10 #include "ui/gfx/mac/io_surface.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 namespace { | 13 namespace { |
14 | 14 |
15 uint32_t LockFlags(gfx::BufferUsage usage) { | 15 uint32_t LockFlags(gfx::BufferUsage usage) { |
16 switch (usage) { | 16 switch (usage) { |
17 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: | 17 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: |
18 return kIOSurfaceLockAvoidSync; | 18 return kIOSurfaceLockAvoidSync; |
19 case gfx::BufferUsage::GPU_READ: | 19 case gfx::BufferUsage::GPU_READ: |
20 case gfx::BufferUsage::SCANOUT: | 20 case gfx::BufferUsage::SCANOUT: |
21 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | 21 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: |
22 return 0; | 22 return 0; |
23 } | 23 } |
24 NOTREACHED(); | 24 NOTREACHED(); |
25 return 0; | 25 return 0; |
26 } | 26 } |
27 | 27 |
28 void FreeIOSurfaceForTesting(gfx::GpuMemoryBufferId id) { | 28 void NoOp() { |
29 gfx::IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, 0); | |
30 } | 29 } |
31 | 30 |
32 } // namespace | 31 } // namespace |
33 | 32 |
34 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( | 33 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( |
35 gfx::GpuMemoryBufferId id, | 34 gfx::GpuMemoryBufferId id, |
36 const gfx::Size& size, | 35 const gfx::Size& size, |
37 gfx::BufferFormat format, | 36 gfx::BufferFormat format, |
38 const DestructionCallback& callback, | 37 const DestructionCallback& callback, |
39 IOSurfaceRef io_surface, | 38 IOSurfaceRef io_surface, |
40 uint32_t lock_flags) | 39 uint32_t lock_flags) |
41 : GpuMemoryBufferImpl(id, size, format, callback), | 40 : GpuMemoryBufferImpl(id, size, format, callback), |
42 io_surface_(io_surface), | 41 io_surface_(io_surface), |
43 lock_flags_(lock_flags) {} | 42 lock_flags_(lock_flags) {} |
44 | 43 |
45 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { | 44 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { |
46 } | 45 } |
47 | 46 |
48 // static | 47 // static |
49 scoped_ptr<GpuMemoryBufferImplIOSurface> | 48 scoped_ptr<GpuMemoryBufferImplIOSurface> |
50 GpuMemoryBufferImplIOSurface::CreateFromHandle( | 49 GpuMemoryBufferImplIOSurface::CreateFromHandle( |
51 const gfx::GpuMemoryBufferHandle& handle, | 50 const gfx::GpuMemoryBufferHandle& handle, |
52 const gfx::Size& size, | 51 const gfx::Size& size, |
53 gfx::BufferFormat format, | 52 gfx::BufferFormat format, |
54 gfx::BufferUsage usage, | 53 gfx::BufferUsage usage, |
55 const DestructionCallback& callback) { | 54 const DestructionCallback& callback) { |
56 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 55 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
57 gfx::IOSurfaceManager::GetInstance()->AcquireIOSurface(handle.id)); | 56 IOSurfaceLookupFromMachPort(handle.mach_port.get())); |
58 if (!io_surface) | 57 if (!io_surface) |
59 return nullptr; | 58 return nullptr; |
60 | 59 |
61 return make_scoped_ptr( | 60 return make_scoped_ptr( |
62 new GpuMemoryBufferImplIOSurface(handle.id, size, format, callback, | 61 new GpuMemoryBufferImplIOSurface(handle.id, size, format, callback, |
63 io_surface.release(), LockFlags(usage))); | 62 io_surface.release(), LockFlags(usage))); |
64 } | 63 } |
65 | 64 |
66 // static | 65 // static |
67 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported( | 66 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported( |
68 gfx::BufferFormat format, | 67 gfx::BufferFormat format, |
69 gfx::BufferUsage usage) { | 68 gfx::BufferUsage usage) { |
70 return GpuMemoryBufferFactoryIOSurface:: | 69 return GpuMemoryBufferFactoryIOSurface:: |
71 IsGpuMemoryBufferConfigurationSupported(format, usage); | 70 IsGpuMemoryBufferConfigurationSupported(format, usage); |
72 } | 71 } |
73 | 72 |
74 // static | 73 // static |
75 base::Closure GpuMemoryBufferImplIOSurface::AllocateForTesting( | 74 base::Closure GpuMemoryBufferImplIOSurface::AllocateForTesting( |
76 const gfx::Size& size, | 75 const gfx::Size& size, |
77 gfx::BufferFormat format, | 76 gfx::BufferFormat format, |
78 gfx::BufferUsage usage, | 77 gfx::BufferUsage usage, |
79 gfx::GpuMemoryBufferHandle* handle) { | 78 gfx::GpuMemoryBufferHandle* handle) { |
80 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 79 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
81 gfx::IOSurfaceManager::CreateIOSurface(size, format)); | 80 gfx::CreateIOSurface(size, format)); |
82 DCHECK(io_surface); | 81 DCHECK(io_surface); |
83 gfx::GpuMemoryBufferId kBufferId(1); | 82 gfx::GpuMemoryBufferId kBufferId(1); |
84 bool rv = gfx::IOSurfaceManager::GetInstance()->RegisterIOSurface( | |
85 kBufferId, 0, io_surface); | |
86 DCHECK(rv); | |
87 handle->type = gfx::IO_SURFACE_BUFFER; | 83 handle->type = gfx::IO_SURFACE_BUFFER; |
88 handle->id = kBufferId; | 84 handle->id = kBufferId; |
89 return base::Bind(&FreeIOSurfaceForTesting, kBufferId); | 85 handle->mach_port.reset(IOSurfaceCreateMachPort(io_surface)); |
| 86 return base::Bind(&NoOp); |
90 } | 87 } |
91 | 88 |
92 bool GpuMemoryBufferImplIOSurface::Map() { | 89 bool GpuMemoryBufferImplIOSurface::Map() { |
93 DCHECK(!mapped_); | 90 DCHECK(!mapped_); |
94 IOReturn status = IOSurfaceLock(io_surface_, lock_flags_, NULL); | 91 IOReturn status = IOSurfaceLock(io_surface_, lock_flags_, NULL); |
95 DCHECK_NE(status, kIOReturnCannotLock); | 92 DCHECK_NE(status, kIOReturnCannotLock); |
96 mapped_ = true; | 93 mapped_ = true; |
97 return true; | 94 return true; |
98 } | 95 } |
99 | 96 |
(...skipping 15 matching lines...) Expand all Loading... |
115 } | 112 } |
116 | 113 |
117 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { | 114 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { |
118 gfx::GpuMemoryBufferHandle handle; | 115 gfx::GpuMemoryBufferHandle handle; |
119 handle.type = gfx::IO_SURFACE_BUFFER; | 116 handle.type = gfx::IO_SURFACE_BUFFER; |
120 handle.id = id_; | 117 handle.id = id_; |
121 return handle; | 118 return handle; |
122 } | 119 } |
123 | 120 |
124 } // namespace content | 121 } // namespace content |
OLD | NEW |