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

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

Issue 10392068: ui: Move gl/ directory out of gfx/, up to ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac_rel Created 8 years, 7 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_surface.h ('k') | ui/gfx/gl/gl_surface_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/gl/gl_surface.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/command_line.h"
11 #include "base/lazy_instance.h"
12 #include "base/logging.h"
13 #include "base/threading/thread_local.h"
14 #include "ui/gfx/gl/gl_context.h"
15 #include "ui/gfx/gl/gl_implementation.h"
16
17 namespace gfx {
18
19 namespace {
20 base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky
21 current_surface_ = LAZY_INSTANCE_INITIALIZER;
22 } // namespace
23
24 // static
25 bool GLSurface::InitializeOneOff() {
26 static bool initialized = false;
27 if (initialized)
28 return true;
29
30 std::vector<GLImplementation> allowed_impls;
31 GetAllowedGLImplementations(&allowed_impls);
32 DCHECK(!allowed_impls.empty());
33
34 // The default implementation is always the first one in list.
35 GLImplementation impl = allowed_impls[0];
36 bool fallback_to_osmesa = false;
37 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
38 std::string requested_implementation_name =
39 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
40 if (requested_implementation_name == "any") {
41 fallback_to_osmesa = true;
42 } else if (requested_implementation_name == "swiftshader") {
43 impl = kGLImplementationEGLGLES2;
44 } else {
45 impl = GetNamedGLImplementation(requested_implementation_name);
46 if (std::find(allowed_impls.begin(),
47 allowed_impls.end(),
48 impl) == allowed_impls.end()) {
49 LOG(ERROR) << "Requested GL implementation is not available.";
50 return false;
51 }
52 }
53 }
54
55 initialized = InitializeGLBindings(impl) && InitializeOneOffInternal();
56 if (!initialized && fallback_to_osmesa) {
57 ClearGLBindings();
58 initialized = InitializeGLBindings(kGLImplementationOSMesaGL) &&
59 InitializeOneOffInternal();
60 }
61
62 if (initialized) {
63 DVLOG(1) << "Using "
64 << GetGLImplementationName(GetGLImplementation())
65 << " GL implementation.";
66 if (CommandLine::ForCurrentProcess()->HasSwitch(
67 switches::kEnableGPUServiceLogging))
68 InitializeDebugGLBindings();
69 }
70 return initialized;
71 }
72
73 GLSurface::GLSurface() {}
74
75 bool GLSurface::Initialize()
76 {
77 return true;
78 }
79
80 bool GLSurface::Resize(const gfx::Size& size) {
81 NOTIMPLEMENTED();
82 return false;
83 }
84
85 std::string GLSurface::GetExtensions() {
86 // Use of GLSurfaceAdapter class means that we can't compare
87 // GetCurrent() and this directly.
88 DCHECK_EQ(GetCurrent()->GetHandle(), GetHandle());
89 return std::string("");
90 }
91
92 unsigned int GLSurface::GetBackingFrameBufferObject() {
93 return 0;
94 }
95
96 bool GLSurface::PostSubBuffer(int x, int y, int width, int height) {
97 return false;
98 }
99
100 bool GLSurface::OnMakeCurrent(GLContext* context) {
101 return true;
102 }
103
104 void GLSurface::SetBufferAllocation(BufferAllocationState state) {
105 }
106
107 void* GLSurface::GetShareHandle() {
108 NOTIMPLEMENTED();
109 return NULL;
110 }
111
112 void* GLSurface::GetDisplay() {
113 NOTIMPLEMENTED();
114 return NULL;
115 }
116
117 void* GLSurface::GetConfig() {
118 NOTIMPLEMENTED();
119 return NULL;
120 }
121
122 unsigned GLSurface::GetFormat() {
123 NOTIMPLEMENTED();
124 return 0;
125 }
126
127 GLSurface* GLSurface::GetCurrent() {
128 return current_surface_.Pointer()->Get();
129 }
130
131 GLSurface::~GLSurface() {
132 if (GetCurrent() == this)
133 SetCurrent(NULL);
134 }
135
136 void GLSurface::SetCurrent(GLSurface* surface) {
137 current_surface_.Pointer()->Set(surface);
138 }
139
140 GLSurfaceAdapter::GLSurfaceAdapter(GLSurface* surface) : surface_(surface) {}
141
142 bool GLSurfaceAdapter::Initialize() {
143 return surface_->Initialize();
144 }
145
146 void GLSurfaceAdapter::Destroy() {
147 surface_->Destroy();
148 }
149
150 bool GLSurfaceAdapter::Resize(const gfx::Size& size) {
151 return surface_->Resize(size);
152 }
153
154 bool GLSurfaceAdapter::IsOffscreen() {
155 return surface_->IsOffscreen();
156 }
157
158 bool GLSurfaceAdapter::SwapBuffers() {
159 return surface_->SwapBuffers();
160 }
161
162 bool GLSurfaceAdapter::PostSubBuffer(int x, int y, int width, int height) {
163 return surface_->PostSubBuffer(x, y, width, height);
164 }
165
166 std::string GLSurfaceAdapter::GetExtensions() {
167 return surface_->GetExtensions();
168 }
169
170 gfx::Size GLSurfaceAdapter::GetSize() {
171 return surface_->GetSize();
172 }
173
174 void* GLSurfaceAdapter::GetHandle() {
175 return surface_->GetHandle();
176 }
177
178 unsigned int GLSurfaceAdapter::GetBackingFrameBufferObject() {
179 return surface_->GetBackingFrameBufferObject();
180 }
181
182 bool GLSurfaceAdapter::OnMakeCurrent(GLContext* context) {
183 return surface_->OnMakeCurrent(context);
184 }
185
186 void GLSurfaceAdapter::SetBufferAllocation(BufferAllocationState state) {
187 surface_->SetBufferAllocation(state);
188 }
189
190 void* GLSurfaceAdapter::GetShareHandle() {
191 return surface_->GetShareHandle();
192 }
193
194 void* GLSurfaceAdapter::GetDisplay() {
195 return surface_->GetDisplay();
196 }
197
198 void* GLSurfaceAdapter::GetConfig() {
199 return surface_->GetConfig();
200 }
201
202 unsigned GLSurfaceAdapter::GetFormat() {
203 return surface_->GetFormat();
204 }
205
206 GLSurfaceAdapter::~GLSurfaceAdapter() {}
207
208 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_surface.h ('k') | ui/gfx/gl/gl_surface_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698