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

Side by Side Diff: cc/surfaces/surface_factory_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698