Chromium Code Reviews| 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" | 16 #include "ui/gl/gpu_switching_manager.h" |
| 17 | 17 |
| 18 namespace gfx { | 18 namespace gfx { |
| 19 | 19 |
| 20 bool g_support_renderer_switching; | 20 bool g_support_renderer_switching; |
| 21 | 21 |
| 22 bool g_force_cgl_set_virtual_screen = false; | |
| 23 | |
| 22 static CGLPixelFormatObj GetPixelFormat() { | 24 static CGLPixelFormatObj GetPixelFormat() { |
| 23 static CGLPixelFormatObj format; | 25 static CGLPixelFormatObj format; |
| 24 if (format) | 26 if (format) |
| 25 return format; | 27 return format; |
| 26 std::vector<CGLPixelFormatAttribute> attribs; | 28 std::vector<CGLPixelFormatAttribute> attribs; |
| 27 // If the system supports dual gpus then allow offline renderers for every | 29 // 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. | 30 // context, so that they can all be in the same share group. |
| 29 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { | 31 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { |
| 30 attribs.push_back(kCGLPFAAllowOfflineRenderers); | 32 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
| 31 g_support_renderer_switching = true; | 33 g_support_renderer_switching = true; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 return false; | 144 return false; |
| 143 | 145 |
| 144 for (int i = 0; i < virtual_screen_count; ++i) { | 146 for (int i = 0; i < virtual_screen_count; ++i) { |
| 145 int screen_renderer_id; | 147 int screen_renderer_id; |
| 146 if (CGLDescribePixelFormat(format, i, kCGLPFARendererID, | 148 if (CGLDescribePixelFormat(format, i, kCGLPFARendererID, |
| 147 &screen_renderer_id) != kCGLNoError) | 149 &screen_renderer_id) != kCGLNoError) |
| 148 return false; | 150 return false; |
| 149 | 151 |
| 150 screen_renderer_id &= kCGLRendererIDMatchingMask; | 152 screen_renderer_id &= kCGLRendererIDMatchingMask; |
| 151 if (screen_renderer_id == renderer_id) { | 153 if (screen_renderer_id == renderer_id) { |
| 152 CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i); | 154 // This call can hang on some AMD drivers |
| 155 // http://crbug.com/227228 | |
| 156 if (g_force_cgl_set_virtual_screen) | |
|
jbauman
2013/04/06 01:52:02
I'd recommend moving this check up to the beginnin
ccameron
2013/04/08 17:25:14
I put the whole thing in an if-block. My initial i
| |
| 157 CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i); | |
| 153 screen_ = i; | 158 screen_ = i; |
| 154 break; | 159 break; |
| 155 } | 160 } |
| 156 } | 161 } |
| 157 renderer_id_ = renderer_id; | 162 renderer_id_ = renderer_id; |
| 158 } | 163 } |
| 159 | 164 |
| 160 if (IsCurrent(surface)) | 165 if (IsCurrent(surface)) |
| 161 return true; | 166 return true; |
| 162 | 167 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 kCGLRPVideoMemory, | 265 kCGLRPVideoMemory, |
| 261 &video_memory) != kCGLNoError) | 266 &video_memory) != kCGLNoError) |
| 262 continue; | 267 continue; |
| 263 *bytes = video_memory; | 268 *bytes = video_memory; |
| 264 return true; | 269 return true; |
| 265 } | 270 } |
| 266 | 271 |
| 267 return false; | 272 return false; |
| 268 } | 273 } |
| 269 | 274 |
| 275 // static | |
| 276 void GLContextCGL::ForceCGLSetVirtualScreen() { | |
| 277 g_force_cgl_set_virtual_screen = true; | |
| 278 } | |
| 279 | |
| 270 GLContextCGL::~GLContextCGL() { | 280 GLContextCGL::~GLContextCGL() { |
| 271 Destroy(); | 281 Destroy(); |
| 272 } | 282 } |
| 273 | 283 |
| 274 GpuPreference GLContextCGL::GetGpuPreference() { | 284 GpuPreference GLContextCGL::GetGpuPreference() { |
| 275 return gpu_preference_; | 285 return gpu_preference_; |
| 276 } | 286 } |
| 277 | 287 |
| 278 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { | 288 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { |
| 279 CGLDestroyRendererInfo(x); | 289 CGLDestroyRendererInfo(x); |
| 280 } | 290 } |
| 281 | 291 |
| 282 } // namespace gfx | 292 } // namespace gfx |
| OLD | NEW |