Commit 426f9c09 authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

aw: Skip GL state restore on skia

Bump draw_gl.h version for skia renderer in android, which does not
require webview to restore any GL state, saving a small amount of work
every frame.

Change-Id: Ieaaf0a957c47b5097a008adf73dc79c5a843c6b9
Reviewed-on: https://chromium-review.googlesource.com/736990
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512829}
parent 2883942d
...@@ -318,7 +318,8 @@ void RenderThreadManager::DrawGL(AwDrawGLInfo* draw_info) { ...@@ -318,7 +318,8 @@ void RenderThreadManager::DrawGL(AwDrawGLInfo* draw_info) {
ScopedAppGLStateRestore state_restore( ScopedAppGLStateRestore state_restore(
draw_info->mode == AwDrawGLInfo::kModeDraw draw_info->mode == AwDrawGLInfo::kModeDraw
? ScopedAppGLStateRestore::MODE_DRAW ? ScopedAppGLStateRestore::MODE_DRAW
: ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT); : ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT,
draw_info->mode < 3 /* save_restore */);
ScopedAllowGL allow_gl; ScopedAllowGL allow_gl;
if (!hardware_renderer_ && draw_info->mode == AwDrawGLInfo::kModeDraw && if (!hardware_renderer_ && draw_info->mode == AwDrawGLInfo::kModeDraw &&
!IsInsideHardwareRelease() && HasFrameForHardwareRendererOnRT()) { !IsInsideHardwareRelease() && HasFrameForHardwareRendererOnRT()) {
......
...@@ -75,14 +75,19 @@ namespace internal { ...@@ -75,14 +75,19 @@ namespace internal {
class ScopedAppGLStateRestoreImpl { class ScopedAppGLStateRestoreImpl {
public: public:
explicit ScopedAppGLStateRestoreImpl(ScopedAppGLStateRestore::CallMode mode); ScopedAppGLStateRestoreImpl(ScopedAppGLStateRestore::CallMode mode,
bool save_restore);
~ScopedAppGLStateRestoreImpl(); ~ScopedAppGLStateRestoreImpl();
StencilState stencil_state() const { return stencil_state_; } StencilState stencil_state() const { return stencil_state_; }
GLint framebuffer_binding_ext() const { return framebuffer_binding_ext_; } GLint framebuffer_binding_ext() const { return framebuffer_binding_ext_; }
private: private:
void SaveHWUIState();
void RestoreHWUIState();
const ScopedAppGLStateRestore::CallMode mode_; const ScopedAppGLStateRestore::CallMode mode_;
const bool save_restore_;
GLint pack_alignment_; GLint pack_alignment_;
GLint unpack_alignment_; GLint unpack_alignment_;
...@@ -158,13 +163,51 @@ class ScopedAppGLStateRestoreImpl { ...@@ -158,13 +163,51 @@ class ScopedAppGLStateRestoreImpl {
}; };
ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl(
ScopedAppGLStateRestore::CallMode mode) ScopedAppGLStateRestore::CallMode mode,
: mode_(mode) { bool save_restore)
: mode_(mode), save_restore_(save_restore) {
TRACE_EVENT0("android_webview", "AppGLStateSave"); TRACE_EVENT0("android_webview", "AppGLStateSave");
MakeAppContextCurrent(); MakeAppContextCurrent();
ClearGLErrors(true, "Incoming GLError"); ClearGLErrors(true, "Incoming GLError");
glGetBooleanv(GL_STENCIL_TEST, &stencil_state_.stencil_test_enabled);
glGetIntegerv(GL_STENCIL_FUNC, &stencil_state_.stencil_front_func);
glGetIntegerv(GL_STENCIL_VALUE_MASK, &stencil_state_.stencil_front_mask);
glGetIntegerv(GL_STENCIL_REF, &stencil_state_.stencil_front_ref);
glGetIntegerv(GL_STENCIL_BACK_FUNC, &stencil_state_.stencil_back_func);
glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &stencil_state_.stencil_back_mask);
glGetIntegerv(GL_STENCIL_BACK_REF, &stencil_state_.stencil_back_ref);
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencil_state_.stencil_clear);
glGetIntegerv(GL_STENCIL_WRITEMASK, &stencil_state_.stencil_front_writemask);
glGetIntegerv(GL_STENCIL_BACK_WRITEMASK,
&stencil_state_.stencil_back_writemask);
glGetIntegerv(GL_STENCIL_FAIL, &stencil_state_.stencil_front_fail_op);
glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL,
&stencil_state_.stencil_front_z_fail_op);
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS,
&stencil_state_.stencil_front_z_pass_op);
glGetIntegerv(GL_STENCIL_BACK_FAIL, &stencil_state_.stencil_back_fail_op);
glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_FAIL,
&stencil_state_.stencil_back_z_fail_op);
glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS,
&stencil_state_.stencil_back_z_pass_op);
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebuffer_binding_ext_);
if (save_restore_) {
SaveHWUIState();
}
if (mode_ == ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT) {
// Android 5.0.0 specific qualcomm workaround. See crbug.com/434570.
glBindRenderbufferEXT(GL_RENDERBUFFER, 0);
}
DCHECK(ClearGLErrors(false, NULL));
}
void ScopedAppGLStateRestoreImpl::SaveHWUIState() {
if (!g_globals_initialized) { if (!g_globals_initialized) {
g_globals_initialized = true; g_globals_initialized = true;
...@@ -183,7 +226,7 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( ...@@ -183,7 +226,7 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl(
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vertex_array_buffer_binding_); glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vertex_array_buffer_binding_);
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &index_array_buffer_binding_); glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &index_array_buffer_binding_);
switch(mode_) { switch (mode_) {
case ScopedAppGLStateRestore::MODE_DRAW: case ScopedAppGLStateRestore::MODE_DRAW:
DCHECK_EQ(0, vertex_array_buffer_binding_); DCHECK_EQ(0, vertex_array_buffer_binding_);
DCHECK_EQ(0, index_array_buffer_binding_); DCHECK_EQ(0, index_array_buffer_binding_);
...@@ -229,30 +272,6 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( ...@@ -229,30 +272,6 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl(
glGetBooleanv(GL_SAMPLE_ALPHA_TO_COVERAGE, &enable_sample_alpha_to_coverage_); glGetBooleanv(GL_SAMPLE_ALPHA_TO_COVERAGE, &enable_sample_alpha_to_coverage_);
glGetBooleanv(GL_SAMPLE_COVERAGE, &enable_sample_coverage_); glGetBooleanv(GL_SAMPLE_COVERAGE, &enable_sample_coverage_);
glGetBooleanv(GL_STENCIL_TEST, &stencil_state_.stencil_test_enabled);
glGetIntegerv(GL_STENCIL_FUNC, &stencil_state_.stencil_front_func);
glGetIntegerv(GL_STENCIL_VALUE_MASK, &stencil_state_.stencil_front_mask);
glGetIntegerv(GL_STENCIL_REF, &stencil_state_.stencil_front_ref);
glGetIntegerv(GL_STENCIL_BACK_FUNC, &stencil_state_.stencil_back_func);
glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &stencil_state_.stencil_back_mask);
glGetIntegerv(GL_STENCIL_BACK_REF, &stencil_state_.stencil_back_ref);
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencil_state_.stencil_clear);
glGetIntegerv(GL_STENCIL_WRITEMASK, &stencil_state_.stencil_front_writemask);
glGetIntegerv(GL_STENCIL_BACK_WRITEMASK,
&stencil_state_.stencil_back_writemask);
glGetIntegerv(GL_STENCIL_FAIL, &stencil_state_.stencil_front_fail_op);
glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL,
&stencil_state_.stencil_front_z_fail_op);
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS,
&stencil_state_.stencil_front_z_pass_op);
glGetIntegerv(GL_STENCIL_BACK_FAIL, &stencil_state_.stencil_back_fail_op);
glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_FAIL,
&stencil_state_.stencil_back_z_fail_op);
glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS,
&stencil_state_.stencil_back_z_pass_op);
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebuffer_binding_ext_);
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_); glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_);
texture_bindings_.resize(g_gl_max_texture_units); texture_bindings_.resize(g_gl_max_texture_units);
...@@ -290,21 +309,21 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( ...@@ -290,21 +309,21 @@ ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl(
glGetVertexAttribfv( glGetVertexAttribfv(
i, GL_CURRENT_VERTEX_ATTRIB, vertex_attrib_[i].current_vertex_attrib); i, GL_CURRENT_VERTEX_ATTRIB, vertex_attrib_[i].current_vertex_attrib);
} }
if (mode_ == ScopedAppGLStateRestore::MODE_RESOURCE_MANAGEMENT) {
// Android 5.0.0 specific qualcomm workaround. See crbug.com/434570.
glBindRenderbufferEXT(GL_RENDERBUFFER, 0);
}
DCHECK(ClearGLErrors(false, NULL));
} }
ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() { ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() {
TRACE_EVENT0("android_webview", "AppGLStateRestore"); TRACE_EVENT0("android_webview", "AppGLStateRestore");
MakeAppContextCurrent(); MakeAppContextCurrent();
if (save_restore_) {
DCHECK(ClearGLErrors(false, NULL));
RestoreHWUIState();
}
DCHECK(ClearGLErrors(false, NULL)); // Do not leak GLError out of chromium.
ClearGLErrors(true, "Chromium GLError");
}
void ScopedAppGLStateRestoreImpl::RestoreHWUIState() {
glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding_ext_); glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding_ext_);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_);
...@@ -412,9 +431,6 @@ ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() { ...@@ -412,9 +431,6 @@ ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() {
glStencilOpSeparate(GL_BACK, stencil_state_.stencil_back_fail_op, glStencilOpSeparate(GL_BACK, stencil_state_.stencil_back_fail_op,
stencil_state_.stencil_back_z_fail_op, stencil_state_.stencil_back_z_fail_op,
stencil_state_.stencil_back_z_pass_op); stencil_state_.stencil_back_z_pass_op);
// Do not leak GLError out of chromium.
ClearGLErrors(true, "Chromium GLError");
} }
} // namespace internal } // namespace internal
...@@ -425,8 +441,9 @@ ScopedAppGLStateRestore* ScopedAppGLStateRestore::Current() { ...@@ -425,8 +441,9 @@ ScopedAppGLStateRestore* ScopedAppGLStateRestore::Current() {
return g_current_instance; return g_current_instance;
} }
ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode,
: impl_(new internal::ScopedAppGLStateRestoreImpl(mode)) { bool save_restore)
: impl_(new internal::ScopedAppGLStateRestoreImpl(mode, save_restore)) {
DCHECK(!g_current_instance); DCHECK(!g_current_instance);
g_current_instance = this; g_current_instance = this;
} }
......
...@@ -45,7 +45,7 @@ class ScopedAppGLStateRestore { ...@@ -45,7 +45,7 @@ class ScopedAppGLStateRestore {
static ScopedAppGLStateRestore* Current(); static ScopedAppGLStateRestore* Current();
explicit ScopedAppGLStateRestore(CallMode mode); ScopedAppGLStateRestore(CallMode mode, bool save_restore);
~ScopedAppGLStateRestore(); ~ScopedAppGLStateRestore();
StencilState stencil_state() const; StencilState stencil_state() const;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
extern "C" { extern "C" {
#endif #endif
// 1 is L/L MR1 // 1 is L/L MR1
// //
// 2 starts at M, and added an imperfect workaround for complex clipping by // 2 starts at M, and added an imperfect workaround for complex clipping by
...@@ -20,7 +19,12 @@ extern "C" { ...@@ -20,7 +19,12 @@ extern "C" {
// This is a temporary workaround for a lack of WebView support for stencil/ // This is a temporary workaround for a lack of WebView support for stencil/
// shader based round rect clipping, and should be removed when webview is // shader based round rect clipping, and should be removed when webview is
// capable of supporting these clips internally when drawing. // capable of supporting these clips internally when drawing.
static const int kAwDrawGLInfoVersion = 2; //
// 3 starts during development of P, when android defaults from HWUI to skia as
// the GL renderer. Skia already maintains and restores its GL state, so there
// is no need for WebView to restore this state. Skia also no longer promises
// GL state on entering draw, such as no vertex array buffer binding.
static const int kAwDrawGLInfoVersion = 3;
// Holds the information required to trigger an OpenGL drawing operation. // Holds the information required to trigger an OpenGL drawing operation.
struct AwDrawGLInfo { struct AwDrawGLInfo {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment