1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67

android_webview / browser / gfx / scoped_app_gl_state_restore.cc [blame]

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "android_webview/browser/gfx/scoped_app_gl_state_restore.h"

#include <string>

#include "android_webview/browser/gfx/scoped_app_gl_state_restore_impl.h"
#include "android_webview/browser/gfx/scoped_app_gl_state_restore_impl_angle.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_surface_egl.h"

namespace android_webview {

namespace {

ScopedAppGLStateRestore* g_current_instance = nullptr;

}  // namespace

// static
ScopedAppGLStateRestore* ScopedAppGLStateRestore::Current() {
  DCHECK(g_current_instance);
  return g_current_instance;
}

ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode,
                                                 bool save_restore) {
  DCHECK(!g_current_instance);
  g_current_instance = this;

  TRACE_EVENT0("android_webview", "AppGLStateSave");
  if (gl::GLSurfaceEGL::GetGLDisplayEGL()
          ->ext->b_EGL_ANGLE_external_context_and_surface) {
    impl_ = std::make_unique<internal::ScopedAppGLStateRestoreImplAngle>(
        mode, save_restore);
  } else {
    impl_ = std::make_unique<internal::ScopedAppGLStateRestoreImpl>(
        mode, save_restore);
  }
}

ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
  DCHECK_EQ(this, g_current_instance);
  g_current_instance = nullptr;

  TRACE_EVENT0("android_webview", "AppGLStateRestore");
  impl_ = nullptr;
}

StencilState ScopedAppGLStateRestore::stencil_state() const {
  return impl_->stencil_state();
}

int ScopedAppGLStateRestore::framebuffer_binding_ext() const {
  return impl_->framebuffer_binding_ext();
}

bool ScopedAppGLStateRestore::skip_draw() const {
  return impl_->skip_draw();
}

ScopedAppGLStateRestore::Impl::Impl() = default;
ScopedAppGLStateRestore::Impl::~Impl() = default;

}  // namespace android_webview