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

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

Issue 2144733005: [WIP] cc: Plumb SurfaceId from clients Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ensure only SurfaceFactoy and tests can update hierarchy Created 4 years, 5 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
« no previous file with comments | « cc/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('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>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SurfaceDamageObserver {
68 public: 68 public:
69 SurfaceFactoryTest() 69 SurfaceFactoryTest()
70 : factory_(new SurfaceFactory(&manager_, &client_)), 70 : factory_(new SurfaceFactory(kArbitraryClientId, &manager_, &client_)),
71 surface_id_(kArbitraryClientId, 3, 0), 71 surface_id_(kArbitraryClientId, 3, 0),
72 frame_sync_token_(GenTestSyncToken(4)), 72 frame_sync_token_(GenTestSyncToken(4)),
73 consumer_sync_token_(GenTestSyncToken(5)) { 73 consumer_sync_token_(GenTestSyncToken(5)) {
74 manager_.AddObserver(this); 74 manager_.AddObserver(this);
75 factory_->Create(surface_id_); 75 factory_->Create(surface_id_);
76 } 76 }
77 77
78 // SurfaceDamageObserver implementation. 78 // SurfaceDamageObserver implementation.
79 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { 79 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override {
80 *changed = true; 80 *changed = true;
81 } 81 }
82 82
83 ~SurfaceFactoryTest() override { 83 ~SurfaceFactoryTest() override {
84 if (!surface_id_.is_null()) 84 if (factory_ && !surface_id_.is_null())
85 factory_->Destroy(surface_id_); 85 factory_->Destroy(surface_id_);
86 manager_.RemoveObserver(this); 86 manager_.RemoveObserver(this);
87 } 87 }
88 88
89 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 89 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
90 size_t num_resource_ids) { 90 size_t num_resource_ids) {
91 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 91 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
92 for (size_t i = 0u; i < num_resource_ids; ++i) { 92 for (size_t i = 0u; i < num_resource_ids; ++i) {
93 TransferableResource resource; 93 TransferableResource resource;
94 resource.id = resource_ids[i]; 94 resource.id = resource_ids[i];
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 surface_id_ = SurfaceId(); 492 surface_id_ = SurfaceId();
493 factory_->DestroyAll(); 493 factory_->DestroyAll();
494 EXPECT_EQ(1u, execute_count); 494 EXPECT_EQ(1u, execute_count);
495 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); 495 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn);
496 } 496 }
497 497
498 TEST_F(SurfaceFactoryTest, DestroySequence) { 498 TEST_F(SurfaceFactoryTest, DestroySequence) {
499 SurfaceId id2(kArbitraryClientId, 5, 0); 499 SurfaceId id2(kArbitraryClientId, 5, 0);
500 factory_->Create(id2); 500 factory_->Create(id2);
501 501
502 manager_.RegisterSurfaceClientId(0);
503
504 // Check that waiting before the sequence is satisfied works. 502 // Check that waiting before the sequence is satisfied works.
505 manager_.GetSurfaceForId(id2) 503 manager_.GetSurfaceForId(id2)
506 ->AddDestructionDependency(SurfaceSequence(0, 4)); 504 ->AddDestructionDependency(SurfaceSequence(0, 4));
507 factory_->Destroy(id2); 505 factory_->Destroy(id2);
508 506
509 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 507 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
510 CompositorFrame frame; 508 CompositorFrame frame;
511 frame.metadata.satisfies_sequences.push_back(6); 509 frame.metadata.satisfies_sequences.push_back(6);
512 frame.metadata.satisfies_sequences.push_back(4); 510 frame.metadata.satisfies_sequences.push_back(4);
513 frame.delegated_frame_data = std::move(frame_data); 511 frame.delegated_frame_data = std::move(frame_data);
514 DCHECK(manager_.GetSurfaceForId(id2)); 512 DCHECK(manager_.GetSurfaceForId(id2));
515 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 513 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
516 SurfaceFactory::DrawCallback()); 514 SurfaceFactory::DrawCallback());
517 DCHECK(!manager_.GetSurfaceForId(id2)); 515 DCHECK(!manager_.GetSurfaceForId(id2));
518 516
519 // Check that waiting after the sequence is satisfied works. 517 // Check that waiting after the sequence is satisfied works.
520 factory_->Create(id2); 518 factory_->Create(id2);
521 DCHECK(manager_.GetSurfaceForId(id2)); 519 DCHECK(manager_.GetSurfaceForId(id2));
522 manager_.GetSurfaceForId(id2) 520 manager_.GetSurfaceForId(id2)
523 ->AddDestructionDependency(SurfaceSequence(0, 6)); 521 ->AddDestructionDependency(SurfaceSequence(0, 6));
524 factory_->Destroy(id2); 522 factory_->Destroy(id2);
525 DCHECK(!manager_.GetSurfaceForId(id2)); 523 DCHECK(!manager_.GetSurfaceForId(id2));
526 } 524 }
527 525
528 // Tests that Surface ID namespace invalidation correctly allows 526 // Tests that Surface ID namespace invalidation correctly allows
529 // Sequences to be ignored. 527 // Sequences to be ignored.
530 TEST_F(SurfaceFactoryTest, InvalidClientId) { 528 TEST_F(SurfaceFactoryTest, InvalidClientId) {
531 uint32_t id_namespace = 9u; 529 const uint32_t client_id = 9u;
532 SurfaceId id(id_namespace, 5, 0); 530 TestSurfaceFactoryClient client2;
533 factory_->Create(id); 531 // Every client must get a new SurfaceFactory.
532 std::unique_ptr<SurfaceFactory> factory2(
533 new SurfaceFactory(client_id, &manager_, &client2));
534 SurfaceId id(client_id, 5, 0);
535 factory2->Create(id);
534 536
535 manager_.RegisterSurfaceClientId(id_namespace); 537 manager_.GetSurfaceForId(id)->AddDestructionDependency(
536 manager_.GetSurfaceForId(id) 538 SurfaceSequence(client_id, 4));
537 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); 539 factory2->Destroy(id);
538 factory_->Destroy(id);
539 540
540 // Verify the dependency has prevented the surface from getting destroyed. 541 // Verify the dependency has prevented the surface from getting destroyed.
541 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 542 EXPECT_TRUE(manager_.GetSurfaceForId(id));
542 543
543 manager_.InvalidateSurfaceClientId(id_namespace); 544 factory2.reset();
544 545
545 // Verify that the invalidated namespace caused the unsatisfied sequence 546 // Verify that the invalidated namespace caused the unsatisfied sequence
546 // to be ignored. 547 // to be ignored.
547 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 548 EXPECT_FALSE(manager_.GetSurfaceForId(id));
548 } 549 }
549 550
550 TEST_F(SurfaceFactoryTest, DestroyCycle) { 551 TEST_F(SurfaceFactoryTest, DestroyCycle) {
551 SurfaceId id2(kArbitraryClientId, 5, 0); 552 SurfaceId id2(kArbitraryClientId, 5, 0);
552 factory_->Create(id2); 553 factory_->Create(id2);
553 554
554 manager_.RegisterSurfaceClientId(0);
555
556 manager_.GetSurfaceForId(id2) 555 manager_.GetSurfaceForId(id2)
557 ->AddDestructionDependency(SurfaceSequence(0, 4)); 556 ->AddDestructionDependency(SurfaceSequence(0, 4));
558 557
559 // Give id2 a frame that references surface_id_. 558 // Give id2 a frame that references surface_id_.
560 { 559 {
561 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 560 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
562 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 561 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
563 frame_data->render_pass_list.push_back(std::move(render_pass)); 562 frame_data->render_pass_list.push_back(std::move(render_pass));
564 CompositorFrame frame; 563 CompositorFrame frame;
565 frame.metadata.referenced_surfaces.push_back(surface_id_); 564 frame.metadata.referenced_surfaces.push_back(surface_id_);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 648
650 factory_->Destroy(surface_id_); 649 factory_->Destroy(surface_id_);
651 surface_id_ = SurfaceId(); 650 surface_id_ = SurfaceId();
652 EXPECT_TRUE(called1); 651 EXPECT_TRUE(called1);
653 EXPECT_TRUE(called2); 652 EXPECT_TRUE(called2);
654 EXPECT_TRUE(called3); 653 EXPECT_TRUE(called3);
655 } 654 }
656 655
657 } // namespace 656 } // namespace
658 } // namespace cc 657 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698