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

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

Issue 2837213003: Restore samplers' state across virtualized GL contexts. (Closed)
Patch Set: Add unit tests covering restoration of sampler state. Created 3 years, 8 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 class GLES2DecoderRestoreStateTest : public GLES2DecoderManualInitTest { 70 class GLES2DecoderRestoreStateTest : public GLES2DecoderManualInitTest {
71 public: 71 public:
72 GLES2DecoderRestoreStateTest() {} 72 GLES2DecoderRestoreStateTest() {}
73 73
74 protected: 74 protected:
75 void AddExpectationsForActiveTexture(GLenum unit); 75 void AddExpectationsForActiveTexture(GLenum unit);
76 void AddExpectationsForBindTexture(GLenum target, GLuint id); 76 void AddExpectationsForBindTexture(GLenum target, GLuint id);
77 void InitializeContextState(ContextState* state, 77 void InitializeContextState(ContextState* state,
78 uint32_t non_default_unit, 78 uint32_t non_default_unit,
79 uint32_t active_unit); 79 uint32_t active_unit);
80
81 // ES3 specific.
82 scoped_refptr<FeatureInfo> SetupForES3Test();
83 void AddExpectationsForBindSampler(GLuint unit, GLuint id);
80 }; 84 };
81 85
82 INSTANTIATE_TEST_CASE_P(Service, 86 INSTANTIATE_TEST_CASE_P(Service,
83 GLES2DecoderRestoreStateTest, 87 GLES2DecoderRestoreStateTest,
84 ::testing::Bool()); 88 ::testing::Bool());
85 89
86 void GLES2DecoderRestoreStateTest::AddExpectationsForActiveTexture( 90 void GLES2DecoderRestoreStateTest::AddExpectationsForActiveTexture(
87 GLenum unit) { 91 GLenum unit) {
88 EXPECT_CALL(*gl_, ActiveTexture(unit)).Times(1).RetiresOnSaturation(); 92 EXPECT_CALL(*gl_, ActiveTexture(unit)).Times(1).RetiresOnSaturation();
89 } 93 }
(...skipping 12 matching lines...) Expand all
102 TextureRef* ref_cube_map = 106 TextureRef* ref_cube_map =
103 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); 107 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
104 state->texture_units[tt].bound_texture_cube_map = ref_cube_map; 108 state->texture_units[tt].bound_texture_cube_map = ref_cube_map;
105 TextureRef* ref_2d = 109 TextureRef* ref_2d =
106 (tt == non_default_unit) 110 (tt == non_default_unit)
107 ? group().texture_manager()->GetTexture(client_texture_id_) 111 ? group().texture_manager()->GetTexture(client_texture_id_)
108 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); 112 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
109 state->texture_units[tt].bound_texture_2d = ref_2d; 113 state->texture_units[tt].bound_texture_2d = ref_2d;
110 } 114 }
111 state->active_texture_unit = active_unit; 115 state->active_texture_unit = active_unit;
116
117 // Set up the sampler units just for convenience of the ES3-specific
118 // tests in this file.
119 state->sampler_units.resize(group().max_texture_units());
120 }
121
122 scoped_refptr<FeatureInfo> GLES2DecoderRestoreStateTest::SetupForES3Test() {
123 InitState init;
124 init.gl_version = "OpenGL ES 3.0";
125 init.context_type = CONTEXT_TYPE_OPENGLES3;
126 InitDecoder(init);
127
128 // Construct a previous ContextState assuming an ES3 context and with all
129 // texture bindings set to default textures.
130 scoped_refptr<FeatureInfo> feature_info = new FeatureInfo;
131 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(
132 gl_.get(), "", "", "OpenGL ES 3.0", CONTEXT_TYPE_OPENGLES3);
133 feature_info->InitializeForTesting(CONTEXT_TYPE_OPENGLES3);
134 return feature_info;
135 }
136
137 void GLES2DecoderRestoreStateTest::AddExpectationsForBindSampler(GLuint unit,
138 GLuint id) {
139 EXPECT_CALL(*gl_, BindSampler(unit, id)).Times(1).RetiresOnSaturation();
112 } 140 }
113 141
114 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) { 142 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) {
115 InitState init; 143 InitState init;
116 init.bind_generates_resource = true; 144 init.bind_generates_resource = true;
117 InitDecoder(init); 145 InitDecoder(init);
118 SetupTexture(); 146 SetupTexture();
119 147
120 InSequence sequence; 148 InSequence sequence;
121 // Expect to restore texture bindings for unit GL_TEXTURE0. 149 // Expect to restore texture bindings for unit GL_TEXTURE0.
122 AddExpectationsForActiveTexture(GL_TEXTURE0); 150 AddExpectationsForActiveTexture(GL_TEXTURE0);
123 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 151 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
124 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 152 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
125 TestHelper::kServiceDefaultTextureCubemapId); 153 TestHelper::kServiceDefaultTextureCubemapId);
126 154
127 // Expect to restore texture bindings for remaining units. 155 // Expect to restore texture bindings for remaining units.
128 for (uint32_t i = 1; i < group().max_texture_units(); ++i) { 156 for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
129 AddExpectationsForActiveTexture(GL_TEXTURE0 + i); 157 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
130 AddExpectationsForBindTexture(GL_TEXTURE_2D, 158 AddExpectationsForBindTexture(GL_TEXTURE_2D,
131 TestHelper::kServiceDefaultTexture2dId); 159 TestHelper::kServiceDefaultTexture2dId);
132 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 160 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
133 TestHelper::kServiceDefaultTextureCubemapId); 161 TestHelper::kServiceDefaultTextureCubemapId);
134 } 162 }
135 163
136 // Expect to restore the active texture unit to GL_TEXTURE0. 164 // Expect to restore the active texture unit to GL_TEXTURE0.
137 AddExpectationsForActiveTexture(GL_TEXTURE0); 165 AddExpectationsForActiveTexture(GL_TEXTURE0);
138 166
139 GetDecoder()->RestoreAllTextureUnitBindings(NULL); 167 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(NULL);
140 } 168 }
141 169
142 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) { 170 TEST_P(GLES2DecoderRestoreStateTest, NullPreviousState) {
143 InitState init; 171 InitState init;
144 InitDecoder(init); 172 InitDecoder(init);
145 SetupTexture(); 173 SetupTexture();
146 174
147 InSequence sequence; 175 InSequence sequence;
148 // Expect to restore texture bindings for unit GL_TEXTURE0. 176 // Expect to restore texture bindings for unit GL_TEXTURE0.
149 AddExpectationsForActiveTexture(GL_TEXTURE0); 177 AddExpectationsForActiveTexture(GL_TEXTURE0);
150 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 178 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
151 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0); 179 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
152 180
153 // Expect to restore texture bindings for remaining units. 181 // Expect to restore texture bindings for remaining units.
154 for (uint32_t i = 1; i < group().max_texture_units(); ++i) { 182 for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
155 AddExpectationsForActiveTexture(GL_TEXTURE0 + i); 183 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
156 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 184 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
157 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0); 185 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
158 } 186 }
159 187
160 // Expect to restore the active texture unit to GL_TEXTURE0. 188 // Expect to restore the active texture unit to GL_TEXTURE0.
161 AddExpectationsForActiveTexture(GL_TEXTURE0); 189 AddExpectationsForActiveTexture(GL_TEXTURE0);
162 190
163 GetDecoder()->RestoreAllTextureUnitBindings(NULL); 191 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(NULL);
164 } 192 }
165 193
166 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) { 194 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) {
167 InitState init; 195 InitState init;
168 init.bind_generates_resource = true; 196 init.bind_generates_resource = true;
169 InitDecoder(init); 197 InitDecoder(init);
170 SetupTexture(); 198 SetupTexture();
171 199
172 // Construct a previous ContextState with all texture bindings 200 // Construct a previous ContextState with all texture bindings
173 // set to default textures. 201 // set to default textures.
174 ContextState prev_state(NULL, NULL, NULL); 202 ContextState prev_state(NULL, NULL, NULL);
175 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0); 203 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
176 204
177 InSequence sequence; 205 InSequence sequence;
178 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, 206 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
179 // since the rest of the bindings haven't changed between the current 207 // since the rest of the bindings haven't changed between the current
180 // state and the |prev_state|. 208 // state and the |prev_state|.
181 AddExpectationsForActiveTexture(GL_TEXTURE0); 209 AddExpectationsForActiveTexture(GL_TEXTURE0);
182 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 210 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
183 211
184 // Expect to restore active texture unit to GL_TEXTURE0. 212 // Expect to restore active texture unit to GL_TEXTURE0.
185 AddExpectationsForActiveTexture(GL_TEXTURE0); 213 AddExpectationsForActiveTexture(GL_TEXTURE0);
186 214
187 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 215 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
188 } 216 }
189 217
190 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) { 218 TEST_P(GLES2DecoderRestoreStateTest, WithPreviousState) {
191 InitState init; 219 InitState init;
192 InitDecoder(init); 220 InitDecoder(init);
193 SetupTexture(); 221 SetupTexture();
194 222
195 // Construct a previous ContextState with all texture bindings 223 // Construct a previous ContextState with all texture bindings
196 // set to default textures. 224 // set to default textures.
197 ContextState prev_state(NULL, NULL, NULL); 225 ContextState prev_state(NULL, NULL, NULL);
198 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0); 226 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
199 227
200 InSequence sequence; 228 InSequence sequence;
201 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit, 229 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
202 // since the rest of the bindings haven't changed between the current 230 // since the rest of the bindings haven't changed between the current
203 // state and the |prev_state|. 231 // state and the |prev_state|.
204 AddExpectationsForActiveTexture(GL_TEXTURE0); 232 AddExpectationsForActiveTexture(GL_TEXTURE0);
205 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 233 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
206 234
207 // Expect to restore active texture unit to GL_TEXTURE0. 235 // Expect to restore active texture unit to GL_TEXTURE0.
208 AddExpectationsForActiveTexture(GL_TEXTURE0); 236 AddExpectationsForActiveTexture(GL_TEXTURE0);
209 237
210 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 238 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
211 } 239 }
212 240
213 TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) { 241 TEST_P(GLES2DecoderRestoreStateTest, ActiveUnit1) {
214 InitState init; 242 InitState init;
215 InitDecoder(init); 243 InitDecoder(init);
216 244
217 // Bind a non-default texture to GL_TEXTURE1 unit. 245 // Bind a non-default texture to GL_TEXTURE1 unit.
218 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 246 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
219 ActiveTexture cmd; 247 ActiveTexture cmd;
220 cmd.Init(GL_TEXTURE1); 248 cmd.Init(GL_TEXTURE1);
221 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 249 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
222 EXPECT_EQ(GL_NO_ERROR, GetGLError()); 250 EXPECT_EQ(GL_NO_ERROR, GetGLError());
223 SetupTexture(); 251 SetupTexture();
224 252
225 // Construct a previous ContextState with all texture bindings 253 // Construct a previous ContextState with all texture bindings
226 // set to default textures. 254 // set to default textures.
227 ContextState prev_state(NULL, NULL, NULL); 255 ContextState prev_state(NULL, NULL, NULL);
228 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0); 256 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
229 257
230 InSequence sequence; 258 InSequence sequence;
231 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit, 259 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit,
232 // since the rest of the bindings haven't changed between the current 260 // since the rest of the bindings haven't changed between the current
233 // state and the |prev_state|. 261 // state and the |prev_state|.
234 AddExpectationsForActiveTexture(GL_TEXTURE1); 262 AddExpectationsForActiveTexture(GL_TEXTURE1);
235 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 263 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
236 264
237 // Expect to restore active texture unit to GL_TEXTURE1. 265 // Expect to restore active texture unit to GL_TEXTURE1.
238 AddExpectationsForActiveTexture(GL_TEXTURE1); 266 AddExpectationsForActiveTexture(GL_TEXTURE1);
239 267
240 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 268 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
241 } 269 }
242 270
243 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) { 271 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) {
244 InitState init; 272 InitState init;
245 init.bind_generates_resource = true; 273 init.bind_generates_resource = true;
246 InitDecoder(init); 274 InitDecoder(init);
247 275
248 // Bind a non-default texture to GL_TEXTURE1 unit. 276 // Bind a non-default texture to GL_TEXTURE1 unit.
249 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 277 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
250 SpecializedSetup<ActiveTexture, 0>(true); 278 SpecializedSetup<ActiveTexture, 0>(true);
(...skipping 17 matching lines...) Expand all
268 TestHelper::kServiceDefaultTexture2dId); 296 TestHelper::kServiceDefaultTexture2dId);
269 297
270 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to 298 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
271 // non-default. 299 // non-default.
272 AddExpectationsForActiveTexture(GL_TEXTURE1); 300 AddExpectationsForActiveTexture(GL_TEXTURE1);
273 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 301 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
274 302
275 // Expect to restore active texture unit to GL_TEXTURE1. 303 // Expect to restore active texture unit to GL_TEXTURE1.
276 AddExpectationsForActiveTexture(GL_TEXTURE1); 304 AddExpectationsForActiveTexture(GL_TEXTURE1);
277 305
278 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 306 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
279 } 307 }
280 308
281 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) { 309 TEST_P(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) {
282 InitState init; 310 InitState init;
283 init.bind_generates_resource = true; 311 init.bind_generates_resource = true;
284 InitDecoder(init); 312 InitDecoder(init);
285 313
286 // Bind a non-default texture to GL_TEXTURE0 unit. 314 // Bind a non-default texture to GL_TEXTURE0 unit.
287 SetupTexture(); 315 SetupTexture();
288 316
(...skipping 11 matching lines...) Expand all
300 328
301 // Expect to restore GL_TEXTURE_2D binding to the default texture 329 // Expect to restore GL_TEXTURE_2D binding to the default texture
302 // for GL_TEXTURE1 unit. 330 // for GL_TEXTURE1 unit.
303 AddExpectationsForActiveTexture(GL_TEXTURE1); 331 AddExpectationsForActiveTexture(GL_TEXTURE1);
304 AddExpectationsForBindTexture(GL_TEXTURE_2D, 332 AddExpectationsForBindTexture(GL_TEXTURE_2D,
305 TestHelper::kServiceDefaultTexture2dId); 333 TestHelper::kServiceDefaultTexture2dId);
306 334
307 // Expect to restore active texture unit to GL_TEXTURE0. 335 // Expect to restore active texture unit to GL_TEXTURE0.
308 AddExpectationsForActiveTexture(GL_TEXTURE0); 336 AddExpectationsForActiveTexture(GL_TEXTURE0);
309 337
310 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 338 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
311 } 339 }
312 340
313 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) { 341 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit0) {
314 InitState init; 342 InitState init;
315 InitDecoder(init); 343 InitDecoder(init);
316 344
317 // Bind a non-default texture to GL_TEXTURE1 unit. 345 // Bind a non-default texture to GL_TEXTURE1 unit.
318 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1)); 346 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
319 SpecializedSetup<ActiveTexture, 0>(true); 347 SpecializedSetup<ActiveTexture, 0>(true);
320 ActiveTexture cmd; 348 ActiveTexture cmd;
(...skipping 15 matching lines...) Expand all
336 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 364 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
337 365
338 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to 366 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
339 // non-default. 367 // non-default.
340 AddExpectationsForActiveTexture(GL_TEXTURE1); 368 AddExpectationsForActiveTexture(GL_TEXTURE1);
341 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 369 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
342 370
343 // Expect to restore active texture unit to GL_TEXTURE1. 371 // Expect to restore active texture unit to GL_TEXTURE1.
344 AddExpectationsForActiveTexture(GL_TEXTURE1); 372 AddExpectationsForActiveTexture(GL_TEXTURE1);
345 373
346 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 374 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
347 } 375 }
348 376
349 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) { 377 TEST_P(GLES2DecoderRestoreStateTest, DefaultUnit1) {
350 InitState init; 378 InitState init;
351 InitDecoder(init); 379 InitDecoder(init);
352 380
353 // Bind a non-default texture to GL_TEXTURE0 unit. 381 // Bind a non-default texture to GL_TEXTURE0 unit.
354 SetupTexture(); 382 SetupTexture();
355 383
356 // Construct a previous ContextState with GL_TEXTURE_2D target in 384 // Construct a previous ContextState with GL_TEXTURE_2D target in
357 // GL_TEXTURE1 unit bound to a non-default texture and the rest 385 // GL_TEXTURE1 unit bound to a non-default texture and the rest
358 // set to default textures. 386 // set to default textures.
359 ContextState prev_state(NULL, NULL, NULL); 387 ContextState prev_state(NULL, NULL, NULL);
360 InitializeContextState(&prev_state, 1, kServiceTextureId); 388 InitializeContextState(&prev_state, 1, kServiceTextureId);
361 389
362 InSequence sequence; 390 InSequence sequence;
363 // Expect to restore GL_TEXTURE_2D binding to the non-default texture 391 // Expect to restore GL_TEXTURE_2D binding to the non-default texture
364 // for GL_TEXTURE0 unit. 392 // for GL_TEXTURE0 unit.
365 AddExpectationsForActiveTexture(GL_TEXTURE0); 393 AddExpectationsForActiveTexture(GL_TEXTURE0);
366 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId); 394 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
367 395
368 // Expect to restore GL_TEXTURE_2D binding to the 0 texture 396 // Expect to restore GL_TEXTURE_2D binding to the 0 texture
369 // for GL_TEXTURE1 unit. 397 // for GL_TEXTURE1 unit.
370 AddExpectationsForActiveTexture(GL_TEXTURE1); 398 AddExpectationsForActiveTexture(GL_TEXTURE1);
371 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0); 399 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
372 400
373 // Expect to restore active texture unit to GL_TEXTURE0. 401 // Expect to restore active texture unit to GL_TEXTURE0.
374 AddExpectationsForActiveTexture(GL_TEXTURE0); 402 AddExpectationsForActiveTexture(GL_TEXTURE0);
375 403
376 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state); 404 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
405 }
406
407 TEST_P(GLES2DecoderRestoreStateTest, ES3NullPreviousStateWithSampler) {
408 // This ES3-specific test is scoped within GLES2DecoderRestoreStateTest
409 // to avoid doing large refactorings of these tests.
410 InitState init;
411 init.gl_version = "OpenGL ES 3.0";
412 init.context_type = CONTEXT_TYPE_OPENGLES3;
413 InitDecoder(init);
414 SetupTexture();
415 SetupSampler();
416
417 InSequence sequence;
418 // Expect to restore texture bindings for unit GL_TEXTURE0.
419 AddExpectationsForActiveTexture(GL_TEXTURE0);
420 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
421 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
422 // Expect to restore sampler binding for unit GL_TEXTURE0.
423 AddExpectationsForBindSampler(0, kServiceSamplerId);
424
425 // Expect to restore texture bindings for remaining units.
426 for (uint32_t i = 1; i < group().max_texture_units(); ++i) {
427 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
428 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
429 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
430 AddExpectationsForBindSampler(i, 0);
431 }
432
433 // Expect to restore the active texture unit to GL_TEXTURE0.
434 AddExpectationsForActiveTexture(GL_TEXTURE0);
435
436 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(NULL);
437 }
438
439 TEST_P(GLES2DecoderRestoreStateTest, ES3RestoreExistingSampler) {
440 // This ES3-specific test is scoped within GLES2DecoderRestoreStateTest
441 // to avoid doing large refactorings of these tests.
442 auto feature_info = SetupForES3Test();
443 SetupSampler();
444
445 // Construct a previous ContextState assuming an ES3 context and with all
446 // texture bindings set to default textures.
447 ContextState prev_state(feature_info.get(), NULL, NULL);
448 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
449
450 InSequence sequence;
451 // Expect to restore sampler binding for unit GL_TEXTURE0.
452 AddExpectationsForBindSampler(0, kServiceSamplerId);
453
454 // Expect to restore the active texture unit to GL_TEXTURE0.
455 AddExpectationsForActiveTexture(GL_TEXTURE0);
456
457 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
458 }
459
460 TEST_P(GLES2DecoderRestoreStateTest, ES3RestoreZeroSampler) {
461 // This ES3-specific test is scoped within GLES2DecoderRestoreStateTest
462 // to avoid doing large refactorings of these tests.
463 auto feature_info = SetupForES3Test();
464
465 // Construct a previous ContextState assuming an ES3 context and with all
466 // texture bindings set to default textures.
467 SamplerManager sampler_manager(feature_info.get());
468 ContextState prev_state(feature_info.get(), NULL, NULL);
469 InitializeContextState(&prev_state, std::numeric_limits<uint32_t>::max(), 0);
470 // Set up a sampler in the previous state. The client_id and service_id
471 // don't matter except that they're non-zero.
472 prev_state.sampler_units[0] = new Sampler(&sampler_manager, 1, 2);
473
474 InSequence sequence;
475 // Expect to restore the zero sampler on unit GL_TEXTURE0.
476 AddExpectationsForBindSampler(0, 0);
477
478 // Expect to restore the active texture unit to GL_TEXTURE0.
479 AddExpectationsForActiveTexture(GL_TEXTURE0);
480
481 GetDecoder()->RestoreAllTextureUnitAndSamplerBindings(&prev_state);
482
483 // Tell the sampler manager to destroy itself without a context so we
484 // don't have to set up more expectations.
485 sampler_manager.Destroy(false);
377 } 486 }
378 487
379 TEST_P(GLES2DecoderManualInitTest, ContextStateCapabilityCaching) { 488 TEST_P(GLES2DecoderManualInitTest, ContextStateCapabilityCaching) {
380 struct TestInfo { 489 struct TestInfo {
381 GLenum gl_enum; 490 GLenum gl_enum;
382 bool default_state; 491 bool default_state;
383 bool expect_set; 492 bool expect_set;
384 }; 493 };
385 494
386 // TODO(vmiura): Should autogen this to match build_gles2_cmd_buffer.py. 495 // TODO(vmiura): Should autogen this to match build_gles2_cmd_buffer.py.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings(). 599 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
491 600
492 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings(). 601 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings().
493 602
494 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings(). 603 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
495 604
496 // TODO(vmiura): Tests for ContextState::RestoreGlobalState(). 605 // TODO(vmiura): Tests for ContextState::RestoreGlobalState().
497 606
498 } // namespace gles2 607 } // namespace gles2
499 } // namespace gpu 608 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc ('k') | ui/gl/gl_state_restorer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698