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

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

Issue 15928002: GPU: Keep track of the last real context and real surface made current. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nix unnecessary changes. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gl_context_egl.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) 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_context_cgl.h" 5 #include "ui/gl/gl_context_cgl.h"
6 6
7 #include <OpenGL/CGLRenderers.h> 7 #include <OpenGL/CGLRenderers.h>
8 #include <OpenGL/CGLTypes.h> 8 #include <OpenGL/CGLTypes.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 if (!format) { 59 if (!format) {
60 LOG(ERROR) << "format == 0."; 60 LOG(ERROR) << "format == 0.";
61 return NULL; 61 return NULL;
62 } 62 }
63 DCHECK_NE(num_virtual_screens, 0); 63 DCHECK_NE(num_virtual_screens, 0);
64 return format; 64 return format;
65 } 65 }
66 66
67 GLContextCGL::GLContextCGL(GLShareGroup* share_group) 67 GLContextCGL::GLContextCGL(GLShareGroup* share_group)
68 : GLContext(share_group), 68 : GLContextReal(share_group),
69 context_(NULL), 69 context_(NULL),
70 gpu_preference_(PreferIntegratedGpu), 70 gpu_preference_(PreferIntegratedGpu),
71 discrete_pixelformat_(NULL), 71 discrete_pixelformat_(NULL),
72 screen_(-1), 72 screen_(-1),
73 renderer_id_(-1), 73 renderer_id_(-1),
74 safe_to_force_gpu_switch_(false) { 74 safe_to_force_gpu_switch_(false) {
75 } 75 }
76 76
77 bool GLContextCGL::Initialize(GLSurface* compatible_surface, 77 bool GLContextCGL::Initialize(GLSurface* compatible_surface,
78 GpuPreference gpu_preference) { 78 GpuPreference gpu_preference) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return true; 179 return true;
180 180
181 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent"); 181 TRACE_EVENT0("gpu", "GLContextCGL::MakeCurrent");
182 182
183 if (CGLSetCurrentContext( 183 if (CGLSetCurrentContext(
184 static_cast<CGLContextObj>(context_)) != kCGLNoError) { 184 static_cast<CGLContextObj>(context_)) != kCGLNoError) {
185 LOG(ERROR) << "Unable to make gl context current."; 185 LOG(ERROR) << "Unable to make gl context current.";
186 return false; 186 return false;
187 } 187 }
188 188
189 SetCurrent(this, surface); 189 SetCurrent(surface);
190 if (!InitializeExtensionBindings()) { 190 if (!InitializeExtensionBindings()) {
191 ReleaseCurrent(surface); 191 ReleaseCurrent(surface);
192 return false; 192 return false;
193 } 193 }
194 194
195 if (!surface->OnMakeCurrent(this)) { 195 if (!surface->OnMakeCurrent(this)) {
196 LOG(ERROR) << "Unable to make gl context current."; 196 LOG(ERROR) << "Unable to make gl context current.";
197 return false; 197 return false;
198 } 198 }
199 199
200 SetRealGLApi(); 200 SetRealGLApi();
201 return true; 201 return true;
202 } 202 }
203 203
204 void GLContextCGL::ReleaseCurrent(GLSurface* surface) { 204 void GLContextCGL::ReleaseCurrent(GLSurface* surface) {
205 if (!IsCurrent(surface)) 205 if (!IsCurrent(surface))
206 return; 206 return;
207 207
208 SetCurrent(NULL, NULL); 208 SetCurrent(NULL);
209 CGLSetCurrentContext(NULL); 209 CGLSetCurrentContext(NULL);
210 } 210 }
211 211
212 bool GLContextCGL::IsCurrent(GLSurface* surface) { 212 bool GLContextCGL::IsCurrent(GLSurface* surface) {
213 bool native_context_is_current = CGLGetCurrentContext() == context_; 213 bool native_context_is_current = CGLGetCurrentContext() == context_;
214 214
215 // If our context is current then our notion of which GLContext is 215 // If our context is current then our notion of which GLContext is
216 // current must be correct. On the other hand, third-party code 216 // current must be correct. On the other hand, third-party code
217 // using OpenGL might change the current context. 217 // using OpenGL might change the current context.
218 DCHECK(!native_context_is_current || (GetCurrent() == this)); 218 DCHECK(!native_context_is_current || (GetRealCurrent() == this));
219 219
220 if (!native_context_is_current) 220 if (!native_context_is_current)
221 return false; 221 return false;
222 222
223 return true; 223 return true;
224 } 224 }
225 225
226 void* GLContextCGL::GetHandle() { 226 void* GLContextCGL::GetHandle() {
227 return context_; 227 return context_;
228 } 228 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 293
294 GLContextCGL::~GLContextCGL() { 294 GLContextCGL::~GLContextCGL() {
295 Destroy(); 295 Destroy();
296 } 296 }
297 297
298 GpuPreference GLContextCGL::GetGpuPreference() { 298 GpuPreference GLContextCGL::GetGpuPreference() {
299 return gpu_preference_; 299 return gpu_preference_;
300 } 300 }
301 301
302 } // namespace gfx 302 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gl_context_egl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698