| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 void RealGLApi::Initialize(DriverGL* driver) { | 248 void RealGLApi::Initialize(DriverGL* driver) { |
| 249 InitializeBase(driver); | 249 InitializeBase(driver); |
| 250 } | 250 } |
| 251 | 251 |
| 252 TraceGLApi::~TraceGLApi() { | 252 TraceGLApi::~TraceGLApi() { |
| 253 } | 253 } |
| 254 | 254 |
| 255 VirtualGLApi::VirtualGLApi() | 255 VirtualGLApi::VirtualGLApi() |
| 256 : real_context_(NULL), | 256 : real_context_(NULL), |
| 257 current_context_(NULL) { | 257 current_context_(NULL), |
| 258 current_active_texture_unit_(GL_TEXTURE0) { |
| 258 } | 259 } |
| 259 | 260 |
| 260 VirtualGLApi::~VirtualGLApi() { | 261 VirtualGLApi::~VirtualGLApi() { |
| 261 } | 262 } |
| 262 | 263 |
| 263 void VirtualGLApi::Initialize(DriverGL* driver, GLContext* real_context) { | 264 void VirtualGLApi::Initialize(DriverGL* driver, GLContext* real_context) { |
| 264 InitializeBase(driver); | 265 InitializeBase(driver); |
| 265 real_context_ = real_context; | 266 real_context_ = real_context; |
| 266 | 267 |
| 267 DCHECK(real_context->IsCurrent(NULL)); | 268 DCHECK(real_context->IsCurrent(NULL)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DCHECK_EQ(real_context_, GLContext::GetRealCurrent()); | 300 DCHECK_EQ(real_context_, GLContext::GetRealCurrent()); |
| 300 DCHECK(real_context_->IsCurrent(NULL)); | 301 DCHECK(real_context_->IsCurrent(NULL)); |
| 301 DCHECK(virtual_context->IsCurrent(surface)); | 302 DCHECK(virtual_context->IsCurrent(surface)); |
| 302 | 303 |
| 303 if (switched_contexts || virtual_context != current_context_) { | 304 if (switched_contexts || virtual_context != current_context_) { |
| 304 // There should be no errors from the previous context leaking into the | 305 // There should be no errors from the previous context leaking into the |
| 305 // new context. | 306 // new context. |
| 306 DCHECK_EQ(glGetErrorFn(), static_cast<GLenum>(GL_NO_ERROR)); | 307 DCHECK_EQ(glGetErrorFn(), static_cast<GLenum>(GL_NO_ERROR)); |
| 307 | 308 |
| 308 current_context_ = virtual_context; | 309 current_context_ = virtual_context; |
| 309 // Set all state that is different from the real state | 310 // Set all state that is different from the real state. |
| 310 // NOTE: !!! This is a temporary implementation that just restores all | |
| 311 // state to let us test that it works. | |
| 312 // TODO: ASAP, change this to something that only restores the state | |
| 313 // needed for individual GL calls. | |
| 314 GLApi* temp = GetCurrentGLApi(); | 311 GLApi* temp = GetCurrentGLApi(); |
| 315 SetGLToRealGLApi(); | 312 SetGLToRealGLApi(); |
| 316 if (virtual_context->GetGLStateRestorer()->IsInitialized()) | 313 if (virtual_context->GetGLStateRestorer()->IsInitialized()) { |
| 317 virtual_context->GetGLStateRestorer()->RestoreState(); | 314 virtual_context->GetGLStateRestorer()->RestoreState( |
| 315 &dirty_texture_state_); |
| 316 // Clear our dirty state after restoring state. |
| 317 ClearDirtyTextureState(); |
| 318 } |
| 318 SetGLApi(temp); | 319 SetGLApi(temp); |
| 319 } | 320 } |
| 320 SetGLApi(this); | 321 SetGLApi(this); |
| 321 | 322 |
| 322 virtual_context->SetCurrent(surface); | 323 virtual_context->SetCurrent(surface); |
| 323 if (!surface->OnMakeCurrent(virtual_context)) { | 324 if (!surface->OnMakeCurrent(virtual_context)) { |
| 324 LOG(ERROR) << "Could not make GLSurface current."; | 325 LOG(ERROR) << "Could not make GLSurface current."; |
| 325 return false; | 326 return false; |
| 326 } | 327 } |
| 327 return true; | 328 return true; |
| 328 } | 329 } |
| 329 | 330 |
| 330 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { | 331 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { |
| 331 if (current_context_ == virtual_context) | 332 if (current_context_ == virtual_context) { |
| 332 current_context_ = NULL; | 333 current_context_ = NULL; |
| 334 ClearDirtyTextureState(); |
| 335 } |
| 333 } | 336 } |
| 334 | 337 |
| 335 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { | 338 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { |
| 336 switch (name) { | 339 switch (name) { |
| 337 case GL_EXTENSIONS: | 340 case GL_EXTENSIONS: |
| 338 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); | 341 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); |
| 339 default: | 342 default: |
| 340 return driver_->fn.glGetStringFn(name); | 343 return driver_->fn.glGetStringFn(name); |
| 341 } | 344 } |
| 342 } | 345 } |
| 343 | 346 |
| 347 void VirtualGLApi::glBindTextureFn(GLenum target, GLuint texture_id) { |
| 348 dirty_texture_state_.AddBinding(current_active_texture_unit_, target); |
| 349 driver_->fn.glBindTextureFn(target, texture_id); |
| 350 } |
| 351 |
| 352 void VirtualGLApi::glActiveTextureFn(GLenum texture_unit) { |
| 353 current_active_texture_unit_ = texture_unit; |
| 354 dirty_texture_state_.UpdateMaxTextureUnit(texture_unit); |
| 355 driver_->fn.glActiveTextureFn(texture_unit); |
| 356 } |
| 357 |
| 358 void VirtualGLApi::ClearDirtyTextureState() { |
| 359 current_active_texture_unit_ = GL_TEXTURE0; |
| 360 dirty_texture_state_.Clear(); |
| 361 } |
| 362 |
| 344 } // namespace gfx | 363 } // namespace gfx |
| OLD | NEW |