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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest_async_pixel.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) 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.
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 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
58 InitState init;
59 init.extensions = "GL_CHROMIUM_async_pixel_transfers";
60 init.gl_version = "3.0";
61 init.bind_generates_resource = true;
62 InitDecoder(init);
63
64 // Set up the texture.
65 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
66 TextureRef* texture_ref = GetTexture(client_texture_id_);
67 Texture* texture = texture_ref->texture();
68
69 // Set a mock Async delegate
70 StrictMock<gpu::MockAsyncPixelTransferManager>* manager =
71 new StrictMock<gpu::MockAsyncPixelTransferManager>;
72 manager->Initialize(group().texture_manager());
73 decoder_->SetAsyncPixelTransferManagerForTest(manager);
74 StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = NULL;
75
76 // Tex(Sub)Image2D upload commands.
77 AsyncTexImage2DCHROMIUM teximage_cmd;
78 teximage_cmd.Init(GL_TEXTURE_2D,
79 0,
80 GL_RGBA,
81 8,
82 8,
83 0,
84 GL_RGBA,
85 GL_UNSIGNED_BYTE,
86 kSharedMemoryId,
87 kSharedMemoryOffset,
88 0,
89 0,
90 0);
91 AsyncTexSubImage2DCHROMIUM texsubimage_cmd;
92 texsubimage_cmd.Init(GL_TEXTURE_2D,
93 0,
94 0,
95 0,
96 8,
97 8,
98 GL_RGBA,
99 GL_UNSIGNED_BYTE,
100 kSharedMemoryId,
101 kSharedMemoryOffset,
102 0,
103 0,
104 0);
105 WaitAsyncTexImage2DCHROMIUM wait_cmd;
106 wait_cmd.Init(GL_TEXTURE_2D);
107 WaitAllAsyncTexImage2DCHROMIUM wait_all_cmd;
108 wait_all_cmd.Init();
109
110 // No transfer state exists initially.
111 EXPECT_FALSE(
112 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
113 texture_ref));
114
115 base::Closure bind_callback;
116
117 // AsyncTexImage2D
118 {
119 // Create transfer state since it doesn't exist.
120 EXPECT_EQ(texture_ref->num_observers(), 0);
121 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
122 .WillOnce(Return(
123 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
124 .RetiresOnSaturation();
125 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _))
126 .WillOnce(SaveArg<2>(&bind_callback))
127 .RetiresOnSaturation();
128 // Command succeeds.
129 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
130 EXPECT_EQ(GL_NO_ERROR, GetGLError());
131 EXPECT_EQ(
132 delegate,
133 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
134 texture_ref));
135 EXPECT_TRUE(texture->IsImmutable());
136 // The texture is safe but the level has not been defined yet.
137 EXPECT_TRUE(texture->SafeToRenderFrom());
138 GLsizei width, height;
139 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
140 EXPECT_EQ(texture_ref->num_observers(), 1);
141 }
142 {
143 // Async redefinitions are not allowed!
144 // Command fails.
145 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
146 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
147 EXPECT_EQ(
148 delegate,
149 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
150 texture_ref));
151 EXPECT_TRUE(texture->IsImmutable());
152 EXPECT_TRUE(texture->SafeToRenderFrom());
153 }
154
155 // Binding/defining of the async transfer
156 {
157 // TODO(epenner): We should check that the manager gets the
158 // BindCompletedAsyncTransfers() call, which is required to
159 // guarantee the delegate calls the bind callback.
160
161 // Simulate the bind callback from the delegate.
162 bind_callback.Run();
163
164 // After the bind callback is run, the texture is safe,
165 // and has the right size etc.
166 EXPECT_TRUE(texture->SafeToRenderFrom());
167 GLsizei width, height;
168 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
169 EXPECT_EQ(width, 8);
170 EXPECT_EQ(height, 8);
171 }
172
173 // AsyncTexSubImage2D
174 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
175 decoder_->GetAsyncPixelTransferManager()->ClearPixelTransferDelegateForTest(
176 texture_ref);
177 EXPECT_EQ(texture_ref->num_observers(), 0);
178 texture->SetImmutable(false);
179 {
180 // Create transfer state since it doesn't exist.
181 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
182 .WillOnce(Return(
183 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
184 .RetiresOnSaturation();
185 EXPECT_CALL(*delegate, AsyncTexSubImage2D(_, _)).RetiresOnSaturation();
186 // Command succeeds.
187 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
188 EXPECT_EQ(GL_NO_ERROR, GetGLError());
189 EXPECT_EQ(
190 delegate,
191 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
192 texture_ref));
193 EXPECT_TRUE(texture->IsImmutable());
194 EXPECT_TRUE(texture->SafeToRenderFrom());
195 }
196 {
197 // No transfer is in progress.
198 EXPECT_CALL(*delegate, TransferIsInProgress())
199 .WillOnce(Return(false)) // texSubImage validation
200 .WillOnce(Return(false)) // async validation
201 .RetiresOnSaturation();
202 EXPECT_CALL(*delegate, AsyncTexSubImage2D(_, _)).RetiresOnSaturation();
203 // Command succeeds.
204 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
205 EXPECT_EQ(GL_NO_ERROR, GetGLError());
206 EXPECT_EQ(
207 delegate,
208 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
209 texture_ref));
210 EXPECT_TRUE(texture->IsImmutable());
211 EXPECT_TRUE(texture->SafeToRenderFrom());
212 }
213 {
214 // A transfer is still in progress!
215 EXPECT_CALL(*delegate, TransferIsInProgress())
216 .WillOnce(Return(true))
217 .RetiresOnSaturation();
218 // No async call, command fails.
219 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
220 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
221 EXPECT_EQ(
222 delegate,
223 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
224 texture_ref));
225 EXPECT_TRUE(texture->IsImmutable());
226 EXPECT_TRUE(texture->SafeToRenderFrom());
227 }
228
229 // Delete delegate on DeleteTexture.
230 {
231 EXPECT_EQ(texture_ref->num_observers(), 1);
232 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
233 DoDeleteTexture(client_texture_id_, kServiceTextureId);
234 EXPECT_FALSE(
235 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
236 texture_ref));
237 texture = NULL;
238 texture_ref = NULL;
239 delegate = NULL;
240 }
241
242 // WaitAsyncTexImage2D
243 {
244 // Get a fresh texture since the existing texture cannot be respecified
245 // asynchronously and AsyncTexSubImage2D does not involve binding.
246 EXPECT_CALL(*gl_, GenTextures(1, _))
247 .WillOnce(SetArgumentPointee<1>(kServiceTextureId));
248 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
249 texture_ref = GetTexture(client_texture_id_);
250 texture = texture_ref->texture();
251 texture->SetImmutable(false);
252 // Create transfer state since it doesn't exist.
253 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
254 .WillOnce(Return(
255 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
256 .RetiresOnSaturation();
257 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _)).RetiresOnSaturation();
258 // Start async transfer.
259 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
260 EXPECT_EQ(GL_NO_ERROR, GetGLError());
261 EXPECT_EQ(
262 delegate,
263 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
264 texture_ref));
265
266 EXPECT_TRUE(texture->IsImmutable());
267 // Wait for completion.
268 EXPECT_CALL(*delegate, WaitForTransferCompletion());
269 EXPECT_CALL(*manager, BindCompletedAsyncTransfers());
270 EXPECT_EQ(error::kNoError, ExecuteCmd(wait_cmd));
271 EXPECT_EQ(GL_NO_ERROR, GetGLError());
272 }
273
274 // WaitAllAsyncTexImage2D
275 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
276 DoDeleteTexture(client_texture_id_, kServiceTextureId);
277 EXPECT_FALSE(
278 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
279 texture_ref));
280 texture = NULL;
281 texture_ref = NULL;
282 delegate = NULL;
283 {
284 // Get a fresh texture since the existing texture cannot be respecified
285 // asynchronously and AsyncTexSubImage2D does not involve binding.
286 EXPECT_CALL(*gl_, GenTextures(1, _))
287 .WillOnce(SetArgumentPointee<1>(kServiceTextureId));
288 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
289 texture_ref = GetTexture(client_texture_id_);
290 texture = texture_ref->texture();
291 texture->SetImmutable(false);
292 // Create transfer state since it doesn't exist.
293 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
294 .WillOnce(Return(
295 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
296 .RetiresOnSaturation();
297 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _)).RetiresOnSaturation();
298 // Start async transfer.
299 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
300 EXPECT_EQ(GL_NO_ERROR, GetGLError());
301 EXPECT_EQ(
302 delegate,
303 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
304 texture_ref));
305
306 EXPECT_TRUE(texture->IsImmutable());
307 // Wait for completion of all uploads.
308 EXPECT_CALL(*manager, WaitAllAsyncTexImage2D()).RetiresOnSaturation();
309 EXPECT_CALL(*manager, BindCompletedAsyncTransfers());
310 EXPECT_EQ(error::kNoError, ExecuteCmd(wait_all_cmd));
311 EXPECT_EQ(GL_NO_ERROR, GetGLError());
312 }
313
314 // Remove PixelTransferManager before the decoder destroys.
315 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
316 decoder_->ResetAsyncPixelTransferManagerForTest();
317 manager = NULL;
318 }
319
320 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransferManager) {
321 InitState init;
322 init.extensions = "GL_CHROMIUM_async_pixel_transfers";
323 init.gl_version = "3.0";
324 init.bind_generates_resource = true;
325 InitDecoder(init);
326
327 // Set up the texture.
328 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
329 TextureRef* texture_ref = GetTexture(client_texture_id_);
330
331 // Set a mock Async delegate.
332 StrictMock<gpu::MockAsyncPixelTransferManager>* manager =
333 new StrictMock<gpu::MockAsyncPixelTransferManager>;
334 manager->Initialize(group().texture_manager());
335 decoder_->SetAsyncPixelTransferManagerForTest(manager);
336 StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = NULL;
337
338 AsyncTexImage2DCHROMIUM teximage_cmd;
339 teximage_cmd.Init(GL_TEXTURE_2D,
340 0,
341 GL_RGBA,
342 8,
343 8,
344 0,
345 GL_RGBA,
346 GL_UNSIGNED_BYTE,
347 kSharedMemoryId,
348 kSharedMemoryOffset,
349 0,
350 0,
351 0);
352
353 // No transfer delegate exists initially.
354 EXPECT_FALSE(
355 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
356 texture_ref));
357
358 // Create delegate on AsyncTexImage2D.
359 {
360 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
361 .WillOnce(Return(
362 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
363 .RetiresOnSaturation();
364 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _)).RetiresOnSaturation();
365
366 // Command succeeds.
367 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
368 EXPECT_EQ(GL_NO_ERROR, GetGLError());
369 }
370
371 // Delegate is cached.
372 EXPECT_EQ(delegate,
373 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
374 texture_ref));
375
376 // Delete delegate on manager teardown.
377 {
378 EXPECT_EQ(texture_ref->num_observers(), 1);
379 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
380 decoder_->ResetAsyncPixelTransferManagerForTest();
381 manager = NULL;
382
383 // Texture ref still valid.
384 EXPECT_EQ(texture_ref, GetTexture(client_texture_id_));
385 EXPECT_EQ(texture_ref->num_observers(), 0);
386 }
387 }
388
389 } // namespace gles2
390 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698