| 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 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_), | 129 base::Bind(&CGLReleasePixelFormat, discrete_pixelformat_), |
| 130 base::TimeDelta::FromSeconds(10)); | 130 base::TimeDelta::FromSeconds(10)); |
| 131 discrete_pixelformat_ = NULL; | 131 discrete_pixelformat_ = NULL; |
| 132 } | 132 } |
| 133 if (context_) { | 133 if (context_) { |
| 134 CGLDestroyContext(static_cast<CGLContextObj>(context_)); | 134 CGLDestroyContext(static_cast<CGLContextObj>(context_)); |
| 135 context_ = NULL; | 135 context_ = NULL; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool GLContextCGL::MakeCurrent(GLSurface* surface) { | 139 bool GLContextCGL::ForceGpuSwitchIfNeeded() { |
| 140 DCHECK(context_); | 140 DCHECK(context_); |
| 141 | 141 |
| 142 // The call to CGLSetVirtualScreen can hang on some AMD drivers | 142 // The call to CGLSetVirtualScreen can hang on some AMD drivers |
| 143 // http://crbug.com/227228 | 143 // http://crbug.com/227228 |
| 144 if (safe_to_force_gpu_switch_) { | 144 if (safe_to_force_gpu_switch_) { |
| 145 int renderer_id = share_group()->GetRendererID(); | 145 int renderer_id = share_group()->GetRendererID(); |
| 146 int screen; | 146 int screen; |
| 147 CGLGetVirtualScreen(static_cast<CGLContextObj>(context_), &screen); | 147 CGLGetVirtualScreen(static_cast<CGLContextObj>(context_), &screen); |
| 148 | 148 |
| 149 if (g_support_renderer_switching && | 149 if (g_support_renderer_switching && |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 screen_renderer_id &= kCGLRendererIDMatchingMask; | 167 screen_renderer_id &= kCGLRendererIDMatchingMask; |
| 168 if (screen_renderer_id == renderer_id) { | 168 if (screen_renderer_id == renderer_id) { |
| 169 CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i); | 169 CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i); |
| 170 screen_ = i; | 170 screen_ = i; |
| 171 break; | 171 break; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 renderer_id_ = renderer_id; | 174 renderer_id_ = renderer_id; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 return true; |
| 178 } |
| 179 |
| 180 bool GLContextCGL::MakeCurrent(GLSurface* surface) { |
| 181 DCHECK(context_); |
| 182 |
| 183 if (!ForceGpuSwitchIfNeeded()) |
| 184 return false; |
| 177 | 185 |
| 178 if (IsCurrent(surface)) | 186 if (IsCurrent(surface)) |
| 179 return true; | 187 return true; |
| 180 | 188 |
| 181 ScopedReleaseCurrent release_current; | 189 ScopedReleaseCurrent release_current; |
| 182 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent"); | 190 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent"); |
| 183 | 191 |
| 184 if (CGLSetCurrentContext( | 192 if (CGLSetCurrentContext( |
| 185 static_cast<CGLContextObj>(context_)) != kCGLNoError) { | 193 static_cast<CGLContextObj>(context_)) != kCGLNoError) { |
| 186 LOG(ERROR) << "Unable to make gl context current."; | 194 LOG(ERROR) << "Unable to make gl context current."; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 302 |
| 295 GLContextCGL::~GLContextCGL() { | 303 GLContextCGL::~GLContextCGL() { |
| 296 Destroy(); | 304 Destroy(); |
| 297 } | 305 } |
| 298 | 306 |
| 299 GpuPreference GLContextCGL::GetGpuPreference() { | 307 GpuPreference GLContextCGL::GetGpuPreference() { |
| 300 return gpu_preference_; | 308 return gpu_preference_; |
| 301 } | 309 } |
| 302 | 310 |
| 303 } // namespace gfx | 311 } // namespace gfx |
| OLD | NEW |