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

Side by Side Diff: ui/gl/gl_surface_mac.cc

Issue 334173006: Clean up GLSurfaceCGL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 6 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
« no previous file with comments | « ui/gl/gl_surface_cgl.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gl/gl_surface.h" 5 #include "ui/gl/gl_surface.h"
6 6
7 #include <OpenGL/CGLRenderers.h>
8
9 #include "base/basictypes.h"
7 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/mac_util.h"
9 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
10 #include "third_party/mesa/src/include/GL/osmesa.h" 14 #include "third_party/mesa/src/include/GL/osmesa.h"
11 #include "ui/gl/gl_bindings.h" 15 #include "ui/gl/gl_bindings.h"
16 #include "ui/gl/gl_context.h"
12 #include "ui/gl/gl_implementation.h" 17 #include "ui/gl/gl_implementation.h"
13 #include "ui/gl/gl_surface_cgl.h"
14 #include "ui/gl/gl_surface_osmesa.h" 18 #include "ui/gl/gl_surface_osmesa.h"
15 #include "ui/gl/gl_surface_stub.h" 19 #include "ui/gl/gl_surface_stub.h"
20 #include "ui/gl/gpu_switching_manager.h"
16 21
17 namespace gfx { 22 namespace gfx {
23 namespace {
24
25 // A "no-op" surface. It is not required that a CGLContextObj have an
26 // associated drawable (pbuffer or fullscreen context) in order to be
27 // made current. Everywhere this surface type is used, we allocate an
28 // FBO at the user level as the drawable of the associated context.
29 class GL_EXPORT NoOpGLSurface : public GLSurface {
30 public:
31 explicit NoOpGLSurface(const gfx::Size& size) : size_(size) {}
32
33 // Implement GLSurface.
34 virtual bool Initialize() OVERRIDE { return true; }
35 virtual void Destroy() OVERRIDE {}
36 virtual bool IsOffscreen() OVERRIDE { return true; }
37 virtual bool SwapBuffers() OVERRIDE {
38 NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurface.";
39 return false;
40 }
41 virtual gfx::Size GetSize() OVERRIDE { return size_; }
42 virtual void* GetHandle() OVERRIDE { return NULL; }
43 virtual void* GetDisplay() OVERRIDE { return NULL; }
44
45 protected:
46 virtual ~NoOpGLSurface() {}
47
48 private:
49 gfx::Size size_;
50
51 DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface);
52 };
53
54 // static
55 bool InitializeOneOffForSandbox() {
56 static bool initialized = false;
57 if (initialized)
58 return true;
59
60 // This is called from the sandbox warmup code on Mac OS X.
61 // GPU-related stuff is very slow without this, probably because
62 // the sandbox prevents loading graphics drivers or some such.
63 std::vector<CGLPixelFormatAttribute> attribs;
64 if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
65 // Avoid switching to the discrete GPU just for this pixel
66 // format selection.
67 attribs.push_back(kCGLPFAAllowOfflineRenderers);
68 }
69 if (GetGLImplementation() == kGLImplementationAppleGL) {
70 attribs.push_back(kCGLPFARendererID);
71 attribs.push_back(static_cast<CGLPixelFormatAttribute>(
72 kCGLRendererGenericFloatID));
73 }
74 attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
75
76 CGLPixelFormatObj format;
77 GLint num_pixel_formats;
78 if (CGLChoosePixelFormat(&attribs.front(),
79 &format,
80 &num_pixel_formats) != kCGLNoError) {
81 LOG(ERROR) << "Error choosing pixel format.";
82 return false;
83 }
84 if (!format) {
85 LOG(ERROR) << "format == 0.";
86 return false;
87 }
88 CGLReleasePixelFormat(format);
89 DCHECK_NE(num_pixel_formats, 0);
90 initialized = true;
91 return true;
92 }
93
94 } // namespace
18 95
19 bool GLSurface::InitializeOneOffInternal() { 96 bool GLSurface::InitializeOneOffInternal() {
20 switch (GetGLImplementation()) { 97 switch (GetGLImplementation()) {
21 case kGLImplementationDesktopGL: 98 case kGLImplementationDesktopGL:
22 case kGLImplementationAppleGL: 99 case kGLImplementationAppleGL:
23 if (!GLSurfaceCGL::InitializeOneOff()) { 100 if (!InitializeOneOffForSandbox()) {
24 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; 101 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
25 return false; 102 return false;
26 } 103 }
27 break; 104 break;
28 default: 105 default:
29 break; 106 break;
30 } 107 }
31 return true; 108 return true;
32 } 109 }
33 110
(...skipping 21 matching lines...) Expand all
55 case kGLImplementationOSMesaGL: { 132 case kGLImplementationOSMesaGL: {
56 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, 133 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
57 size)); 134 size));
58 if (!surface->Initialize()) 135 if (!surface->Initialize())
59 return NULL; 136 return NULL;
60 137
61 return surface; 138 return surface;
62 } 139 }
63 case kGLImplementationDesktopGL: 140 case kGLImplementationDesktopGL:
64 case kGLImplementationAppleGL: { 141 case kGLImplementationAppleGL: {
65 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size)); 142 scoped_refptr<GLSurface> surface(new NoOpGLSurface(size));
66 if (!surface->Initialize()) 143 if (!surface->Initialize())
67 return NULL; 144 return NULL;
68 145
69 return surface; 146 return surface;
70 } 147 }
71 case kGLImplementationMockGL: 148 case kGLImplementationMockGL:
72 return new GLSurfaceStub; 149 return new GLSurfaceStub;
73 default: 150 default:
74 NOTREACHED(); 151 NOTREACHED();
75 return NULL; 152 return NULL;
76 } 153 }
77 } 154 }
78 155
79 } // namespace gfx 156 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_cgl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698