OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains the ContextState class. | 5 // This file contains the ContextState class. |
6 | 6 |
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ | 7 #ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
8 #define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ | 8 #define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 }; | 94 }; |
95 | 95 |
96 struct GPU_EXPORT ContextState { | 96 struct GPU_EXPORT ContextState { |
97 ContextState(FeatureInfo* feature_info, | 97 ContextState(FeatureInfo* feature_info, |
98 ErrorStateClient* error_state_client, | 98 ErrorStateClient* error_state_client, |
99 Logger* logger); | 99 Logger* logger); |
100 ~ContextState(); | 100 ~ContextState(); |
101 | 101 |
102 void Initialize(); | 102 void Initialize(); |
103 | 103 |
104 void SetIgnoreCachedStateForTest(bool ignore) { | |
105 ignore_cached_state = ignore; | |
106 } | |
107 | |
108 void RestoreState(const ContextState* prev_state) const; | 104 void RestoreState(const ContextState* prev_state) const; |
109 void InitCapabilities(const ContextState* prev_state) const; | 105 void InitCapabilities(const ContextState* prev_state) const; |
110 void InitState(const ContextState* prev_state) const; | 106 void InitState(const ContextState* prev_state) const; |
111 | 107 |
112 void RestoreActiveTexture() const; | 108 void RestoreActiveTexture() const; |
113 void RestoreAllTextureUnitBindings(const ContextState* prev_state) const; | 109 void RestoreAllTextureUnitBindings(const ContextState* prev_state) const; |
114 void RestoreActiveTextureUnitBinding(unsigned int target) const; | 110 void RestoreActiveTextureUnitBinding(unsigned int target) const; |
115 void RestoreVertexAttribValues() const; | 111 void RestoreVertexAttribValues() const; |
116 void RestoreVertexAttribArrays( | 112 void RestoreVertexAttribArrays( |
117 const scoped_refptr<VertexAttribManager> attrib_manager) const; | 113 const scoped_refptr<VertexAttribManager> attrib_manager) const; |
118 void RestoreVertexAttribs() const; | 114 void RestoreVertexAttribs() const; |
119 void RestoreBufferBindings() const; | 115 void RestoreBufferBindings() const; |
120 void RestoreGlobalState(const ContextState* prev_state) const; | 116 void RestoreGlobalState(const ContextState* prev_state) const; |
121 void RestoreProgramBindings() const; | 117 void RestoreProgramBindings() const; |
122 void RestoreRenderbufferBindings() const; | 118 void RestoreRenderbufferBindings() const; |
123 void RestoreTextureUnitBindings( | 119 void RestoreTextureUnitBindings( |
124 GLuint unit, const ContextState* prev_state) const; | 120 GLuint unit, const ContextState* prev_state) const; |
125 | 121 |
126 // Helper for getting cached state. | 122 // Helper for getting cached state. |
127 bool GetStateAsGLint( | 123 bool GetStateAsGLint( |
128 GLenum pname, GLint* params, GLsizei* num_written) const; | 124 GLenum pname, GLint* params, GLsizei* num_written) const; |
129 bool GetStateAsGLfloat( | 125 bool GetStateAsGLfloat( |
130 GLenum pname, GLfloat* params, GLsizei* num_written) const; | 126 GLenum pname, GLfloat* params, GLsizei* num_written) const; |
131 bool GetEnabled(GLenum cap) const; | 127 bool GetEnabled(GLenum cap) const; |
132 | 128 |
133 inline void SetDeviceColorMask(GLboolean red, | |
134 GLboolean green, | |
135 GLboolean blue, | |
136 GLboolean alpha) { | |
137 if (cached_color_mask_red == red && cached_color_mask_green == green && | |
138 cached_color_mask_blue == blue && cached_color_mask_alpha == alpha && | |
139 !ignore_cached_state) | |
140 return; | |
141 cached_color_mask_red = red; | |
142 cached_color_mask_green = green; | |
143 cached_color_mask_blue = blue; | |
144 cached_color_mask_alpha = alpha; | |
145 glColorMask(red, green, blue, alpha); | |
146 } | |
147 | |
148 inline void SetDeviceDepthMask(GLboolean mask) { | |
149 if (cached_depth_mask == mask && !ignore_cached_state) | |
150 return; | |
151 cached_depth_mask = mask; | |
152 glDepthMask(mask); | |
153 } | |
154 | |
155 inline void SetDeviceStencilMaskSeparate(GLenum op, GLuint mask) { | |
156 if (op == GL_FRONT) { | |
157 if (cached_stencil_front_writemask == mask && !ignore_cached_state) | |
158 return; | |
159 cached_stencil_front_writemask = mask; | |
160 } else if (op == GL_BACK) { | |
161 if (cached_stencil_back_writemask == mask && !ignore_cached_state) | |
162 return; | |
163 cached_stencil_back_writemask = mask; | |
164 } else { | |
165 NOTREACHED(); | |
166 return; | |
167 } | |
168 glStencilMaskSeparate(op, mask); | |
169 } | |
170 | |
171 ErrorState* GetErrorState(); | 129 ErrorState* GetErrorState(); |
172 | 130 |
173 #include "gpu/command_buffer/service/context_state_autogen.h" | 131 #include "gpu/command_buffer/service/context_state_autogen.h" |
174 | 132 |
175 EnableFlags enable_flags; | 133 EnableFlags enable_flags; |
176 | 134 |
177 // Current active texture by 0 - n index. | 135 // Current active texture by 0 - n index. |
178 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would | 136 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would |
179 // be 2. | 137 // be 2. |
180 GLuint active_texture_unit; | 138 GLuint active_texture_unit; |
(...skipping 16 matching lines...) Expand all Loading... |
197 scoped_refptr<Program> current_program; | 155 scoped_refptr<Program> current_program; |
198 | 156 |
199 // The currently bound renderbuffer | 157 // The currently bound renderbuffer |
200 scoped_refptr<Renderbuffer> bound_renderbuffer; | 158 scoped_refptr<Renderbuffer> bound_renderbuffer; |
201 | 159 |
202 // A map of of target -> Query for current queries | 160 // A map of of target -> Query for current queries |
203 typedef std::map<GLuint, scoped_refptr<QueryManager::Query> > QueryMap; | 161 typedef std::map<GLuint, scoped_refptr<QueryManager::Query> > QueryMap; |
204 QueryMap current_queries; | 162 QueryMap current_queries; |
205 | 163 |
206 bool pack_reverse_row_order; | 164 bool pack_reverse_row_order; |
207 bool ignore_cached_state; | |
208 | 165 |
209 mutable bool fbo_binding_for_scissor_workaround_dirty_; | 166 mutable bool fbo_binding_for_scissor_workaround_dirty_; |
210 FeatureInfo* feature_info_; | 167 FeatureInfo* feature_info_; |
211 | 168 |
212 private: | 169 private: |
213 scoped_ptr<ErrorState> error_state_; | 170 scoped_ptr<ErrorState> error_state_; |
214 }; | 171 }; |
215 | 172 |
216 } // namespace gles2 | 173 } // namespace gles2 |
217 } // namespace gpu | 174 } // namespace gpu |
218 | 175 |
219 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ | 176 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
220 | 177 |
OLD | NEW |