Chromium Code Reviews| 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 | |
|
Mark Mentovai
2011/10/12 00:48:18
Fix indentation.
Ken Russell (switch to Gerrit)
2011/10/12 01:16:36
Done.
| |
| 36 // format selection. | |
| 37 attribs.push_back(kCGLPFAAllowOfflineRenderers); | |
| 38 } | |
| 39 attribs.push_back((CGLPixelFormatAttribute) 0); | |
|
Mark Mentovai
2011/10/12 00:48:18
Use a proper C++<style>(cast).
Ken Russell (switch to Gerrit)
2011/10/12 01:16:36
Done.
| |
| 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 } |
| 39 if (num_pixel_formats == 0) { | 49 if (num_pixel_formats == 0) { |
| 40 LOG(ERROR) << "num_pixel_formats == 0."; | 50 LOG(ERROR) << "num_pixel_formats == 0."; |
| 41 return false; | 51 return false; |
| 42 } | 52 } |
| 43 if (!g_pixel_format) { | 53 if (!format) { |
| 44 LOG(ERROR) << "pixel_format == 0."; | 54 LOG(ERROR) << "pixel_format == 0."; |
|
Mark Mentovai
2011/10/12 00:48:18
This isn’t called pixel_format now (and actually w
Ken Russell (switch to Gerrit)
2011/10/12 01:16:36
Fixed.
| |
| 45 return false; | 55 return false; |
| 46 } | 56 } |
| 47 | 57 CGLReleasePixelFormat(format); |
|
Mark Mentovai
2011/10/12 00:48:18
Is there any way for format to be nonzero but num_
Ken Russell (switch to Gerrit)
2011/10/12 01:16:36
Thanks for the suggestion. Implemented.
| |
| 48 initialized = true; | 58 initialized = true; |
| 49 return true; | 59 return true; |
| 50 } | 60 } |
| 51 | 61 |
| 52 void* GLSurfaceCGL::GetPixelFormat() { | 62 void* GLSurfaceCGL::GetPixelFormat() { |
| 53 return g_pixel_format; | 63 return g_pixel_format; |
| 54 } | 64 } |
| 55 | 65 |
| 56 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size) | 66 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size) |
| 57 : size_(size), | 67 : size_(size), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 106 |
| 97 gfx::Size PbufferGLSurfaceCGL::GetSize() { | 107 gfx::Size PbufferGLSurfaceCGL::GetSize() { |
| 98 return size_; | 108 return size_; |
| 99 } | 109 } |
| 100 | 110 |
| 101 void* PbufferGLSurfaceCGL::GetHandle() { | 111 void* PbufferGLSurfaceCGL::GetHandle() { |
| 102 return pbuffer_; | 112 return pbuffer_; |
| 103 } | 113 } |
| 104 | 114 |
| 105 } // namespace gfx | 115 } // namespace gfx |
| OLD | NEW |