OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/surface/accelerated_surface_mac.h" | 5 #include "ui/surface/accelerated_surface_mac.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/scoped_cftyperef.h" | 8 #include "base/mac/scoped_cftyperef.h" |
9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
11 #include "ui/gl/gl_context.h" | 11 #include "ui/gl/gl_context.h" |
12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_surface.h" | 13 #include "ui/gl/gl_surface.h" |
14 #include "ui/gl/io_surface_support_mac.h" | |
15 #include "ui/gl/scoped_make_current.h" | 14 #include "ui/gl/scoped_make_current.h" |
16 | 15 |
| 16 // Note that this must be included after gl_bindings.h to avoid conflicts. |
| 17 #include <OpenGL/CGLIOSurface.h> |
| 18 |
17 AcceleratedSurface::AcceleratedSurface() | 19 AcceleratedSurface::AcceleratedSurface() |
18 : io_surface_id_(0), | 20 : io_surface_id_(0), |
19 allocate_fbo_(false), | 21 allocate_fbo_(false), |
20 texture_(0), | 22 texture_(0), |
21 fbo_(0) { | 23 fbo_(0) { |
22 } | 24 } |
23 | 25 |
24 AcceleratedSurface::~AcceleratedSurface() {} | 26 AcceleratedSurface::~AcceleratedSurface() {} |
25 | 27 |
26 bool AcceleratedSurface::Initialize( | 28 bool AcceleratedSurface::Initialize( |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // allocation occurred. | 187 // allocation occurred. |
186 return 0; | 188 return 0; |
187 } | 189 } |
188 | 190 |
189 // Only support IO surfaces if the GL implementation is the native desktop GL. | 191 // Only support IO surfaces if the GL implementation is the native desktop GL. |
190 // IO surfaces will not work with, for example, OSMesa software renderer | 192 // IO surfaces will not work with, for example, OSMesa software renderer |
191 // GL contexts. | 193 // GL contexts. |
192 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) | 194 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) |
193 return 0; | 195 return 0; |
194 | 196 |
195 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); | |
196 if (!io_surface_support) | |
197 return 0; | |
198 | |
199 ui::ScopedMakeCurrent make_current(gl_context_.get(), gl_surface_.get()); | 197 ui::ScopedMakeCurrent make_current(gl_context_.get(), gl_surface_.get()); |
200 if (!make_current.Succeeded()) | 198 if (!make_current.Succeeded()) |
201 return 0; | 199 return 0; |
202 | 200 |
203 gfx::Size clamped_size = ClampToValidDimensions(size); | 201 gfx::Size clamped_size = ClampToValidDimensions(size); |
204 | 202 |
205 // GL_TEXTURE_RECTANGLE_ARB is the best supported render target on | 203 // GL_TEXTURE_RECTANGLE_ARB is the best supported render target on |
206 // Mac OS X and is required for IOSurface interoperability. | 204 // Mac OS X and is required for IOSurface interoperability. |
207 GLenum target = GL_TEXTURE_RECTANGLE_ARB; | 205 GLenum target = GL_TEXTURE_RECTANGLE_ARB; |
208 if (allocate_fbo_) { | 206 if (allocate_fbo_) { |
209 AllocateRenderBuffers(target, clamped_size); | 207 AllocateRenderBuffers(target, clamped_size); |
210 } else if (!texture_) { | 208 } else if (!texture_) { |
211 // Generate the texture object. | 209 // Generate the texture object. |
212 texture_ = CreateTexture(target); | 210 texture_ = CreateTexture(target); |
213 } | 211 } |
214 | 212 |
215 // Allocate a new IOSurface, which is the GPU resource that can be | 213 // Allocate a new IOSurface, which is the GPU resource that can be |
216 // shared across processes. | 214 // shared across processes. |
217 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 215 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
218 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 216 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
219 0, | 217 0, |
220 &kCFTypeDictionaryKeyCallBacks, | 218 &kCFTypeDictionaryKeyCallBacks, |
221 &kCFTypeDictionaryValueCallBacks)); | 219 &kCFTypeDictionaryValueCallBacks)); |
222 AddIntegerValue(properties, | 220 AddIntegerValue(properties, kIOSurfaceWidth, clamped_size.width()); |
223 io_surface_support->GetKIOSurfaceWidth(), | 221 AddIntegerValue(properties, kIOSurfaceHeight, clamped_size.height()); |
224 clamped_size.width()); | 222 AddIntegerValue(properties, kIOSurfaceBytesPerElement, 4); |
225 AddIntegerValue(properties, | 223 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); |
226 io_surface_support->GetKIOSurfaceHeight(), | |
227 clamped_size.height()); | |
228 AddIntegerValue(properties, | |
229 io_surface_support->GetKIOSurfaceBytesPerElement(), 4); | |
230 AddBooleanValue(properties, | |
231 io_surface_support->GetKIOSurfaceIsGlobal(), true); | |
232 // I believe we should be able to unreference the IOSurfaces without | 224 // I believe we should be able to unreference the IOSurfaces without |
233 // synchronizing with the browser process because they are | 225 // synchronizing with the browser process because they are |
234 // ultimately reference counted by the operating system. | 226 // ultimately reference counted by the operating system. |
235 io_surface_.reset(io_surface_support->IOSurfaceCreate(properties)); | 227 io_surface_.reset(IOSurfaceCreate(properties)); |
236 | 228 |
237 // Don't think we need to identify a plane. | 229 // Don't think we need to identify a plane. |
238 GLuint plane = 0; | 230 GLuint plane = 0; |
239 CGLError error = io_surface_support->CGLTexImageIOSurface2D( | 231 CGLError error = CGLTexImageIOSurface2D( |
240 static_cast<CGLContextObj>(gl_context_->GetHandle()), | 232 static_cast<CGLContextObj>(gl_context_->GetHandle()), |
241 target, | 233 target, |
242 GL_RGBA, | 234 GL_RGBA, |
243 clamped_size.width(), | 235 clamped_size.width(), |
244 clamped_size.height(), | 236 clamped_size.height(), |
245 GL_BGRA, | 237 GL_BGRA, |
246 GL_UNSIGNED_INT_8_8_8_8_REV, | 238 GL_UNSIGNED_INT_8_8_8_8_REV, |
247 io_surface_.get(), | 239 io_surface_.get(), |
248 plane); | 240 plane); |
249 if (error != kCGLNoError) { | 241 if (error != kCGLNoError) { |
250 DLOG(ERROR) << "CGL error " << error << " during CGLTexImageIOSurface2D"; | 242 DLOG(ERROR) << "CGL error " << error << " during CGLTexImageIOSurface2D"; |
251 } | 243 } |
252 if (allocate_fbo_) { | 244 if (allocate_fbo_) { |
253 // Set up the frame buffer object. | 245 // Set up the frame buffer object. |
254 if (!SetupFrameBufferObject(target)) { | 246 if (!SetupFrameBufferObject(target)) { |
255 DLOG(ERROR) << "Failed to set up frame buffer object"; | 247 DLOG(ERROR) << "Failed to set up frame buffer object"; |
256 } | 248 } |
257 } | 249 } |
258 surface_size_ = size; | 250 surface_size_ = size; |
259 real_surface_size_ = clamped_size; | 251 real_surface_size_ = clamped_size; |
260 | 252 |
261 // Now send back an identifier for the IOSurface. We originally | 253 // Now send back an identifier for the IOSurface. We originally |
262 // intended to send back a mach port from IOSurfaceCreateMachPort | 254 // intended to send back a mach port from IOSurfaceCreateMachPort |
263 // but it looks like Chrome IPC would need to be modified to | 255 // but it looks like Chrome IPC would need to be modified to |
264 // properly send mach ports between processes. For the time being we | 256 // properly send mach ports between processes. For the time being we |
265 // make our IOSurfaces global and send back their identifiers. On | 257 // make our IOSurfaces global and send back their identifiers. On |
266 // the browser process side the identifier is reconstituted into an | 258 // the browser process side the identifier is reconstituted into an |
267 // IOSurface for on-screen rendering. | 259 // IOSurface for on-screen rendering. |
268 io_surface_id_ = io_surface_support->IOSurfaceGetID(io_surface_); | 260 io_surface_id_ = IOSurfaceGetID(io_surface_); |
269 return io_surface_id_; | 261 return io_surface_id_; |
270 } | 262 } |
271 | 263 |
272 uint32 AcceleratedSurface::GetSurfaceId() { | 264 uint32 AcceleratedSurface::GetSurfaceId() { |
273 return io_surface_id_; | 265 return io_surface_id_; |
274 } | 266 } |
OLD | NEW |