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

Unified Diff: ui/gl/gl_context_cgl.cc

Issue 13746002: Force GPU switch with CGLSetVirtualScreen only for compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only transition compositor contexts 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 side-by-side diff with in-line comments
Download patch
« gpu/command_buffer/service/gles2_cmd_decoder.cc ('K') | « ui/gl/gl_context_cgl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_context_cgl.cc
diff --git a/ui/gl/gl_context_cgl.cc b/ui/gl/gl_context_cgl.cc
index 7d5a92317cd91d87baaa6bcd59a57709f3c0d666..511718e128af6b17bfb6807697e58fa22dd9fc38 100644
--- a/ui/gl/gl_context_cgl.cc
+++ b/ui/gl/gl_context_cgl.cc
@@ -19,6 +19,8 @@ namespace gfx {
bool g_support_renderer_switching;
+bool g_safe_to_force_gpu_switch = false;
jbauman 2013/04/09 00:47:13 Not necessary anymore.
Ken Russell (switch to Gerrit) 2013/04/09 00:48:58 This is left over from a previous version of the p
ccameron 2013/04/09 17:28:55 Done.
+
static CGLPixelFormatObj GetPixelFormat() {
static CGLPixelFormatObj format;
if (format)
@@ -58,7 +60,8 @@ GLContextCGL::GLContextCGL(GLShareGroup* share_group)
gpu_preference_(PreferIntegratedGpu),
discrete_pixelformat_(NULL),
screen_(-1),
- renderer_id_(-1) {
+ renderer_id_(-1),
+ safe_to_force_gpu_switch_(false) {
}
bool GLContextCGL::Initialize(GLSurface* compatible_surface,
@@ -125,36 +128,41 @@ void GLContextCGL::Destroy() {
bool GLContextCGL::MakeCurrent(GLSurface* surface) {
DCHECK(context_);
- int renderer_id = share_group()->GetRendererID();
- int screen;
- CGLGetVirtualScreen(static_cast<CGLContextObj>(context_), &screen);
-
- if (g_support_renderer_switching &&
- !discrete_pixelformat_ && renderer_id != -1 &&
- (screen != screen_ || renderer_id != renderer_id_)) {
- // Attempt to find a virtual screen that's using the requested renderer,
- // and switch the context to use that screen. Don't attempt to switch if
- // the context requires the discrete GPU.
- CGLPixelFormatObj format = GetPixelFormat();
- int virtual_screen_count;
- if (CGLDescribePixelFormat(format, 0, kCGLPFAVirtualScreenCount,
- &virtual_screen_count) != kCGLNoError)
- return false;
- for (int i = 0; i < virtual_screen_count; ++i) {
- int screen_renderer_id;
- if (CGLDescribePixelFormat(format, i, kCGLPFARendererID,
- &screen_renderer_id) != kCGLNoError)
+ // The call to CGLSetVirtualScreen can hang on some AMD drivers
+ // http://crbug.com/227228
+ if (safe_to_force_gpu_switch_) {
+ int renderer_id = share_group()->GetRendererID();
+ int screen;
+ CGLGetVirtualScreen(static_cast<CGLContextObj>(context_), &screen);
+
+ if (g_support_renderer_switching &&
+ !discrete_pixelformat_ && renderer_id != -1 &&
+ (screen != screen_ || renderer_id != renderer_id_)) {
+ // Attempt to find a virtual screen that's using the requested renderer,
+ // and switch the context to use that screen. Don't attempt to switch if
+ // the context requires the discrete GPU.
+ CGLPixelFormatObj format = GetPixelFormat();
+ int virtual_screen_count;
+ if (CGLDescribePixelFormat(format, 0, kCGLPFAVirtualScreenCount,
+ &virtual_screen_count) != kCGLNoError)
return false;
- screen_renderer_id &= kCGLRendererIDMatchingMask;
- if (screen_renderer_id == renderer_id) {
- CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i);
- screen_ = i;
- break;
+ for (int i = 0; i < virtual_screen_count; ++i) {
+ int screen_renderer_id;
+ if (CGLDescribePixelFormat(format, i, kCGLPFARendererID,
+ &screen_renderer_id) != kCGLNoError)
+ return false;
+
+ screen_renderer_id &= kCGLRendererIDMatchingMask;
+ if (screen_renderer_id == renderer_id) {
+ CGLSetVirtualScreen(static_cast<CGLContextObj>(context_), i);
+ screen_ = i;
+ break;
+ }
}
+ renderer_id_ = renderer_id;
}
- renderer_id_ = renderer_id;
}
if (IsCurrent(surface))
@@ -267,6 +275,11 @@ bool GLContextCGL::GetTotalGpuMemory(size_t* bytes) {
return false;
}
+void GLContextCGL::SetSafeToForceGpuSwitch() {
+ safe_to_force_gpu_switch_ = true;
+}
+
+
GLContextCGL::~GLContextCGL() {
Destroy();
}
« gpu/command_buffer/service/gles2_cmd_decoder.cc ('K') | « ui/gl/gl_context_cgl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698