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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 DCHECK(filtered_exts_initialized_); | 514 DCHECK(filtered_exts_initialized_); |
515 #endif | 515 #endif |
516 if (index >= filtered_exts_.size()) { | 516 if (index >= filtered_exts_.size()) { |
517 return NULL; | 517 return NULL; |
518 } | 518 } |
519 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); | 519 return reinterpret_cast<const GLubyte*>(filtered_exts_[index].c_str()); |
520 } | 520 } |
521 return GLApiBase::glGetStringiFn(name, index); | 521 return GLApiBase::glGetStringiFn(name, index); |
522 } | 522 } |
523 | 523 |
524 void RealGLApi::glFlushFn() { | |
525 GLApiBase::glFlushFn(); | |
526 } | |
527 | |
528 void RealGLApi::glFinishFn() { | |
529 GLApiBase::glFinishFn(); | |
530 } | |
531 | |
532 void RealGLApi::InitializeFilteredExtensions() { | 524 void RealGLApi::InitializeFilteredExtensions() { |
533 if (disabled_exts_.size()) { | 525 if (disabled_exts_.size()) { |
534 filtered_exts_.clear(); | 526 filtered_exts_.clear(); |
535 if (WillUseGLGetStringForExtensions()) { | 527 if (WillUseGLGetStringForExtensions()) { |
536 filtered_exts_str_ = | 528 filtered_exts_str_ = |
537 FilterGLExtensionList(reinterpret_cast<const char*>( | 529 FilterGLExtensionList(reinterpret_cast<const char*>( |
538 GLApiBase::glGetStringFn(GL_EXTENSIONS)), | 530 GLApiBase::glGetStringFn(GL_EXTENSIONS)), |
539 disabled_exts_); | 531 disabled_exts_); |
540 filtered_exts_ = base::SplitString( | 532 filtered_exts_ = base::SplitString( |
541 filtered_exts_str_, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 533 filtered_exts_str_, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
(...skipping 17 matching lines...) Expand all Loading... |
559 | 551 |
560 TraceGLApi::~TraceGLApi() { | 552 TraceGLApi::~TraceGLApi() { |
561 } | 553 } |
562 | 554 |
563 NoContextGLApi::NoContextGLApi() { | 555 NoContextGLApi::NoContextGLApi() { |
564 } | 556 } |
565 | 557 |
566 NoContextGLApi::~NoContextGLApi() { | 558 NoContextGLApi::~NoContextGLApi() { |
567 } | 559 } |
568 | 560 |
569 VirtualGLApi::VirtualGLApi() | |
570 : real_context_(NULL), | |
571 current_context_(NULL) { | |
572 } | |
573 | |
574 VirtualGLApi::~VirtualGLApi() { | |
575 } | |
576 | |
577 void VirtualGLApi::Initialize(DriverGL* driver, GLContext* real_context) { | |
578 InitializeBase(driver); | |
579 real_context_ = real_context; | |
580 | |
581 DCHECK(real_context->IsCurrent(NULL)); | |
582 extensions_ = real_context->GetExtensions(); | |
583 extensions_vec_ = base::SplitString(extensions_, " ", base::TRIM_WHITESPACE, | |
584 base::SPLIT_WANT_ALL); | |
585 } | |
586 | |
587 bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) { | |
588 bool switched_contexts = g_current_gl_context_tls->Get() != this; | |
589 GLSurface* current_surface = GLSurface::GetCurrent(); | |
590 if (switched_contexts || surface != current_surface) { | |
591 // MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent() | |
592 // calls if the GLSurface uses the same underlying surface or renders to | |
593 // an FBO. | |
594 if (switched_contexts || !current_surface || | |
595 !virtual_context->IsCurrent(surface)) { | |
596 if (!real_context_->MakeCurrent(surface)) { | |
597 return false; | |
598 } | |
599 } | |
600 } | |
601 | |
602 DCHECK_EQ(real_context_, GLContext::GetRealCurrent()); | |
603 DCHECK(real_context_->IsCurrent(NULL)); | |
604 DCHECK(virtual_context->IsCurrent(surface)); | |
605 | |
606 if (switched_contexts || virtual_context != current_context_) { | |
607 #if DCHECK_IS_ON() | |
608 GLenum error = glGetErrorFn(); | |
609 // Accepting a context loss error here enables using debug mode to work on | |
610 // context loss handling in virtual context mode. | |
611 // There should be no other errors from the previous context leaking into | |
612 // the new context. | |
613 DCHECK(error == GL_NO_ERROR || error == GL_CONTEXT_LOST_KHR) << | |
614 "GL error was: " << error; | |
615 #endif | |
616 | |
617 // Set all state that is different from the real state | |
618 GLApi* temp = GetCurrentGLApi(); | |
619 SetGLToRealGLApi(); | |
620 if (virtual_context->GetGLStateRestorer()->IsInitialized()) { | |
621 GLStateRestorer* virtual_state = virtual_context->GetGLStateRestorer(); | |
622 GLStateRestorer* current_state = current_context_ ? | |
623 current_context_->GetGLStateRestorer() : | |
624 nullptr; | |
625 if (switched_contexts || virtual_context != current_context_) { | |
626 if (current_state) | |
627 current_state->PauseQueries(); | |
628 virtual_state->ResumeQueries(); | |
629 } | |
630 | |
631 virtual_state->RestoreState( | |
632 (current_state && !switched_contexts) ? current_state : NULL); | |
633 } | |
634 SetGLApi(temp); | |
635 current_context_ = virtual_context; | |
636 } | |
637 SetGLApi(this); | |
638 | |
639 virtual_context->SetCurrent(surface); | |
640 if (!surface->OnMakeCurrent(virtual_context)) { | |
641 LOG(ERROR) << "Could not make GLSurface current."; | |
642 return false; | |
643 } | |
644 return true; | |
645 } | |
646 | |
647 void VirtualGLApi::OnReleaseVirtuallyCurrent(GLContext* virtual_context) { | |
648 if (current_context_ == virtual_context) | |
649 current_context_ = NULL; | |
650 } | |
651 | |
652 void VirtualGLApi::glGetIntegervFn(GLenum pname, GLint* params) { | |
653 switch (pname) { | |
654 case GL_NUM_EXTENSIONS: | |
655 *params = static_cast<GLint>(extensions_vec_.size()); | |
656 break; | |
657 default: | |
658 driver_->fn.glGetIntegervFn(pname, params); | |
659 break; | |
660 } | |
661 } | |
662 | |
663 const GLubyte* VirtualGLApi::glGetStringFn(GLenum name) { | |
664 switch (name) { | |
665 case GL_EXTENSIONS: | |
666 return reinterpret_cast<const GLubyte*>(extensions_.c_str()); | |
667 default: | |
668 return driver_->fn.glGetStringFn(name); | |
669 } | |
670 } | |
671 | |
672 const GLubyte* VirtualGLApi::glGetStringiFn(GLenum name, GLuint index) { | |
673 switch (name) { | |
674 case GL_EXTENSIONS: | |
675 if (index >= extensions_vec_.size()) | |
676 return NULL; | |
677 return reinterpret_cast<const GLubyte*>(extensions_vec_[index].c_str()); | |
678 default: | |
679 return driver_->fn.glGetStringiFn(name, index); | |
680 } | |
681 } | |
682 | |
683 void VirtualGLApi::glFlushFn() { | |
684 GLApiBase::glFlushFn(); | |
685 } | |
686 | |
687 void VirtualGLApi::glFinishFn() { | |
688 GLApiBase::glFinishFn(); | |
689 } | |
690 | |
691 } // namespace gl | 561 } // namespace gl |
OLD | NEW |