summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authorboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 00:40:02 +0000
committerboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-01 00:40:02 +0000
commit819d8e0cf9dd0a5522021c91aef0e34519a17925 (patch)
treecbe3e1655803e5de76e35307de8e60b1e0882a3b /android_webview
parent21c88ef2167cb7f48c04b5ce4b9050c337bd61aa (diff)
downloadchromium_src-819d8e0cf9dd0a5522021c91aef0e34519a17925.zip
chromium_src-819d8e0cf9dd0a5522021c91aef0e34519a17925.tar.gz
chromium_src-819d8e0cf9dd0a5522021c91aef0e34519a17925.tar.bz2
aw: Restore VertexArrayOES binding correctly
Correctly restore the VAO binding of app. Make sure vertex attrib is restored into default (0) VAO. Also restore vertex attribute vector. BUG= NOTRY=true Review URL: https://codereview.chromium.org/255333002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267397 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/browser/scoped_app_gl_state_restore.cc105
-rw-r--r--android_webview/browser/scoped_app_gl_state_restore.h2
2 files changed, 63 insertions, 44 deletions
diff --git a/android_webview/browser/scoped_app_gl_state_restore.cc b/android_webview/browser/scoped_app_gl_state_restore.cc
index 059ce67..f7987da 100644
--- a/android_webview/browser/scoped_app_gl_state_restore.cc
+++ b/android_webview/browser/scoped_app_gl_state_restore.cc
@@ -52,7 +52,7 @@ void GLEnableDisable(GLenum cap, bool enable) {
bool g_globals_initialized = false;
GLint g_gl_max_texture_units = 0;
-bool g_oes_vertex_array_object = false;
+bool g_supports_oes_vertex_array_object = false;
} // namespace
@@ -60,6 +60,18 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) : mode_(mode) {
TRACE_EVENT0("android_webview", "AppGLStateSave");
MakeAppContextCurrent();
+ if (!g_globals_initialized) {
+ g_globals_initialized = true;
+
+ glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &g_gl_max_texture_units);
+ DCHECK_GT(g_gl_max_texture_units, 0);
+
+ std::string extensions(
+ reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
+ g_supports_oes_vertex_array_object =
+ extensions.find("GL_OES_vertex_array_object") != std::string::npos;
+ }
+
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &vertex_array_buffer_binding_);
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &index_array_buffer_binding_);
@@ -83,21 +95,6 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) : mode_(mode) {
glGetIntegerv(GL_PACK_ALIGNMENT, &pack_alignment_);
glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment_);
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) {
- glGetVertexAttribiv(
- i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &vertex_attrib_[i].enabled);
- glGetVertexAttribiv(
- i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &vertex_attrib_[i].size);
- glGetVertexAttribiv(
- i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &vertex_attrib_[i].type);
- glGetVertexAttribiv(
- i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &vertex_attrib_[i].normalized);
- glGetVertexAttribiv(
- i, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &vertex_attrib_[i].stride);
- glGetVertexAttribPointerv(
- i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer);
- }
-
glGetBooleanv(GL_DEPTH_TEST, &depth_test_);
glGetBooleanv(GL_CULL_FACE, &cull_face_);
glGetIntegerv(GL_CULL_FACE_MODE, &cull_face_mode_);
@@ -128,18 +125,6 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) : mode_(mode) {
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebuffer_binding_ext_);
- if (!g_globals_initialized) {
- g_globals_initialized = true;
-
- glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &g_gl_max_texture_units);
- DCHECK_GT(g_gl_max_texture_units, 0);
-
- std::string extensions(
- reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
- g_oes_vertex_array_object =
- extensions.find("GL_OES_vertex_array_object") != std::string::npos;
- }
-
glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_);
texture_bindings_.resize(g_gl_max_texture_units);
@@ -152,8 +137,32 @@ ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) : mode_(mode) {
&bindings.texture_external_oes);
}
- if (g_oes_vertex_array_object)
+ if (g_supports_oes_vertex_array_object) {
glGetIntegerv(GL_VERTEX_ARRAY_BINDING_OES, &vertex_array_bindings_oes_);
+ glBindVertexArrayOES(0);
+ }
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) {
+ glGetVertexAttribiv(
+ i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &vertex_attrib_[i].enabled);
+ glGetVertexAttribiv(
+ i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &vertex_attrib_[i].size);
+ glGetVertexAttribiv(
+ i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &vertex_attrib_[i].type);
+ glGetVertexAttribiv(
+ i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &vertex_attrib_[i].normalized);
+ glGetVertexAttribiv(
+ i, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &vertex_attrib_[i].stride);
+ glGetVertexAttribPointerv(
+ i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer);
+ glGetVertexAttribPointerv(
+ i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer);
+ glGetVertexAttribiv(i,
+ GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING,
+ &vertex_attrib_[i].vertex_attrib_array_buffer_binding);
+ glGetVertexAttribfv(
+ i, GL_CURRENT_VERTEX_ATTRIB, vertex_attrib_[i].current_vertex_attrib);
+ }
}
ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
@@ -161,22 +170,14 @@ ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
MakeAppContextCurrent();
glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding_ext_);
- glBindBuffer(GL_ARRAY_BUFFER, vertex_array_buffer_binding_);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_);
- for (int ii = 0; ii < g_gl_max_texture_units; ++ii) {
- glActiveTexture(GL_TEXTURE0 + ii);
- TextureBindings& bindings = texture_bindings_[ii];
- glBindTexture(GL_TEXTURE_2D, bindings.texture_2d);
- glBindTexture(GL_TEXTURE_CUBE_MAP, bindings.texture_cube_map);
- glBindTexture(GL_TEXTURE_EXTERNAL_OES, bindings.texture_external_oes);
- }
- glActiveTexture(active_texture_);
-
- glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment_);
- glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment_);
+ if (g_supports_oes_vertex_array_object)
+ glBindVertexArrayOES(0);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) {
+ glBindBuffer(GL_ARRAY_BUFFER,
+ vertex_attrib_[i].vertex_attrib_array_buffer_binding);
glVertexAttribPointer(i,
vertex_attrib_[i].size,
vertex_attrib_[i].type,
@@ -184,6 +185,8 @@ ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
vertex_attrib_[i].stride,
vertex_attrib_[i].pointer);
+ glVertexAttrib4fv(i, vertex_attrib_[i].current_vertex_attrib);
+
if (vertex_attrib_[i].enabled) {
glEnableVertexAttribArray(i);
} else {
@@ -191,6 +194,23 @@ ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
}
}
+ if (g_supports_oes_vertex_array_object && vertex_array_bindings_oes_ != 0)
+ glBindVertexArrayOES(vertex_array_bindings_oes_);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vertex_array_buffer_binding_);
+
+ for (int ii = 0; ii < g_gl_max_texture_units; ++ii) {
+ glActiveTexture(GL_TEXTURE0 + ii);
+ TextureBindings& bindings = texture_bindings_[ii];
+ glBindTexture(GL_TEXTURE_2D, bindings.texture_2d);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, bindings.texture_cube_map);
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, bindings.texture_external_oes);
+ }
+ glActiveTexture(active_texture_);
+
+ glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment_);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment_);
+
GLEnableDisable(GL_DEPTH_TEST, depth_test_);
GLEnableDisable(GL_CULL_FACE, cull_face_);
@@ -239,9 +259,6 @@ ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {
GLEnableDisable(GL_STENCIL_TEST, stencil_test_);
glStencilFunc(stencil_func_, stencil_mask_, stencil_ref_);
-
- if (g_oes_vertex_array_object)
- glBindVertexArrayOES(vertex_array_bindings_oes_);
}
} // 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 d28c9a5..299d43b 100644
--- a/android_webview/browser/scoped_app_gl_state_restore.h
+++ b/android_webview/browser/scoped_app_gl_state_restore.h
@@ -40,6 +40,8 @@ class ScopedAppGLStateRestore {
GLint normalized;
GLint stride;
GLvoid* pointer;
+ GLint vertex_attrib_array_buffer_binding;
+ GLfloat current_vertex_attrib[4];
} vertex_attrib_[3];
GLint vertex_array_buffer_binding_;