OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/gfx/gl/gl_surface_cgl.h" | |
6 | |
7 #include <OpenGL/CGLRenderers.h> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/logging.h" | |
11 #include "base/mac/mac_util.h" | |
12 #include "ui/gfx/gl/gl_bindings.h" | |
13 #include "ui/gfx/gl/gl_context.h" | |
14 #include "ui/gfx/gl/gl_implementation.h" | |
15 | |
16 namespace gfx { | |
17 | |
18 namespace { | |
19 CGLPixelFormatObj g_pixel_format; | |
20 } | |
21 | |
22 GLSurfaceCGL::GLSurfaceCGL() {} | |
23 | |
24 bool GLSurfaceCGL::InitializeOneOff() { | |
25 static bool initialized = false; | |
26 if (initialized) | |
27 return true; | |
28 | |
29 // This is called from the sandbox warmup code on Mac OS X. | |
30 // GPU-related stuff is very slow without this, probably because | |
31 // the sandbox prevents loading graphics drivers or some such. | |
32 std::vector<CGLPixelFormatAttribute> attribs; | |
33 if (GLContext::SupportsDualGpus()) { | |
34 // Avoid switching to the discrete GPU just for this pixel | |
35 // format selection. | |
36 attribs.push_back(kCGLPFAAllowOfflineRenderers); | |
37 } | |
38 if (GetGLImplementation() == kGLImplementationAppleGL) { | |
39 attribs.push_back(kCGLPFARendererID); | |
40 attribs.push_back(static_cast<CGLPixelFormatAttribute>( | |
41 kCGLRendererGenericFloatID)); | |
42 } | |
43 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); | |
44 | |
45 CGLPixelFormatObj format; | |
46 GLint num_pixel_formats; | |
47 if (CGLChoosePixelFormat(&attribs.front(), | |
48 &format, | |
49 &num_pixel_formats) != kCGLNoError) { | |
50 LOG(ERROR) << "Error choosing pixel format."; | |
51 return false; | |
52 } | |
53 if (!format) { | |
54 LOG(ERROR) << "format == 0."; | |
55 return false; | |
56 } | |
57 CGLReleasePixelFormat(format); | |
58 DCHECK_NE(num_pixel_formats, 0); | |
59 initialized = true; | |
60 return true; | |
61 } | |
62 | |
63 void* GLSurfaceCGL::GetPixelFormat() { | |
64 return g_pixel_format; | |
65 } | |
66 | |
67 GLSurfaceCGL::~GLSurfaceCGL() {} | |
68 | |
69 NoOpGLSurfaceCGL::NoOpGLSurfaceCGL(const gfx::Size& size) | |
70 : size_(size) { | |
71 } | |
72 | |
73 bool NoOpGLSurfaceCGL::Initialize() { | |
74 return true; | |
75 } | |
76 | |
77 void NoOpGLSurfaceCGL::Destroy() { | |
78 } | |
79 | |
80 bool NoOpGLSurfaceCGL::IsOffscreen() { | |
81 return true; | |
82 } | |
83 | |
84 bool NoOpGLSurfaceCGL::SwapBuffers() { | |
85 NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurfaceCGL."; | |
86 return false; | |
87 } | |
88 | |
89 gfx::Size NoOpGLSurfaceCGL::GetSize() { | |
90 return size_; | |
91 } | |
92 | |
93 void* NoOpGLSurfaceCGL::GetHandle() { | |
94 return NULL; | |
95 } | |
96 | |
97 NoOpGLSurfaceCGL::~NoOpGLSurfaceCGL() { | |
98 Destroy(); | |
99 } | |
100 | |
101 } // namespace gfx | |
OLD | NEW |