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/gl/gl_context_cgl.h" | 5 #include "ui/gl/gl_context_cgl.h" |
6 | 6 |
7 #include <OpenGL/CGLRenderers.h> | 7 #include <OpenGL/CGLRenderers.h> |
8 #include <OpenGL/CGLTypes.h> | 8 #include <OpenGL/CGLTypes.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_surface_cgl.h" | 15 #include "ui/gl/gl_surface_cgl.h" |
16 #include "ui/gl/gpu_switching_manager.h" | |
17 | 16 |
18 namespace gfx { | 17 namespace gfx { |
19 | 18 |
20 GLContextCGL::GLContextCGL(GLShareGroup* share_group) | 19 GLContextCGL::GLContextCGL(GLShareGroup* share_group) |
21 : GLContext(share_group), | 20 : GLContext(share_group), |
22 context_(NULL), | 21 context_(NULL), |
23 gpu_preference_(PreferIntegratedGpu), | 22 gpu_preference_(PreferIntegratedGpu), |
24 discrete_pixelformat_(NULL) { | 23 discrete_pixelformat_(NULL) { |
25 } | 24 } |
26 | 25 |
27 bool GLContextCGL::Initialize(GLSurface* compatible_surface, | 26 bool GLContextCGL::Initialize(GLSurface* compatible_surface, |
28 GpuPreference gpu_preference) { | 27 GpuPreference gpu_preference) { |
29 DCHECK(compatible_surface); | 28 DCHECK(compatible_surface); |
30 | 29 |
31 gpu_preference = GpuSwitchingManager::GetInstance()->AdjustGpuPreference( | |
32 gpu_preference); | |
33 | |
34 GLContextCGL* share_context = share_group() ? | 30 GLContextCGL* share_context = share_group() ? |
35 static_cast<GLContextCGL*>(share_group()->GetContext()) : NULL; | 31 static_cast<GLContextCGL*>(share_group()->GetContext()) : NULL; |
36 | 32 |
37 std::vector<CGLPixelFormatAttribute> attribs; | 33 std::vector<CGLPixelFormatAttribute> attribs; |
38 // If the system supports dual gpus then allow offline renderers for every | 34 // If the system supports dual gpus then allow offline renderers for every |
39 // context, so that they can all be in the same share group. | 35 // context, so that they can all be in the same share group. |
40 if (SupportsDualGpus()) | 36 if (SupportsDualGpus()) |
41 attribs.push_back(kCGLPFAAllowOfflineRenderers); | 37 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
42 if (GetGLImplementation() == kGLImplementationAppleGL) { | 38 if (GetGLImplementation() == kGLImplementationAppleGL) { |
43 attribs.push_back(kCGLPFARendererID); | 39 attribs.push_back(kCGLPFARendererID); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 209 } |
214 | 210 |
215 GLContextCGL::~GLContextCGL() { | 211 GLContextCGL::~GLContextCGL() { |
216 Destroy(); | 212 Destroy(); |
217 } | 213 } |
218 | 214 |
219 GpuPreference GLContextCGL::GetGpuPreference() { | 215 GpuPreference GLContextCGL::GetGpuPreference() { |
220 return gpu_preference_; | 216 return gpu_preference_; |
221 } | 217 } |
222 | 218 |
| 219 void GLContextCGL::ForceUseOfDiscreteGPU() { |
| 220 static CGLPixelFormatObj format = NULL; |
| 221 if (format) |
| 222 return; |
| 223 CGLPixelFormatAttribute attribs[1]; |
| 224 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); |
| 225 GLint num_pixel_formats = 0; |
| 226 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats); |
| 227 // format is deliberately leaked. |
| 228 } |
| 229 |
223 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { | 230 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { |
224 CGLDestroyRendererInfo(x); | 231 CGLDestroyRendererInfo(x); |
225 } | 232 } |
226 | 233 |
227 void GLContextCGL::ForceUseOfDiscreteGPU() { | 234 void GLContextCGL::ForceUseOfDiscreteGPU() { |
228 static CGLPixelFormatObj format = NULL; | 235 static CGLPixelFormatObj format = NULL; |
229 if (format) | 236 if (format) |
230 return; | 237 return; |
231 CGLPixelFormatAttribute attribs[1]; | 238 CGLPixelFormatAttribute attribs[1]; |
232 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); | 239 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); |
233 GLint num_pixel_formats = 0; | 240 GLint num_pixel_formats = 0; |
234 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats); | 241 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats); |
235 // format is deliberately leaked. | 242 // format is deliberately leaked. |
236 } | 243 } |
237 | 244 |
238 } // namespace gfx | 245 } // namespace gfx |
OLD | NEW |