OLD | NEW |
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 "cc/surfaces/surface_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, | 61 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, |
62 gpu::CommandBufferId::FromUnsafeValue(id), 1); | 62 gpu::CommandBufferId::FromUnsafeValue(id), 1); |
63 return token; | 63 return token; |
64 } | 64 } |
65 | 65 |
66 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { | 66 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { |
67 public: | 67 public: |
68 SurfaceFactoryTest() | 68 SurfaceFactoryTest() |
69 : factory_( | 69 : factory_( |
70 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), | 70 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), |
71 local_frame_id_(3, 0), | 71 local_frame_id_(3, base::UnguessableToken::Create()), |
72 frame_sync_token_(GenTestSyncToken(4)), | 72 frame_sync_token_(GenTestSyncToken(4)), |
73 consumer_sync_token_(GenTestSyncToken(5)) { | 73 consumer_sync_token_(GenTestSyncToken(5)) { |
74 manager_.AddObserver(this); | 74 manager_.AddObserver(this); |
75 factory_->Create(local_frame_id_); | 75 factory_->Create(local_frame_id_); |
76 } | 76 } |
77 | 77 |
78 const SurfaceId& last_created_surface_id() const { | 78 const SurfaceId& last_created_surface_id() const { |
79 return last_created_surface_id_; | 79 return last_created_surface_id_; |
80 } | 80 } |
81 | 81 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 SCOPED_TRACE("fourth frame, second unref"); | 425 SCOPED_TRACE("fourth frame, second unref"); |
426 ResourceId expected_returned_ids[] = {12, 13}; | 426 ResourceId expected_returned_ids[] = {12, 13}; |
427 int expected_returned_counts[] = {2, 2}; | 427 int expected_returned_counts[] = {2, 2}; |
428 CheckReturnedResourcesMatchExpected( | 428 CheckReturnedResourcesMatchExpected( |
429 expected_returned_ids, expected_returned_counts, | 429 expected_returned_ids, expected_returned_counts, |
430 arraysize(expected_returned_counts), consumer_sync_token_); | 430 arraysize(expected_returned_counts), consumer_sync_token_); |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
435 LocalFrameId local_frame_id(6, 0); | 435 LocalFrameId local_frame_id(6, base::UnguessableToken::Create()); |
436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
437 factory_->Create(local_frame_id); | 437 factory_->Create(local_frame_id); |
438 Surface* surface = manager_.GetSurfaceForId(surface_id); | 438 Surface* surface = manager_.GetSurfaceForId(surface_id); |
439 ASSERT_NE(nullptr, surface); | 439 ASSERT_NE(nullptr, surface); |
440 EXPECT_EQ(2, surface->frame_index()); | 440 EXPECT_EQ(2, surface->frame_index()); |
441 | 441 |
442 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), | 442 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
443 SurfaceFactory::DrawCallback()); | 443 SurfaceFactory::DrawCallback()); |
444 EXPECT_EQ(2, surface->frame_index()); | 444 EXPECT_EQ(2, surface->frame_index()); |
445 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); | 445 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); |
446 factory_->Destroy(local_frame_id); | 446 factory_->Destroy(local_frame_id); |
447 } | 447 } |
448 | 448 |
449 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 449 void CreateSurfaceDrawCallback(SurfaceFactory* factory, |
450 uint32_t* execute_count) { | 450 uint32_t* execute_count) { |
451 LocalFrameId new_id(7, 0); | 451 LocalFrameId new_id(7, base::UnguessableToken::Create()); |
452 factory->Create(new_id); | 452 factory->Create(new_id); |
453 factory->Destroy(new_id); | 453 factory->Destroy(new_id); |
454 *execute_count += 1; | 454 *execute_count += 1; |
455 } | 455 } |
456 | 456 |
457 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { | 457 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { |
458 LocalFrameId local_frame_id(6, 0); | 458 LocalFrameId local_frame_id(6, base::UnguessableToken::Create()); |
459 factory_->Create(local_frame_id); | 459 factory_->Create(local_frame_id); |
460 | 460 |
461 uint32_t execute_count = 0; | 461 uint32_t execute_count = 0; |
462 factory_->SubmitCompositorFrame( | 462 factory_->SubmitCompositorFrame( |
463 local_frame_id, CompositorFrame(), | 463 local_frame_id, CompositorFrame(), |
464 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | 464 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), |
465 &execute_count)); | 465 &execute_count)); |
466 EXPECT_EQ(0u, execute_count); | 466 EXPECT_EQ(0u, execute_count); |
467 factory_->Destroy(local_frame_id); | 467 factory_->Destroy(local_frame_id); |
468 EXPECT_EQ(1u, execute_count); | 468 EXPECT_EQ(1u, execute_count); |
469 } | 469 } |
470 | 470 |
471 void DrawCallback(uint32_t* execute_count) { | 471 void DrawCallback(uint32_t* execute_count) { |
472 *execute_count += 1; | 472 *execute_count += 1; |
473 } | 473 } |
474 | 474 |
475 // Tests doing a DestroyAll before shutting down the factory; | 475 // Tests doing a DestroyAll before shutting down the factory; |
476 TEST_F(SurfaceFactoryTest, DestroyAll) { | 476 TEST_F(SurfaceFactoryTest, DestroyAll) { |
477 LocalFrameId id(7, 0); | 477 LocalFrameId id(7, base::UnguessableToken::Create()); |
478 factory_->Create(id); | 478 factory_->Create(id); |
479 | 479 |
480 TransferableResource resource; | 480 TransferableResource resource; |
481 resource.id = 1; | 481 resource.id = 1; |
482 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 482 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
483 CompositorFrame frame; | 483 CompositorFrame frame; |
484 frame.resource_list.push_back(resource); | 484 frame.resource_list.push_back(resource); |
485 uint32_t execute_count = 0; | 485 uint32_t execute_count = 0; |
486 factory_->SubmitCompositorFrame(id, std::move(frame), | 486 factory_->SubmitCompositorFrame(id, std::move(frame), |
487 base::Bind(&DrawCallback, &execute_count)); | 487 base::Bind(&DrawCallback, &execute_count)); |
488 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); | 488 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); |
489 local_frame_id_ = LocalFrameId(); | 489 local_frame_id_ = LocalFrameId(); |
490 factory_->DestroyAll(); | 490 factory_->DestroyAll(); |
491 EXPECT_EQ(1u, execute_count); | 491 EXPECT_EQ(1u, execute_count); |
492 } | 492 } |
493 | 493 |
494 TEST_F(SurfaceFactoryTest, DestroySequence) { | 494 TEST_F(SurfaceFactoryTest, DestroySequence) { |
495 LocalFrameId local_frame_id2(5, 0); | 495 LocalFrameId local_frame_id2(5, base::UnguessableToken::Create()); |
496 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 496 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
497 factory_->Create(local_frame_id2); | 497 factory_->Create(local_frame_id2); |
498 | 498 |
499 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 499 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
500 | 500 |
501 // Check that waiting before the sequence is satisfied works. | 501 // Check that waiting before the sequence is satisfied works. |
502 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 502 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
503 SurfaceSequence(kArbitraryFrameSinkId, 4)); | 503 SurfaceSequence(kArbitraryFrameSinkId, 4)); |
504 factory_->Destroy(local_frame_id2); | 504 factory_->Destroy(local_frame_id2); |
505 | 505 |
(...skipping 13 matching lines...) Expand all Loading... |
519 SurfaceSequence(FrameSinkId(0, 0), 6)); | 519 SurfaceSequence(FrameSinkId(0, 0), 6)); |
520 factory_->Destroy(local_frame_id2); | 520 factory_->Destroy(local_frame_id2); |
521 DCHECK(!manager_.GetSurfaceForId(id2)); | 521 DCHECK(!manager_.GetSurfaceForId(id2)); |
522 } | 522 } |
523 | 523 |
524 // Tests that Surface ID namespace invalidation correctly allows | 524 // Tests that Surface ID namespace invalidation correctly allows |
525 // Sequences to be ignored. | 525 // Sequences to be ignored. |
526 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { | 526 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { |
527 FrameSinkId frame_sink_id(1234, 5678); | 527 FrameSinkId frame_sink_id(1234, 5678); |
528 | 528 |
529 LocalFrameId local_frame_id(5, 0); | 529 LocalFrameId local_frame_id(5, base::UnguessableToken::Create()); |
530 SurfaceId id(factory_->frame_sink_id(), local_frame_id); | 530 SurfaceId id(factory_->frame_sink_id(), local_frame_id); |
531 factory_->Create(local_frame_id); | 531 factory_->Create(local_frame_id); |
532 | 532 |
533 manager_.RegisterFrameSinkId(frame_sink_id); | 533 manager_.RegisterFrameSinkId(frame_sink_id); |
534 manager_.GetSurfaceForId(id)->AddDestructionDependency( | 534 manager_.GetSurfaceForId(id)->AddDestructionDependency( |
535 SurfaceSequence(frame_sink_id, 4)); | 535 SurfaceSequence(frame_sink_id, 4)); |
536 factory_->Destroy(local_frame_id); | 536 factory_->Destroy(local_frame_id); |
537 | 537 |
538 // Verify the dependency has prevented the surface from getting destroyed. | 538 // Verify the dependency has prevented the surface from getting destroyed. |
539 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 539 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
540 | 540 |
541 manager_.InvalidateFrameSinkId(frame_sink_id); | 541 manager_.InvalidateFrameSinkId(frame_sink_id); |
542 | 542 |
543 // Verify that the invalidated namespace caused the unsatisfied sequence | 543 // Verify that the invalidated namespace caused the unsatisfied sequence |
544 // to be ignored. | 544 // to be ignored. |
545 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 545 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
546 } | 546 } |
547 | 547 |
548 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 548 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
549 LocalFrameId local_frame_id2(5, 0); | 549 LocalFrameId local_frame_id2(5, base::UnguessableToken::Create()); |
550 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 550 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
551 factory_->Create(local_frame_id2); | 551 factory_->Create(local_frame_id2); |
552 | 552 |
553 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); | 553 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); |
554 | 554 |
555 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 555 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
556 SurfaceSequence(FrameSinkId(0, 0), 4)); | 556 SurfaceSequence(FrameSinkId(0, 0), 4)); |
557 | 557 |
558 // Give id2 a frame that references local_frame_id_. | 558 // Give id2 a frame that references local_frame_id_. |
559 { | 559 { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 649 |
650 factory_->Destroy(local_frame_id_); | 650 factory_->Destroy(local_frame_id_); |
651 local_frame_id_ = LocalFrameId(); | 651 local_frame_id_ = LocalFrameId(); |
652 EXPECT_TRUE(called1); | 652 EXPECT_TRUE(called1); |
653 EXPECT_TRUE(called2); | 653 EXPECT_TRUE(called2); |
654 EXPECT_TRUE(called3); | 654 EXPECT_TRUE(called3); |
655 } | 655 } |
656 | 656 |
657 } // namespace | 657 } // namespace |
658 } // namespace cc | 658 } // namespace cc |
OLD | NEW |