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

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

Issue 268773006: Refactor gles2_cmd_decoder_unittest.cc into components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
(Empty)
1 // Copyright (c) 2014 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
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/common/id_allocator.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/context_state.h"
18 #include "gpu/command_buffer/service/gl_surface_mock.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20
21 #include "gpu/command_buffer/service/gpu_switches.h"
22 #include "gpu/command_buffer/service/image_manager.h"
23 #include "gpu/command_buffer/service/mailbox_manager.h"
24 #include "gpu/command_buffer/service/mocks.h"
25 #include "gpu/command_buffer/service/program_manager.h"
26 #include "gpu/command_buffer/service/test_helper.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gl/gl_implementation.h"
29 #include "ui/gl/gl_mock.h"
30 #include "ui/gl/gl_surface_stub.h"
31
32 #if !defined(GL_DEPTH24_STENCIL8)
33 #define GL_DEPTH24_STENCIL8 0x88F0
34 #endif
35
36 using ::gfx::MockGLInterface;
37 using ::testing::_;
38 using ::testing::DoAll;
39 using ::testing::InSequence;
40 using ::testing::Invoke;
41 using ::testing::MatcherCast;
42 using ::testing::Mock;
43 using ::testing::Pointee;
44 using ::testing::Return;
45 using ::testing::SaveArg;
46 using ::testing::SetArrayArgument;
47 using ::testing::SetArgumentPointee;
48 using ::testing::SetArgPointee;
49 using ::testing::StrEq;
50 using ::testing::StrictMock;
51
52 namespace gpu {
53 namespace gles2 {
54
55 using namespace cmds;
56
57 class GLES2DecoderRestoreStateTest : public GLES2DecoderManualInitTest {
58 public:
59 GLES2DecoderRestoreStateTest() {}
60
61 protected:
62 void AddExpectationsForActiveTexture(GLenum unit);
63 void AddExpectationsForBindTexture(GLenum target, GLuint id);
64 void InitializeContextState(ContextState* state,
65 uint32 non_default_unit,
66 uint32 active_unit);
67 };
68
69 void GLES2DecoderRestoreStateTest::AddExpectationsForActiveTexture(
70 GLenum unit) {
71 EXPECT_CALL(*gl_, ActiveTexture(unit)).Times(1).RetiresOnSaturation();
72 }
73
74 void GLES2DecoderRestoreStateTest::AddExpectationsForBindTexture(GLenum target,
75 GLuint id) {
76 EXPECT_CALL(*gl_, BindTexture(target, id)).Times(1).RetiresOnSaturation();
77 }
78
79 void GLES2DecoderRestoreStateTest::InitializeContextState(
80 ContextState* state,
81 uint32 non_default_unit,
82 uint32 active_unit) {
83 state->texture_units.resize(group().max_texture_units());
84 for (uint32 tt = 0; tt < state->texture_units.size(); ++tt) {
85 TextureRef* ref_cube_map =
86 group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
87 state->texture_units[tt].bound_texture_cube_map = ref_cube_map;
88 TextureRef* ref_2d =
89 (tt == non_default_unit)
90 ? group().texture_manager()->GetTexture(client_texture_id_)
91 : group().texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
92 state->texture_units[tt].bound_texture_2d = ref_2d;
93 }
94 state->active_texture_unit = active_unit;
95 }
96
97 TEST_F(GLES2DecoderRestoreStateTest, NullPreviousStateBGR) {
98 InitState init;
99 init.gl_version = "3.0";
100 init.bind_generates_resource = true;
101 InitDecoder(init);
102 SetupTexture();
103
104 InSequence sequence;
105 // Expect to restore texture bindings for unit GL_TEXTURE0.
106 AddExpectationsForActiveTexture(GL_TEXTURE0);
107 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
108 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
109 TestHelper::kServiceDefaultTextureCubemapId);
110
111 // Expect to restore texture bindings for remaining units.
112 for (uint32 i = 1; i < group().max_texture_units(); ++i) {
113 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
114 AddExpectationsForBindTexture(GL_TEXTURE_2D,
115 TestHelper::kServiceDefaultTexture2dId);
116 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP,
117 TestHelper::kServiceDefaultTextureCubemapId);
118 }
119
120 // Expect to restore the active texture unit to GL_TEXTURE0.
121 AddExpectationsForActiveTexture(GL_TEXTURE0);
122
123 GetDecoder()->RestoreAllTextureUnitBindings(NULL);
124 }
125
126 TEST_F(GLES2DecoderRestoreStateTest, NullPreviousState) {
127 InitState init;
128 init.gl_version = "3.0";
129 InitDecoder(init);
130 SetupTexture();
131
132 InSequence sequence;
133 // Expect to restore texture bindings for unit GL_TEXTURE0.
134 AddExpectationsForActiveTexture(GL_TEXTURE0);
135 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
136 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
137
138 // Expect to restore texture bindings for remaining units.
139 for (uint32 i = 1; i < group().max_texture_units(); ++i) {
140 AddExpectationsForActiveTexture(GL_TEXTURE0 + i);
141 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
142 AddExpectationsForBindTexture(GL_TEXTURE_CUBE_MAP, 0);
143 }
144
145 // Expect to restore the active texture unit to GL_TEXTURE0.
146 AddExpectationsForActiveTexture(GL_TEXTURE0);
147
148 GetDecoder()->RestoreAllTextureUnitBindings(NULL);
149 }
150
151 TEST_F(GLES2DecoderRestoreStateTest, WithPreviousStateBGR) {
152 InitState init;
153 init.gl_version = "3.0";
154 init.bind_generates_resource = true;
155 InitDecoder(init);
156 SetupTexture();
157
158 // Construct a previous ContextState with all texture bindings
159 // set to default textures.
160 ContextState prev_state(NULL, NULL, NULL);
161 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
162
163 InSequence sequence;
164 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
165 // since the rest of the bindings haven't changed between the current
166 // state and the |prev_state|.
167 AddExpectationsForActiveTexture(GL_TEXTURE0);
168 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
169
170 // Expect to restore active texture unit to GL_TEXTURE0.
171 AddExpectationsForActiveTexture(GL_TEXTURE0);
172
173 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
174 }
175
176 TEST_F(GLES2DecoderRestoreStateTest, WithPreviousState) {
177 InitState init;
178 init.gl_version = "3.0";
179 InitDecoder(init);
180 SetupTexture();
181
182 // Construct a previous ContextState with all texture bindings
183 // set to default textures.
184 ContextState prev_state(NULL, NULL, NULL);
185 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
186
187 InSequence sequence;
188 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE0 unit,
189 // since the rest of the bindings haven't changed between the current
190 // state and the |prev_state|.
191 AddExpectationsForActiveTexture(GL_TEXTURE0);
192 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
193
194 // Expect to restore active texture unit to GL_TEXTURE0.
195 AddExpectationsForActiveTexture(GL_TEXTURE0);
196
197 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
198 }
199
200 TEST_F(GLES2DecoderRestoreStateTest, ActiveUnit1) {
201 InitState init;
202 init.gl_version = "3.0";
203 InitDecoder(init);
204
205 // Bind a non-default texture to GL_TEXTURE1 unit.
206 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
207 ActiveTexture cmd;
208 cmd.Init(GL_TEXTURE1);
209 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
210 EXPECT_EQ(GL_NO_ERROR, GetGLError());
211 SetupTexture();
212
213 // Construct a previous ContextState with all texture bindings
214 // set to default textures.
215 ContextState prev_state(NULL, NULL, NULL);
216 InitializeContextState(&prev_state, std::numeric_limits<uint32>::max(), 0);
217
218 InSequence sequence;
219 // Expect to restore only GL_TEXTURE_2D binding for GL_TEXTURE1 unit,
220 // since the rest of the bindings haven't changed between the current
221 // state and the |prev_state|.
222 AddExpectationsForActiveTexture(GL_TEXTURE1);
223 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
224
225 // Expect to restore active texture unit to GL_TEXTURE1.
226 AddExpectationsForActiveTexture(GL_TEXTURE1);
227
228 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
229 }
230
231 TEST_F(GLES2DecoderRestoreStateTest, NonDefaultUnit0BGR) {
232 InitState init;
233 init.gl_version = "3.0";
234 init.bind_generates_resource = true;
235 InitDecoder(init);
236
237 // Bind a non-default texture to GL_TEXTURE1 unit.
238 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
239 SpecializedSetup<ActiveTexture, 0>(true);
240 ActiveTexture cmd;
241 cmd.Init(GL_TEXTURE1);
242 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
243 EXPECT_EQ(GL_NO_ERROR, GetGLError());
244 SetupTexture();
245
246 // Construct a previous ContextState with GL_TEXTURE_2D target in
247 // GL_TEXTURE0 unit bound to a non-default texture and the rest
248 // set to default textures.
249 ContextState prev_state(NULL, NULL, NULL);
250 InitializeContextState(&prev_state, 0, kServiceTextureId);
251
252 InSequence sequence;
253 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
254 // a default texture.
255 AddExpectationsForActiveTexture(GL_TEXTURE0);
256 AddExpectationsForBindTexture(GL_TEXTURE_2D,
257 TestHelper::kServiceDefaultTexture2dId);
258
259 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
260 // non-default.
261 AddExpectationsForActiveTexture(GL_TEXTURE1);
262 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
263
264 // Expect to restore active texture unit to GL_TEXTURE1.
265 AddExpectationsForActiveTexture(GL_TEXTURE1);
266
267 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
268 }
269
270 TEST_F(GLES2DecoderRestoreStateTest, NonDefaultUnit1BGR) {
271 InitState init;
272 init.gl_version = "3.0";
273 init.bind_generates_resource = true;
274 InitDecoder(init);
275
276 // Bind a non-default texture to GL_TEXTURE0 unit.
277 SetupTexture();
278
279 // Construct a previous ContextState with GL_TEXTURE_2D target in
280 // GL_TEXTURE1 unit bound to a non-default texture and the rest
281 // set to default textures.
282 ContextState prev_state(NULL, NULL, NULL);
283 InitializeContextState(&prev_state, 1, kServiceTextureId);
284
285 InSequence sequence;
286 // Expect to restore GL_TEXTURE_2D binding to the non-default texture
287 // for GL_TEXTURE0 unit.
288 AddExpectationsForActiveTexture(GL_TEXTURE0);
289 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
290
291 // Expect to restore GL_TEXTURE_2D binding to the default texture
292 // for GL_TEXTURE1 unit.
293 AddExpectationsForActiveTexture(GL_TEXTURE1);
294 AddExpectationsForBindTexture(GL_TEXTURE_2D,
295 TestHelper::kServiceDefaultTexture2dId);
296
297 // Expect to restore active texture unit to GL_TEXTURE0.
298 AddExpectationsForActiveTexture(GL_TEXTURE0);
299
300 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
301 }
302
303 TEST_F(GLES2DecoderRestoreStateTest, DefaultUnit0) {
304 InitState init;
305 init.gl_version = "3.0";
306 InitDecoder(init);
307
308 // Bind a non-default texture to GL_TEXTURE1 unit.
309 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
310 SpecializedSetup<ActiveTexture, 0>(true);
311 ActiveTexture cmd;
312 cmd.Init(GL_TEXTURE1);
313 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
314 EXPECT_EQ(GL_NO_ERROR, GetGLError());
315 SetupTexture();
316
317 // Construct a previous ContextState with GL_TEXTURE_2D target in
318 // GL_TEXTURE0 unit bound to a non-default texture and the rest
319 // set to default textures.
320 ContextState prev_state(NULL, NULL, NULL);
321 InitializeContextState(&prev_state, 0, kServiceTextureId);
322
323 InSequence sequence;
324 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE0 unit to
325 // the 0 texture.
326 AddExpectationsForActiveTexture(GL_TEXTURE0);
327 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
328
329 // Expect to restore GL_TEXTURE_2D binding for GL_TEXTURE1 unit to
330 // non-default.
331 AddExpectationsForActiveTexture(GL_TEXTURE1);
332 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
333
334 // Expect to restore active texture unit to GL_TEXTURE1.
335 AddExpectationsForActiveTexture(GL_TEXTURE1);
336
337 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
338 }
339
340 TEST_F(GLES2DecoderRestoreStateTest, DefaultUnit1) {
341 InitState init;
342 init.gl_version = "3.0";
343 InitDecoder(init);
344
345 // Bind a non-default texture to GL_TEXTURE0 unit.
346 SetupTexture();
347
348 // Construct a previous ContextState with GL_TEXTURE_2D target in
349 // GL_TEXTURE1 unit bound to a non-default texture and the rest
350 // set to default textures.
351 ContextState prev_state(NULL, NULL, NULL);
352 InitializeContextState(&prev_state, 1, kServiceTextureId);
353
354 InSequence sequence;
355 // Expect to restore GL_TEXTURE_2D binding to the non-default texture
356 // for GL_TEXTURE0 unit.
357 AddExpectationsForActiveTexture(GL_TEXTURE0);
358 AddExpectationsForBindTexture(GL_TEXTURE_2D, kServiceTextureId);
359
360 // Expect to restore GL_TEXTURE_2D binding to the 0 texture
361 // for GL_TEXTURE1 unit.
362 AddExpectationsForActiveTexture(GL_TEXTURE1);
363 AddExpectationsForBindTexture(GL_TEXTURE_2D, 0);
364
365 // Expect to restore active texture unit to GL_TEXTURE0.
366 AddExpectationsForActiveTexture(GL_TEXTURE0);
367
368 GetDecoder()->RestoreAllTextureUnitBindings(&prev_state);
369 }
370
371 // TODO(vmiura): Tests for VAO restore.
372
373 // TODO(vmiura): Tests for ContextState::RestoreAttribute().
374
375 // TODO(vmiura): Tests for ContextState::RestoreBufferBindings().
376
377 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
378
379 // TODO(vmiura): Tests for ContextState::RestoreRenderbufferBindings().
380
381 // TODO(vmiura): Tests for ContextState::RestoreProgramBindings().
382
383 // TODO(vmiura): Tests for ContextState::RestoreGlobalState().
384
385 } // namespace gles2
386 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698