Chromium Code Reviews| Index: ui/gfx/gl/gl_context_mac.cc |
| =================================================================== |
| --- ui/gfx/gl/gl_context_mac.cc (revision 105158) |
| +++ ui/gfx/gl/gl_context_mac.cc (working copy) |
| @@ -4,6 +4,7 @@ |
| #include "base/basictypes.h" |
| #include "base/logging.h" |
| +#include "base/mac/mac_util.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "third_party/mesa/MesaLib/include/GL/osmesa.h" |
| #include "ui/gfx/gl/gl_bindings.h" |
| @@ -20,18 +21,19 @@ |
| scoped_refptr<GLContext> GLContext::CreateGLContext( |
| GLShareGroup* share_group, |
| - GLSurface* compatible_surface) { |
| + GLSurface* compatible_surface, |
| + GpuPreference gpu_preference) { |
| switch (GetGLImplementation()) { |
| case kGLImplementationDesktopGL: { |
| scoped_refptr<GLContext> context(new GLContextCGL(share_group)); |
| - if (!context->Initialize(compatible_surface)) |
| + if (!context->Initialize(compatible_surface, gpu_preference)) |
| return NULL; |
| return context; |
| } |
| case kGLImplementationOSMesaGL: { |
| scoped_refptr<GLContext> context(new GLContextOSMesa(share_group)); |
| - if (!context->Initialize(compatible_surface)) |
| + if (!context->Initialize(compatible_surface, gpu_preference)) |
| return NULL; |
| return context; |
| @@ -44,4 +46,88 @@ |
| } |
| } |
| + |
| +bool GLContext::SupportsDualGpus() { |
|
Mark Mentovai
2011/10/13 03:50:33
Found it!
Ken Russell (switch to Gerrit)
2011/10/13 20:09:32
Whoops, sorry. I meant gl_context_mac.cc.
|
| + // We need to know the GL implementation in order to correctly |
| + // answer whether dual GPUs are supported. This introduces an |
| + // initialization cycle with GLSurface::InitializeOneOff() which we |
| + // need to break. |
| + static bool initializing = false; |
|
Mark Mentovai
2011/10/13 03:50:33
You only care about one thread, right?
Ken Russell (switch to Gerrit)
2011/10/13 20:09:32
Yes, for the time being. gl_surface_mac.cc already
|
| + static bool initialized = false; |
| + static bool supports_dual_gpus = false; |
| + |
| + if (initialized) { |
| + return supports_dual_gpus; |
| + } |
| + |
| + if (!initializing) { |
| + initializing = true; |
| + if (!GLSurface::InitializeOneOff()) { |
| + return false; |
|
Mark Mentovai
2011/10/13 03:50:33
At this early-return point, do you want to set ini
Ken Russell (switch to Gerrit)
2011/10/13 20:09:32
Sorry, this doesn't work. I need to handle the cas
|
| + } |
| + } |
| + |
| + initialized = true; |
| + |
| + if (!base::mac::IsOSLionOrLater()) { |
| + return false; |
| + } |
| + |
| + if (GetGLImplementation() != kGLImplementationDesktopGL) { |
| + return false; |
| + } |
| + |
| + // Enumerate all hardware-accelerated renderers. If we find one |
| + // online and one offline, assume we're on a dual-GPU system. |
| + GLuint display_mask = static_cast<GLuint>(-1); |
| + CGLRendererInfoObj renderer_info = NULL; |
| + GLint num_renderers = 0; |
| + |
| + bool found_online = false; |
| + bool found_offline = false; |
| + |
| + if (CGLQueryRendererInfo(display_mask, |
| + &renderer_info, |
| + &num_renderers) != kCGLNoError) { |
| + return false; |
| + } |
| + |
| + for (GLint i = 0; i < num_renderers; ++i) { |
| + GLint accelerated = 0; |
| + if (CGLDescribeRenderer(renderer_info, |
| + i, |
| + kCGLRPAccelerated, |
| + &accelerated) != kCGLNoError) { |
| + CGLDestroyRendererInfo(renderer_info); |
|
Mark Mentovai
2011/10/13 03:50:33
You’ve been good about not leaking this, but with
Ken Russell (switch to Gerrit)
2011/10/13 20:09:32
OK. I generalized ScopedCFTypeRef to take a freein
|
| + return false; |
| + } |
| + |
| + if (!accelerated) |
| + continue; |
| + |
| + GLint online = 0; |
| + if (CGLDescribeRenderer(renderer_info, |
| + i, |
| + kCGLRPOnline, |
| + &online) != kCGLNoError) { |
| + CGLDestroyRendererInfo(renderer_info); |
| + return false; |
| + } |
| + |
| + if (online) { |
| + found_online = true; |
| + } else { |
| + found_offline = true; |
|
Mark Mentovai
2011/10/13 03:50:33
Will a graphics card without a display attached in
Ken Russell (switch to Gerrit)
2011/10/13 20:09:32
I'm not sure, but I suspect that the card in that
|
| + } |
| + } |
| + |
| + CGLDestroyRendererInfo(renderer_info); |
| + |
| + if (found_online && found_offline) { |
| + supports_dual_gpus = true; |
| + } |
| + |
| + return supports_dual_gpus; |
| +} |
| + |
| } // namespace gfx |