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

Side by Side Diff: ui/gfx/gl/gl_context_mac.cc

Issue 8233027: Support dynamic switching between integrated and discrete GPUs on Mac OS X. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/mac/mac_util.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" 9 #include "third_party/mesa/MesaLib/include/GL/osmesa.h"
9 #include "ui/gfx/gl/gl_bindings.h" 10 #include "ui/gfx/gl/gl_bindings.h"
10 #include "ui/gfx/gl/gl_context_cgl.h" 11 #include "ui/gfx/gl/gl_context_cgl.h"
11 #include "ui/gfx/gl/gl_context_osmesa.h" 12 #include "ui/gfx/gl/gl_context_osmesa.h"
12 #include "ui/gfx/gl/gl_context_stub.h" 13 #include "ui/gfx/gl/gl_context_stub.h"
13 #include "ui/gfx/gl/gl_implementation.h" 14 #include "ui/gfx/gl/gl_implementation.h"
14 #include "ui/gfx/gl/gl_surface_cgl.h" 15 #include "ui/gfx/gl/gl_surface_cgl.h"
15 #include "ui/gfx/gl/gl_surface_osmesa.h" 16 #include "ui/gfx/gl/gl_surface_osmesa.h"
16 17
17 namespace gfx { 18 namespace gfx {
18 19
19 class GLShareGroup; 20 class GLShareGroup;
20 21
21 scoped_refptr<GLContext> GLContext::CreateGLContext( 22 scoped_refptr<GLContext> GLContext::CreateGLContext(
22 GLShareGroup* share_group, 23 GLShareGroup* share_group,
23 GLSurface* compatible_surface) { 24 GLSurface* compatible_surface,
25 GpuPreference gpu_preference) {
24 switch (GetGLImplementation()) { 26 switch (GetGLImplementation()) {
25 case kGLImplementationDesktopGL: { 27 case kGLImplementationDesktopGL: {
26 scoped_refptr<GLContext> context(new GLContextCGL(share_group)); 28 scoped_refptr<GLContext> context(new GLContextCGL(share_group));
27 if (!context->Initialize(compatible_surface)) 29 if (!context->Initialize(compatible_surface, gpu_preference))
28 return NULL; 30 return NULL;
29 31
30 return context; 32 return context;
31 } 33 }
32 case kGLImplementationOSMesaGL: { 34 case kGLImplementationOSMesaGL: {
33 scoped_refptr<GLContext> context(new GLContextOSMesa(share_group)); 35 scoped_refptr<GLContext> context(new GLContextOSMesa(share_group));
34 if (!context->Initialize(compatible_surface)) 36 if (!context->Initialize(compatible_surface, gpu_preference))
35 return NULL; 37 return NULL;
36 38
37 return context; 39 return context;
38 } 40 }
39 case kGLImplementationMockGL: 41 case kGLImplementationMockGL:
40 return new GLContextStub; 42 return new GLContextStub;
41 default: 43 default:
42 NOTREACHED(); 44 NOTREACHED();
43 return NULL; 45 return NULL;
44 } 46 }
45 } 47 }
46 48
49
50 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.
51 // We need to know the GL implementation in order to correctly
52 // answer whether dual GPUs are supported. This introduces an
53 // initialization cycle with GLSurface::InitializeOneOff() which we
54 // need to break.
55 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
56 static bool initialized = false;
57 static bool supports_dual_gpus = false;
58
59 if (initialized) {
60 return supports_dual_gpus;
61 }
62
63 if (!initializing) {
64 initializing = true;
65 if (!GLSurface::InitializeOneOff()) {
66 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
67 }
68 }
69
70 initialized = true;
71
72 if (!base::mac::IsOSLionOrLater()) {
73 return false;
74 }
75
76 if (GetGLImplementation() != kGLImplementationDesktopGL) {
77 return false;
78 }
79
80 // Enumerate all hardware-accelerated renderers. If we find one
81 // online and one offline, assume we're on a dual-GPU system.
82 GLuint display_mask = static_cast<GLuint>(-1);
83 CGLRendererInfoObj renderer_info = NULL;
84 GLint num_renderers = 0;
85
86 bool found_online = false;
87 bool found_offline = false;
88
89 if (CGLQueryRendererInfo(display_mask,
90 &renderer_info,
91 &num_renderers) != kCGLNoError) {
92 return false;
93 }
94
95 for (GLint i = 0; i < num_renderers; ++i) {
96 GLint accelerated = 0;
97 if (CGLDescribeRenderer(renderer_info,
98 i,
99 kCGLRPAccelerated,
100 &accelerated) != kCGLNoError) {
101 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
102 return false;
103 }
104
105 if (!accelerated)
106 continue;
107
108 GLint online = 0;
109 if (CGLDescribeRenderer(renderer_info,
110 i,
111 kCGLRPOnline,
112 &online) != kCGLNoError) {
113 CGLDestroyRendererInfo(renderer_info);
114 return false;
115 }
116
117 if (online) {
118 found_online = true;
119 } else {
120 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
121 }
122 }
123
124 CGLDestroyRendererInfo(renderer_info);
125
126 if (found_online && found_offline) {
127 supports_dual_gpus = true;
128 }
129
130 return supports_dual_gpus;
131 }
132
47 } // namespace gfx 133 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698