Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / context_state.h
blobb4e812c295c6becb5a29988c61d0631dc8b9123c
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
3 // found in the LICENSE file.
5 // This file contains the ContextState class.
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
8 #define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
10 #include <vector>
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "gpu/command_buffer/service/gl_utils.h"
14 #include "gpu/command_buffer/service/query_manager.h"
15 #include "gpu/command_buffer/service/texture_manager.h"
16 #include "gpu/command_buffer/service/valuebuffer_manager.h"
17 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
18 #include "gpu/command_buffer/service/vertex_array_manager.h"
19 #include "gpu/gpu_export.h"
21 namespace gpu {
22 namespace gles2 {
24 class Buffer;
25 class ErrorState;
26 class ErrorStateClient;
27 class FeatureInfo;
28 class Framebuffer;
29 class Program;
30 class Renderbuffer;
32 // State associated with each texture unit.
33 struct GPU_EXPORT TextureUnit {
34 TextureUnit();
35 ~TextureUnit();
37 // The last target that was bound to this texture unit.
38 GLenum bind_target;
40 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
41 scoped_refptr<TextureRef> bound_texture_2d;
43 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
44 // glBindTexture
45 scoped_refptr<TextureRef> bound_texture_cube_map;
47 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
48 // glBindTexture
49 scoped_refptr<TextureRef> bound_texture_external_oes;
51 // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
52 // glBindTexture
53 scoped_refptr<TextureRef> bound_texture_rectangle_arb;
55 scoped_refptr<TextureRef> GetInfoForSamplerType(
56 GLenum type) {
57 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
58 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
59 switch (type) {
60 case GL_SAMPLER_2D:
61 return bound_texture_2d;
62 case GL_SAMPLER_CUBE:
63 return bound_texture_cube_map;
64 case GL_SAMPLER_EXTERNAL_OES:
65 return bound_texture_external_oes;
66 case GL_SAMPLER_2D_RECT_ARB:
67 return bound_texture_rectangle_arb;
70 NOTREACHED();
71 return NULL;
74 void Unbind(TextureRef* texture) {
75 if (bound_texture_2d.get() == texture) {
76 bound_texture_2d = NULL;
78 if (bound_texture_cube_map.get() == texture) {
79 bound_texture_cube_map = NULL;
81 if (bound_texture_external_oes.get() == texture) {
82 bound_texture_external_oes = NULL;
87 struct Vec4 {
88 Vec4() {
89 v[0] = 0.0f;
90 v[1] = 0.0f;
91 v[2] = 0.0f;
92 v[3] = 1.0f;
94 float v[4];
97 struct GPU_EXPORT ContextState {
98 ContextState(FeatureInfo* feature_info,
99 ErrorStateClient* error_state_client,
100 Logger* logger);
101 ~ContextState();
103 void Initialize();
105 void SetIgnoreCachedStateForTest(bool ignore) {
106 ignore_cached_state = ignore;
109 void RestoreState(const ContextState* prev_state);
110 void InitCapabilities(const ContextState* prev_state) const;
111 void InitState(const ContextState* prev_state) const;
113 void RestoreActiveTexture() const;
114 void RestoreAllTextureUnitBindings(const ContextState* prev_state) const;
115 void RestoreActiveTextureUnitBinding(unsigned int target) const;
116 void RestoreVertexAttribValues() const;
117 void RestoreVertexAttribArrays(
118 const scoped_refptr<VertexAttribManager> attrib_manager) const;
119 void RestoreVertexAttribs() const;
120 void RestoreBufferBindings() const;
121 void RestoreGlobalState(const ContextState* prev_state) const;
122 void RestoreProgramBindings() const;
123 void RestoreRenderbufferBindings();
124 void RestoreTextureUnitBindings(
125 GLuint unit, const ContextState* prev_state) const;
127 // Helper for getting cached state.
128 bool GetStateAsGLint(
129 GLenum pname, GLint* params, GLsizei* num_written) const;
130 bool GetStateAsGLfloat(
131 GLenum pname, GLfloat* params, GLsizei* num_written) const;
132 bool GetEnabled(GLenum cap) const;
134 inline void SetDeviceColorMask(GLboolean red,
135 GLboolean green,
136 GLboolean blue,
137 GLboolean alpha) {
138 if (cached_color_mask_red == red && cached_color_mask_green == green &&
139 cached_color_mask_blue == blue && cached_color_mask_alpha == alpha &&
140 !ignore_cached_state)
141 return;
142 cached_color_mask_red = red;
143 cached_color_mask_green = green;
144 cached_color_mask_blue = blue;
145 cached_color_mask_alpha = alpha;
146 glColorMask(red, green, blue, alpha);
149 inline void SetDeviceDepthMask(GLboolean mask) {
150 if (cached_depth_mask == mask && !ignore_cached_state)
151 return;
152 cached_depth_mask = mask;
153 glDepthMask(mask);
156 inline void SetDeviceStencilMaskSeparate(GLenum op, GLuint mask) {
157 if (op == GL_FRONT) {
158 if (cached_stencil_front_writemask == mask && !ignore_cached_state)
159 return;
160 cached_stencil_front_writemask = mask;
161 } else if (op == GL_BACK) {
162 if (cached_stencil_back_writemask == mask && !ignore_cached_state)
163 return;
164 cached_stencil_back_writemask = mask;
165 } else {
166 NOTREACHED();
167 return;
169 glStencilMaskSeparate(op, mask);
172 ErrorState* GetErrorState();
174 #include "gpu/command_buffer/service/context_state_autogen.h"
176 EnableFlags enable_flags;
178 // Current active texture by 0 - n index.
179 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
180 // be 2.
181 GLuint active_texture_unit;
183 // The currently bound array buffer. If this is 0 it is illegal to call
184 // glVertexAttribPointer.
185 scoped_refptr<Buffer> bound_array_buffer;
187 // Which textures are bound to texture units through glActiveTexture.
188 std::vector<TextureUnit> texture_units;
190 // The values for each attrib.
191 std::vector<Vec4> attrib_values;
193 // Class that manages vertex attribs.
194 scoped_refptr<VertexAttribManager> vertex_attrib_manager;
195 scoped_refptr<VertexAttribManager> default_vertex_attrib_manager;
197 // The program in use by glUseProgram
198 scoped_refptr<Program> current_program;
200 // The currently bound renderbuffer
201 scoped_refptr<Renderbuffer> bound_renderbuffer;
202 bool bound_renderbuffer_valid;
204 // The currently bound valuebuffer
205 scoped_refptr<Valuebuffer> bound_valuebuffer;
207 // A map of of target -> Query for current queries
208 typedef std::map<GLuint, scoped_refptr<QueryManager::Query> > QueryMap;
209 QueryMap current_queries;
211 bool pack_reverse_row_order;
212 bool ignore_cached_state;
214 mutable bool fbo_binding_for_scissor_workaround_dirty_;
215 FeatureInfo* feature_info_;
217 private:
218 scoped_ptr<ErrorState> error_state_;
221 } // namespace gles2
222 } // namespace gpu
224 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_