Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest_context_state.cc

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" 9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 (tt == non_default_unit) 92 (tt == non_default_unit)
93 ? group().texture_manager()->GetTexture(client_texture_id_) 93 ? group().texture_manager()->GetTexture(client_texture_id_)
94 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); 94 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
95 state->texture_units[tt].bound_texture_2d = ref_2d; 95 state->texture_units[tt].bound_texture_2d = ref_2d;
96 } 96 }
97 state->active_texture_unit = active_unit; 97 state->active_texture_unit = active_unit;
98 } 98 }
99 99
100 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) { 100 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) {
101 InitState init; 101 InitState init;
102 init.gl_version = "3.0";
103 init.bind_generates_resource = true; 102 init.bind_generates_resource = true;
104 InitDecoder(init); 103 InitDecoder(init);
105 SetupTexture(); 104 SetupTexture();
106 105
107 InSequence sequence; 106 InSequence sequence;
108 // Expect to restore texture bindings for unit GL_TEXTURE0. 107 // Expect to restore texture bindings for unit GL_TEXTURE0.
109 AddExpectationsForActiveTexture(GL_TEXTURE0); 108 AddExpectationsForActiveTexture(GL_TEXTURE0);
110 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 109 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
111 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 110 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
112 TestHelper::kServiceDefaultTextureCubemapId); 111 TestHelper::kServiceDefaultTextureCubemapId);
113 112
114 // Expect to restore texture bindings for remaining units. 113 // Expect to restore texture bindings for remaining units.
115 for (uint32 i = 1; i < group().max_texture_units(); ++i) { 114 for (uint32 i = 1; i < group().max_texture_units(); ++i) {
116 AddExpectationsForActiveTexture(GL_TEXTURE0 + i); 115 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
117 AddExpectationsForBindTexture(GL_TEXTURE_2D, 116 AddExpectationsForBindTexture(GL_TEXTURE_2D,
118 TestHelper::kServiceDefaultTexture2dId); 117 TestHelper::kServiceDefaultTexture2dId);
119 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 118 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
120 TestHelper::kServiceDefaultTextureCubemapId); 119 TestHelper::kServiceDefaultTextureCubemapId);
121 } 120 }
122 121
123 // Expect to restore the active texture unit to GL_TEXTURE0. 122 // Expect to restore the active texture unit to GL_TEXTURE0.
124 AddExpectationsForActiveTexture(GL_TEXTURE0); 123 AddExpectationsForActiveTexture(GL_TEXTURE0);
125 124
126 GetDecoder()->RestoreAllTextureUnitBindings(NULL); 125 GetDecoder()->RestoreAllTextureUnitBindings(NULL);
127 } 126 }
128 127
129 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) { 128 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) {
130 InitState init; 129 InitState init;
131 init.gl_version = "3.0";
132 InitDecoder(init); 130 InitDecoder(init);
133 SetupTexture(); 131 SetupTexture();
134 132
135 InSequence sequence; 133 InSequence sequence;
136 // Expect to restore texture bindings for unit GL_TEXTURE0. 134 // Expect to restore texture bindings for unit GL_TEXTURE0.
137 AddExpectationsForActiveTexture(GL_TEXTURE0); 135 AddExpectationsForActiveTexture(GL_TEXTURE0);
138 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 136 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
139 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0); 137 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
140 138
141 // Expect to restore texture bindings for remaining units. 139 // Expect to restore texture bindings for remaining units.
142 for (uint32 i = 1; i < group().max_texture_units(); ++i) { 140 for (uint32 i = 1; i < group().max_texture_units(); ++i) {
143 AddExpectationsForActiveTexture(GL_TEXTURE0 + i); 141 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
144 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 142 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
145 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0); 143 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
146 } 144 }
147 145
148 // Expect to restore the active texture unit to GL_TEXTURE0. 146 // Expect to restore the active texture unit to GL_TEXTURE0.
149 AddExpectationsForActiveTexture(GL_TEXTURE0); 147 AddExpectationsForActiveTexture(GL_TEXTURE0);
150 148
151 GetDecoder()->RestoreAllTextureUnitBindings(NULL); 149 GetDecoder()->RestoreAllTextureUnitBindings(NULL);
152 } 150 }
153 151
154 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) { 152 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) {
155 InitState init; 153 InitState init;
156 init.gl_version = "3.0";
157 init.bind_generates_resource = true; 154 init.bind_generates_resource = true;
158 InitDecoder(init); 155 InitDecoder(init);
159 SetupTexture(); 156 SetupTexture();
160 157
161 // Construct a previous ContextState with all texture bindings 158 // Construct a previous ContextState with all texture bindings
162 // set to default textures. 159 // set to default textures.
163 ContextState prev_state(NULL, NULL, NULL); 160 ContextState prev_state(NULL, NULL, NULL);
164 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0); 161 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
165 162
166 InSequence sequence; 163 InSequence sequence;
167 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, 164 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
168 // since the rest of the bindings haven't changed between the current 165 // since the rest of the bindings haven't changed between the current
169 // state and the |prev_state|. 166 // state and the |prev_state|.
170 AddExpectationsForActiveTexture(GL_TEXTURE0); 167 AddExpectationsForActiveTexture(GL_TEXTURE0);
171 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 168 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
172 169
173 // Expect to restore active texture unit to GL_TEXTURE0. 170 // Expect to restore active texture unit to GL_TEXTURE0.
174 AddExpectationsForActiveTexture(GL_TEXTURE0); 171 AddExpectationsForActiveTexture(GL_TEXTURE0);
175 172
176 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 173 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
177 } 174 }
178 175
179 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) { 176 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) {
180 InitState init; 177 InitState init;
181 init.gl_version = "3.0";
182 InitDecoder(init); 178 InitDecoder(init);
183 SetupTexture(); 179 SetupTexture();
184 180
185 // Construct a previous ContextState with all texture bindings 181 // Construct a previous ContextState with all texture bindings
186 // set to default textures. 182 // set to default textures.
187 ContextState prev_state(NULL, NULL, NULL); 183 ContextState prev_state(NULL, NULL, NULL);
188 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0); 184 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
189 185
190 InSequence sequence; 186 InSequence sequence;
191 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, 187 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
192 // since the rest of the bindings haven't changed between the current 188 // since the rest of the bindings haven't changed between the current
193 // state and the |prev_state|. 189 // state and the |prev_state|.
194 AddExpectationsForActiveTexture(GL_TEXTURE0); 190 AddExpectationsForActiveTexture(GL_TEXTURE0);
195 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 191 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
196 192
197 // Expect to restore active texture unit to GL_TEXTURE0. 193 // Expect to restore active texture unit to GL_TEXTURE0.
198 AddExpectationsForActiveTexture(GL_TEXTURE0); 194 AddExpectationsForActiveTexture(GL_TEXTURE0);
199 195
200 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 196 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
201 } 197 }
202 198
203 TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) { 199 TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) {
204 InitState init; 200 InitState init;
205 init.gl_version = "3.0";
206 InitDecoder(init); 201 InitDecoder(init);
207 202
208 // Bind a non-default texture to GL_TEXTURE1 unit. 203 // Bind a non-default texture to GL_TEXTURE1 unit.
209 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 204 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
210 ActiveTexture cmd; 205 ActiveTexture cmd;
211 cmd.Init(GL_TEXTURE1); 206 cmd.Init(GL_TEXTURE1);
212 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 207 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
213 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 208 EXPECT_EQ(GL_NO_ERROR, GetGLError());
214 SetupTexture(); 209 SetupTexture();
215 210
(...skipping 10 matching lines...) Expand all
226 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 221 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
227 222
228 // Expect to restore active texture unit to GL_TEXTURE1. 223 // Expect to restore active texture unit to GL_TEXTURE1.
229 AddExpectationsForActiveTexture(GL_TEXTURE1); 224 AddExpectationsForActiveTexture(GL_TEXTURE1);
230 225
231 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 226 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
232 } 227 }
233 228
234 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) { 229 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) {
235 InitState init; 230 InitState init;
236 init.gl_version = "3.0";
237 init.bind_generates_resource = true; 231 init.bind_generates_resource = true;
238 InitDecoder(init); 232 InitDecoder(init);
239 233
240 // Bind a non-default texture to GL_TEXTURE1 unit. 234 // Bind a non-default texture to GL_TEXTURE1 unit.
241 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 235 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
242 SpecializedSetup<ActiveTexture, 0>(true); 236 SpecializedSetup<ActiveTexture, 0>(true);
243 ActiveTexture cmd; 237 ActiveTexture cmd;
244 cmd.Init(GL_TEXTURE1); 238 cmd.Init(GL_TEXTURE1);
245 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 239 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
246 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 240 EXPECT_EQ(GL_NO_ERROR, GetGLError());
(...skipping 18 matching lines...) Expand all
265 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 259 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
266 260
267 // Expect to restore active texture unit to GL_TEXTURE1. 261 // Expect to restore active texture unit to GL_TEXTURE1.
268 AddExpectationsForActiveTexture(GL_TEXTURE1); 262 AddExpectationsForActiveTexture(GL_TEXTURE1);
269 263
270 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 264 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
271 } 265 }
272 266
273 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) { 267 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) {
274 InitState init; 268 InitState init;
275 init.gl_version = "3.0";
276 init.bind_generates_resource = true; 269 init.bind_generates_resource = true;
277 InitDecoder(init); 270 InitDecoder(init);
278 271
279 // Bind a non-default texture to GL_TEXTURE0 unit. 272 // Bind a non-default texture to GL_TEXTURE0 unit.
280 SetupTexture(); 273 SetupTexture();
281 274
282 // Construct a previous ContextState with GL_TEXTURE_2D target in 275 // Construct a previous ContextState with GL_TEXTURE_2D target in
283 // GL_TEXTURE1 unit bound to a non-default texture and the rest 276 // GL_TEXTURE1 unit bound to a non-default texture and the rest
284 // set to default textures. 277 // set to default textures.
285 ContextState prev_state(NULL, NULL, NULL); 278 ContextState prev_state(NULL, NULL, NULL);
(...skipping 12 matching lines...) Expand all
298 TestHelper::kServiceDefaultTexture2dId); 291 TestHelper::kServiceDefaultTexture2dId);
299 292
300 // Expect to restore active texture unit to GL_TEXTURE0. 293 // Expect to restore active texture unit to GL_TEXTURE0.
301 AddExpectationsForActiveTexture(GL_TEXTURE0); 294 AddExpectationsForActiveTexture(GL_TEXTURE0);
302 295
303 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 296 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
304 } 297 }
305 298
306 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) { 299 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) {
307 InitState init; 300 InitState init;
308 init.gl_version = "3.0";
309 InitDecoder(init); 301 InitDecoder(init);
310 302
311 // Bind a non-default texture to GL_TEXTURE1 unit. 303 // Bind a non-default texture to GL_TEXTURE1 unit.
312 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 304 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
313 SpecializedSetup<ActiveTexture, 0>(true); 305 SpecializedSetup<ActiveTexture, 0>(true);
314 ActiveTexture cmd; 306 ActiveTexture cmd;
315 cmd.Init(GL_TEXTURE1); 307 cmd.Init(GL_TEXTURE1);
316 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 308 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
317 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 309 EXPECT_EQ(GL_NO_ERROR, GetGLError());
318 SetupTexture(); 310 SetupTexture();
(...skipping 16 matching lines...) Expand all
335 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 327 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
336 328
337 // Expect to restore active texture unit to GL_TEXTURE1. 329 // Expect to restore active texture unit to GL_TEXTURE1.
338 AddExpectationsForActiveTexture(GL_TEXTURE1); 330 AddExpectationsForActiveTexture(GL_TEXTURE1);
339 331
340 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 332 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
341 } 333 }
342 334
343 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) { 335 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) {
344 InitState init; 336 InitState init;
345 init.gl_version = "3.0";
346 InitDecoder(init); 337 InitDecoder(init);
347 338
348 // Bind a non-default texture to GL_TEXTURE0 unit. 339 // Bind a non-default texture to GL_TEXTURE0 unit.
349 SetupTexture(); 340 SetupTexture();
350 341
351 // Construct a previous ContextState with GL_TEXTURE_2D target in 342 // Construct a previous ContextState with GL_TEXTURE_2D target in
352 // GL_TEXTURE1 unit bound to a non-default texture and the rest 343 // GL_TEXTURE1 unit bound to a non-default texture and the rest
353 // set to default textures. 344 // set to default textures.
354 ContextState prev_state(NULL, NULL, NULL); 345 ContextState prev_state(NULL, NULL, NULL);
355 InitializeContextState(&prev_state, 1, kServiceTextureId); 346 InitializeContextState(&prev_state, 1, kServiceTextureId);
(...skipping 28 matching lines...) Expand all
384 {GL_DEPTH_TEST, false, false}, 375 {GL_DEPTH_TEST, false, false},
385 {GL_DITHER, true, true}, 376 {GL_DITHER, true, true},
386 {GL_POLYGON_OFFSET_FILL, false, true}, 377 {GL_POLYGON_OFFSET_FILL, false, true},
387 {GL_SAMPLE_ALPHA_TO_COVERAGE, false, true}, 378 {GL_SAMPLE_ALPHA_TO_COVERAGE, false, true},
388 {GL_SAMPLE_COVERAGE, false, true}, 379 {GL_SAMPLE_COVERAGE, false, true},
389 {GL_SCISSOR_TEST, false, true}, 380 {GL_SCISSOR_TEST, false, true},
390 {GL_STENCIL_TEST, false, false}, 381 {GL_STENCIL_TEST, false, false},
391 {0, false, false}}; 382 {0, false, false}};
392 383
393 InitState init; 384 InitState init;
394 init.gl_version = "2.1";
395 InitDecoder(init); 385 InitDecoder(init);
396 386
397 for (int i = 0; test[i].gl_enum; i++) { 387 for (int i = 0; test[i].gl_enum; i++) {
398 bool enable_state = test[i].default_state; 388 bool enable_state = test[i].default_state;
399 389
400 // Test setting default state initially is ignored. 390 // Test setting default state initially is ignored.
401 EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set); 391 EnableDisableTest(test[i].gl_enum, enable_state, test[i].expect_set);
402 392
403 // Test new and cached state changes. 393 // Test new and cached state changes.
404 for (int n = 0; n < 3; n++) { 394 for (int n = 0; n < 3; n++) {
(...skipping 13 matching lines...) Expand all
418 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings(). 408 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
419 409
420 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings(). 410 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings().
421 411
422 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings(). 412 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
423 413
424 // TODO(vmiura): Tests for ContextState::RestoreGlobalState(). 414 // TODO(vmiura): Tests for ContextState::RestoreGlobalState().
425 415
426 } // namespace gles2 416 } // namespace gles2
427 } // namespace gpu 417 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698