Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 5 | #include <vector> |
| 6 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 7 | #include "base/basictypes.h" |
| 8 | #include "ui/gl/gl_bindings.h" |
| 9 | |
| 10 | namespace gfx { |
| 11 | class GLContext; |
| 12 | } |
| 13 | |
| 14 | namespace android_webview { |
| 15 | |
| 16 | // This class is not thread safe and should only be used on the UI thread. |
| 17 | class ScopedAppGLStateRestore { |
| 18 | public: |
Ben Murdoch | 9ab5563 | 2013-07-18 11:57:30 +0100 | [diff] [blame] | 19 | enum CallMode { |
| 20 | MODE_DRAW, |
| 21 | MODE_DETACH_FROM_WINDOW |
| 22 | }; |
| 23 | |
| 24 | ScopedAppGLStateRestore(CallMode mode); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 25 | ~ScopedAppGLStateRestore(); |
| 26 | |
Ben Murdoch | fb25065 | 2013-07-31 11:42:55 +0100 | [diff] [blame] | 27 | bool stencil_enabled() const { return stencil_test_; } |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 28 | GLint framebuffer_binding_ext() const { return framebuffer_binding_ext_; } |
Ben Murdoch | fb25065 | 2013-07-31 11:42:55 +0100 | [diff] [blame] | 29 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 30 | private: |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 31 | const CallMode mode_; |
| 32 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 33 | GLint pack_alignment_; |
| 34 | GLint unpack_alignment_; |
| 35 | |
| 36 | struct { |
| 37 | GLint enabled; |
| 38 | GLint size; |
| 39 | GLint type; |
| 40 | GLint normalized; |
| 41 | GLint stride; |
| 42 | GLvoid* pointer; |
| 43 | } vertex_attrib_[3]; |
| 44 | |
| 45 | GLint vertex_array_buffer_binding_; |
| 46 | GLint index_array_buffer_binding_; |
| 47 | |
| 48 | GLboolean depth_test_; |
| 49 | GLboolean cull_face_; |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 50 | GLint cull_face_mode_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 51 | GLboolean color_mask_[4]; |
Ben Murdoch | a3f7b4e | 2013-07-24 10:36:34 +0100 | [diff] [blame] | 52 | GLfloat color_clear_[4]; |
| 53 | GLfloat depth_clear_; |
| 54 | GLint current_program_; |
| 55 | GLint depth_func_; |
| 56 | GLboolean depth_mask_; |
| 57 | GLfloat depth_rage_[2]; |
| 58 | GLint front_face_; |
| 59 | GLint hint_generate_mipmap_; |
| 60 | GLfloat line_width_; |
| 61 | GLfloat polygon_offset_factor_; |
| 62 | GLfloat polygon_offset_units_; |
| 63 | GLfloat sample_coverage_value_; |
| 64 | GLboolean sample_coverage_invert_; |
| 65 | |
| 66 | GLboolean enable_dither_; |
| 67 | GLboolean enable_polygon_offset_fill_; |
| 68 | GLboolean enable_sample_alpha_to_coverage_; |
| 69 | GLboolean enable_sample_coverage_; |
| 70 | |
| 71 | // Not saved/restored in MODE_DRAW. |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 72 | GLboolean blend_enabled_; |
| 73 | GLint blend_src_rgb_; |
| 74 | GLint blend_src_alpha_; |
| 75 | GLint blend_dest_rgb_; |
| 76 | GLint blend_dest_alpha_; |
| 77 | GLint active_texture_; |
| 78 | GLint viewport_[4]; |
| 79 | GLboolean scissor_test_; |
| 80 | GLint scissor_box_[4]; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 81 | |
Ben Murdoch | fb25065 | 2013-07-31 11:42:55 +0100 | [diff] [blame] | 82 | GLboolean stencil_test_; |
| 83 | GLint stencil_func_; |
| 84 | GLint stencil_mask_; |
| 85 | GLint stencil_ref_; |
| 86 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 87 | GLint framebuffer_binding_ext_; |
| 88 | |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame] | 89 | struct TextureBindings { |
| 90 | GLint texture_2d; |
| 91 | GLint texture_cube_map; |
| 92 | GLint texture_external_oes; |
| 93 | // TODO(boliu): TEXTURE_RECTANGLE_ARB |
| 94 | }; |
| 95 | |
| 96 | std::vector<TextureBindings> texture_bindings_; |
| 97 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 98 | DISALLOW_COPY_AND_ASSIGN(ScopedAppGLStateRestore); |
| 99 | }; |
| 100 | |
| 101 | } // namespace android_webview |