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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: rebase 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 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(),
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_); 489 // EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
538 DCHECK(!manager_.GetSurfaceForId(id2)); 490 DCHECK(!manager_.GetSurfaceForId(id2));
539 491
540 // Check that waiting after the sequence is satisfied works. 492 // Check that waiting after the sequence is satisfied works.
541 factory_->Create(local_frame_id2); 493 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
494 SurfaceFactory::DrawCallback());
542 DCHECK(manager_.GetSurfaceForId(id2)); 495 DCHECK(manager_.GetSurfaceForId(id2));
543 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 496 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
544 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); 497 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6));
545 factory_->Destroy(local_frame_id2); 498 factory2->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(),
499 SurfaceFactory::DrawCallback());
546 DCHECK(!manager_.GetSurfaceForId(id2)); 500 DCHECK(!manager_.GetSurfaceForId(id2));
547 } 501 }
548 502
549 // Tests that Surface ID namespace invalidation correctly allows 503 // Tests that Surface ID namespace invalidation correctly allows
550 // Sequences to be ignored. 504 // Sequences to be ignored.
551 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { 505 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
552 FrameSinkId frame_sink_id(1234, 5678); 506 FrameSinkId frame_sink_id(1234, 5678);
553 507
554 LocalFrameId local_frame_id(5, 1); 508 LocalFrameId local_frame_id(5, 1);
555 SurfaceId id(factory_->frame_sink_id(), local_frame_id); 509 SurfaceId id(factory_->frame_sink_id(), local_frame_id);
556 factory_->Create(local_frame_id); 510 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
511 SurfaceFactory::DrawCallback());
557 512
558 manager_.RegisterFrameSinkId(frame_sink_id); 513 manager_.RegisterFrameSinkId(frame_sink_id);
559 manager_.GetSurfaceForId(id)->AddDestructionDependency( 514 manager_.GetSurfaceForId(id)->AddDestructionDependency(
560 SurfaceSequence(frame_sink_id, 4)); 515 SurfaceSequence(frame_sink_id, 4));
561 factory_->Destroy(local_frame_id); 516
517 LocalFrameId local_frame_id_2(6, 0);
518 factory_->SubmitCompositorFrame(local_frame_id_2, CompositorFrame(),
519 SurfaceFactory::DrawCallback());
562 520
563 // Verify the dependency has prevented the surface from getting destroyed. 521 // Verify the dependency has prevented the surface from getting destroyed.
564 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 522 EXPECT_TRUE(manager_.GetSurfaceForId(id));
565 523
566 manager_.InvalidateFrameSinkId(frame_sink_id); 524 manager_.InvalidateFrameSinkId(frame_sink_id);
567 525
568 // Verify that the invalidated namespace caused the unsatisfied sequence 526 // Verify that the invalidated namespace caused the unsatisfied sequence
569 // to be ignored. 527 // to be ignored.
570 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 528 EXPECT_FALSE(manager_.GetSurfaceForId(id));
571 } 529 }
572 530
573 TEST_F(SurfaceFactoryTest, DestroyCycle) { 531 TEST_F(SurfaceFactoryTest, DestroyCycle) {
574 LocalFrameId local_frame_id2(5, 1); 532 LocalFrameId local_frame_id2(5, 1);
575 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 533 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
576 factory_->Create(local_frame_id2); 534 SurfaceFactory* factory2 =
535 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_);
536 // factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
537 // SurfaceFactory::DrawCallback());
577 538
578 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); 539 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId);
579 540
580 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
581 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
582 541
583 // Give id2 a frame that references local_frame_id_. 542 // Give id2 a frame that references local_frame_id_.
584 { 543 {
585 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 544 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
586 CompositorFrame frame; 545 CompositorFrame frame;
587 frame.render_pass_list.push_back(std::move(render_pass)); 546 frame.render_pass_list.push_back(std::move(render_pass));
588 frame.metadata.referenced_surfaces.push_back( 547 frame.metadata.referenced_surfaces.push_back(
589 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 548 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
590 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), 549 factory2->SubmitCompositorFrame(local_frame_id2, std::move(frame),
591 SurfaceFactory::DrawCallback()); 550 SurfaceFactory::DrawCallback());
592 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); 551 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2);
593 } 552 }
594 factory_->Destroy(local_frame_id2); 553 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
554 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
555 factory2->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(),
556 SurfaceFactory::DrawCallback());
557 LOG(ERROR) << manager_.GetSurfaceForId(id2)->referenced_surfaces().size();
595 558
559 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
560 SurfaceSequence(FrameSinkId(0, 0), 4));
561 factory2->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(),
562 SurfaceFactory::DrawCallback());
563 LOG(ERROR) << manager_.GetSurfaceForId(id2)->referenced_surfaces().size();
596 // Give local_frame_id_ a frame that references id2. 564 // Give local_frame_id_ a frame that references id2.
597 { 565 {
598 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 566 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
599 CompositorFrame frame; 567 CompositorFrame frame;
600 frame.render_pass_list.push_back(std::move(render_pass)); 568 frame.render_pass_list.push_back(std::move(render_pass));
601 frame.metadata.referenced_surfaces.push_back(id2); 569 frame.metadata.referenced_surfaces.push_back(id2);
602 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 570 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
603 SurfaceFactory::DrawCallback()); 571 SurfaceFactory::DrawCallback());
604 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
605 } 572 }
606 factory_->Destroy(local_frame_id_); 573 factory_->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(),
574 SurfaceFactory::DrawCallback());
607 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 575 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
608 // local_frame_id_ should be retained by reference from id2. 576 // local_frame_id_ should be retained by reference from id2.
609 EXPECT_TRUE(manager_.GetSurfaceForId( 577 EXPECT_TRUE(manager_.GetSurfaceForId(
610 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); 578 SurfaceId(factory_->frame_sink_id(), local_frame_id_)));
611 579
612 // Satisfy last destruction dependency for id2. 580 // Satisfy last destruction dependency for id2.
613 std::vector<uint32_t> to_satisfy; 581 std::vector<uint32_t> to_satisfy;
614 to_satisfy.push_back(4); 582 to_satisfy.push_back(4);
615 manager_.DidSatisfySequences(kAnotherArbitraryFrameSinkId, &to_satisfy); 583 manager_.DidSatisfySequences(kAnotherArbitraryFrameSinkId, &to_satisfy);
616 584
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 request = CopyOutputRequest::CreateRequest( 633 request = CopyOutputRequest::CreateRequest(
666 base::Bind(&CopyRequestTestCallback, &called3)); 634 base::Bind(&CopyRequestTestCallback, &called3));
667 request->set_source(source1); 635 request->set_source(source1);
668 636
669 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); 637 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request));
670 // Two callbacks are from source1, so the first should be called. 638 // Two callbacks are from source1, so the first should be called.
671 EXPECT_TRUE(called1); 639 EXPECT_TRUE(called1);
672 EXPECT_FALSE(called2); 640 EXPECT_FALSE(called2);
673 EXPECT_FALSE(called3); 641 EXPECT_FALSE(called3);
674 642
675 factory_->Destroy(local_frame_id_);
676 local_frame_id_ = LocalFrameId(); 643 local_frame_id_ = LocalFrameId();
644 factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(),
645 SurfaceFactory::DrawCallback());
677 EXPECT_TRUE(called1); 646 EXPECT_TRUE(called1);
678 EXPECT_TRUE(called2); 647 EXPECT_TRUE(called2);
679 EXPECT_TRUE(called3); 648 EXPECT_TRUE(called3);
680 } 649 }
681 650
682 } // namespace 651 } // namespace
683 } // namespace cc 652 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698