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

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

Issue 1331843005: Implemented new fence syncs which replaces the old sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted mojo readme, changed wait() to take a pointer Created 5 years, 2 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 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/feature_info.h" 5 #include "gpu/command_buffer/service/feature_info.h"
6 #include "gpu/command_buffer/service/gpu_service_test.h" 6 #include "gpu/command_buffer/service/gpu_service_test.h"
7 #include "gpu/command_buffer/service/mailbox_manager_impl.h" 7 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
8 #include "gpu/command_buffer/service/mailbox_manager_sync.h" 8 #include "gpu/command_buffer/service/mailbox_manager_sync.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_context_stub.h"
12 #include "ui/gl/gl_mock.h" 12 #include "ui/gl/gl_mock.h"
13 #include "ui/gl/gl_surface_stub.h" 13 #include "ui/gl/gl_surface_stub.h"
14 14
15 namespace gpu { 15 namespace gpu {
16 namespace gles2 { 16 namespace gles2 {
17 17
18 using namespace ::testing; 18 using namespace ::testing;
19 19
20 static const SyncToken g_sync_token = {gpu::CommandBufferNamespace::GPU_IO, 123,
21 0};
22
20 class MailboxManagerTest : public GpuServiceTest { 23 class MailboxManagerTest : public GpuServiceTest {
21 public: 24 public:
22 MailboxManagerTest() {} 25 MailboxManagerTest() {}
23 ~MailboxManagerTest() override {} 26 ~MailboxManagerTest() override {}
24 27
25 protected: 28 protected:
26 void SetUp() override { 29 void SetUp() override {
27 GpuServiceTest::SetUp(); 30 GpuServiceTest::SetUp();
28 feature_info_ = new FeatureInfo; 31 feature_info_ = new FeatureInfo;
29 manager_ = new MailboxManagerImpl; 32 manager_ = new MailboxManagerImpl;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { 272 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) {
270 InSequence sequence; 273 InSequence sequence;
271 274
272 Texture* texture = DefineTexture(); 275 Texture* texture = DefineTexture();
273 Mailbox name = Mailbox::Generate(); 276 Mailbox name = Mailbox::Generate();
274 277
275 manager_->ProduceTexture(name, texture); 278 manager_->ProduceTexture(name, texture);
276 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 279 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
277 280
278 // Synchronize 281 // Synchronize
279 manager_->PushTextureUpdates(0); 282 manager_->PushTextureUpdates(g_sync_token);
280 manager2_->PullTextureUpdates(0); 283 manager2_->PullTextureUpdates(g_sync_token);
281 284
282 DestroyTexture(texture); 285 DestroyTexture(texture);
283 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 286 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
284 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 287 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
285 } 288 }
286 289
287 TEST_F(MailboxManagerSyncTest, ProduceSyncClobberDestroy) { 290 TEST_F(MailboxManagerSyncTest, ProduceSyncClobberDestroy) {
288 InSequence sequence; 291 InSequence sequence;
289 292
290 Texture* texture = DefineTexture(); 293 Texture* texture = DefineTexture();
291 Mailbox name = Mailbox::Generate(); 294 Mailbox name = Mailbox::Generate();
292 295
293 manager_->ProduceTexture(name, texture); 296 manager_->ProduceTexture(name, texture);
294 manager_->PushTextureUpdates(0); 297 manager_->PushTextureUpdates(g_sync_token);
295 298
296 // Clobber 299 // Clobber
297 Texture* old_texture = texture; 300 Texture* old_texture = texture;
298 texture = DefineTexture(); 301 texture = DefineTexture();
299 manager_->ProduceTexture(name, texture); 302 manager_->ProduceTexture(name, texture);
300 303
301 DestroyTexture(old_texture); 304 DestroyTexture(old_texture);
302 DestroyTexture(texture); 305 DestroyTexture(texture);
303 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 306 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
304 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 307 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
305 } 308 }
306 309
307 // Duplicates a texture into a second manager instance, and then 310 // Duplicates a texture into a second manager instance, and then
308 // makes sure a redefinition becomes visible there too. 311 // makes sure a redefinition becomes visible there too.
309 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { 312 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) {
310 const GLuint kNewTextureId = 1234; 313 const GLuint kNewTextureId = 1234;
311 InSequence sequence; 314 InSequence sequence;
312 315
313 Texture* texture = DefineTexture(); 316 Texture* texture = DefineTexture();
314 Mailbox name = Mailbox::Generate(); 317 Mailbox name = Mailbox::Generate();
315 318
316 manager_->ProduceTexture(name, texture); 319 manager_->ProduceTexture(name, texture);
317 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 320 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
318 321
319 // Synchronize 322 // Synchronize
320 manager_->PushTextureUpdates(0); 323 manager_->PushTextureUpdates(g_sync_token);
321 manager2_->PullTextureUpdates(0); 324 manager2_->PullTextureUpdates(g_sync_token);
322 325
323 EXPECT_CALL(*gl_, GenTextures(1, _)) 326 EXPECT_CALL(*gl_, GenTextures(1, _))
324 .WillOnce(SetArgPointee<1>(kNewTextureId)); 327 .WillOnce(SetArgPointee<1>(kNewTextureId));
325 SetupUpdateTexParamExpectations( 328 SetupUpdateTexParamExpectations(
326 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 329 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
327 Texture* new_texture = manager2_->ConsumeTexture(name); 330 Texture* new_texture = manager2_->ConsumeTexture(name);
328 EXPECT_FALSE(new_texture == NULL); 331 EXPECT_FALSE(new_texture == NULL);
329 EXPECT_NE(texture, new_texture); 332 EXPECT_NE(texture, new_texture);
330 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 333 EXPECT_EQ(kNewTextureId, new_texture->service_id());
331 334
332 // Resize original texture 335 // Resize original texture
333 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA, 336 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA,
334 GL_UNSIGNED_BYTE, gfx::Rect(16, 32)); 337 GL_UNSIGNED_BYTE, gfx::Rect(16, 32));
335 // Should have been orphaned 338 // Should have been orphaned
336 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 339 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
337 340
338 // Synchronize again 341 // Synchronize again
339 manager_->PushTextureUpdates(0); 342 manager_->PushTextureUpdates(g_sync_token);
340 SetupUpdateTexParamExpectations( 343 SetupUpdateTexParamExpectations(
341 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 344 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
342 manager2_->PullTextureUpdates(0); 345 manager2_->PullTextureUpdates(g_sync_token);
343 GLsizei width, height; 346 GLsizei width, height;
344 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr); 347 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr);
345 EXPECT_EQ(16, width); 348 EXPECT_EQ(16, width);
346 EXPECT_EQ(32, height); 349 EXPECT_EQ(32, height);
347 350
348 // Should have gotten a new attachment 351 // Should have gotten a new attachment
349 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) != NULL); 352 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) != NULL);
350 // Resize original texture again.... 353 // Resize original texture again....
351 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 1, 0, GL_RGBA, 354 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 1, 0, GL_RGBA,
352 GL_UNSIGNED_BYTE, gfx::Rect(64, 64)); 355 GL_UNSIGNED_BYTE, gfx::Rect(64, 64));
353 // ...and immediately delete the texture which should save the changes. 356 // ...and immediately delete the texture which should save the changes.
354 SetupUpdateTexParamExpectations( 357 SetupUpdateTexParamExpectations(
355 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 358 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
356 DestroyTexture(texture); 359 DestroyTexture(texture);
357 360
358 // Should be still around since there is a ref from manager2 361 // Should be still around since there is a ref from manager2
359 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); 362 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name));
360 363
361 // The last change to the texture should be visible without a sync point (i.e. 364 // The last change to the texture should be visible without a sync point (i.e.
362 // push). 365 // push).
363 manager2_->PullTextureUpdates(0); 366 manager2_->PullTextureUpdates(g_sync_token);
364 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr); 367 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr);
365 EXPECT_EQ(64, width); 368 EXPECT_EQ(64, width);
366 EXPECT_EQ(64, height); 369 EXPECT_EQ(64, height);
367 370
368 DestroyTexture(new_texture); 371 DestroyTexture(new_texture);
369 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 372 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
370 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 373 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
371 } 374 }
372 375
373 // Makes sure changes are correctly published even when updates are 376 // Makes sure changes are correctly published even when updates are
374 // pushed in both directions, i.e. makes sure we don't clobber a shared 377 // pushed in both directions, i.e. makes sure we don't clobber a shared
375 // texture definition with an older version. 378 // texture definition with an older version.
376 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { 379 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) {
377 const GLuint kNewTextureId1 = 1234; 380 const GLuint kNewTextureId1 = 1234;
378 const GLuint kNewTextureId2 = 4321; 381 const GLuint kNewTextureId2 = 4321;
379 382
380 Texture* texture1 = DefineTexture(); 383 Texture* texture1 = DefineTexture();
381 Mailbox name1 = Mailbox::Generate(); 384 Mailbox name1 = Mailbox::Generate();
382 Texture* texture2 = DefineTexture(); 385 Texture* texture2 = DefineTexture();
383 Mailbox name2 = Mailbox::Generate(); 386 Mailbox name2 = Mailbox::Generate();
384 Texture* new_texture1 = NULL; 387 Texture* new_texture1 = NULL;
385 Texture* new_texture2 = NULL; 388 Texture* new_texture2 = NULL;
386 389
387 manager_->ProduceTexture(name1, texture1); 390 manager_->ProduceTexture(name1, texture1);
388 manager2_->ProduceTexture(name2, texture2); 391 manager2_->ProduceTexture(name2, texture2);
389 392
390 // Make visible. 393 // Make visible.
391 manager_->PushTextureUpdates(0); 394 manager_->PushTextureUpdates(g_sync_token);
392 manager2_->PushTextureUpdates(0); 395 manager2_->PushTextureUpdates(g_sync_token);
393 396
394 // Create textures in the other manager instances for texture1 and texture2, 397 // Create textures in the other manager instances for texture1 and texture2,
395 // respectively to create a real sharing scenario. Otherwise, there would 398 // respectively to create a real sharing scenario. Otherwise, there would
396 // never be conflicting updates/pushes. 399 // never be conflicting updates/pushes.
397 { 400 {
398 InSequence sequence; 401 InSequence sequence;
399 EXPECT_CALL(*gl_, GenTextures(1, _)) 402 EXPECT_CALL(*gl_, GenTextures(1, _))
400 .WillOnce(SetArgPointee<1>(kNewTextureId1)); 403 .WillOnce(SetArgPointee<1>(kNewTextureId1));
401 SetupUpdateTexParamExpectations( 404 SetupUpdateTexParamExpectations(
402 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 405 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
403 new_texture1 = manager2_->ConsumeTexture(name1); 406 new_texture1 = manager2_->ConsumeTexture(name1);
404 EXPECT_CALL(*gl_, GenTextures(1, _)) 407 EXPECT_CALL(*gl_, GenTextures(1, _))
405 .WillOnce(SetArgPointee<1>(kNewTextureId2)); 408 .WillOnce(SetArgPointee<1>(kNewTextureId2));
406 SetupUpdateTexParamExpectations( 409 SetupUpdateTexParamExpectations(
407 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 410 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
408 new_texture2 = manager_->ConsumeTexture(name2); 411 new_texture2 = manager_->ConsumeTexture(name2);
409 } 412 }
410 EXPECT_EQ(kNewTextureId1, new_texture1->service_id()); 413 EXPECT_EQ(kNewTextureId1, new_texture1->service_id());
411 EXPECT_EQ(kNewTextureId2, new_texture2->service_id()); 414 EXPECT_EQ(kNewTextureId2, new_texture2->service_id());
412 415
413 // Make a change to texture1 416 // Make a change to texture1
414 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter()); 417 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter());
415 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 418 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
416 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 419 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
417 420
418 // Make sure this does not clobber it with the previous version we pushed. 421 // Make sure this does not clobber it with the previous version we pushed.
419 manager_->PullTextureUpdates(0); 422 manager_->PullTextureUpdates(g_sync_token);
420 423
421 // Make a change to texture2 424 // Make a change to texture2
422 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); 425 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter());
423 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 426 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
424 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); 427 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
425 428
426 Mock::VerifyAndClearExpectations(gl_.get()); 429 Mock::VerifyAndClearExpectations(gl_.get());
427 430
428 // Synchronize in both directions 431 // Synchronize in both directions
429 manager_->PushTextureUpdates(0); 432 manager_->PushTextureUpdates(g_sync_token);
430 manager2_->PushTextureUpdates(0); 433 manager2_->PushTextureUpdates(g_sync_token);
431 // manager1 should see the change to texture2 mag_filter being applied. 434 // manager1 should see the change to texture2 mag_filter being applied.
432 SetupUpdateTexParamExpectations( 435 SetupUpdateTexParamExpectations(
433 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); 436 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
434 manager_->PullTextureUpdates(0); 437 manager_->PullTextureUpdates(g_sync_token);
435 // manager2 should see the change to texture1 min_filter being applied. 438 // manager2 should see the change to texture1 min_filter being applied.
436 SetupUpdateTexParamExpectations( 439 SetupUpdateTexParamExpectations(
437 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); 440 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
438 manager2_->PullTextureUpdates(0); 441 manager2_->PullTextureUpdates(g_sync_token);
439 442
440 DestroyTexture(texture1); 443 DestroyTexture(texture1);
441 DestroyTexture(texture2); 444 DestroyTexture(texture2);
442 DestroyTexture(new_texture1); 445 DestroyTexture(new_texture1);
443 DestroyTexture(new_texture2); 446 DestroyTexture(new_texture2);
444 } 447 }
445 448
446 // If a texture is shared with another manager instance, but the mailbox 449 // If a texture is shared with another manager instance, but the mailbox
447 // is then clobbered with a different texture in the source context, this should 450 // is then clobbered with a different texture in the source context, this should
448 // disconnect the earlier texture from updates. 451 // disconnect the earlier texture from updates.
449 TEST_F(MailboxManagerSyncTest, ProduceAndClobber) { 452 TEST_F(MailboxManagerSyncTest, ProduceAndClobber) {
450 const GLuint kNewTextureId = 1234; 453 const GLuint kNewTextureId = 1234;
451 InSequence sequence; 454 InSequence sequence;
452 455
453 Texture* texture = DefineTexture(); 456 Texture* texture = DefineTexture();
454 Mailbox name = Mailbox::Generate(); 457 Mailbox name = Mailbox::Generate();
455 458
456 manager_->ProduceTexture(name, texture); 459 manager_->ProduceTexture(name, texture);
457 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 460 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
458 461
459 // Synchronize 462 // Synchronize
460 manager_->PushTextureUpdates(0); 463 manager_->PushTextureUpdates(g_sync_token);
461 manager2_->PullTextureUpdates(0); 464 manager2_->PullTextureUpdates(g_sync_token);
462 465
463 EXPECT_CALL(*gl_, GenTextures(1, _)) 466 EXPECT_CALL(*gl_, GenTextures(1, _))
464 .WillOnce(SetArgPointee<1>(kNewTextureId)); 467 .WillOnce(SetArgPointee<1>(kNewTextureId));
465 SetupUpdateTexParamExpectations( 468 SetupUpdateTexParamExpectations(
466 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 469 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
467 Texture* new_texture = manager2_->ConsumeTexture(name); 470 Texture* new_texture = manager2_->ConsumeTexture(name);
468 EXPECT_FALSE(new_texture == NULL); 471 EXPECT_FALSE(new_texture == NULL);
469 EXPECT_NE(texture, new_texture); 472 EXPECT_NE(texture, new_texture);
470 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 473 EXPECT_EQ(kNewTextureId, new_texture->service_id());
471 474
472 Texture* old_texture = texture; 475 Texture* old_texture = texture;
473 texture = DefineTexture(); 476 texture = DefineTexture();
474 manager_->ProduceTexture(name, texture); 477 manager_->ProduceTexture(name, texture);
475 478
476 // Make a change to the new texture 479 // Make a change to the new texture
477 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter()); 480 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter());
478 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 481 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
479 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 482 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
480 483
481 // Synchronize in both directions - no changes, since it's not shared 484 // Synchronize in both directions - no changes, since it's not shared
482 manager_->PushTextureUpdates(0); 485 manager_->PushTextureUpdates(g_sync_token);
483 manager2_->PullTextureUpdates(0); 486 manager2_->PullTextureUpdates(g_sync_token);
484 EXPECT_EQ(static_cast<GLuint>(GL_LINEAR), new_texture->min_filter()); 487 EXPECT_EQ(static_cast<GLuint>(GL_LINEAR), new_texture->min_filter());
485 488
486 // Make a change to the previously shared texture 489 // Make a change to the previously shared texture
487 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), old_texture->mag_filter()); 490 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), old_texture->mag_filter());
488 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 491 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
489 SetParameter(old_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); 492 SetParameter(old_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
490 493
491 // Synchronize and expect update 494 // Synchronize and expect update
492 manager_->PushTextureUpdates(0); 495 manager_->PushTextureUpdates(g_sync_token);
493 SetupUpdateTexParamExpectations( 496 SetupUpdateTexParamExpectations(
494 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); 497 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
495 manager2_->PullTextureUpdates(0); 498 manager2_->PullTextureUpdates(g_sync_token);
496 499
497 EXPECT_CALL(*gl_, GenTextures(1, _)) 500 EXPECT_CALL(*gl_, GenTextures(1, _))
498 .WillOnce(SetArgPointee<1>(kNewTextureId)); 501 .WillOnce(SetArgPointee<1>(kNewTextureId));
499 SetupUpdateTexParamExpectations( 502 SetupUpdateTexParamExpectations(
500 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); 503 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
501 Texture* tmp_texture = manager2_->ConsumeTexture(name); 504 Texture* tmp_texture = manager2_->ConsumeTexture(name);
502 EXPECT_NE(new_texture, tmp_texture); 505 EXPECT_NE(new_texture, tmp_texture);
503 DestroyTexture(tmp_texture); 506 DestroyTexture(tmp_texture);
504 507
505 DestroyTexture(old_texture); 508 DestroyTexture(old_texture);
506 DestroyTexture(texture); 509 DestroyTexture(texture);
507 DestroyTexture(new_texture); 510 DestroyTexture(new_texture);
508 511
509 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 512 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
510 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 513 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
511 } 514 }
512 515
513 TEST_F(MailboxManagerSyncTest, ClearedStateSynced) { 516 TEST_F(MailboxManagerSyncTest, ClearedStateSynced) {
514 const GLuint kNewTextureId = 1234; 517 const GLuint kNewTextureId = 1234;
515 518
516 Texture* texture = DefineTexture(); 519 Texture* texture = DefineTexture();
517 EXPECT_TRUE(texture->SafeToRenderFrom()); 520 EXPECT_TRUE(texture->SafeToRenderFrom());
518 521
519 Mailbox name = Mailbox::Generate(); 522 Mailbox name = Mailbox::Generate();
520 523
521 manager_->ProduceTexture(name, texture); 524 manager_->ProduceTexture(name, texture);
522 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 525 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
523 526
524 // Synchronize 527 // Synchronize
525 manager_->PushTextureUpdates(0); 528 manager_->PushTextureUpdates(g_sync_token);
526 manager2_->PullTextureUpdates(0); 529 manager2_->PullTextureUpdates(g_sync_token);
527 530
528 EXPECT_CALL(*gl_, GenTextures(1, _)) 531 EXPECT_CALL(*gl_, GenTextures(1, _))
529 .WillOnce(SetArgPointee<1>(kNewTextureId)); 532 .WillOnce(SetArgPointee<1>(kNewTextureId));
530 SetupUpdateTexParamExpectations( 533 SetupUpdateTexParamExpectations(
531 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 534 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
532 Texture* new_texture = manager2_->ConsumeTexture(name); 535 Texture* new_texture = manager2_->ConsumeTexture(name);
533 EXPECT_FALSE(new_texture == NULL); 536 EXPECT_FALSE(new_texture == NULL);
534 EXPECT_NE(texture, new_texture); 537 EXPECT_NE(texture, new_texture);
535 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 538 EXPECT_EQ(kNewTextureId, new_texture->service_id());
536 EXPECT_TRUE(texture->SafeToRenderFrom()); 539 EXPECT_TRUE(texture->SafeToRenderFrom());
537 540
538 // Change cleared to false. 541 // Change cleared to false.
539 SetLevelCleared(texture, texture->target(), 0, false); 542 SetLevelCleared(texture, texture->target(), 0, false);
540 EXPECT_FALSE(texture->SafeToRenderFrom()); 543 EXPECT_FALSE(texture->SafeToRenderFrom());
541 544
542 // Synchronize 545 // Synchronize
543 manager_->PushTextureUpdates(0); 546 manager_->PushTextureUpdates(g_sync_token);
544 SetupUpdateTexParamExpectations( 547 SetupUpdateTexParamExpectations(
545 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 548 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
546 manager2_->PullTextureUpdates(0); 549 manager2_->PullTextureUpdates(g_sync_token);
547 550
548 // Cleared state should be synced. 551 // Cleared state should be synced.
549 EXPECT_FALSE(new_texture->SafeToRenderFrom()); 552 EXPECT_FALSE(new_texture->SafeToRenderFrom());
550 553
551 DestroyTexture(texture); 554 DestroyTexture(texture);
552 DestroyTexture(new_texture); 555 DestroyTexture(new_texture);
553 556
554 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 557 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
555 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 558 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
556 } 559 }
557 560
558 TEST_F(MailboxManagerSyncTest, SyncIncompleteTexture) { 561 TEST_F(MailboxManagerSyncTest, SyncIncompleteTexture) {
559 const GLuint kNewTextureId = 1234; 562 const GLuint kNewTextureId = 1234;
560 563
561 // Create but not define texture. 564 // Create but not define texture.
562 Texture* texture = CreateTexture(); 565 Texture* texture = CreateTexture();
563 SetTarget(texture, GL_TEXTURE_2D, 1); 566 SetTarget(texture, GL_TEXTURE_2D, 1);
564 EXPECT_FALSE(texture->IsDefined()); 567 EXPECT_FALSE(texture->IsDefined());
565 568
566 Mailbox name = Mailbox::Generate(); 569 Mailbox name = Mailbox::Generate();
567 manager_->ProduceTexture(name, texture); 570 manager_->ProduceTexture(name, texture);
568 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 571 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
569 572
570 // Synchronize 573 // Synchronize
571 manager_->PushTextureUpdates(0); 574 manager_->PushTextureUpdates(g_sync_token);
572 manager2_->PullTextureUpdates(0); 575 manager2_->PullTextureUpdates(g_sync_token);
573 576
574 // Should sync to new texture which is not defined. 577 // Should sync to new texture which is not defined.
575 EXPECT_CALL(*gl_, GenTextures(1, _)) 578 EXPECT_CALL(*gl_, GenTextures(1, _))
576 .WillOnce(SetArgPointee<1>(kNewTextureId)); 579 .WillOnce(SetArgPointee<1>(kNewTextureId));
577 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(), 580 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(),
578 texture->mag_filter(), texture->wrap_s(), 581 texture->mag_filter(), texture->wrap_s(),
579 texture->wrap_t()); 582 texture->wrap_t());
580 Texture* new_texture = manager2_->ConsumeTexture(name); 583 Texture* new_texture = manager2_->ConsumeTexture(name);
581 ASSERT_TRUE(new_texture); 584 ASSERT_TRUE(new_texture);
582 EXPECT_NE(texture, new_texture); 585 EXPECT_NE(texture, new_texture);
583 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 586 EXPECT_EQ(kNewTextureId, new_texture->service_id());
584 EXPECT_FALSE(new_texture->IsDefined()); 587 EXPECT_FALSE(new_texture->IsDefined());
585 588
586 // Change cleared to false. 589 // Change cleared to false.
587 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, 590 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA,
588 GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); 591 GL_UNSIGNED_BYTE, gfx::Rect(1, 1));
589 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 592 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
590 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 593 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
591 EXPECT_TRUE(texture->IsDefined()); 594 EXPECT_TRUE(texture->IsDefined());
592 595
593 // Synchronize 596 // Synchronize
594 manager_->PushTextureUpdates(0); 597 manager_->PushTextureUpdates(g_sync_token);
595 SetupUpdateTexParamExpectations( 598 SetupUpdateTexParamExpectations(
596 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 599 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
597 manager2_->PullTextureUpdates(0); 600 manager2_->PullTextureUpdates(g_sync_token);
598 601
599 // Cleared state should be synced. 602 // Cleared state should be synced.
600 EXPECT_TRUE(new_texture->IsDefined()); 603 EXPECT_TRUE(new_texture->IsDefined());
601 604
602 DestroyTexture(texture); 605 DestroyTexture(texture);
603 DestroyTexture(new_texture); 606 DestroyTexture(new_texture);
604 607
605 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 608 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
606 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 609 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
607 } 610 }
608 611
609 // Putting the same texture into multiple mailboxes should result in sharing 612 // Putting the same texture into multiple mailboxes should result in sharing
610 // only a single texture also within a synchronized manager instance. 613 // only a single texture also within a synchronized manager instance.
611 TEST_F(MailboxManagerSyncTest, SharedThroughMultipleMailboxes) { 614 TEST_F(MailboxManagerSyncTest, SharedThroughMultipleMailboxes) {
612 const GLuint kNewTextureId = 1234; 615 const GLuint kNewTextureId = 1234;
613 InSequence sequence; 616 InSequence sequence;
614 617
615 Texture* texture = DefineTexture(); 618 Texture* texture = DefineTexture();
616 Mailbox name1 = Mailbox::Generate(); 619 Mailbox name1 = Mailbox::Generate();
617 Mailbox name2 = Mailbox::Generate(); 620 Mailbox name2 = Mailbox::Generate();
618 621
619 manager_->ProduceTexture(name1, texture); 622 manager_->ProduceTexture(name1, texture);
620 623
621 // Share 624 // Share
622 manager_->PushTextureUpdates(0); 625 manager_->PushTextureUpdates(g_sync_token);
623 EXPECT_CALL(*gl_, GenTextures(1, _)) 626 EXPECT_CALL(*gl_, GenTextures(1, _))
624 .WillOnce(SetArgPointee<1>(kNewTextureId)); 627 .WillOnce(SetArgPointee<1>(kNewTextureId));
625 manager2_->PullTextureUpdates(0); 628 manager2_->PullTextureUpdates(g_sync_token);
626 SetupUpdateTexParamExpectations( 629 SetupUpdateTexParamExpectations(
627 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 630 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
628 Texture* new_texture = manager2_->ConsumeTexture(name1); 631 Texture* new_texture = manager2_->ConsumeTexture(name1);
629 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 632 EXPECT_EQ(kNewTextureId, new_texture->service_id());
630 633
631 manager_->ProduceTexture(name2, texture); 634 manager_->ProduceTexture(name2, texture);
632 635
633 // Synchronize 636 // Synchronize
634 manager_->PushTextureUpdates(0); 637 manager_->PushTextureUpdates(g_sync_token);
635 manager2_->PullTextureUpdates(0); 638 manager2_->PullTextureUpdates(g_sync_token);
636 639
637 // name2 should return the same texture 640 // name2 should return the same texture
638 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2)); 641 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2));
639 642
640 // Even after destroying the source texture, the original mailbox should 643 // Even after destroying the source texture, the original mailbox should
641 // still exist. 644 // still exist.
642 DestroyTexture(texture); 645 DestroyTexture(texture);
643 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name1)); 646 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name1));
644 DestroyTexture(new_texture); 647 DestroyTexture(new_texture);
645 } 648 }
646 649
647 // A: produce texture1 into M, B: consume into new_texture 650 // A: produce texture1 into M, B: consume into new_texture
648 // B: produce texture2 into M, A: produce texture1 into M 651 // B: produce texture2 into M, A: produce texture1 into M
649 // B: consume M should return new_texture 652 // B: consume M should return new_texture
650 TEST_F(MailboxManagerSyncTest, ProduceBothWays) { 653 TEST_F(MailboxManagerSyncTest, ProduceBothWays) {
651 const GLuint kNewTextureId = 1234; 654 const GLuint kNewTextureId = 1234;
652 InSequence sequence; 655 InSequence sequence;
653 656
654 Texture* texture1 = DefineTexture(); 657 Texture* texture1 = DefineTexture();
655 Texture* texture2 = DefineTexture(); 658 Texture* texture2 = DefineTexture();
656 Mailbox name = Mailbox::Generate(); 659 Mailbox name = Mailbox::Generate();
657 660
658 manager_->ProduceTexture(name, texture1); 661 manager_->ProduceTexture(name, texture1);
659 662
660 // Share 663 // Share
661 manager_->PushTextureUpdates(0); 664 manager_->PushTextureUpdates(g_sync_token);
662 EXPECT_CALL(*gl_, GenTextures(1, _)) 665 EXPECT_CALL(*gl_, GenTextures(1, _))
663 .WillOnce(SetArgPointee<1>(kNewTextureId)); 666 .WillOnce(SetArgPointee<1>(kNewTextureId));
664 SetupUpdateTexParamExpectations( 667 SetupUpdateTexParamExpectations(
665 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 668 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
666 Texture* new_texture = manager2_->ConsumeTexture(name); 669 Texture* new_texture = manager2_->ConsumeTexture(name);
667 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 670 EXPECT_EQ(kNewTextureId, new_texture->service_id());
668 671
669 // Clobber 672 // Clobber
670 manager2_->ProduceTexture(name, texture2); 673 manager2_->ProduceTexture(name, texture2);
671 manager_->ProduceTexture(name, texture1); 674 manager_->ProduceTexture(name, texture1);
672 675
673 // Synchronize manager -> manager2 676 // Synchronize manager -> manager2
674 manager_->PushTextureUpdates(0); 677 manager_->PushTextureUpdates(g_sync_token);
675 manager2_->PullTextureUpdates(0); 678 manager2_->PullTextureUpdates(g_sync_token);
676 679
677 // name should return the original texture, and not texture2 or a new one. 680 // name should return the original texture, and not texture2 or a new one.
678 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); 681 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name));
679 682
680 DestroyTexture(texture1); 683 DestroyTexture(texture1);
681 DestroyTexture(texture2); 684 DestroyTexture(texture2);
682 DestroyTexture(new_texture); 685 DestroyTexture(new_texture);
683 } 686 }
684 687
685 // TODO: Texture::level_infos_[][].size() 688 // TODO: Texture::level_infos_[][].size()
686 689
687 // TODO: unsupported targets and formats 690 // TODO: unsupported targets and formats
688 691
689 } // namespace gles2 692 } // namespace gles2
690 } // namespace gpu 693 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/mailbox_manager_sync.cc ('k') | gpu/command_buffer/service/sync_point_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698