Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_io_surface.cc

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h" 10 #include "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
11 #include "ui/gl/gl_bindings.h" 11 #include "ui/gl/gl_bindings.h"
12 12
13 namespace content { 13 namespace content {
14 namespace { 14 namespace {
15 15
16 base::StaticAtomicSequenceNumber g_next_buffer_id; 16 base::StaticAtomicSequenceNumber g_next_buffer_id;
17 17
18 void Noop() { 18 void Noop() {
19 } 19 }
20 20
21 void GpuMemoryBufferCreated( 21 void GpuMemoryBufferCreated(
22 const gfx::Size& size, 22 const gfx::Size& size,
23 unsigned internalformat, 23 gfx::GpuMemoryBuffer::Format format,
24 const GpuMemoryBufferImpl::CreationCallback& callback, 24 const GpuMemoryBufferImpl::CreationCallback& callback,
25 const gfx::GpuMemoryBufferHandle& handle) { 25 const gfx::GpuMemoryBufferHandle& handle) {
26 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); 26 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type);
27 27
28 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle( 28 callback.Run(GpuMemoryBufferImplIOSurface::CreateFromHandle(
29 handle, size, internalformat, base::Bind(&Noop))); 29 handle, size, format, base::Bind(&Noop)));
30 } 30 }
31 31
32 void GpuMemoryBufferCreatedForChildProcess( 32 void GpuMemoryBufferCreatedForChildProcess(
33 const GpuMemoryBufferImpl::AllocationCallback& callback, 33 const GpuMemoryBufferImpl::AllocationCallback& callback,
34 const gfx::GpuMemoryBufferHandle& handle) { 34 const gfx::GpuMemoryBufferHandle& handle) {
35 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type); 35 DCHECK_EQ(gfx::IO_SURFACE_BUFFER, handle.type);
36 36
37 callback.Run(handle); 37 callback.Run(handle);
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface( 42 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
43 const gfx::Size& size, 43 const gfx::Size& size,
44 unsigned internalformat, 44 Format format,
45 const DestructionCallback& callback, 45 const DestructionCallback& callback,
46 IOSurfaceRef io_surface) 46 IOSurfaceRef io_surface)
47 : GpuMemoryBufferImpl(size, internalformat, callback), 47 : GpuMemoryBufferImpl(size, format, callback), io_surface_(io_surface) {
48 io_surface_(io_surface) {
49 } 48 }
50 49
51 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() { 50 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
52 } 51 }
53 52
54 // static 53 // static
55 void GpuMemoryBufferImplIOSurface::Create(const gfx::Size& size, 54 void GpuMemoryBufferImplIOSurface::Create(const gfx::Size& size,
56 unsigned internalformat, 55 Format format,
57 unsigned usage,
58 int client_id, 56 int client_id,
59 const CreationCallback& callback) { 57 const CreationCallback& callback) {
60 gfx::GpuMemoryBufferHandle handle; 58 gfx::GpuMemoryBufferHandle handle;
61 handle.type = gfx::IO_SURFACE_BUFFER; 59 handle.type = gfx::IO_SURFACE_BUFFER;
62 handle.global_id.primary_id = g_next_buffer_id.GetNext(); 60 handle.global_id.primary_id = g_next_buffer_id.GetNext();
63 handle.global_id.secondary_id = client_id; 61 handle.global_id.secondary_id = client_id;
64 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 62 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
65 handle, 63 handle,
66 size, 64 size,
67 internalformat, 65 format,
68 usage, 66 MAP,
69 base::Bind(&GpuMemoryBufferCreated, size, internalformat, callback)); 67 base::Bind(&GpuMemoryBufferCreated, size, format, callback));
70 } 68 }
71 69
72 // static 70 // static
73 void GpuMemoryBufferImplIOSurface::AllocateForChildProcess( 71 void GpuMemoryBufferImplIOSurface::AllocateForChildProcess(
74 const gfx::Size& size, 72 const gfx::Size& size,
75 unsigned internalformat, 73 Format format,
76 unsigned usage,
77 int child_client_id, 74 int child_client_id,
78 const AllocationCallback& callback) { 75 const AllocationCallback& callback) {
79 gfx::GpuMemoryBufferHandle handle; 76 gfx::GpuMemoryBufferHandle handle;
80 handle.type = gfx::IO_SURFACE_BUFFER; 77 handle.type = gfx::IO_SURFACE_BUFFER;
81 handle.global_id.primary_id = g_next_buffer_id.GetNext(); 78 handle.global_id.primary_id = g_next_buffer_id.GetNext();
82 handle.global_id.secondary_id = child_client_id; 79 handle.global_id.secondary_id = child_client_id;
83 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer( 80 GpuMemoryBufferFactoryHost::GetInstance()->CreateGpuMemoryBuffer(
84 handle, 81 handle,
85 size, 82 size,
86 internalformat, 83 format,
87 usage, 84 MAP,
88 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback)); 85 base::Bind(&GpuMemoryBufferCreatedForChildProcess, callback));
89 } 86 }
90 87
91 // static 88 // static
92 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle( 89 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle(
93 const gfx::GpuMemoryBufferHandle& handle, 90 const gfx::GpuMemoryBufferHandle& handle,
94 const gfx::Size& size, 91 const gfx::Size& size,
95 unsigned internalformat, 92 Format format,
96 const DestructionCallback& callback) { 93 const DestructionCallback& callback) {
97 DCHECK(IsFormatSupported(internalformat)); 94 DCHECK(IsFormatSupported(format));
98 95
99 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( 96 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
100 IOSurfaceLookup(handle.io_surface_id)); 97 IOSurfaceLookup(handle.io_surface_id));
101 if (!io_surface) 98 if (!io_surface)
102 return scoped_ptr<GpuMemoryBufferImpl>(); 99 return scoped_ptr<GpuMemoryBufferImpl>();
103 100
104 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface( 101 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface(
105 size, internalformat, callback, io_surface.get())); 102 size, format, callback, io_surface.get()));
106 } 103 }
107 104
108 // static 105 // static
109 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(unsigned internalformat) { 106 bool GpuMemoryBufferImplIOSurface::IsFormatSupported(Format format) {
110 switch (internalformat) { 107 switch (format) {
111 case GL_BGRA8_EXT: 108 case BGRA_8888:
112 return true; 109 return true;
113 default: 110 case RGBA_8888:
111 case RGBX_8888:
114 return false; 112 return false;
115 } 113 }
114
115 NOTREACHED();
116 return false;
116 } 117 }
117 118
118 // static 119 // static
119 bool GpuMemoryBufferImplIOSurface::IsUsageSupported(unsigned usage) { 120 bool GpuMemoryBufferImplIOSurface::IsUsageSupported(Usage usage) {
120 switch (usage) { 121 switch (usage) {
121 case GL_IMAGE_MAP_CHROMIUM: 122 case MAP:
122 return true; 123 return true;
123 default: 124 case SCANOUT:
124 return false; 125 return false;
125 } 126 }
127
128 NOTREACHED();
129 return false;
126 } 130 }
127 131
128 // static 132 // static
129 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported( 133 bool GpuMemoryBufferImplIOSurface::IsConfigurationSupported(Format format,
130 unsigned internalformat, 134 Usage usage) {
131 unsigned usage) { 135 return IsFormatSupported(format) && IsUsageSupported(usage);
132 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
133 } 136 }
134 137
135 // static 138 // static
136 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(unsigned internalformat) { 139 uint32 GpuMemoryBufferImplIOSurface::PixelFormat(Format format) {
137 switch (internalformat) { 140 switch (format) {
138 case GL_BGRA8_EXT: 141 case BGRA_8888:
139 return 'BGRA'; 142 return 'BGRA';
140 default: 143 case RGBA_8888:
144 case RGBX_8888:
141 NOTREACHED(); 145 NOTREACHED();
142 return 0; 146 return 0;
143 } 147 }
148
149 NOTREACHED();
150 return 0;
144 } 151 }
145 152
146 void* GpuMemoryBufferImplIOSurface::Map() { 153 void* GpuMemoryBufferImplIOSurface::Map() {
147 DCHECK(!mapped_); 154 DCHECK(!mapped_);
148 IOSurfaceLock(io_surface_, 0, NULL); 155 IOSurfaceLock(io_surface_, 0, NULL);
149 mapped_ = true; 156 mapped_ = true;
150 return IOSurfaceGetBaseAddress(io_surface_); 157 return IOSurfaceGetBaseAddress(io_surface_);
151 } 158 }
152 159
153 void GpuMemoryBufferImplIOSurface::Unmap() { 160 void GpuMemoryBufferImplIOSurface::Unmap() {
154 DCHECK(mapped_); 161 DCHECK(mapped_);
155 IOSurfaceUnlock(io_surface_, 0, NULL); 162 IOSurfaceUnlock(io_surface_, 0, NULL);
156 mapped_ = false; 163 mapped_ = false;
157 } 164 }
158 165
159 uint32 GpuMemoryBufferImplIOSurface::GetStride() const { 166 uint32 GpuMemoryBufferImplIOSurface::GetStride() const {
160 return IOSurfaceGetBytesPerRow(io_surface_); 167 return IOSurfaceGetBytesPerRow(io_surface_);
161 } 168 }
162 169
163 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const { 170 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const {
164 gfx::GpuMemoryBufferHandle handle; 171 gfx::GpuMemoryBufferHandle handle;
165 handle.type = gfx::IO_SURFACE_BUFFER; 172 handle.type = gfx::IO_SURFACE_BUFFER;
166 handle.io_surface_id = IOSurfaceGetID(io_surface_); 173 handle.io_surface_id = IOSurfaceGetID(io_surface_);
167 return handle; 174 return handle;
168 } 175 }
169 176
170 } // namespace content 177 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698