scoped_app_gl_state_restore.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2013 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. #include "android_webview/browser/gfx/scoped_app_gl_state_restore.h"
  5. #include <string>
  6. #include "android_webview/browser/gfx/scoped_app_gl_state_restore_impl.h"
  7. #include "android_webview/browser/gfx/scoped_app_gl_state_restore_impl_angle.h"
  8. #include "base/trace_event/trace_event.h"
  9. #include "ui/gl/gl_surface_egl.h"
  10. namespace android_webview {
  11. namespace {
  12. ScopedAppGLStateRestore* g_current_instance = nullptr;
  13. } // namespace
  14. // static
  15. ScopedAppGLStateRestore* ScopedAppGLStateRestore::Current() {
  16. DCHECK(g_current_instance);
  17. return g_current_instance;
  18. }
  19. ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode,
  20. bool save_restore) {
  21. DCHECK(!g_current_instance);
  22. g_current_instance = this;
  23. TRACE_EVENT0("android_webview", "AppGLStateSave");
  24. if (gl::GLSurfaceEGL::GetGLDisplayEGL()
  25. ->ext->b_EGL_ANGLE_external_context_and_surface) {
  26. impl_ = std::make_unique<internal::ScopedAppGLStateRestoreImplAngle>(
  27. mode, save_restore);
  28. } else {
  29. impl_ = std::make_unique<internal::ScopedAppGLStateRestoreImpl>(
  30. mode, save_restore);
  31. }
  32. }
  33. ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
  34. DCHECK_EQ(this, g_current_instance);
  35. g_current_instance = nullptr;
  36. TRACE_EVENT0("android_webview", "AppGLStateRestore");
  37. impl_ = nullptr;
  38. }
  39. StencilState ScopedAppGLStateRestore::stencil_state() const {
  40. return impl_->stencil_state();
  41. }
  42. int ScopedAppGLStateRestore::framebuffer_binding_ext() const {
  43. return impl_->framebuffer_binding_ext();
  44. }
  45. bool ScopedAppGLStateRestore::skip_draw() const {
  46. return impl_->skip_draw();
  47. }
  48. ScopedAppGLStateRestore::Impl::Impl() = default;
  49. ScopedAppGLStateRestore::Impl::~Impl() = default;
  50. } // namespace android_webview