| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 bool g_globals_initialized = false; | 65 bool g_globals_initialized = false; |
| 66 GLint g_gl_max_texture_units = 0; | 66 GLint g_gl_max_texture_units = 0; |
| 67 bool g_supports_oes_vertex_array_object = false; | 67 bool g_supports_oes_vertex_array_object = false; |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 namespace internal { | 71 namespace internal { |
| 72 | 72 |
| 73 class ScopedAppGLStateRestoreImpl { | 73 class ScopedAppGLStateRestoreImpl { |
| 74 public: | 74 public: |
| 75 ScopedAppGLStateRestoreImpl(ScopedAppGLStateRestore::CallMode mode); | 75 explicit ScopedAppGLStateRestoreImpl(ScopedAppGLStateRestore::CallMode mode); |
| 76 ~ScopedAppGLStateRestoreImpl(); | 76 ~ScopedAppGLStateRestoreImpl(); |
| 77 | 77 |
| 78 bool stencil_enabled() const { return stencil_test_; } | 78 StencilState stencil_state() const { return stencil_state_; } |
| 79 GLint framebuffer_binding_ext() const { return framebuffer_binding_ext_; } | 79 GLint framebuffer_binding_ext() const { return framebuffer_binding_ext_; } |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 const ScopedAppGLStateRestore::CallMode mode_; | 82 const ScopedAppGLStateRestore::CallMode mode_; |
| 83 | 83 |
| 84 GLint pack_alignment_; | 84 GLint pack_alignment_; |
| 85 GLint unpack_alignment_; | 85 GLint unpack_alignment_; |
| 86 | 86 |
| 87 struct { | 87 struct { |
| 88 GLint enabled; | 88 GLint enabled; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 GLboolean blend_enabled_; | 128 GLboolean blend_enabled_; |
| 129 GLint blend_src_rgb_; | 129 GLint blend_src_rgb_; |
| 130 GLint blend_src_alpha_; | 130 GLint blend_src_alpha_; |
| 131 GLint blend_dest_rgb_; | 131 GLint blend_dest_rgb_; |
| 132 GLint blend_dest_alpha_; | 132 GLint blend_dest_alpha_; |
| 133 GLint active_texture_; | 133 GLint active_texture_; |
| 134 GLint viewport_[4]; | 134 GLint viewport_[4]; |
| 135 GLboolean scissor_test_; | 135 GLboolean scissor_test_; |
| 136 GLint scissor_box_[4]; | 136 GLint scissor_box_[4]; |
| 137 | 137 |
| 138 GLboolean stencil_test_; | 138 StencilState stencil_state_; |
| 139 GLint stencil_front_func_; | |
| 140 GLint stencil_front_ref_; | |
| 141 GLint stencil_front_mask_; | |
| 142 GLint stencil_back_func_; | |
| 143 GLint stencil_back_ref_; | |
| 144 GLint stencil_back_mask_; | |
| 145 GLint stencil_clear_; | |
| 146 GLint stencil_front_writemask_; | |
| 147 GLint stencil_back_writemask_; | |
| 148 GLint stencil_front_fail_op_; | |
| 149 GLint stencil_front_z_fail_op_; | |
| 150 GLint stencil_front_z_pass_op_; | |
| 151 GLint stencil_back_fail_op_; | |
| 152 GLint stencil_back_z_fail_op_; | |
| 153 GLint stencil_back_z_pass_op_; | |
| 154 | 139 |
| 155 GLint framebuffer_binding_ext_; | 140 GLint framebuffer_binding_ext_; |
| 156 | 141 |
| 157 struct TextureBindings { | 142 struct TextureBindings { |
| 158 GLint texture_2d; | 143 GLint texture_2d; |
| 159 GLint texture_cube_map; | 144 GLint texture_cube_map; |
| 160 GLint texture_external_oes; | 145 GLint texture_external_oes; |
| 161 // TODO(boliu): TEXTURE_RECTANGLE_ARB | 146 // TODO(boliu): TEXTURE_RECTANGLE_ARB |
| 162 }; | 147 }; |
| 163 | 148 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 glGetFloatv(GL_SAMPLE_COVERAGE_VALUE, &sample_coverage_value_); | 217 glGetFloatv(GL_SAMPLE_COVERAGE_VALUE, &sample_coverage_value_); |
| 233 glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT, &sample_coverage_invert_); | 218 glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT, &sample_coverage_invert_); |
| 234 glGetIntegerv(GL_BLEND_EQUATION_RGB, &blend_equation_rgb_); | 219 glGetIntegerv(GL_BLEND_EQUATION_RGB, &blend_equation_rgb_); |
| 235 glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blend_equation_alpha_); | 220 glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blend_equation_alpha_); |
| 236 | 221 |
| 237 glGetBooleanv(GL_DITHER, &enable_dither_); | 222 glGetBooleanv(GL_DITHER, &enable_dither_); |
| 238 glGetBooleanv(GL_POLYGON_OFFSET_FILL, &enable_polygon_offset_fill_); | 223 glGetBooleanv(GL_POLYGON_OFFSET_FILL, &enable_polygon_offset_fill_); |
| 239 glGetBooleanv(GL_SAMPLE_ALPHA_TO_COVERAGE, &enable_sample_alpha_to_coverage_); | 224 glGetBooleanv(GL_SAMPLE_ALPHA_TO_COVERAGE, &enable_sample_alpha_to_coverage_); |
| 240 glGetBooleanv(GL_SAMPLE_COVERAGE, &enable_sample_coverage_); | 225 glGetBooleanv(GL_SAMPLE_COVERAGE, &enable_sample_coverage_); |
| 241 | 226 |
| 242 glGetBooleanv(GL_STENCIL_TEST, &stencil_test_); | 227 glGetBooleanv(GL_STENCIL_TEST, &stencil_state_.stencil_test_enabled); |
| 243 glGetIntegerv(GL_STENCIL_FUNC, &stencil_front_func_); | 228 glGetIntegerv(GL_STENCIL_FUNC, &stencil_state_.stencil_front_func); |
| 244 glGetIntegerv(GL_STENCIL_VALUE_MASK, &stencil_front_mask_); | 229 glGetIntegerv(GL_STENCIL_VALUE_MASK, &stencil_state_.stencil_front_mask); |
| 245 glGetIntegerv(GL_STENCIL_REF, &stencil_front_ref_); | 230 glGetIntegerv(GL_STENCIL_REF, &stencil_state_.stencil_front_ref); |
| 246 glGetIntegerv(GL_STENCIL_BACK_FUNC, &stencil_back_func_); | 231 glGetIntegerv(GL_STENCIL_BACK_FUNC, &stencil_state_.stencil_back_func); |
| 247 glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &stencil_back_mask_); | 232 glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &stencil_state_.stencil_back_mask); |
| 248 glGetIntegerv(GL_STENCIL_BACK_REF, &stencil_back_ref_); | 233 glGetIntegerv(GL_STENCIL_BACK_REF, &stencil_state_.stencil_back_ref); |
| 249 glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencil_clear_); | 234 glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencil_state_.stencil_clear); |
| 250 glGetIntegerv(GL_STENCIL_WRITEMASK, &stencil_front_writemask_); | 235 glGetIntegerv(GL_STENCIL_WRITEMASK, &stencil_state_.stencil_front_writemask); |
| 251 glGetIntegerv(GL_STENCIL_BACK_WRITEMASK, &stencil_back_writemask_); | 236 glGetIntegerv(GL_STENCIL_BACK_WRITEMASK, |
| 252 glGetIntegerv(GL_STENCIL_FAIL, &stencil_front_fail_op_); | 237 &stencil_state_.stencil_back_writemask); |
| 253 glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &stencil_front_z_fail_op_); | 238 glGetIntegerv(GL_STENCIL_FAIL, &stencil_state_.stencil_front_fail_op); |
| 254 glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &stencil_front_z_pass_op_); | 239 glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, |
| 255 glGetIntegerv(GL_STENCIL_BACK_FAIL, &stencil_back_fail_op_); | 240 &stencil_state_.stencil_front_z_fail_op); |
| 256 glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_FAIL, &stencil_back_z_fail_op_); | 241 glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, |
| 257 glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS, &stencil_back_z_pass_op_); | 242 &stencil_state_.stencil_front_z_pass_op); |
| 243 glGetIntegerv(GL_STENCIL_BACK_FAIL, &stencil_state_.stencil_back_fail_op); |
| 244 glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_FAIL, |
| 245 &stencil_state_.stencil_back_z_fail_op); |
| 246 glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS, |
| 247 &stencil_state_.stencil_back_z_pass_op); |
| 258 | 248 |
| 259 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebuffer_binding_ext_); | 249 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebuffer_binding_ext_); |
| 260 | 250 |
| 261 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_); | 251 glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture_); |
| 262 | 252 |
| 263 texture_bindings_.resize(g_gl_max_texture_units); | 253 texture_bindings_.resize(g_gl_max_texture_units); |
| 264 for (int ii = 0; ii < g_gl_max_texture_units; ++ii) { | 254 for (int ii = 0; ii < g_gl_max_texture_units; ++ii) { |
| 265 glActiveTexture(GL_TEXTURE0 + ii); | 255 glActiveTexture(GL_TEXTURE0 + ii); |
| 266 TextureBindings& bindings = texture_bindings_[ii]; | 256 TextureBindings& bindings = texture_bindings_[ii]; |
| 267 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bindings.texture_2d); | 257 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bindings.texture_2d); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 385 |
| 396 glViewport(viewport_[0], viewport_[1], viewport_[2], viewport_[3]); | 386 glViewport(viewport_[0], viewport_[1], viewport_[2], viewport_[3]); |
| 397 | 387 |
| 398 GLEnableDisable(GL_SCISSOR_TEST, scissor_test_); | 388 GLEnableDisable(GL_SCISSOR_TEST, scissor_test_); |
| 399 | 389 |
| 400 glScissor( | 390 glScissor( |
| 401 scissor_box_[0], scissor_box_[1], scissor_box_[2], scissor_box_[3]); | 391 scissor_box_[0], scissor_box_[1], scissor_box_[2], scissor_box_[3]); |
| 402 break; | 392 break; |
| 403 } | 393 } |
| 404 | 394 |
| 405 GLEnableDisable(GL_STENCIL_TEST, stencil_test_); | 395 GLEnableDisable(GL_STENCIL_TEST, stencil_state_.stencil_test_enabled); |
| 406 glStencilFuncSeparate( | 396 glStencilFuncSeparate(GL_FRONT, stencil_state_.stencil_front_func, |
| 407 GL_FRONT, stencil_front_func_, stencil_front_mask_, stencil_front_ref_); | 397 stencil_state_.stencil_front_mask, |
| 408 glStencilFuncSeparate( | 398 stencil_state_.stencil_front_ref); |
| 409 GL_BACK, stencil_back_func_, stencil_back_mask_, stencil_back_ref_); | 399 glStencilFuncSeparate(GL_BACK, stencil_state_.stencil_back_func, |
| 410 glClearStencil(stencil_clear_); | 400 stencil_state_.stencil_back_mask, |
| 411 glStencilMaskSeparate(GL_FRONT, stencil_front_writemask_); | 401 stencil_state_.stencil_back_ref); |
| 412 glStencilMaskSeparate(GL_BACK, stencil_back_writemask_); | 402 glClearStencil(stencil_state_.stencil_clear); |
| 413 glStencilOpSeparate(GL_FRONT, | 403 glStencilMaskSeparate(GL_FRONT, stencil_state_.stencil_front_writemask); |
| 414 stencil_front_fail_op_, | 404 glStencilMaskSeparate(GL_BACK, stencil_state_.stencil_back_writemask); |
| 415 stencil_front_z_fail_op_, | 405 glStencilOpSeparate(GL_FRONT, stencil_state_.stencil_front_fail_op, |
| 416 stencil_front_z_pass_op_); | 406 stencil_state_.stencil_front_z_fail_op, |
| 417 glStencilOpSeparate(GL_BACK, | 407 stencil_state_.stencil_front_z_pass_op); |
| 418 stencil_back_fail_op_, | 408 glStencilOpSeparate(GL_BACK, stencil_state_.stencil_back_fail_op, |
| 419 stencil_back_z_fail_op_, | 409 stencil_state_.stencil_back_z_fail_op, |
| 420 stencil_back_z_pass_op_); | 410 stencil_state_.stencil_back_z_pass_op); |
| 421 | 411 |
| 422 // Do not leak GLError out of chromium. | 412 // Do not leak GLError out of chromium. |
| 423 ClearGLErrors(true, "Chromium GLError"); | 413 ClearGLErrors(true, "Chromium GLError"); |
| 424 } | 414 } |
| 425 | 415 |
| 426 } // namespace internal | 416 } // namespace internal |
| 427 | 417 |
| 428 ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) | 418 ScopedAppGLStateRestore::ScopedAppGLStateRestore(CallMode mode) |
| 429 : impl_(new internal::ScopedAppGLStateRestoreImpl(mode)) { | 419 : impl_(new internal::ScopedAppGLStateRestoreImpl(mode)) { |
| 430 } | 420 } |
| 431 | 421 |
| 432 ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {} | 422 ScopedAppGLStateRestore::~ScopedAppGLStateRestore() {} |
| 433 | 423 |
| 434 bool ScopedAppGLStateRestore::stencil_enabled() const { | 424 StencilState ScopedAppGLStateRestore::stencil_state() const { |
| 435 return impl_->stencil_enabled(); | 425 return impl_->stencil_state(); |
| 436 } | 426 } |
| 437 int ScopedAppGLStateRestore::framebuffer_binding_ext() const { | 427 int ScopedAppGLStateRestore::framebuffer_binding_ext() const { |
| 438 return impl_->framebuffer_binding_ext(); | 428 return impl_->framebuffer_binding_ext(); |
| 439 } | 429 } |
| 440 | 430 |
| 441 } // namespace android_webview | 431 } // namespace android_webview |
| OLD | NEW |