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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { | 67 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { |
68 public: | 68 public: |
69 SurfaceFactoryTest() | 69 SurfaceFactoryTest() |
70 : factory_( | 70 : factory_( |
71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), | 71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), |
72 local_frame_id_(3, 1), | 72 local_frame_id_(3, 1), |
73 frame_sync_token_(GenTestSyncToken(4)), | 73 frame_sync_token_(GenTestSyncToken(4)), |
74 consumer_sync_token_(GenTestSyncToken(5)) { | 74 consumer_sync_token_(GenTestSyncToken(5)) { |
75 manager_.AddObserver(this); | 75 manager_.AddObserver(this); |
76 factory_->Create(local_frame_id_); | 76 factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(), |
77 SurfaceFactory::DrawCallback()); | |
77 } | 78 } |
78 | 79 |
79 const SurfaceId& last_created_surface_id() const { | 80 const SurfaceId& last_created_surface_id() const { |
80 return last_created_surface_id_; | 81 return last_created_surface_id_; |
81 } | 82 } |
82 | 83 |
83 // SurfaceObserver implementation. | 84 // SurfaceObserver implementation. |
84 void OnSurfaceCreated(const SurfaceId& surface_id, | 85 void OnSurfaceCreated(const SurfaceId& surface_id, |
85 const gfx::Size& frame, | 86 const gfx::Size& frame, |
86 float device_scale_factor) override { | 87 float device_scale_factor) override { |
87 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id()); | 88 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id()); |
88 last_created_surface_id_ = surface_id; | 89 last_created_surface_id_ = surface_id; |
89 } | 90 } |
90 | 91 |
91 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { | 92 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { |
92 *changed = true; | 93 *changed = true; |
93 } | 94 } |
94 | 95 |
95 ~SurfaceFactoryTest() override { | 96 ~SurfaceFactoryTest() override { |
96 if (local_frame_id_.is_valid()) | |
97 factory_->Destroy(local_frame_id_); | |
98 manager_.RemoveObserver(this); | 97 manager_.RemoveObserver(this); |
99 } | 98 } |
100 | 99 |
101 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 100 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
102 size_t num_resource_ids) { | 101 size_t num_resource_ids) { |
103 CompositorFrame frame; | 102 CompositorFrame frame; |
104 for (size_t i = 0u; i < num_resource_ids; ++i) { | 103 for (size_t i = 0u; i < num_resource_ids; ++i) { |
105 TransferableResource resource; | 104 TransferableResource resource; |
106 resource.id = resource_ids[i]; | 105 resource.id = resource_ids[i]; |
107 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 106 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 int expected_returned_counts[] = {2, 2}; | 427 int expected_returned_counts[] = {2, 2}; |
429 CheckReturnedResourcesMatchExpected( | 428 CheckReturnedResourcesMatchExpected( |
430 expected_returned_ids, expected_returned_counts, | 429 expected_returned_ids, expected_returned_counts, |
431 arraysize(expected_returned_counts), consumer_sync_token_); | 430 arraysize(expected_returned_counts), consumer_sync_token_); |
432 } | 431 } |
433 } | 432 } |
434 | 433 |
435 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
436 LocalFrameId local_frame_id(6, 1); | 435 LocalFrameId local_frame_id(6, 1); |
437 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); | 436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); |
438 factory_->Create(local_frame_id); | 437 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
438 SurfaceFactory::DrawCallback()); | |
439 Surface* surface = manager_.GetSurfaceForId(surface_id); | 439 Surface* surface = manager_.GetSurfaceForId(surface_id); |
440 ASSERT_NE(nullptr, surface); | 440 ASSERT_NE(nullptr, surface); |
441 EXPECT_EQ(2, surface->frame_index()); | 441 EXPECT_EQ(2, surface->frame_index()); |
442 | |
443 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), | |
444 SurfaceFactory::DrawCallback()); | |
445 EXPECT_EQ(2, surface->frame_index()); | |
446 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); | 442 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); |
447 factory_->Destroy(local_frame_id); | |
448 } | 443 } |
449 | 444 |
450 void CreateSurfaceDrawCallback(SurfaceFactory* factory, | 445 // Tests that SurfaceFactory doesn't return resources after Reset(). |
451 uint32_t* execute_count) { | 446 TEST_F(SurfaceFactoryTest, Reset) { |
452 LocalFrameId new_id(7, 0); | 447 LocalFrameId id(7, 0); |
453 factory->Create(new_id); | |
454 factory->Destroy(new_id); | |
455 *execute_count += 1; | |
456 } | |
457 | |
458 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { | |
459 LocalFrameId local_frame_id(6, 1); | |
460 factory_->Create(local_frame_id); | |
461 | |
462 uint32_t execute_count = 0; | |
463 factory_->SubmitCompositorFrame( | |
464 local_frame_id, CompositorFrame(), | |
465 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), | |
466 &execute_count)); | |
467 EXPECT_EQ(0u, execute_count); | |
468 factory_->Destroy(local_frame_id); | |
469 EXPECT_EQ(1u, execute_count); | |
470 } | |
471 | |
472 void DrawCallback(uint32_t* execute_count) { | |
473 *execute_count += 1; | |
474 } | |
475 | |
476 // Tests doing a DestroyAll before shutting down the factory; | |
477 TEST_F(SurfaceFactoryTest, DestroyAll) { | |
478 LocalFrameId id(7, 1); | |
479 factory_->Create(id); | |
480 | 448 |
481 TransferableResource resource; | 449 TransferableResource resource; |
482 resource.id = 1; | 450 resource.id = 1; |
483 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 451 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
484 CompositorFrame frame; | 452 CompositorFrame frame; |
485 frame.resource_list.push_back(resource); | 453 frame.resource_list.push_back(resource); |
486 uint32_t execute_count = 0; | |
487 factory_->SubmitCompositorFrame(id, std::move(frame), | 454 factory_->SubmitCompositorFrame(id, std::move(frame), |
488 base::Bind(&DrawCallback, &execute_count)); | 455 SurfaceFactory::DrawCallback()); |
489 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); | |
490 local_frame_id_ = LocalFrameId(); | |
491 factory_->DestroyAll(); | |
492 EXPECT_EQ(1u, execute_count); | |
493 } | |
494 | |
495 // Tests that SurfaceFactory doesn't return resources after Reset(). | |
496 TEST_F(SurfaceFactoryTest, Reset) { | |
497 LocalFrameId id(7, 0); | |
498 factory_->Create(id); | |
499 | |
500 TransferableResource resource; | |
501 resource.id = 1; | |
502 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | |
503 CompositorFrame frame; | |
504 frame.resource_list.push_back(resource); | |
505 uint32_t execute_count = 0; | |
506 factory_->SubmitCompositorFrame(id, std::move(frame), | |
507 base::Bind(&DrawCallback, &execute_count)); | |
508 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); | 456 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); |
509 | 457 |
510 SurfaceId surface_id(kArbitraryFrameSinkId, id); | 458 SurfaceId surface_id(kArbitraryFrameSinkId, id); |
511 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); | 459 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); |
512 factory_->Reset(); | 460 factory_->Reset(); |
513 EXPECT_TRUE(client_.returned_resources().empty()); | 461 EXPECT_TRUE(client_.returned_resources().empty()); |
514 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); | 462 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); |
515 EXPECT_TRUE(client_.returned_resources().empty()); | 463 EXPECT_TRUE(client_.returned_resources().empty()); |
516 local_frame_id_ = LocalFrameId(); | 464 local_frame_id_ = LocalFrameId(); |
517 } | 465 } |
518 | 466 |
519 TEST_F(SurfaceFactoryTest, DestroySequence) { | 467 TEST_F(SurfaceFactoryTest, DestroySequence) { |
520 LocalFrameId local_frame_id2(5, 1); | 468 LocalFrameId local_frame_id2(5, 1); |
469 std::unique_ptr<SurfaceFactory> factory2( | |
470 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); | |
521 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 471 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
522 factory_->Create(local_frame_id2); | 472 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(), |
473 SurfaceFactory::DrawCallback()); | |
523 | 474 |
524 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); | 475 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); |
525 | 476 |
526 // Check that waiting before the sequence is satisfied works. | 477 // Check that waiting before the sequence is satisfied works. |
527 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 478 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
528 SurfaceSequence(kArbitraryFrameSinkId, 4)); | 479 SurfaceSequence(kArbitraryFrameSinkId, 4)); |
529 factory_->Destroy(local_frame_id2); | 480 factory2->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(), |
Fady Samuel
2016/11/10 23:33:37
If staraz@ lands his patch first then this will no
danakj
2016/11/10 23:57:58
Also if you use 0s to signify nothing instead of O
Saman Sami
2016/11/11 17:49:59
Done.
| |
481 SurfaceFactory::DrawCallback()); | |
530 | 482 |
531 CompositorFrame frame; | 483 CompositorFrame frame; |
532 frame.metadata.satisfies_sequences.push_back(6); | 484 frame.metadata.satisfies_sequences.push_back(6); |
533 frame.metadata.satisfies_sequences.push_back(4); | 485 frame.metadata.satisfies_sequences.push_back(4); |
534 DCHECK(manager_.GetSurfaceForId(id2)); | 486 DCHECK(manager_.GetSurfaceForId(id2)); |
535 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 487 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
536 SurfaceFactory::DrawCallback()); | 488 SurfaceFactory::DrawCallback()); |
537 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); | |
538 DCHECK(!manager_.GetSurfaceForId(id2)); | 489 DCHECK(!manager_.GetSurfaceForId(id2)); |
539 | 490 |
540 // Check that waiting after the sequence is satisfied works. | 491 // Check that waiting after the sequence is satisfied works. |
541 factory_->Create(local_frame_id2); | 492 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(), |
493 SurfaceFactory::DrawCallback()); | |
542 DCHECK(manager_.GetSurfaceForId(id2)); | 494 DCHECK(manager_.GetSurfaceForId(id2)); |
543 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | 495 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
544 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); | 496 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); |
545 factory_->Destroy(local_frame_id2); | 497 factory2->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(), |
498 SurfaceFactory::DrawCallback()); | |
546 DCHECK(!manager_.GetSurfaceForId(id2)); | 499 DCHECK(!manager_.GetSurfaceForId(id2)); |
547 } | 500 } |
548 | 501 |
549 // Tests that Surface ID namespace invalidation correctly allows | 502 // Tests that Surface ID namespace invalidation correctly allows |
550 // Sequences to be ignored. | 503 // Sequences to be ignored. |
551 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { | 504 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { |
552 FrameSinkId frame_sink_id(1234, 5678); | 505 FrameSinkId frame_sink_id(1234, 5678); |
553 | 506 |
554 LocalFrameId local_frame_id(5, 1); | 507 LocalFrameId local_frame_id(5, 1); |
555 SurfaceId id(factory_->frame_sink_id(), local_frame_id); | 508 SurfaceId id(factory_->frame_sink_id(), local_frame_id); |
556 factory_->Create(local_frame_id); | 509 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), |
510 SurfaceFactory::DrawCallback()); | |
557 | 511 |
558 manager_.RegisterFrameSinkId(frame_sink_id); | 512 manager_.RegisterFrameSinkId(frame_sink_id); |
559 manager_.GetSurfaceForId(id)->AddDestructionDependency( | 513 manager_.GetSurfaceForId(id)->AddDestructionDependency( |
560 SurfaceSequence(frame_sink_id, 4)); | 514 SurfaceSequence(frame_sink_id, 4)); |
561 factory_->Destroy(local_frame_id); | 515 |
516 LocalFrameId local_frame_id_2(6, 0); | |
517 factory_->SubmitCompositorFrame(local_frame_id_2, CompositorFrame(), | |
518 SurfaceFactory::DrawCallback()); | |
562 | 519 |
563 // Verify the dependency has prevented the surface from getting destroyed. | 520 // Verify the dependency has prevented the surface from getting destroyed. |
564 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 521 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
565 | 522 |
566 manager_.InvalidateFrameSinkId(frame_sink_id); | 523 manager_.InvalidateFrameSinkId(frame_sink_id); |
567 | 524 |
568 // Verify that the invalidated namespace caused the unsatisfied sequence | 525 // Verify that the invalidated namespace caused the unsatisfied sequence |
569 // to be ignored. | 526 // to be ignored. |
570 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 527 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
571 } | 528 } |
572 | 529 |
573 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 530 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
574 LocalFrameId local_frame_id2(5, 1); | 531 LocalFrameId local_frame_id2(5, 1); |
575 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); | 532 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); |
576 factory_->Create(local_frame_id2); | 533 std::unique_ptr<SurfaceFactory> factory2( |
577 | 534 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)); |
578 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); | 535 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); |
579 | |
580 manager_.GetSurfaceForId(id2)->AddDestructionDependency( | |
581 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); | |
582 | |
583 // Give id2 a frame that references local_frame_id_. | 536 // Give id2 a frame that references local_frame_id_. |
584 { | 537 { |
585 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 538 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
586 CompositorFrame frame; | 539 CompositorFrame frame; |
587 frame.render_pass_list.push_back(std::move(render_pass)); | 540 frame.render_pass_list.push_back(std::move(render_pass)); |
588 frame.metadata.referenced_surfaces.push_back( | 541 frame.metadata.referenced_surfaces.push_back( |
589 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); | 542 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); |
590 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), | 543 factory2->SubmitCompositorFrame(local_frame_id2, std::move(frame), |
591 SurfaceFactory::DrawCallback()); | 544 SurfaceFactory::DrawCallback()); |
592 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); | 545 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); |
593 } | 546 } |
594 factory_->Destroy(local_frame_id2); | 547 manager_.GetSurfaceForId(id2)->AddDestructionDependency( |
595 | 548 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); |
549 factory2->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(), | |
550 SurfaceFactory::DrawCallback()); | |
596 // Give local_frame_id_ a frame that references id2. | 551 // Give local_frame_id_ a frame that references id2. |
597 { | 552 { |
598 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); | 553 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); |
599 CompositorFrame frame; | 554 CompositorFrame frame; |
600 frame.render_pass_list.push_back(std::move(render_pass)); | 555 frame.render_pass_list.push_back(std::move(render_pass)); |
601 frame.metadata.referenced_surfaces.push_back(id2); | 556 frame.metadata.referenced_surfaces.push_back(id2); |
602 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 557 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
603 SurfaceFactory::DrawCallback()); | 558 SurfaceFactory::DrawCallback()); |
604 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); | |
605 } | 559 } |
606 factory_->Destroy(local_frame_id_); | 560 factory_->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(), |
561 SurfaceFactory::DrawCallback()); | |
607 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); | 562 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
608 // local_frame_id_ should be retained by reference from id2. | 563 // local_frame_id_ should be retained by reference from id2. |
609 EXPECT_TRUE(manager_.GetSurfaceForId( | 564 EXPECT_TRUE(manager_.GetSurfaceForId( |
610 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); | 565 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); |
611 | 566 |
612 // Satisfy last destruction dependency for id2. | 567 // Satisfy last destruction dependency for id2. |
613 std::vector<uint32_t> to_satisfy; | 568 std::vector<uint32_t> to_satisfy; |
614 to_satisfy.push_back(4); | 569 to_satisfy.push_back(4); |
615 manager_.DidSatisfySequences(kAnotherArbitraryFrameSinkId, &to_satisfy); | 570 manager_.DidSatisfySequences(kAnotherArbitraryFrameSinkId, &to_satisfy); |
616 | 571 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 request = CopyOutputRequest::CreateRequest( | 620 request = CopyOutputRequest::CreateRequest( |
666 base::Bind(&CopyRequestTestCallback, &called3)); | 621 base::Bind(&CopyRequestTestCallback, &called3)); |
667 request->set_source(source1); | 622 request->set_source(source1); |
668 | 623 |
669 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); | 624 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); |
670 // Two callbacks are from source1, so the first should be called. | 625 // Two callbacks are from source1, so the first should be called. |
671 EXPECT_TRUE(called1); | 626 EXPECT_TRUE(called1); |
672 EXPECT_FALSE(called2); | 627 EXPECT_FALSE(called2); |
673 EXPECT_FALSE(called3); | 628 EXPECT_FALSE(called3); |
674 | 629 |
675 factory_->Destroy(local_frame_id_); | |
676 local_frame_id_ = LocalFrameId(); | 630 local_frame_id_ = LocalFrameId(); |
631 factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(), | |
632 SurfaceFactory::DrawCallback()); | |
677 EXPECT_TRUE(called1); | 633 EXPECT_TRUE(called1); |
678 EXPECT_TRUE(called2); | 634 EXPECT_TRUE(called2); |
679 EXPECT_TRUE(called3); | 635 EXPECT_TRUE(called3); |
680 } | 636 } |
681 | 637 |
682 } // namespace | 638 } // namespace |
683 } // namespace cc | 639 } // namespace cc |
OLD | NEW |