| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/gl/gl_surface_cgl.h" | 5 #include "ui/gfx/gl/gl_surface_cgl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/mac_util.h" |
| 9 #include "ui/gfx/gl/gl_bindings.h" | 10 #include "ui/gfx/gl/gl_bindings.h" |
| 11 #include "ui/gfx/gl/gl_context.h" |
| 10 | 12 |
| 11 namespace gfx { | 13 namespace gfx { |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 CGLPixelFormatObj g_pixel_format; | 16 CGLPixelFormatObj g_pixel_format; |
| 15 } | 17 } |
| 16 | 18 |
| 17 GLSurfaceCGL::GLSurfaceCGL() { | 19 GLSurfaceCGL::GLSurfaceCGL() { |
| 18 } | 20 } |
| 19 | 21 |
| 20 GLSurfaceCGL::~GLSurfaceCGL() { | 22 GLSurfaceCGL::~GLSurfaceCGL() { |
| 21 } | 23 } |
| 22 | 24 |
| 23 bool GLSurfaceCGL::InitializeOneOff() { | 25 bool GLSurfaceCGL::InitializeOneOff() { |
| 24 static bool initialized = false; | 26 static bool initialized = false; |
| 25 if (initialized) | 27 if (initialized) |
| 26 return true; | 28 return true; |
| 27 | 29 |
| 28 static const CGLPixelFormatAttribute attribs[] = { | 30 // This is called from the sandbox warmup code on Mac OS X. |
| 29 (CGLPixelFormatAttribute) kCGLPFAPBuffer, | 31 // GPU-related stuff is very slow without this, probably because |
| 30 (CGLPixelFormatAttribute) 0 | 32 // the sandbox prevents loading graphics drivers or some such. |
| 31 }; | 33 std::vector<CGLPixelFormatAttribute> attribs; |
| 34 if (GLContext::SupportsDualGpus()) { |
| 35 // Avoid switching to the discrete GPU just for this pixel |
| 36 // format selection. |
| 37 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
| 38 } |
| 39 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); |
| 40 |
| 41 CGLPixelFormatObj format; |
| 32 GLint num_pixel_formats; | 42 GLint num_pixel_formats; |
| 33 if (CGLChoosePixelFormat(attribs, | 43 if (CGLChoosePixelFormat(&attribs.front(), |
| 34 &g_pixel_format, | 44 &format, |
| 35 &num_pixel_formats) != kCGLNoError) { | 45 &num_pixel_formats) != kCGLNoError) { |
| 36 LOG(ERROR) << "Error choosing pixel format."; | 46 LOG(ERROR) << "Error choosing pixel format."; |
| 37 return false; | 47 return false; |
| 38 } | 48 } |
| 49 if (format) { |
| 50 CGLReleasePixelFormat(format); |
| 51 } else { |
| 52 LOG(ERROR) << "format == 0."; |
| 53 return false; |
| 54 } |
| 39 if (num_pixel_formats == 0) { | 55 if (num_pixel_formats == 0) { |
| 40 LOG(ERROR) << "num_pixel_formats == 0."; | 56 LOG(ERROR) << "num_pixel_formats == 0."; |
| 41 return false; | 57 return false; |
| 42 } | 58 } |
| 43 if (!g_pixel_format) { | |
| 44 LOG(ERROR) << "pixel_format == 0."; | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 initialized = true; | 59 initialized = true; |
| 49 return true; | 60 return true; |
| 50 } | 61 } |
| 51 | 62 |
| 52 void* GLSurfaceCGL::GetPixelFormat() { | 63 void* GLSurfaceCGL::GetPixelFormat() { |
| 53 return g_pixel_format; | 64 return g_pixel_format; |
| 54 } | 65 } |
| 55 | 66 |
| 56 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size) | 67 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size) |
| 57 : size_(size), | 68 : size_(size), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 107 |
| 97 gfx::Size PbufferGLSurfaceCGL::GetSize() { | 108 gfx::Size PbufferGLSurfaceCGL::GetSize() { |
| 98 return size_; | 109 return size_; |
| 99 } | 110 } |
| 100 | 111 |
| 101 void* PbufferGLSurfaceCGL::GetHandle() { | 112 void* PbufferGLSurfaceCGL::GetHandle() { |
| 102 return pbuffer_; | 113 return pbuffer_; |
| 103 } | 114 } |
| 104 | 115 |
| 105 } // namespace gfx | 116 } // namespace gfx |
| OLD | NEW |