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

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

Issue 2403573002: cc: Introduce mechanism to observe CompositorFrames submitted to new surfaceIDs (Closed)
Patch Set: Created 4 years, 2 months 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); 57 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient);
58 }; 58 };
59 59
60 gpu::SyncToken GenTestSyncToken(int id) { 60 gpu::SyncToken GenTestSyncToken(int id) {
61 gpu::SyncToken token; 61 gpu::SyncToken token;
62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
63 gpu::CommandBufferId::FromUnsafeValue(id), 1); 63 gpu::CommandBufferId::FromUnsafeValue(id), 1);
64 return token; 64 return token;
65 } 65 }
66 66
67 class SurfaceFactoryTest : public testing::Test, public SurfaceDamageObserver { 67 class SurfaceFactoryTest : public testing::Test, public SurfaceManagerObserver {
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, 0), 72 local_frame_id_(3, 0),
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_->Create(local_frame_id_);
77 } 77 }
78 78
79 // SurfaceDamageObserver implementation. 79 const SurfaceId& last_seen_surface_id() const {
80 return last_seen_surface_id_;
81 }
82
83 // SurfaceManagerObserver implementation.
84 void OnSurfaceCreated(const SurfaceId& surface_id,
85 const gfx::Size& frame,
86 float device_scale_factor) override {
87 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id());
88 last_seen_surface_id_ = surface_id;
89 }
90
80 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { 91 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override {
81 *changed = true; 92 *changed = true;
82 } 93 }
83 94
84 ~SurfaceFactoryTest() override { 95 ~SurfaceFactoryTest() override {
85 if (!local_frame_id_.is_null()) 96 if (!local_frame_id_.is_null())
86 factory_->Destroy(local_frame_id_); 97 factory_->Destroy(local_frame_id_);
87 manager_.RemoveObserver(this); 98 manager_.RemoveObserver(this);
88 } 99 }
89 100
90 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 101 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
91 size_t num_resource_ids) { 102 size_t num_resource_ids) {
92 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 103 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
93 for (size_t i = 0u; i < num_resource_ids; ++i) { 104 for (size_t i = 0u; i < num_resource_ids; ++i) {
94 TransferableResource resource; 105 TransferableResource resource;
95 resource.id = resource_ids[i]; 106 resource.id = resource_ids[i];
96 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 107 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
97 resource.mailbox_holder.sync_token = frame_sync_token_; 108 resource.mailbox_holder.sync_token = frame_sync_token_;
98 frame_data->resource_list.push_back(resource); 109 frame_data->resource_list.push_back(resource);
99 } 110 }
100 CompositorFrame frame; 111 CompositorFrame frame;
101 frame.delegated_frame_data = std::move(frame_data); 112 frame.delegated_frame_data = std::move(frame_data);
102 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 113 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
103 SurfaceFactory::DrawCallback()); 114 SurfaceFactory::DrawCallback());
115 EXPECT_EQ(last_seen_surface_id_.local_frame_id(), local_frame_id_);
104 } 116 }
105 117
106 void UnrefResources(ResourceId* ids_to_unref, 118 void UnrefResources(ResourceId* ids_to_unref,
107 int* counts_to_unref, 119 int* counts_to_unref,
108 size_t num_ids_to_unref) { 120 size_t num_ids_to_unref) {
109 ReturnedResourceArray unref_array; 121 ReturnedResourceArray unref_array;
110 for (size_t i = 0; i < num_ids_to_unref; ++i) { 122 for (size_t i = 0; i < num_ids_to_unref; ++i) {
111 ReturnedResource resource; 123 ReturnedResource resource;
112 resource.sync_token = consumer_sync_token_; 124 resource.sync_token = consumer_sync_token_;
113 resource.id = ids_to_unref[i]; 125 resource.id = ids_to_unref[i];
(...skipping 24 matching lines...) Expand all
138 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 150 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
139 factory_->RefResources( 151 factory_->RefResources(
140 surface->GetEligibleFrame().delegated_frame_data->resource_list); 152 surface->GetEligibleFrame().delegated_frame_data->resource_list);
141 } 153 }
142 154
143 protected: 155 protected:
144 SurfaceManager manager_; 156 SurfaceManager manager_;
145 TestSurfaceFactoryClient client_; 157 TestSurfaceFactoryClient client_;
146 std::unique_ptr<SurfaceFactory> factory_; 158 std::unique_ptr<SurfaceFactory> factory_;
147 LocalFrameId local_frame_id_; 159 LocalFrameId local_frame_id_;
160 SurfaceId last_seen_surface_id_;
vmpstr 2016/10/11 21:59:04 last_created_surface_id_ maybe? Or is the only way
Fady Samuel 2016/10/11 23:11:45 renamed to last_created_surface_id.
148 161
149 // This is the sync token submitted with the frame. It should never be 162 // This is the sync token submitted with the frame. It should never be
150 // returned to the client. 163 // returned to the client.
151 const gpu::SyncToken frame_sync_token_; 164 const gpu::SyncToken frame_sync_token_;
152 165
153 // This is the sync token returned by the consumer. It should always be 166 // This is the sync token returned by the consumer. It should always be
154 // returned to the client. 167 // returned to the client.
155 const gpu::SyncToken consumer_sync_token_; 168 const gpu::SyncToken consumer_sync_token_;
156 }; 169 };
157 170
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 factory_->Create(local_frame_id); 441 factory_->Create(local_frame_id);
429 Surface* surface = manager_.GetSurfaceForId(surface_id); 442 Surface* surface = manager_.GetSurfaceForId(surface_id);
430 ASSERT_NE(nullptr, surface); 443 ASSERT_NE(nullptr, surface);
431 EXPECT_EQ(2, surface->frame_index()); 444 EXPECT_EQ(2, surface->frame_index());
432 CompositorFrame frame; 445 CompositorFrame frame;
433 frame.delegated_frame_data.reset(new DelegatedFrameData); 446 frame.delegated_frame_data.reset(new DelegatedFrameData);
434 447
435 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame), 448 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame),
436 SurfaceFactory::DrawCallback()); 449 SurfaceFactory::DrawCallback());
437 EXPECT_EQ(2, surface->frame_index()); 450 EXPECT_EQ(2, surface->frame_index());
451 EXPECT_EQ(last_seen_surface_id().local_frame_id(), local_frame_id);
438 factory_->Destroy(local_frame_id); 452 factory_->Destroy(local_frame_id);
439 } 453 }
440 454
441 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 455 void CreateSurfaceDrawCallback(SurfaceFactory* factory,
442 uint32_t* execute_count) { 456 uint32_t* execute_count) {
443 LocalFrameId new_id(7, 0); 457 LocalFrameId new_id(7, 0);
444 factory->Create(new_id); 458 factory->Create(new_id);
445 factory->Destroy(new_id); 459 factory->Destroy(new_id);
446 *execute_count += 1; 460 *execute_count += 1;
447 } 461 }
(...skipping 26 matching lines...) Expand all
474 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 488 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
475 TransferableResource resource; 489 TransferableResource resource;
476 resource.id = 1; 490 resource.id = 1;
477 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 491 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
478 frame_data->resource_list.push_back(resource); 492 frame_data->resource_list.push_back(resource);
479 CompositorFrame frame; 493 CompositorFrame frame;
480 frame.delegated_frame_data = std::move(frame_data); 494 frame.delegated_frame_data = std::move(frame_data);
481 uint32_t execute_count = 0; 495 uint32_t execute_count = 0;
482 factory_->SubmitCompositorFrame(id, std::move(frame), 496 factory_->SubmitCompositorFrame(id, std::move(frame),
483 base::Bind(&DrawCallback, &execute_count)); 497 base::Bind(&DrawCallback, &execute_count));
484 498 EXPECT_EQ(last_seen_surface_id().local_frame_id(), id);
485 local_frame_id_ = LocalFrameId(); 499 local_frame_id_ = LocalFrameId();
486 factory_->DestroyAll(); 500 factory_->DestroyAll();
487 EXPECT_EQ(1u, execute_count); 501 EXPECT_EQ(1u, execute_count);
488 } 502 }
489 503
490 TEST_F(SurfaceFactoryTest, DestroySequence) { 504 TEST_F(SurfaceFactoryTest, DestroySequence) {
491 LocalFrameId local_frame_id2(5, 0); 505 LocalFrameId local_frame_id2(5, 0);
492 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 506 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
493 factory_->Create(local_frame_id2); 507 factory_->Create(local_frame_id2);
494 508
495 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 509 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
496 510
497 // Check that waiting before the sequence is satisfied works. 511 // Check that waiting before the sequence is satisfied works.
498 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 512 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
499 SurfaceSequence(kArbitraryFrameSinkId, 4)); 513 SurfaceSequence(kArbitraryFrameSinkId, 4));
500 factory_->Destroy(local_frame_id2); 514 factory_->Destroy(local_frame_id2);
501 515
502 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 516 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
503 CompositorFrame frame; 517 CompositorFrame frame;
504 frame.metadata.satisfies_sequences.push_back(6); 518 frame.metadata.satisfies_sequences.push_back(6);
505 frame.metadata.satisfies_sequences.push_back(4); 519 frame.metadata.satisfies_sequences.push_back(4);
506 frame.delegated_frame_data = std::move(frame_data); 520 frame.delegated_frame_data = std::move(frame_data);
507 DCHECK(manager_.GetSurfaceForId(id2)); 521 DCHECK(manager_.GetSurfaceForId(id2));
508 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 522 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
509 SurfaceFactory::DrawCallback()); 523 SurfaceFactory::DrawCallback());
524 EXPECT_EQ(last_seen_surface_id().local_frame_id(), local_frame_id_);
510 DCHECK(!manager_.GetSurfaceForId(id2)); 525 DCHECK(!manager_.GetSurfaceForId(id2));
511 526
512 // Check that waiting after the sequence is satisfied works. 527 // Check that waiting after the sequence is satisfied works.
513 factory_->Create(local_frame_id2); 528 factory_->Create(local_frame_id2);
514 DCHECK(manager_.GetSurfaceForId(id2)); 529 DCHECK(manager_.GetSurfaceForId(id2));
515 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 530 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
516 SurfaceSequence(FrameSinkId(0, 0), 6)); 531 SurfaceSequence(FrameSinkId(0, 0), 6));
517 factory_->Destroy(local_frame_id2); 532 factory_->Destroy(local_frame_id2);
518 DCHECK(!manager_.GetSurfaceForId(id2)); 533 DCHECK(!manager_.GetSurfaceForId(id2));
519 } 534 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 { 571 {
557 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 572 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
558 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 573 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
559 frame_data->render_pass_list.push_back(std::move(render_pass)); 574 frame_data->render_pass_list.push_back(std::move(render_pass));
560 CompositorFrame frame; 575 CompositorFrame frame;
561 frame.metadata.referenced_surfaces.push_back( 576 frame.metadata.referenced_surfaces.push_back(
562 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 577 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
563 frame.delegated_frame_data = std::move(frame_data); 578 frame.delegated_frame_data = std::move(frame_data);
564 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), 579 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame),
565 SurfaceFactory::DrawCallback()); 580 SurfaceFactory::DrawCallback());
581 EXPECT_EQ(last_seen_surface_id().local_frame_id(), local_frame_id2);
566 } 582 }
567 factory_->Destroy(local_frame_id2); 583 factory_->Destroy(local_frame_id2);
568 584
569 // Give local_frame_id_ a frame that references id2. 585 // Give local_frame_id_ a frame that references id2.
570 { 586 {
571 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 587 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
572 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 588 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
573 frame_data->render_pass_list.push_back(std::move(render_pass)); 589 frame_data->render_pass_list.push_back(std::move(render_pass));
574 CompositorFrame frame; 590 CompositorFrame frame;
575 frame.metadata.referenced_surfaces.push_back(id2); 591 frame.metadata.referenced_surfaces.push_back(id2);
576 frame.delegated_frame_data = std::move(frame_data); 592 frame.delegated_frame_data = std::move(frame_data);
577 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 593 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
578 SurfaceFactory::DrawCallback()); 594 SurfaceFactory::DrawCallback());
595 EXPECT_EQ(last_seen_surface_id().local_frame_id(), local_frame_id_);
579 } 596 }
580 factory_->Destroy(local_frame_id_); 597 factory_->Destroy(local_frame_id_);
581 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 598 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
582 // local_frame_id_ should be retained by reference from id2. 599 // local_frame_id_ should be retained by reference from id2.
583 EXPECT_TRUE(manager_.GetSurfaceForId( 600 EXPECT_TRUE(manager_.GetSurfaceForId(
584 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); 601 SurfaceId(factory_->frame_sink_id(), local_frame_id_)));
585 602
586 // Satisfy last destruction dependency for id2. 603 // Satisfy last destruction dependency for id2.
587 std::vector<uint32_t> to_satisfy; 604 std::vector<uint32_t> to_satisfy;
588 to_satisfy.push_back(4); 605 to_satisfy.push_back(4);
(...skipping 17 matching lines...) Expand all
606 { 623 {
607 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 624 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
608 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 625 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
609 frame_data->render_pass_list.push_back(std::move(render_pass)); 626 frame_data->render_pass_list.push_back(std::move(render_pass));
610 CompositorFrame frame; 627 CompositorFrame frame;
611 frame.metadata.referenced_surfaces.push_back( 628 frame.metadata.referenced_surfaces.push_back(
612 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 629 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
613 frame.delegated_frame_data = std::move(frame_data); 630 frame.delegated_frame_data = std::move(frame_data);
614 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 631 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
615 SurfaceFactory::DrawCallback()); 632 SurfaceFactory::DrawCallback());
633 EXPECT_EQ(last_seen_surface_id().local_frame_id(), local_frame_id_);
616 } 634 }
617 void* source1 = &source1; 635 void* source1 = &source1;
618 void* source2 = &source2; 636 void* source2 = &source2;
619 637
620 bool called1 = false; 638 bool called1 = false;
621 std::unique_ptr<CopyOutputRequest> request; 639 std::unique_ptr<CopyOutputRequest> request;
622 request = CopyOutputRequest::CreateRequest( 640 request = CopyOutputRequest::CreateRequest(
623 base::Bind(&CopyRequestTestCallback, &called1)); 641 base::Bind(&CopyRequestTestCallback, &called1));
624 request->set_source(source1); 642 request->set_source(source1);
625 643
(...skipping 23 matching lines...) Expand all
649 667
650 factory_->Destroy(local_frame_id_); 668 factory_->Destroy(local_frame_id_);
651 local_frame_id_ = LocalFrameId(); 669 local_frame_id_ = LocalFrameId();
652 EXPECT_TRUE(called1); 670 EXPECT_TRUE(called1);
653 EXPECT_TRUE(called2); 671 EXPECT_TRUE(called2);
654 EXPECT_TRUE(called3); 672 EXPECT_TRUE(called3);
655 } 673 }
656 674
657 } // namespace 675 } // namespace
658 } // namespace cc 676 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698