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

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

Issue 8698008: This change adds the apple software renderer as an option on Chrome/Mac. It's enabled by passing... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 "ui/gfx/gl/gl_surface_cgl.h" 5 #include "ui/gfx/gl/gl_surface_cgl.h"
6 6
7 #include <OpenGL/CGLRenderers.h>
8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/mac/mac_util.h" 11 #include "base/mac/mac_util.h"
10 #include "ui/gfx/gl/gl_bindings.h" 12 #include "ui/gfx/gl/gl_bindings.h"
11 #include "ui/gfx/gl/gl_context.h" 13 #include "ui/gfx/gl/gl_context.h"
14 #include "ui/gfx/gl/gl_implementation.h"
12 15
13 namespace gfx { 16 namespace gfx {
14 17
15 namespace { 18 namespace {
16 CGLPixelFormatObj g_pixel_format; 19 CGLPixelFormatObj g_pixel_format;
17 } 20 }
18 21
19 GLSurfaceCGL::GLSurfaceCGL() { 22 GLSurfaceCGL::GLSurfaceCGL() {
20 } 23 }
21 24
22 GLSurfaceCGL::~GLSurfaceCGL() { 25 GLSurfaceCGL::~GLSurfaceCGL() {
23 } 26 }
24 27
25 bool GLSurfaceCGL::InitializeOneOff() { 28 bool GLSurfaceCGL::InitializeOneOff() {
26 static bool initialized = false; 29 static bool initialized = false;
27 if (initialized) 30 if (initialized)
28 return true; 31 return true;
29 32
30 // This is called from the sandbox warmup code on Mac OS X. 33 // This is called from the sandbox warmup code on Mac OS X.
31 // GPU-related stuff is very slow without this, probably because 34 // GPU-related stuff is very slow without this, probably because
32 // the sandbox prevents loading graphics drivers or some such. 35 // the sandbox prevents loading graphics drivers or some such.
33 std::vector<CGLPixelFormatAttribute> attribs; 36 std::vector<CGLPixelFormatAttribute> attribs;
34 if (GLContext::SupportsDualGpus()) { 37 if (GLContext::SupportsDualGpus()) {
35 // Avoid switching to the discrete GPU just for this pixel 38 // Avoid switching to the discrete GPU just for this pixel
36 // format selection. 39 // format selection.
37 attribs.push_back(kCGLPFAAllowOfflineRenderers); 40 attribs.push_back(kCGLPFAAllowOfflineRenderers);
38 } 41 }
42 if (GetGLImplementation() == kGLImplementationAppleGL) {
43 attribs.push_back(kCGLPFARendererID);
44 attribs.push_back(static_cast<CGLPixelFormatAttribute>(
45 kCGLRendererGenericFloatID));
46 }
39 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0)); 47 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
40 48
41 CGLPixelFormatObj format; 49 CGLPixelFormatObj format;
42 GLint num_pixel_formats; 50 GLint num_pixel_formats;
43 if (CGLChoosePixelFormat(&attribs.front(), 51 if (CGLChoosePixelFormat(&attribs.front(),
44 &format, 52 &format,
45 &num_pixel_formats) != kCGLNoError) { 53 &num_pixel_formats) != kCGLNoError) {
46 LOG(ERROR) << "Error choosing pixel format."; 54 LOG(ERROR) << "Error choosing pixel format.";
47 return false; 55 return false;
48 } 56 }
49 if (!format) { 57 if (!format) {
50 LOG(ERROR) << "format == 0."; 58 LOG(ERROR) << "format == 0.";
51 return false; 59 return false;
52 } 60 }
53 CGLReleasePixelFormat(format); 61 CGLReleasePixelFormat(format);
54 DCHECK_NE(num_pixel_formats, 0); 62 DCHECK_NE(num_pixel_formats, 0);
55 initialized = true; 63 initialized = true;
56 return true; 64 return true;
57 } 65 }
58 66
59 void* GLSurfaceCGL::GetPixelFormat() { 67 void* GLSurfaceCGL::GetPixelFormat() {
60 return g_pixel_format; 68 return g_pixel_format;
61 } 69 }
62 70
63 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size) 71 PbufferGLSurfaceCGL::PbufferGLSurfaceCGL(const gfx::Size& size)
Ken Russell (switch to Gerrit) 2011/12/06 19:23:47 Can we just delete the PbufferGLSurfaceCGL at this
Stephen White 2011/12/06 19:49:04 Good idea.
64 : size_(size), 72 : size_(size),
65 pbuffer_(NULL) { 73 pbuffer_(NULL) {
66 } 74 }
67 75
68 PbufferGLSurfaceCGL::~PbufferGLSurfaceCGL() { 76 PbufferGLSurfaceCGL::~PbufferGLSurfaceCGL() {
69 Destroy(); 77 Destroy();
70 } 78 }
71 79
72 bool PbufferGLSurfaceCGL::Initialize() { 80 bool PbufferGLSurfaceCGL::Initialize() {
73 if (CGLCreatePBuffer(size_.width(), 81 if (CGLCreatePBuffer(size_.width(),
(...skipping 29 matching lines...) Expand all
103 111
104 gfx::Size PbufferGLSurfaceCGL::GetSize() { 112 gfx::Size PbufferGLSurfaceCGL::GetSize() {
105 return size_; 113 return size_;
106 } 114 }
107 115
108 void* PbufferGLSurfaceCGL::GetHandle() { 116 void* PbufferGLSurfaceCGL::GetHandle() {
109 return pbuffer_; 117 return pbuffer_;
110 } 118 }
111 119
112 } // namespace gfx 120 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698