| OLD | NEW |
| 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_gl_api_implementation.h" | 5 #include "ui/gl/gl_gl_api_implementation.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 252 |
| 253 bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) { | 253 bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) { |
| 254 bool switched_contexts = g_current_gl_context != this; | 254 bool switched_contexts = g_current_gl_context != this; |
| 255 GLSurface* current_surface = GLSurface::GetCurrent(); | 255 GLSurface* current_surface = GLSurface::GetCurrent(); |
| 256 if (switched_contexts || surface != current_surface) { | 256 if (switched_contexts || surface != current_surface) { |
| 257 if (!switched_contexts && current_surface && | 257 if (!switched_contexts && current_surface && |
| 258 virtual_context->IsCurrent(surface)) { | 258 virtual_context->IsCurrent(surface)) { |
| 259 // MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent() | 259 // MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent() |
| 260 // calls if the GLSurface uses the same underlying surface or renders to | 260 // calls if the GLSurface uses the same underlying surface or renders to |
| 261 // an FBO. | 261 // an FBO. |
| 262 real_context_->SetCurrent(surface); |
| 262 if (!surface->OnMakeCurrent(real_context_)) { | 263 if (!surface->OnMakeCurrent(real_context_)) { |
| 263 LOG(ERROR) << "Could not make GLSurface current."; | 264 LOG(ERROR) << "Could not make GLSurface current."; |
| 264 return false; | 265 return false; |
| 265 } | 266 } |
| 266 } else if (!real_context_->MakeCurrent(surface)) { | 267 } else if (!real_context_->MakeCurrent(surface)) { |
| 267 return false; | 268 return false; |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 | 271 |
| 271 DCHECK(GLSurface::GetCurrent()); | 272 DCHECK_EQ(real_context_, GLContext::GetRealCurrent()); |
| 272 DCHECK(real_context_->IsCurrent(GLSurface::GetCurrent())); | 273 DCHECK(GLSurface::GetRealCurrent()); |
| 274 DCHECK(real_context_->IsCurrent(GLSurface::GetRealCurrent())); |
| 273 DCHECK(virtual_context->IsCurrent(surface)); | 275 DCHECK(virtual_context->IsCurrent(surface)); |
| 274 | 276 |
| 275 if (switched_contexts || virtual_context != current_context_) { | 277 if (switched_contexts || virtual_context != current_context_) { |
| 276 // There should be no errors from the previous context leaking into the | 278 // There should be no errors from the previous context leaking into the |
| 277 // new context. | 279 // new context. |
| 278 DCHECK_EQ(glGetErrorFn(), static_cast<GLenum>(GL_NO_ERROR)); | 280 DCHECK_EQ(glGetErrorFn(), static_cast<GLenum>(GL_NO_ERROR)); |
| 279 | 281 |
| 280 current_context_ = virtual_context; | 282 current_context_ = virtual_context; |
| 281 // Set all state that is different from the real state | 283 // Set all state that is different from the real state |
| 282 // NOTE: !!! This is a temporary implementation that just restores all | 284 // NOTE: !!! This is a temporary implementation that just restores all |
| 283 // state to let us test that it works. | 285 // state to let us test that it works. |
| 284 // TODO: ASAP, change this to something that only restores the state | 286 // TODO: ASAP, change this to something that only restores the state |
| 285 // needed for individual GL calls. | 287 // needed for individual GL calls. |
| 286 GLApi* temp = GetCurrentGLApi(); | 288 GLApi* temp = GetCurrentGLApi(); |
| 287 SetGLToRealGLApi(); | 289 SetGLToRealGLApi(); |
| 288 if (virtual_context->GetGLStateRestorer()->IsInitialized()) | 290 if (virtual_context->GetGLStateRestorer()->IsInitialized()) |
| 289 virtual_context->GetGLStateRestorer()->RestoreState(); | 291 virtual_context->GetGLStateRestorer()->RestoreState(); |
| 290 SetGLApi(temp); | 292 SetGLApi(temp); |
| 291 } | 293 } |
| 292 SetGLApi(this); | 294 SetGLApi(this); |
| 295 |
| 293 return true; | 296 return true; |
| 294 } | 297 } |
| 295 | 298 |
| 296 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { | 299 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { |
| 297 if (current_context_ == virtual_context) | 300 if (current_context_ == virtual_context) |
| 298 current_context_ = NULL; | 301 current_context_ = NULL; |
| 299 } | 302 } |
| 300 | 303 |
| 301 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { | 304 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { |
| 302 switch (name) { | 305 switch (name) { |
| 303 case GL_EXTENSIONS: | 306 case GL_EXTENSIONS: |
| 304 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); | 307 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); |
| 305 default: | 308 default: |
| 306 return driver_->fn.glGetStringFn(name); | 309 return driver_->fn.glGetStringFn(name); |
| 307 } | 310 } |
| 308 } | 311 } |
| 309 | 312 |
| 310 } // namespace gfx | 313 } // namespace gfx |
| OLD | NEW |