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

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

Issue 197563003: gpu: Allow fences to check whether a flush has occurred (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: line brk Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gpu/command_buffer/service/mailbox_synchronizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/mailbox_manager.h" 5 #include "gpu/command_buffer/service/mailbox_manager.h"
6 6
7 #include "gpu/command_buffer/service/feature_info.h" 7 #include "gpu/command_buffer/service/feature_info.h"
8 #include "gpu/command_buffer/service/mailbox_synchronizer.h" 8 #include "gpu/command_buffer/service/mailbox_synchronizer.h"
9 #include "gpu/command_buffer/service/texture_manager.h" 9 #include "gpu/command_buffer/service/texture_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gl/gl_context_stub.h"
11 #include "ui/gl/gl_mock.h" 12 #include "ui/gl/gl_mock.h"
13 #include "ui/gl/gl_surface_stub.h"
12 14
13 namespace gpu { 15 namespace gpu {
14 namespace gles2 { 16 namespace gles2 {
15 17
16 using namespace ::testing; 18 using namespace ::testing;
17 19
18 class MailboxManagerTest : public testing::Test { 20 class MailboxManagerTest : public testing::Test {
19 public: 21 public:
20 MailboxManagerTest() {} 22 MailboxManagerTest() {}
21 virtual ~MailboxManagerTest() {} 23 virtual ~MailboxManagerTest() {}
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 MailboxManagerSyncTest() {} 183 MailboxManagerSyncTest() {}
182 virtual ~MailboxManagerSyncTest() {} 184 virtual ~MailboxManagerSyncTest() {}
183 185
184 protected: 186 protected:
185 virtual void SetUp() { 187 virtual void SetUp() {
186 MailboxSynchronizer::Initialize(); 188 MailboxSynchronizer::Initialize();
187 MailboxManagerTest::SetUp(); 189 MailboxManagerTest::SetUp();
188 manager2_ = new MailboxManager; 190 manager2_ = new MailboxManager;
189 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); 191 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
190 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); 192 ::gfx::MockGLInterface::SetGLInterface(gl_.get());
193 context_ = new gfx::GLContextStub();
194 surface_ = new gfx::GLSurfaceStub();
195 context_->MakeCurrent(surface_);
191 } 196 }
192 197
193 Texture* DefineTexture() { 198 Texture* DefineTexture() {
194 Texture* texture = CreateTexture(); 199 Texture* texture = CreateTexture();
195 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( 200 const GLsizei levels_needed = TextureManager::ComputeMipMapCount(
196 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); 201 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth);
197 SetTarget(texture, GL_TEXTURE_2D, levels_needed); 202 SetTarget(texture, GL_TEXTURE_2D, levels_needed);
198 SetLevelInfo(texture, 203 SetLevelInfo(texture,
199 GL_TEXTURE_2D, 204 GL_TEXTURE_2D,
200 0, 205 0,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 .Times(1) 247 .Times(1)
243 .RetiresOnSaturation(); 248 .RetiresOnSaturation();
244 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture)) 249 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kCurrentTexture))
245 .Times(1) 250 .Times(1)
246 .RetiresOnSaturation(); 251 .RetiresOnSaturation();
247 } 252 }
248 253
249 virtual void TearDown() { 254 virtual void TearDown() {
250 MailboxManagerTest::TearDown(); 255 MailboxManagerTest::TearDown();
251 MailboxSynchronizer::Terminate(); 256 MailboxSynchronizer::Terminate();
257 context_->ReleaseCurrent(NULL);
252 ::gfx::MockGLInterface::SetGLInterface(NULL); 258 ::gfx::MockGLInterface::SetGLInterface(NULL);
253 gl_.reset(); 259 gl_.reset();
254 } 260 }
255 261
256 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; 262 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_;
257 scoped_refptr<MailboxManager> manager2_; 263 scoped_refptr<MailboxManager> manager2_;
264 scoped_refptr<gfx::GLContext> context_;
265 scoped_refptr<gfx::GLSurface> surface_;
258 266
259 private: 267 private:
260 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); 268 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest);
261 }; 269 };
262 270
263 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { 271 TEST_F(MailboxManagerSyncTest, ProduceDestroy) {
264 Texture* texture = DefineTexture(); 272 Texture* texture = DefineTexture();
265 Mailbox name = Mailbox::Generate(); 273 Mailbox name = Mailbox::Generate();
266 274
267 InSequence sequence; 275 InSequence sequence;
268 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); 276 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture);
269 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 277 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
270 278
271 DestroyTexture(texture); 279 DestroyTexture(texture);
272 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 280 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
273 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); 281 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name));
274 } 282 }
275 283
276 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { 284 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) {
277 InSequence sequence; 285 InSequence sequence;
278 286
279 Texture* texture = DefineTexture(); 287 Texture* texture = DefineTexture();
280 Mailbox name = Mailbox::Generate(); 288 Mailbox name = Mailbox::Generate();
281 289
282 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); 290 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture);
283 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 291 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
284 292
285 // Synchronize 293 // Synchronize
286 EXPECT_CALL(*gl_, Flush()).Times(1);
287 manager_->PushTextureUpdates(); 294 manager_->PushTextureUpdates();
288 manager2_->PullTextureUpdates(); 295 manager2_->PullTextureUpdates();
289 296
290 DestroyTexture(texture); 297 DestroyTexture(texture);
291 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 298 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
292 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); 299 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name));
293 } 300 }
294 301
295 // Duplicates a texture into a second manager instance, and then 302 // Duplicates a texture into a second manager instance, and then
296 // makes sure a redefinition becomes visible there too. 303 // makes sure a redefinition becomes visible there too.
297 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { 304 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) {
298 const GLuint kNewTextureId = 1234; 305 const GLuint kNewTextureId = 1234;
299 InSequence sequence; 306 InSequence sequence;
300 307
301 Texture* texture = DefineTexture(); 308 Texture* texture = DefineTexture();
302 Mailbox name = Mailbox::Generate(); 309 Mailbox name = Mailbox::Generate();
303 310
304 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); 311 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture);
305 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 312 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name));
306 313
307 // Synchronize 314 // Synchronize
308 EXPECT_CALL(*gl_, Flush()).Times(1);
309 manager_->PushTextureUpdates(); 315 manager_->PushTextureUpdates();
310 manager2_->PullTextureUpdates(); 316 manager2_->PullTextureUpdates();
311 317
312 EXPECT_CALL(*gl_, GenTextures(1, _)) 318 EXPECT_CALL(*gl_, GenTextures(1, _))
313 .WillOnce(SetArgPointee<1>(kNewTextureId)); 319 .WillOnce(SetArgPointee<1>(kNewTextureId));
314 SetupUpdateTexParamExpectations( 320 SetupUpdateTexParamExpectations(
315 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 321 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
316 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); 322 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name);
317 EXPECT_FALSE(new_texture == NULL); 323 EXPECT_FALSE(new_texture == NULL);
318 EXPECT_NE(texture, new_texture); 324 EXPECT_NE(texture, new_texture);
319 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 325 EXPECT_EQ(kNewTextureId, new_texture->service_id());
320 326
321 // Resize original texture 327 // Resize original texture
322 SetLevelInfo(texture, 328 SetLevelInfo(texture,
323 GL_TEXTURE_2D, 329 GL_TEXTURE_2D,
324 0, 330 0,
325 GL_RGBA, 331 GL_RGBA,
326 16, 332 16,
327 32, 333 32,
328 1, 334 1,
329 0, 335 0,
330 GL_RGBA, 336 GL_RGBA,
331 GL_UNSIGNED_BYTE, 337 GL_UNSIGNED_BYTE,
332 true); 338 true);
333 // Should have been orphaned 339 // Should have been orphaned
334 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 340 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
335 341
336 // Synchronize again 342 // Synchronize again
337 EXPECT_CALL(*gl_, Flush()).Times(1);
338 manager_->PushTextureUpdates(); 343 manager_->PushTextureUpdates();
339 SetupUpdateTexParamExpectations( 344 SetupUpdateTexParamExpectations(
340 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 345 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
341 manager2_->PullTextureUpdates(); 346 manager2_->PullTextureUpdates();
342 GLsizei width, height; 347 GLsizei width, height;
343 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); 348 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height);
344 EXPECT_EQ(16, width); 349 EXPECT_EQ(16, width);
345 EXPECT_EQ(32, height); 350 EXPECT_EQ(32, height);
346 351
347 // Should have gotten a new attachment 352 // Should have gotten a new attachment
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 Mailbox name1 = Mailbox::Generate(); 394 Mailbox name1 = Mailbox::Generate();
390 Texture* texture2 = DefineTexture(); 395 Texture* texture2 = DefineTexture();
391 Mailbox name2 = Mailbox::Generate(); 396 Mailbox name2 = Mailbox::Generate();
392 Texture* new_texture1 = NULL; 397 Texture* new_texture1 = NULL;
393 Texture* new_texture2 = NULL; 398 Texture* new_texture2 = NULL;
394 399
395 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1); 400 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1);
396 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2); 401 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2);
397 402
398 // Make visible. 403 // Make visible.
399 EXPECT_CALL(*gl_, Flush()).Times(2);
400 manager_->PushTextureUpdates(); 404 manager_->PushTextureUpdates();
401 manager2_->PushTextureUpdates(); 405 manager2_->PushTextureUpdates();
402 406
403 // Create textures in the other manager instances for texture1 and texture2, 407 // Create textures in the other manager instances for texture1 and texture2,
404 // respectively to create a real sharing scenario. Otherwise, there would 408 // respectively to create a real sharing scenario. Otherwise, there would
405 // never be conflicting updates/pushes. 409 // never be conflicting updates/pushes.
406 { 410 {
407 InSequence sequence; 411 InSequence sequence;
408 EXPECT_CALL(*gl_, GenTextures(1, _)) 412 EXPECT_CALL(*gl_, GenTextures(1, _))
409 .WillOnce(SetArgPointee<1>(kNewTextureId1)); 413 .WillOnce(SetArgPointee<1>(kNewTextureId1));
(...skipping 18 matching lines...) Expand all
428 manager_->PullTextureUpdates(); 432 manager_->PullTextureUpdates();
429 433
430 // Make a change to texture2 434 // Make a change to texture2
431 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); 435 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter());
432 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 436 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
433 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); 437 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
434 438
435 Mock::VerifyAndClearExpectations(gl_.get()); 439 Mock::VerifyAndClearExpectations(gl_.get());
436 440
437 // Synchronize in both directions 441 // Synchronize in both directions
438 EXPECT_CALL(*gl_, Flush()).Times(2);
439 manager_->PushTextureUpdates(); 442 manager_->PushTextureUpdates();
440 manager2_->PushTextureUpdates(); 443 manager2_->PushTextureUpdates();
441 // manager1 should see the change to texture2 mag_filter being applied. 444 // manager1 should see the change to texture2 mag_filter being applied.
442 SetupUpdateTexParamExpectations( 445 SetupUpdateTexParamExpectations(
443 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); 446 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
444 manager_->PullTextureUpdates(); 447 manager_->PullTextureUpdates();
445 // manager2 should see the change to texture1 min_filter being applied. 448 // manager2 should see the change to texture1 min_filter being applied.
446 SetupUpdateTexParamExpectations( 449 SetupUpdateTexParamExpectations(
447 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); 450 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
448 manager2_->PullTextureUpdates(); 451 manager2_->PullTextureUpdates();
449 452
450 DestroyTexture(texture1); 453 DestroyTexture(texture1);
451 DestroyTexture(texture2); 454 DestroyTexture(texture2);
452 DestroyTexture(new_texture1); 455 DestroyTexture(new_texture1);
453 DestroyTexture(new_texture2); 456 DestroyTexture(new_texture2);
454 } 457 }
455 458
456 // TODO: different texture into same mailbox 459 // TODO: different texture into same mailbox
457 460
458 // TODO: same texture, multiple mailboxes 461 // TODO: same texture, multiple mailboxes
459 462
460 // TODO: Produce incomplete texture 463 // TODO: Produce incomplete texture
461 464
462 // TODO: Texture::level_infos_[][].size() 465 // TODO: Texture::level_infos_[][].size()
463 466
464 // TODO: unsupported targets and formats 467 // TODO: unsupported targets and formats
465 468
466 } // namespace gles2 469 } // namespace gles2
467 } // namespace gpu 470 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/mailbox_synchronizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698