Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: ui/gl/gl_context_cgl.cc

Issue 13957008: Merge 193302 "Force GPU switch with CGLSetVirtualScreen only for..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1453/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 DCHECK_NE(num_virtual_screens, 0); 51 DCHECK_NE(num_virtual_screens, 0);
52 return format; 52 return format;
53 } 53 }
54 54
55 GLContextCGL::GLContextCGL(GLShareGroup* share_group) 55 GLContextCGL::GLContextCGL(GLShareGroup* share_group)
56 : GLContext(share_group), 56 : GLContext(share_group),
57 context_(NULL), 57 context_(NULL),
58 gpu_preference_(PreferIntegratedGpu), 58 gpu_preference_(PreferIntegratedGpu),
59 discrete_pixelformat_(NULL), 59 discrete_pixelformat_(NULL),
60 screen_(-1), 60 screen_(-1),
61 renderer_id_(-1) { 61 renderer_id_(-1),
62 safe_to_force_gpu_switch_(false) {
62 } 63 }
63 64
64 bool GLContextCGL::Initialize(GLSurface* compatible_surface, 65 bool GLContextCGL::Initialize(GLSurface* compatible_surface,
65 GpuPreference gpu_preference) { 66 GpuPreference gpu_preference) {
66 DCHECK(compatible_surface); 67 DCHECK(compatible_surface);
67 68
68 gpu_preference = ui::GpuSwitchingManager::GetInstance()->AdjustGpuPreference( 69 gpu_preference = ui::GpuSwitchingManager::GetInstance()->AdjustGpuPreference(
69 gpu_preference); 70 gpu_preference);
70 71
71 GLContextCGL* share_context = share_group() ? 72 GLContextCGL* share_context = share_group() ?
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 discrete_pixelformat_ = NULL; 119 discrete_pixelformat_ = NULL;
119 } 120 }
120 if (context_) { 121 if (context_) {
121 CGLDestroyContext(static_cast<CGLContextObj>(context_)); 122 CGLDestroyContext(static_cast<CGLContextObj>(context_));
122 context_ = NULL; 123 context_ = NULL;
123 } 124 }
124 } 125 }
125 126
126 bool GLContextCGL::MakeCurrent(GLSurface* surface) { 127 bool GLContextCGL::MakeCurrent(GLSurface* surface) {
127 DCHECK(context_); 128 DCHECK(context_);
128 int renderer_id = share_group()->GetRendererID();
129 int screen;
130 CGLGetVirtualScreen(static_cast<CGLContextObj>(context_), &screen);
131 129
132 if (g_support_renderer_switching && 130 // The call to CGLSetVirtualScreen can hang on some AMD drivers
133 !discrete_pixelformat_ && renderer_id != -1 && 131 // http://crbug.com/227228
134 (screen != screen_ || renderer_id != renderer_id_)) { 132 if (safe_to_force_gpu_switch_) {
135 // Attempt to find a virtual screen that's using the requested renderer, 133 int renderer_id = share_group()->GetRendererID();
136 // and switch the context to use that screen. Don't attempt to switch if 134 int screen;
137 // the context requires the discrete GPU. 135 CGLGetVirtualScreen(static_cast<CGLContextObj>(context_), &screen);
138 CGLPixelFormatObj format = GetPixelFormat();
139 int virtual_screen_count;
140 if (CGLDescribePixelFormat(format, 0, kCGLPFAVirtualScreenCount,
141 &virtual_screen_count) != kCGLNoError)
142 return false;
143 136
144 for (int i = 0; i < virtual_screen_count; ++i) { 137 if (g_support_renderer_switching &&
145 int screen_renderer_id; 138 !discrete_pixelformat_ && renderer_id != -1 &&
146 if (CGLDescribePixelFormat(format, i, kCGLPFARendererID, 139 (screen != screen_ || renderer_id != renderer_id_)) {
147 &screen_renderer_id) != kCGLNoError) 140 // Attempt to find a virtual screen that's using the requested renderer,
141 // and switch the context to use that screen. Don't attempt to switch if
142 // the context requires the discrete GPU.
143 CGLPixelFormatObj format = GetPixelFormat();
144 int virtual_screen_count;
145 if (CGLDescribePixelFormat(format, 0, kCGLPFAVirtualScreenCount,
146 &virtual_screen_count) != kCGLNoError)
148 return false; 147 return false;
149 148
150 screen_renderer_id &= kCGLRendererIDMatchingMask; 149 for (int i = 0; i < virtual_screen_count; ++i) {
151 if (screen_renderer_id == renderer_id) { 150 int screen_renderer_id;
152 CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i); 151 if (CGLDescribePixelFormat(format, i, kCGLPFARendererID,
153 screen_ = i; 152 &screen_renderer_id) != kCGLNoError)
154 break; 153 return false;
154
155 screen_renderer_id &= kCGLRendererIDMatchingMask;
156 if (screen_renderer_id == renderer_id) {
157 CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i);
158 screen_ = i;
159 break;
160 }
155 } 161 }
162 renderer_id_ = renderer_id;
156 } 163 }
157 renderer_id_ = renderer_id;
158 } 164 }
159 165
160 if (IsCurrent(surface)) 166 if (IsCurrent(surface))
161 return true; 167 return true;
162 168
163 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent"); 169 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent");
164 170
165 if (CGLSetCurrentContext( 171 if (CGLSetCurrentContext(
166 static_cast<CGLContextObj>(context_)) != kCGLNoError) { 172 static_cast<CGLContextObj>(context_)) != kCGLNoError) {
167 LOG(ERROR) << "Unable to make gl context current."; 173 LOG(ERROR) << "Unable to make gl context current.";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 kCGLRPVideoMemory, 266 kCGLRPVideoMemory,
261 &video_memory) != kCGLNoError) 267 &video_memory) != kCGLNoError)
262 continue; 268 continue;
263 *bytes = video_memory; 269 *bytes = video_memory;
264 return true; 270 return true;
265 } 271 }
266 272
267 return false; 273 return false;
268 } 274 }
269 275
276 void GLContextCGL::SetSafeToForceGpuSwitch() {
277 safe_to_force_gpu_switch_ = true;
278 }
279
280
270 GLContextCGL::~GLContextCGL() { 281 GLContextCGL::~GLContextCGL() {
271 Destroy(); 282 Destroy();
272 } 283 }
273 284
274 GpuPreference GLContextCGL::GetGpuPreference() { 285 GpuPreference GLContextCGL::GetGpuPreference() {
275 return gpu_preference_; 286 return gpu_preference_;
276 } 287 }
277 288
278 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { 289 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const {
279 CGLDestroyRendererInfo(x); 290 CGLDestroyRendererInfo(x);
280 } 291 }
281 292
282 } // namespace gfx 293 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698