OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 5 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 g_app_context_surface.Get().MakeCurrent(); | 44 g_app_context_surface.Get().MakeCurrent(); |
45 } | 45 } |
46 | 46 |
47 void GLEnableDisable(GLenum cap, bool enable) { | 47 void GLEnableDisable(GLenum cap, bool enable) { |
48 if (enable) | 48 if (enable) |
49 glEnable(cap); | 49 glEnable(cap); |
50 else | 50 else |
51 glDisable(cap); | 51 glDisable(cap); |
52 } | 52 } |
53 | 53 |
| 54 bool ClearGLErrors(bool warn, const char* msg) { |
| 55 bool no_error = true; |
| 56 GLenum error; |
| 57 while ((error = glGetError()) != GL_NO_ERROR) { |
| 58 DLOG_IF(WARNING, warn) << error << " " << msg; |
| 59 no_error = false; |
| 60 } |
| 61 |
| 62 return no_error; |
| 63 } |
| 64 |
54 bool g_globals_initialized = false; | 65 bool g_globals_initialized = false; |
55 GLint g_gl_max_texture_units = 0; | 66 GLint g_gl_max_texture_units = 0; |
56 bool g_supports_oes_vertex_array_object = false; | 67 bool g_supports_oes_vertex_array_object = false; |
57 | 68 |
58 } // namespace | 69 } // namespace |
59 | 70 |
60 namespace internal { | 71 namespace internal { |
61 | 72 |
62 class ScopedAppGLStateRestoreImpl { | 73 class ScopedAppGLStateRestoreImpl { |
63 public: | 74 public: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 152 |
142 DISALLOW_COPY_AND_ASSIGN(ScopedAppGLStateRestoreImpl); | 153 DISALLOW_COPY_AND_ASSIGN(ScopedAppGLStateRestoreImpl); |
143 }; | 154 }; |
144 | 155 |
145 ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( | 156 ScopedAppGLStateRestoreImpl::ScopedAppGLStateRestoreImpl( |
146 ScopedAppGLStateRestore::CallMode mode) | 157 ScopedAppGLStateRestore::CallMode mode) |
147 : mode_(mode) { | 158 : mode_(mode) { |
148 TRACE_EVENT0("android_webview", "AppGLStateSave"); | 159 TRACE_EVENT0("android_webview", "AppGLStateSave"); |
149 MakeAppContextCurrent(); | 160 MakeAppContextCurrent(); |
150 | 161 |
| 162 ClearGLErrors(true, "Incoming GLError"); |
| 163 |
151 if (!g_globals_initialized) { | 164 if (!g_globals_initialized) { |
152 g_globals_initialized = true; | 165 g_globals_initialized = true; |
153 | 166 |
154 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &g_gl_max_texture_units); | 167 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &g_gl_max_texture_units); |
155 DCHECK_GT(g_gl_max_texture_units, 0); | 168 DCHECK_GT(g_gl_max_texture_units, 0); |
156 | 169 |
157 std::string extensions( | 170 std::string extensions( |
158 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); | 171 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); |
159 g_supports_oes_vertex_array_object = | 172 g_supports_oes_vertex_array_object = |
160 extensions.find("GL_OES_vertex_array_object") != std::string::npos; | 173 extensions.find("GL_OES_vertex_array_object") != std::string::npos; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 glGetVertexAttribPointerv( | 257 glGetVertexAttribPointerv( |
245 i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer); | 258 i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer); |
246 glGetVertexAttribPointerv( | 259 glGetVertexAttribPointerv( |
247 i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer); | 260 i, GL_VERTEX_ATTRIB_ARRAY_POINTER, &vertex_attrib_[i].pointer); |
248 glGetVertexAttribiv(i, | 261 glGetVertexAttribiv(i, |
249 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, | 262 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, |
250 &vertex_attrib_[i].vertex_attrib_array_buffer_binding); | 263 &vertex_attrib_[i].vertex_attrib_array_buffer_binding); |
251 glGetVertexAttribfv( | 264 glGetVertexAttribfv( |
252 i, GL_CURRENT_VERTEX_ATTRIB, vertex_attrib_[i].current_vertex_attrib); | 265 i, GL_CURRENT_VERTEX_ATTRIB, vertex_attrib_[i].current_vertex_attrib); |
253 } | 266 } |
| 267 DCHECK(ClearGLErrors(false, NULL)); |
254 } | 268 } |
255 | 269 |
256 ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() { | 270 ScopedAppGLStateRestoreImpl::~ScopedAppGLStateRestoreImpl() { |
257 TRACE_EVENT0("android_webview", "AppGLStateRestore"); | 271 TRACE_EVENT0("android_webview", "AppGLStateRestore"); |
258 MakeAppContextCurrent(); | 272 MakeAppContextCurrent(); |
259 | 273 |
| 274 DCHECK(ClearGLErrors(false, NULL)); |
| 275 |
260 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding_ext_); | 276 glBindFramebufferEXT(GL_FRAMEBUFFER, framebuffer_binding_ext_); |
261 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_); | 277 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_buffer_binding_); |
262 | 278 |
263 if (g_supports_oes_vertex_array_object) | 279 if (g_supports_oes_vertex_array_object) |
264 glBindVertexArrayOES(0); | 280 glBindVertexArrayOES(0); |
265 | 281 |
266 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) { | 282 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(vertex_attrib_); ++i) { |
267 glBindBuffer(GL_ARRAY_BUFFER, | 283 glBindBuffer(GL_ARRAY_BUFFER, |
268 vertex_attrib_[i].vertex_attrib_array_buffer_binding); | 284 vertex_attrib_[i].vertex_attrib_array_buffer_binding); |
269 glVertexAttribPointer(i, | 285 glVertexAttribPointer(i, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 356 |
341 GLEnableDisable(GL_SCISSOR_TEST, scissor_test_); | 357 GLEnableDisable(GL_SCISSOR_TEST, scissor_test_); |
342 | 358 |
343 glScissor( | 359 glScissor( |
344 scissor_box_[0], scissor_box_[1], scissor_box_[2], scissor_box_[3]); | 360 scissor_box_[0], scissor_box_[1], scissor_box_[2], scissor_box_[3]); |
345 break; | 361 break; |
346 } | 362 } |
347 | 363 |
348 GLEnableDisable(GL_STENCIL_TEST, stencil_test_); | 364 GLEnableDisable(GL_STENCIL_TEST, stencil_test_); |
349 glStencilFunc(stencil_func_, stencil_mask_, stencil_ref_); | 365 glStencilFunc(stencil_func_, stencil_mask_, stencil_ref_); |
| 366 |
| 367 // Do not leak GLError out of chromium. |
| 368 ClearGLErrors(true, "Chromium GLError"); |
350 } | 369 } |
351 | 370 |
352 } // namespace internal | 371 } // namespace internal |
353 | 372 |
354 ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) | 373 ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) |
355 : impl_(new internal::ScopedAppGLStateRestoreImpl(mode)) { | 374 : impl_(new internal::ScopedAppGLStateRestoreImpl(mode)) { |
356 } | 375 } |
357 | 376 |
358 ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {} | 377 ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {} |
359 | 378 |
360 bool ScopedAppGLStateRestore::stencil_enabled() const { | 379 bool ScopedAppGLStateRestore::stencil_enabled() const { |
361 return impl_->stencil_enabled(); | 380 return impl_->stencil_enabled(); |
362 } | 381 } |
363 int ScopedAppGLStateRestore::framebuffer_binding_ext() const { | 382 int ScopedAppGLStateRestore::framebuffer_binding_ext() const { |
364 return impl_->framebuffer_binding_ext(); | 383 return impl_->framebuffer_binding_ext(); |
365 } | 384 } |
366 | 385 |
367 } // namespace android_webview | 386 } // namespace android_webview |
OLD | NEW |