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

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

Issue 2425923003: Replaced is_null() with is_valid in SurfaceId and related classes. (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
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_id.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "cc/output/compositor_frame.h" 14 #include "cc/output/compositor_frame.h"
15 #include "cc/output/copy_output_request.h" 15 #include "cc/output/copy_output_request.h"
16 #include "cc/output/copy_output_result.h" 16 #include "cc/output/copy_output_result.h"
17 #include "cc/resources/resource_provider.h" 17 #include "cc/resources/resource_provider.h"
18 #include "cc/surfaces/surface.h" 18 #include "cc/surfaces/surface.h"
19 #include "cc/surfaces/surface_factory_client.h" 19 #include "cc/surfaces/surface_factory_client.h"
20 #include "cc/surfaces/surface_manager.h" 20 #include "cc/surfaces/surface_manager.h"
21 #include "cc/test/scheduler_test_common.h" 21 #include "cc/test/scheduler_test_common.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
24 24
25 namespace cc { 25 namespace cc {
26 namespace { 26 namespace {
27 27
28 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); 28 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1);
29 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2);
29 30
30 class TestSurfaceFactoryClient : public SurfaceFactoryClient { 31 class TestSurfaceFactoryClient : public SurfaceFactoryClient {
31 public: 32 public:
32 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} 33 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
33 ~TestSurfaceFactoryClient() override {} 34 ~TestSurfaceFactoryClient() override {}
34 35
35 void ReturnResources(const ReturnedResourceArray& resources) override { 36 void ReturnResources(const ReturnedResourceArray& resources) override {
36 returned_resources_.insert( 37 returned_resources_.insert(
37 returned_resources_.end(), resources.begin(), resources.end()); 38 returned_resources_.end(), resources.begin(), resources.end());
38 } 39 }
(...skipping 22 matching lines...) Expand all
61 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
62 gpu::CommandBufferId::FromUnsafeValue(id), 1); 63 gpu::CommandBufferId::FromUnsafeValue(id), 1);
63 return token; 64 return token;
64 } 65 }
65 66
66 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { 67 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver {
67 public: 68 public:
68 SurfaceFactoryTest() 69 SurfaceFactoryTest()
69 : factory_( 70 : factory_(
70 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), 71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)),
71 local_frame_id_(3, 0), 72 local_frame_id_(3, 1),
72 frame_sync_token_(GenTestSyncToken(4)), 73 frame_sync_token_(GenTestSyncToken(4)),
73 consumer_sync_token_(GenTestSyncToken(5)) { 74 consumer_sync_token_(GenTestSyncToken(5)) {
74 manager_.AddObserver(this); 75 manager_.AddObserver(this);
75 factory_->Create(local_frame_id_); 76 factory_->Create(local_frame_id_);
76 } 77 }
77 78
78 const SurfaceId& last_created_surface_id() const { 79 const SurfaceId& last_created_surface_id() const {
79 return last_created_surface_id_; 80 return last_created_surface_id_;
80 } 81 }
81 82
82 // SurfaceObserver implementation. 83 // SurfaceObserver implementation.
83 void OnSurfaceCreated(const SurfaceId& surface_id, 84 void OnSurfaceCreated(const SurfaceId& surface_id,
84 const gfx::Size& frame, 85 const gfx::Size& frame,
85 float device_scale_factor) override { 86 float device_scale_factor) override {
86 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id()); 87 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id());
87 last_created_surface_id_ = surface_id; 88 last_created_surface_id_ = surface_id;
88 } 89 }
89 90
90 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { 91 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override {
91 *changed = true; 92 *changed = true;
92 } 93 }
93 94
94 ~SurfaceFactoryTest() override { 95 ~SurfaceFactoryTest() override {
95 if (!local_frame_id_.is_null()) 96 if (local_frame_id_.is_valid())
96 factory_->Destroy(local_frame_id_); 97 factory_->Destroy(local_frame_id_);
97 manager_.RemoveObserver(this); 98 manager_.RemoveObserver(this);
98 } 99 }
99 100
100 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 101 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
101 size_t num_resource_ids) { 102 size_t num_resource_ids) {
102 CompositorFrame frame; 103 CompositorFrame frame;
103 for (size_t i = 0u; i < num_resource_ids; ++i) { 104 for (size_t i = 0u; i < num_resource_ids; ++i) {
104 TransferableResource resource; 105 TransferableResource resource;
105 resource.id = resource_ids[i]; 106 resource.id = resource_ids[i];
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 SCOPED_TRACE("fourth frame, second unref"); 426 SCOPED_TRACE("fourth frame, second unref");
426 ResourceId expected_returned_ids[] = {12, 13}; 427 ResourceId expected_returned_ids[] = {12, 13};
427 int expected_returned_counts[] = {2, 2}; 428 int expected_returned_counts[] = {2, 2};
428 CheckReturnedResourcesMatchExpected( 429 CheckReturnedResourcesMatchExpected(
429 expected_returned_ids, expected_returned_counts, 430 expected_returned_ids, expected_returned_counts,
430 arraysize(expected_returned_counts), consumer_sync_token_); 431 arraysize(expected_returned_counts), consumer_sync_token_);
431 } 432 }
432 } 433 }
433 434
434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 435 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
435 LocalFrameId local_frame_id(6, 0); 436 LocalFrameId local_frame_id(6, 1);
436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 437 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
437 factory_->Create(local_frame_id); 438 factory_->Create(local_frame_id);
438 Surface* surface = manager_.GetSurfaceForId(surface_id); 439 Surface* surface = manager_.GetSurfaceForId(surface_id);
439 ASSERT_NE(nullptr, surface); 440 ASSERT_NE(nullptr, surface);
440 EXPECT_EQ(2, surface->frame_index()); 441 EXPECT_EQ(2, surface->frame_index());
441 442
442 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), 443 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
443 SurfaceFactory::DrawCallback()); 444 SurfaceFactory::DrawCallback());
444 EXPECT_EQ(2, surface->frame_index()); 445 EXPECT_EQ(2, surface->frame_index());
445 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); 446 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id);
446 factory_->Destroy(local_frame_id); 447 factory_->Destroy(local_frame_id);
447 } 448 }
448 449
449 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 450 void CreateSurfaceDrawCallback(SurfaceFactory* factory,
450 uint32_t* execute_count) { 451 uint32_t* execute_count) {
451 LocalFrameId new_id(7, 0); 452 LocalFrameId new_id(7, 0);
452 factory->Create(new_id); 453 factory->Create(new_id);
453 factory->Destroy(new_id); 454 factory->Destroy(new_id);
454 *execute_count += 1; 455 *execute_count += 1;
455 } 456 }
456 457
457 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { 458 TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
458 LocalFrameId local_frame_id(6, 0); 459 LocalFrameId local_frame_id(6, 1);
459 factory_->Create(local_frame_id); 460 factory_->Create(local_frame_id);
460 461
461 uint32_t execute_count = 0; 462 uint32_t execute_count = 0;
462 factory_->SubmitCompositorFrame( 463 factory_->SubmitCompositorFrame(
463 local_frame_id, CompositorFrame(), 464 local_frame_id, CompositorFrame(),
464 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), 465 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
465 &execute_count)); 466 &execute_count));
466 EXPECT_EQ(0u, execute_count); 467 EXPECT_EQ(0u, execute_count);
467 factory_->Destroy(local_frame_id); 468 factory_->Destroy(local_frame_id);
468 EXPECT_EQ(1u, execute_count); 469 EXPECT_EQ(1u, execute_count);
469 } 470 }
470 471
471 void DrawCallback(uint32_t* execute_count) { 472 void DrawCallback(uint32_t* execute_count) {
472 *execute_count += 1; 473 *execute_count += 1;
473 } 474 }
474 475
475 // Tests doing a DestroyAll before shutting down the factory; 476 // Tests doing a DestroyAll before shutting down the factory;
476 TEST_F(SurfaceFactoryTest, DestroyAll) { 477 TEST_F(SurfaceFactoryTest, DestroyAll) {
477 LocalFrameId id(7, 0); 478 LocalFrameId id(7, 1);
478 factory_->Create(id); 479 factory_->Create(id);
479 480
480 TransferableResource resource; 481 TransferableResource resource;
481 resource.id = 1; 482 resource.id = 1;
482 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 483 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
483 CompositorFrame frame; 484 CompositorFrame frame;
484 frame.resource_list.push_back(resource); 485 frame.resource_list.push_back(resource);
485 uint32_t execute_count = 0; 486 uint32_t execute_count = 0;
486 factory_->SubmitCompositorFrame(id, std::move(frame), 487 factory_->SubmitCompositorFrame(id, std::move(frame),
487 base::Bind(&DrawCallback, &execute_count)); 488 base::Bind(&DrawCallback, &execute_count));
(...skipping 21 matching lines...) Expand all
509 SurfaceId surface_id(kArbitraryFrameSinkId, id); 510 SurfaceId surface_id(kArbitraryFrameSinkId, id);
510 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); 511 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id);
511 factory_->Reset(); 512 factory_->Reset();
512 EXPECT_TRUE(client_.returned_resources().empty()); 513 EXPECT_TRUE(client_.returned_resources().empty());
513 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); 514 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id);
514 EXPECT_TRUE(client_.returned_resources().empty()); 515 EXPECT_TRUE(client_.returned_resources().empty());
515 local_frame_id_ = LocalFrameId(); 516 local_frame_id_ = LocalFrameId();
516 } 517 }
517 518
518 TEST_F(SurfaceFactoryTest, DestroySequence) { 519 TEST_F(SurfaceFactoryTest, DestroySequence) {
519 LocalFrameId local_frame_id2(5, 0); 520 LocalFrameId local_frame_id2(5, 1);
520 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 521 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
521 factory_->Create(local_frame_id2); 522 factory_->Create(local_frame_id2);
522 523
523 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 524 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
524 525
525 // Check that waiting before the sequence is satisfied works. 526 // Check that waiting before the sequence is satisfied works.
526 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 527 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
527 SurfaceSequence(kArbitraryFrameSinkId, 4)); 528 SurfaceSequence(kArbitraryFrameSinkId, 4));
528 factory_->Destroy(local_frame_id2); 529 factory_->Destroy(local_frame_id2);
529 530
530 CompositorFrame frame; 531 CompositorFrame frame;
531 frame.metadata.satisfies_sequences.push_back(6); 532 frame.metadata.satisfies_sequences.push_back(6);
532 frame.metadata.satisfies_sequences.push_back(4); 533 frame.metadata.satisfies_sequences.push_back(4);
533 DCHECK(manager_.GetSurfaceForId(id2)); 534 DCHECK(manager_.GetSurfaceForId(id2));
534 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 535 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
535 SurfaceFactory::DrawCallback()); 536 SurfaceFactory::DrawCallback());
536 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); 537 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
537 DCHECK(!manager_.GetSurfaceForId(id2)); 538 DCHECK(!manager_.GetSurfaceForId(id2));
538 539
539 // Check that waiting after the sequence is satisfied works. 540 // Check that waiting after the sequence is satisfied works.
540 factory_->Create(local_frame_id2); 541 factory_->Create(local_frame_id2);
541 DCHECK(manager_.GetSurfaceForId(id2)); 542 DCHECK(manager_.GetSurfaceForId(id2));
542 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 543 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
543 SurfaceSequence(FrameSinkId(0, 0), 6)); 544 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6));
544 factory_->Destroy(local_frame_id2); 545 factory_->Destroy(local_frame_id2);
545 DCHECK(!manager_.GetSurfaceForId(id2)); 546 DCHECK(!manager_.GetSurfaceForId(id2));
546 } 547 }
547 548
548 // Tests that Surface ID namespace invalidation correctly allows 549 // Tests that Surface ID namespace invalidation correctly allows
549 // Sequences to be ignored. 550 // Sequences to be ignored.
550 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { 551 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
551 FrameSinkId frame_sink_id(1234, 5678); 552 FrameSinkId frame_sink_id(1234, 5678);
552 553
553 LocalFrameId local_frame_id(5, 0); 554 LocalFrameId local_frame_id(5, 1);
554 SurfaceId id(factory_->frame_sink_id(), local_frame_id); 555 SurfaceId id(factory_->frame_sink_id(), local_frame_id);
555 factory_->Create(local_frame_id); 556 factory_->Create(local_frame_id);
556 557
557 manager_.RegisterFrameSinkId(frame_sink_id); 558 manager_.RegisterFrameSinkId(frame_sink_id);
558 manager_.GetSurfaceForId(id)->AddDestructionDependency( 559 manager_.GetSurfaceForId(id)->AddDestructionDependency(
559 SurfaceSequence(frame_sink_id, 4)); 560 SurfaceSequence(frame_sink_id, 4));
560 factory_->Destroy(local_frame_id); 561 factory_->Destroy(local_frame_id);
561 562
562 // Verify the dependency has prevented the surface from getting destroyed. 563 // Verify the dependency has prevented the surface from getting destroyed.
563 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 564 EXPECT_TRUE(manager_.GetSurfaceForId(id));
564 565
565 manager_.InvalidateFrameSinkId(frame_sink_id); 566 manager_.InvalidateFrameSinkId(frame_sink_id);
566 567
567 // Verify that the invalidated namespace caused the unsatisfied sequence 568 // Verify that the invalidated namespace caused the unsatisfied sequence
568 // to be ignored. 569 // to be ignored.
569 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 570 EXPECT_FALSE(manager_.GetSurfaceForId(id));
570 } 571 }
571 572
572 TEST_F(SurfaceFactoryTest, DestroyCycle) { 573 TEST_F(SurfaceFactoryTest, DestroyCycle) {
573 LocalFrameId local_frame_id2(5, 0); 574 LocalFrameId local_frame_id2(5, 1);
574 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 575 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
575 factory_->Create(local_frame_id2); 576 factory_->Create(local_frame_id2);
576 577
577 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); 578 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId);
578 579
579 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 580 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
580 SurfaceSequence(FrameSinkId(0, 0), 4)); 581 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
581 582
582 // Give id2 a frame that references local_frame_id_. 583 // Give id2 a frame that references local_frame_id_.
583 { 584 {
584 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 585 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
585 CompositorFrame frame; 586 CompositorFrame frame;
586 frame.render_pass_list.push_back(std::move(render_pass)); 587 frame.render_pass_list.push_back(std::move(render_pass));
587 frame.metadata.referenced_surfaces.push_back( 588 frame.metadata.referenced_surfaces.push_back(
588 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 589 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
589 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), 590 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame),
590 SurfaceFactory::DrawCallback()); 591 SurfaceFactory::DrawCallback());
(...skipping 13 matching lines...) Expand all
604 } 605 }
605 factory_->Destroy(local_frame_id_); 606 factory_->Destroy(local_frame_id_);
606 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 607 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
607 // local_frame_id_ should be retained by reference from id2. 608 // local_frame_id_ should be retained by reference from id2.
608 EXPECT_TRUE(manager_.GetSurfaceForId( 609 EXPECT_TRUE(manager_.GetSurfaceForId(
609 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); 610 SurfaceId(factory_->frame_sink_id(), local_frame_id_)));
610 611
611 // Satisfy last destruction dependency for id2. 612 // Satisfy last destruction dependency for id2.
612 std::vector<uint32_t> to_satisfy; 613 std::vector<uint32_t> to_satisfy;
613 to_satisfy.push_back(4); 614 to_satisfy.push_back(4);
614 manager_.DidSatisfySequences(FrameSinkId(0, 0), &to_satisfy); 615 manager_.DidSatisfySequences(kAnotherArbitraryFrameSinkId, &to_satisfy);
615 616
616 // id2 and local_frame_id_ are in a reference cycle that has no surface 617 // id2 and local_frame_id_ are in a reference cycle that has no surface
617 // sequences holding on to it, so they should be destroyed. 618 // sequences holding on to it, so they should be destroyed.
618 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); 619 EXPECT_TRUE(!manager_.GetSurfaceForId(id2));
619 EXPECT_TRUE(!manager_.GetSurfaceForId( 620 EXPECT_TRUE(!manager_.GetSurfaceForId(
620 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); 621 SurfaceId(factory_->frame_sink_id(), local_frame_id_)));
621 622
622 local_frame_id_ = LocalFrameId(); 623 local_frame_id_ = LocalFrameId();
623 } 624 }
624 625
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 674
674 factory_->Destroy(local_frame_id_); 675 factory_->Destroy(local_frame_id_);
675 local_frame_id_ = LocalFrameId(); 676 local_frame_id_ = LocalFrameId();
676 EXPECT_TRUE(called1); 677 EXPECT_TRUE(called1);
677 EXPECT_TRUE(called2); 678 EXPECT_TRUE(called2);
678 EXPECT_TRUE(called3); 679 EXPECT_TRUE(called3);
679 } 680 }
680 681
681 } // namespace 682 } // namespace
682 } // namespace cc 683 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698