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

Side by Side Diff: ui/gfx/gl/gl_surface_cgl.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
« no previous file with comments | « ui/gfx/gl/gl_share_group.cc ('k') | ui/gfx/gl/gpu_preference.h » ('j') | 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) 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 "ui/gfx/gl/gl_surface_cgl.h" 5 #include "ui/gfx/gl/gl_surface_cgl.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/mac_util.h"
9 #include "ui/gfx/gl/gl_bindings.h" 10 #include "ui/gfx/gl/gl_bindings.h"
11 #include "ui/gfx/gl/gl_context.h"
10 12
11 namespace gfx { 13 namespace gfx {
12 14
13 namespace { 15 namespace {
14 CGLPixelFormatObj g_pixel_format; 16 CGLPixelFormatObj g_pixel_format;
15 } 17 }
16 18
17 GLSurfaceCGL::GLSurfaceCGL() { 19 GLSurfaceCGL::GLSurfaceCGL() {
18 } 20 }
19 21
20 GLSurfaceCGL::~GLSurfaceCGL() { 22 GLSurfaceCGL::~GLSurfaceCGL() {
21 } 23 }
22 24
23 bool GLSurfaceCGL::InitializeOneOff() { 25 bool GLSurfaceCGL::InitializeOneOff() {
24 static bool initialized = false; 26 static bool initialized = false;
25 if (initialized) 27 if (initialized)
26 return true; 28 return true;
27 29
28 static const CGLPixelFormatAttribute attribs[] = { 30 // This is called from the sandbox warmup code on Mac OS X.
29 (CGLPixelFormatAttribute) kCGLPFAPBuffer, 31 // GPU-related stuff is very slow without this, probably because
30 (CGLPixelFormatAttribute) 0 32 // the sandbox prevents loading graphics drivers or some such.
31 }; 33 std::vector<CGLPixelFormatAttribute> attribs;
34 if (GLContext::SupportsDualGpus()) {
35 // Avoid switching to the discrete GPU just for this pixel
36 // format selection.
37 attribs.push_back(kCGLPFAAllowOfflineRenderers);
38 }
39 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
40
41 CGLPixelFormatObj format;
32 GLint num_pixel_formats; 42 GLint num_pixel_formats;
33 if (CGLChoosePixelFormat(attribs, 43 if (CGLChoosePixelFormat(&attribs.front(),
34 &g_pixel_format, 44 &format,
35 &num_pixel_formats) != kCGLNoError) { 45 &num_pixel_formats) != kCGLNoError) {
36 LOG(ERROR) << "Error choosing pixel format."; 46 LOG(ERROR) << "Error choosing pixel format.";
37 return false; 47 return false;
38 } 48 }
39 if (num_pixel_formats == 0) { 49 if (!format) {
40 LOG(ERROR) << "num_pixel_formats == 0."; 50 LOG(ERROR) << "format == 0.";
41 return false; 51 return false;
42 } 52 }
43 if (!g_pixel_format) { 53 CGLReleasePixelFormat(format);
44 LOG(ERROR) << "pixel_format == 0."; 54 DCHECK_NE(num_pixel_formats, 0);
45 return false;
46 }
47
48 initialized = true; 55 initialized = true;
49 return true; 56 return true;
50 } 57 }
51 58
52 void* GLSurfaceCGL::GetPixelFormat() { 59 void* GLSurfaceCGL::GetPixelFormat() {
53 return g_pixel_format; 60 return g_pixel_format;
54 } 61 }
55 62
56 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size) 63 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size)
57 : size_(size), 64 : size_(size),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 103
97 gfx::Size PbufferGLSurfaceCGL::GetSize() { 104 gfx::Size PbufferGLSurfaceCGL::GetSize() {
98 return size_; 105 return size_;
99 } 106 }
100 107
101 void* PbufferGLSurfaceCGL::GetHandle() { 108 void* PbufferGLSurfaceCGL::GetHandle() {
102 return pbuffer_; 109 return pbuffer_;
103 } 110 }
104 111
105 } // namespace gfx 112 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_share_group.cc ('k') | ui/gfx/gl/gpu_preference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698