diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 23:40:06 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 23:40:06 +0000 |
commit | b5d4a2a0f2a3d3173f6361bcf0eba5673d23125b (patch) | |
tree | 6e29bb0de79100614f72e08ed730eee0be05dbb2 /android_webview | |
parent | 37ac95b451ae3cdddf327b9bfc3ba350b149b5ff (diff) | |
download | chromium_src-b5d4a2a0f2a3d3173f6361bcf0eba5673d23125b.zip chromium_src-b5d4a2a0f2a3d3173f6361bcf0eba5673d23125b.tar.gz chromium_src-b5d4a2a0f2a3d3173f6361bcf0eba5673d23125b.tar.bz2 |
[Android WebView] More App GL state save/restore
Restores state that matches ContextState::RestoreGlobalState
with some exceptions.
Also remove some unneeded states from MODE_DRAW.
BUG=
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/19787007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/browser/scoped_app_gl_state_restore.cc | 117 | ||||
-rw-r--r-- | android_webview/browser/scoped_app_gl_state_restore.h | 24 |
2 files changed, 99 insertions, 42 deletions
diff --git a/android_webview/browser/scoped_app_gl_state_restore.cc b/android_webview/browser/scoped_app_gl_state_restore.cc index 70e5075..4928464 100644 --- a/android_webview/browser/scoped_app_gl_state_restore.cc +++ b/android_webview/browser/scoped_app_gl_state_restore.cc @@ -4,6 +4,7 @@ #include "android_webview/browser/scoped_app_gl_state_restore.h" +#include "base/debug/trace_event.h" #include "base/lazy_instance.h" #include "ui/gl/gl_context.h" #include "ui/gl/gl_surface_stub.h" @@ -40,15 +41,23 @@ void MakeAppContextCurrent() { g_app_context_surface.Get().MakeCurrent(); } +void GLEnableDisable(GLenum cap, bool enable) { + if (enable) + glEnable(cap); + else + glDisable(cap); +} + } // namespace -ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) { +ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) : mode_(mode) { + TRACE_EVENT0("android_webview", "AppGLStateSave"); MakeAppContextCurrent(); glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vertex_array_buffer_binding_); glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &index_array_buffer_binding_); - switch(mode) { + switch(mode_) { case MODE_DRAW: // TODO(boliu): These should always be 0 in draw case. When we have // guarantee that we are no longer making GL calls outside of draw, DCHECK @@ -64,6 +73,15 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) { index_array_buffer_binding_ = 0; break; case MODE_DETACH_FROM_WINDOW: + glGetBooleanv(GL_BLEND, &blend_enabled_); + glGetIntegerv(GL_BLEND_SRC_RGB, &blend_src_rgb_); + glGetIntegerv(GL_BLEND_SRC_ALPHA, &blend_src_alpha_); + glGetIntegerv(GL_BLEND_DST_RGB, &blend_dest_rgb_); + glGetIntegerv(GL_BLEND_DST_ALPHA, &blend_dest_alpha_); + glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_); + glGetIntegerv(GL_VIEWPORT, viewport_); + glGetBooleanv(GL_SCISSOR_TEST, &scissor_test_); + glGetIntegerv(GL_SCISSOR_BOX, scissor_box_); break; } @@ -89,20 +107,32 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) { glGetBooleanv(GL_DEPTH_TEST, &depth_test_); glGetBooleanv(GL_CULL_FACE, &cull_face_); + glGetIntegerv(GL_CULL_FACE_MODE, &cull_face_mode_); glGetBooleanv(GL_COLOR_WRITEMASK, color_mask_); - glGetBooleanv(GL_BLEND, &blend_enabled_); - glGetIntegerv(GL_BLEND_SRC_RGB, &blend_src_rgb_); - glGetIntegerv(GL_BLEND_SRC_ALPHA, &blend_src_alpha_); - glGetIntegerv(GL_BLEND_DST_RGB, &blend_dest_rgb_); - glGetIntegerv(GL_BLEND_DST_ALPHA, &blend_dest_alpha_); - glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_); - glGetIntegerv(GL_VIEWPORT, viewport_); - glGetBooleanv(GL_SCISSOR_TEST, &scissor_test_); - glGetIntegerv(GL_SCISSOR_BOX, scissor_box_); glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_); + glGetFloatv(GL_COLOR_CLEAR_VALUE, color_clear_); + glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depth_clear_); + glGetIntegerv(GL_DEPTH_FUNC, &depth_func_); + glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_mask_); + glGetFloatv(GL_DEPTH_RANGE, depth_rage_); + glGetIntegerv(GL_FRONT_FACE, &front_face_); + glGetIntegerv(GL_GENERATE_MIPMAP_HINT, &hint_generate_mipmap_); + glGetFloatv(GL_LINE_WIDTH, &line_width_); + glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &polygon_offset_factor_); + glGetFloatv(GL_POLYGON_OFFSET_UNITS, &polygon_offset_units_); + glGetFloatv(GL_SAMPLE_COVERAGE_VALUE, &sample_coverage_value_); + glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT, &sample_coverage_invert_); + + glGetBooleanv(GL_DITHER, &enable_dither_); + glGetBooleanv(GL_POLYGON_OFFSET_FILL, &enable_polygon_offset_fill_); + glGetBooleanv(GL_SAMPLE_ALPHA_TO_COVERAGE, &enable_sample_alpha_to_coverage_); + glGetBooleanv(GL_SAMPLE_COVERAGE, &enable_sample_coverage_); + + // Intentionally not saving/restoring stencil related state. } ScopedAppGLStateRestore::~ScopedAppGLStateRestore() { + TRACE_EVENT0("android_webview", "AppGLStateRestore"); MakeAppContextCurrent(); glBindBuffer(GL_ARRAY_BUFFER, vertex_array_buffer_binding_); @@ -127,42 +157,47 @@ ScopedAppGLStateRestore::~ScopedAppGLStateRestore() { } } - if (depth_test_) { - glEnable(GL_DEPTH_TEST); - } else { - glDisable(GL_DEPTH_TEST); - } + GLEnableDisable(GL_DEPTH_TEST, depth_test_); - if (cull_face_) { - glEnable(GL_CULL_FACE); - } else { - glDisable(GL_CULL_FACE); - } + GLEnableDisable(GL_CULL_FACE, cull_face_); + glCullFace(cull_face_mode_); glColorMask(color_mask_[0], color_mask_[1], color_mask_[2], color_mask_[3]); - if (blend_enabled_) { - glEnable(GL_BLEND); - } else { - glDisable(GL_BLEND); - } - - glBlendFuncSeparate( - blend_src_rgb_, blend_dest_rgb_, blend_src_alpha_, blend_dest_alpha_); - glActiveTexture(active_texture_); - - glViewport(viewport_[0], viewport_[1], viewport_[2], viewport_[3]); + glUseProgram(current_program_); - if (scissor_test_) { - glEnable(GL_SCISSOR_TEST); - } else { - glDisable(GL_SCISSOR_TEST); + glClearColor( + color_clear_[0], color_clear_[1], color_clear_[2], color_clear_[3]); + glClearDepth(depth_clear_); + glDepthFunc(depth_func_); + glDepthMask(depth_mask_); + glDepthRange(depth_rage_[0], depth_rage_[1]); + glFrontFace(front_face_); + glHint(GL_GENERATE_MIPMAP_HINT, hint_generate_mipmap_); + // TODO(boliu): GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES ?? + glLineWidth(line_width_); + glPolygonOffset(polygon_offset_factor_, polygon_offset_units_); + glSampleCoverage(sample_coverage_value_, sample_coverage_invert_); + + GLEnableDisable(GL_DITHER, enable_dither_); + GLEnableDisable(GL_POLYGON_OFFSET_FILL, enable_polygon_offset_fill_); + GLEnableDisable(GL_SAMPLE_ALPHA_TO_COVERAGE, + enable_sample_alpha_to_coverage_); + GLEnableDisable(GL_SAMPLE_COVERAGE, enable_sample_coverage_); + + if (mode_ == MODE_DETACH_FROM_WINDOW) { + GLEnableDisable(GL_BLEND, blend_enabled_); + glBlendFuncSeparate( + blend_src_rgb_, blend_dest_rgb_, blend_src_alpha_, blend_dest_alpha_); + glActiveTexture(active_texture_); + + glViewport(viewport_[0], viewport_[1], viewport_[2], viewport_[3]); + + GLEnableDisable(GL_SCISSOR_TEST, scissor_test_); + + glScissor( + scissor_box_[0], scissor_box_[1], scissor_box_[2], scissor_box_[3]); } - - glScissor( - scissor_box_[0], scissor_box_[1], scissor_box_[2], scissor_box_[3]); - - glUseProgram(current_program_); } } // namespace android_webview diff --git a/android_webview/browser/scoped_app_gl_state_restore.h b/android_webview/browser/scoped_app_gl_state_restore.h index c8eb0ba..f856de8 100644 --- a/android_webview/browser/scoped_app_gl_state_restore.h +++ b/android_webview/browser/scoped_app_gl_state_restore.h @@ -23,6 +23,8 @@ class ScopedAppGLStateRestore { ~ScopedAppGLStateRestore(); private: + const CallMode mode_; + GLint texture_external_oes_binding_; GLint pack_alignment_; GLint unpack_alignment_; @@ -41,7 +43,28 @@ class ScopedAppGLStateRestore { GLboolean depth_test_; GLboolean cull_face_; + GLint cull_face_mode_; GLboolean color_mask_[4]; + GLfloat color_clear_[4]; + GLfloat depth_clear_; + GLint current_program_; + GLint depth_func_; + GLboolean depth_mask_; + GLfloat depth_rage_[2]; + GLint front_face_; + GLint hint_generate_mipmap_; + GLfloat line_width_; + GLfloat polygon_offset_factor_; + GLfloat polygon_offset_units_; + GLfloat sample_coverage_value_; + GLboolean sample_coverage_invert_; + + GLboolean enable_dither_; + GLboolean enable_polygon_offset_fill_; + GLboolean enable_sample_alpha_to_coverage_; + GLboolean enable_sample_coverage_; + + // Not saved/restored in MODE_DRAW. GLboolean blend_enabled_; GLint blend_src_rgb_; GLint blend_src_alpha_; @@ -51,7 +74,6 @@ class ScopedAppGLStateRestore { GLint viewport_[4]; GLboolean scissor_test_; GLint scissor_box_[4]; - GLint current_program_; DISALLOW_COPY_AND_ASSIGN(ScopedAppGLStateRestore); }; |