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 "base/memory/scoped_ptr.h" |
13 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_surface_cgl.h" | 16 #include "ui/gl/gl_surface_cgl.h" |
16 #include "ui/gl/gpu_switching_manager.h" | 17 #include "ui/gl/gpu_switching_manager.h" |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 | 20 |
| 21 namespace { |
| 22 |
20 bool g_support_renderer_switching; | 23 bool g_support_renderer_switching; |
21 | 24 |
| 25 struct CGLRendererInfoObjDeleter { |
| 26 void operator()(CGLRendererInfoObj* x) { |
| 27 if (x) |
| 28 CGLDestroyRendererInfo(*x); |
| 29 } |
| 30 }; |
| 31 |
| 32 } // namespace |
| 33 |
22 static CGLPixelFormatObj GetPixelFormat() { | 34 static CGLPixelFormatObj GetPixelFormat() { |
23 static CGLPixelFormatObj format; | 35 static CGLPixelFormatObj format; |
24 if (format) | 36 if (format) |
25 return format; | 37 return format; |
26 std::vector<CGLPixelFormatAttribute> attribs; | 38 std::vector<CGLPixelFormatAttribute> attribs; |
27 // If the system supports dual gpus then allow offline renderers for every | 39 // If the system supports dual gpus then allow offline renderers for every |
28 // context, so that they can all be in the same share group. | 40 // context, so that they can all be in the same share group. |
29 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { | 41 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { |
30 attribs.push_back(kCGLPFAAllowOfflineRenderers); | 42 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
31 g_support_renderer_switching = true; | 43 g_support_renderer_switching = true; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 250 |
239 // Iterate through the list of all renderers | 251 // Iterate through the list of all renderers |
240 GLuint display_mask = static_cast<GLuint>(-1); | 252 GLuint display_mask = static_cast<GLuint>(-1); |
241 CGLRendererInfoObj renderer_info = NULL; | 253 CGLRendererInfoObj renderer_info = NULL; |
242 GLint num_renderers = 0; | 254 GLint num_renderers = 0; |
243 if (CGLQueryRendererInfo(display_mask, | 255 if (CGLQueryRendererInfo(display_mask, |
244 &renderer_info, | 256 &renderer_info, |
245 &num_renderers) != kCGLNoError) | 257 &num_renderers) != kCGLNoError) |
246 return false; | 258 return false; |
247 | 259 |
248 ScopedCGLRendererInfoObj scoper(renderer_info); | 260 scoped_ptr<CGLRendererInfoObj, |
| 261 CGLRendererInfoObjDeleter> scoper(&renderer_info); |
249 | 262 |
250 for (GLint renderer_index = 0; | 263 for (GLint renderer_index = 0; |
251 renderer_index < num_renderers; | 264 renderer_index < num_renderers; |
252 ++renderer_index) { | 265 ++renderer_index) { |
253 // Skip this if this renderer is not the current renderer. | 266 // Skip this if this renderer is not the current renderer. |
254 GLint renderer_id = 0; | 267 GLint renderer_id = 0; |
255 if (CGLDescribeRenderer(renderer_info, | 268 if (CGLDescribeRenderer(renderer_info, |
256 renderer_index, | 269 renderer_index, |
257 kCGLRPRendererID, | 270 kCGLRPRendererID, |
258 &renderer_id) != kCGLNoError) | 271 &renderer_id) != kCGLNoError) |
(...skipping 20 matching lines...) Expand all Loading... |
279 | 292 |
280 | 293 |
281 GLContextCGL::~GLContextCGL() { | 294 GLContextCGL::~GLContextCGL() { |
282 Destroy(); | 295 Destroy(); |
283 } | 296 } |
284 | 297 |
285 GpuPreference GLContextCGL::GetGpuPreference() { | 298 GpuPreference GLContextCGL::GetGpuPreference() { |
286 return gpu_preference_; | 299 return gpu_preference_; |
287 } | 300 } |
288 | 301 |
289 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { | |
290 CGLDestroyRendererInfo(x); | |
291 } | |
292 | |
293 } // namespace gfx | 302 } // namespace gfx |
OLD | NEW |