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

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

Issue 2449853004: Getting rid of DelegatedFrameData (Closed)
Patch Set: IsEmpty + 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>
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/output/delegated_frame_data.h"
18 #include "cc/resources/resource_provider.h" 17 #include "cc/resources/resource_provider.h"
19 #include "cc/surfaces/surface.h" 18 #include "cc/surfaces/surface.h"
20 #include "cc/surfaces/surface_factory_client.h" 19 #include "cc/surfaces/surface_factory_client.h"
21 #include "cc/surfaces/surface_manager.h" 20 #include "cc/surfaces/surface_manager.h"
22 #include "cc/test/scheduler_test_common.h" 21 #include "cc/test/scheduler_test_common.h"
23 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
25 24
26 namespace cc { 25 namespace cc {
27 namespace { 26 namespace {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 92 }
94 93
95 ~SurfaceFactoryTest() override { 94 ~SurfaceFactoryTest() override {
96 if (!local_frame_id_.is_null()) 95 if (!local_frame_id_.is_null())
97 factory_->Destroy(local_frame_id_); 96 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 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 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;
108 resource.mailbox_holder.sync_token = frame_sync_token_; 107 resource.mailbox_holder.sync_token = frame_sync_token_;
109 frame_data->resource_list.push_back(resource); 108 frame.resource_list.push_back(resource);
110 } 109 }
111 CompositorFrame frame;
112 frame.delegated_frame_data = std::move(frame_data);
113 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 110 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
114 SurfaceFactory::DrawCallback()); 111 SurfaceFactory::DrawCallback());
115 EXPECT_EQ(last_created_surface_id_.local_frame_id(), local_frame_id_); 112 EXPECT_EQ(last_created_surface_id_.local_frame_id(), local_frame_id_);
116 } 113 }
117 114
118 void UnrefResources(ResourceId* ids_to_unref, 115 void UnrefResources(ResourceId* ids_to_unref,
119 int* counts_to_unref, 116 int* counts_to_unref,
120 size_t num_ids_to_unref) { 117 size_t num_ids_to_unref) {
121 ReturnedResourceArray unref_array; 118 ReturnedResourceArray unref_array;
122 for (size_t i = 0; i < num_ids_to_unref; ++i) { 119 for (size_t i = 0; i < num_ids_to_unref; ++i) {
(...skipping 18 matching lines...) Expand all
141 EXPECT_EQ(expected_sync_token, resource.sync_token); 138 EXPECT_EQ(expected_sync_token, resource.sync_token);
142 EXPECT_EQ(expected_returned_ids[i], resource.id); 139 EXPECT_EQ(expected_returned_ids[i], resource.id);
143 EXPECT_EQ(expected_returned_counts[i], resource.count); 140 EXPECT_EQ(expected_returned_counts[i], resource.count);
144 } 141 }
145 client_.clear_returned_resources(); 142 client_.clear_returned_resources();
146 } 143 }
147 144
148 void RefCurrentFrameResources() { 145 void RefCurrentFrameResources() {
149 Surface* surface = manager_.GetSurfaceForId( 146 Surface* surface = manager_.GetSurfaceForId(
150 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 147 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
151 factory_->RefResources( 148 factory_->RefResources(surface->GetEligibleFrame().resource_list);
152 surface->GetEligibleFrame().delegated_frame_data->resource_list);
153 } 149 }
154 150
155 protected: 151 protected:
156 SurfaceManager manager_; 152 SurfaceManager manager_;
157 TestSurfaceFactoryClient client_; 153 TestSurfaceFactoryClient client_;
158 std::unique_ptr<SurfaceFactory> factory_; 154 std::unique_ptr<SurfaceFactory> factory_;
159 LocalFrameId local_frame_id_; 155 LocalFrameId local_frame_id_;
160 SurfaceId last_created_surface_id_; 156 SurfaceId last_created_surface_id_;
161 157
162 // This is the sync token submitted with the frame. It should never be 158 // This is the sync token submitted with the frame. It should never be
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 432 }
437 433
438 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
439 LocalFrameId local_frame_id(6, 0); 435 LocalFrameId local_frame_id(6, 0);
440 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
441 factory_->Create(local_frame_id); 437 factory_->Create(local_frame_id);
442 Surface* surface = manager_.GetSurfaceForId(surface_id); 438 Surface* surface = manager_.GetSurfaceForId(surface_id);
443 ASSERT_NE(nullptr, surface); 439 ASSERT_NE(nullptr, surface);
444 EXPECT_EQ(2, surface->frame_index()); 440 EXPECT_EQ(2, surface->frame_index());
445 CompositorFrame frame; 441 CompositorFrame frame;
446 frame.delegated_frame_data.reset(new DelegatedFrameData);
447 442
448 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame), 443 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame),
danakj 2016/10/27 23:06:56 just pass a CompositorFrame(), no need for the fra
Saman Sami 2016/10/28 16:47:35 Done.
449 SurfaceFactory::DrawCallback()); 444 SurfaceFactory::DrawCallback());
450 EXPECT_EQ(2, surface->frame_index()); 445 EXPECT_EQ(2, surface->frame_index());
451 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);
452 factory_->Destroy(local_frame_id); 447 factory_->Destroy(local_frame_id);
453 } 448 }
454 449
455 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 450 void CreateSurfaceDrawCallback(SurfaceFactory* factory,
456 uint32_t* execute_count) { 451 uint32_t* execute_count) {
457 LocalFrameId new_id(7, 0); 452 LocalFrameId new_id(7, 0);
458 factory->Create(new_id); 453 factory->Create(new_id);
459 factory->Destroy(new_id); 454 factory->Destroy(new_id);
460 *execute_count += 1; 455 *execute_count += 1;
461 } 456 }
462 457
463 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { 458 TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
464 LocalFrameId local_frame_id(6, 0); 459 LocalFrameId local_frame_id(6, 0);
465 factory_->Create(local_frame_id); 460 factory_->Create(local_frame_id);
466 CompositorFrame frame; 461 CompositorFrame frame;
467 frame.delegated_frame_data.reset(new DelegatedFrameData);
468 462
469 uint32_t execute_count = 0; 463 uint32_t execute_count = 0;
470 factory_->SubmitCompositorFrame( 464 factory_->SubmitCompositorFrame(
471 local_frame_id, std::move(frame), 465 local_frame_id, std::move(frame),
danakj 2016/10/27 23:06:56 same
Saman Sami 2016/10/28 16:47:35 Done.
472 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), 466 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
473 &execute_count)); 467 &execute_count));
474 EXPECT_EQ(0u, execute_count); 468 EXPECT_EQ(0u, execute_count);
475 factory_->Destroy(local_frame_id); 469 factory_->Destroy(local_frame_id);
476 EXPECT_EQ(1u, execute_count); 470 EXPECT_EQ(1u, execute_count);
477 } 471 }
478 472
479 void DrawCallback(uint32_t* execute_count) { 473 void DrawCallback(uint32_t* execute_count) {
480 *execute_count += 1; 474 *execute_count += 1;
481 } 475 }
482 476
483 // Tests doing a DestroyAll before shutting down the factory; 477 // Tests doing a DestroyAll before shutting down the factory;
484 TEST_F(SurfaceFactoryTest, DestroyAll) { 478 TEST_F(SurfaceFactoryTest, DestroyAll) {
485 LocalFrameId id(7, 0); 479 LocalFrameId id(7, 0);
486 factory_->Create(id); 480 factory_->Create(id);
487 481
488 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
489 TransferableResource resource; 482 TransferableResource resource;
490 resource.id = 1; 483 resource.id = 1;
491 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 484 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
492 frame_data->resource_list.push_back(resource);
493 CompositorFrame frame; 485 CompositorFrame frame;
494 frame.delegated_frame_data = std::move(frame_data); 486 frame.resource_list.push_back(resource);
495 uint32_t execute_count = 0; 487 uint32_t execute_count = 0;
496 factory_->SubmitCompositorFrame(id, std::move(frame), 488 factory_->SubmitCompositorFrame(id, std::move(frame),
497 base::Bind(&DrawCallback, &execute_count)); 489 base::Bind(&DrawCallback, &execute_count));
498 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); 490 EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
499 local_frame_id_ = LocalFrameId(); 491 local_frame_id_ = LocalFrameId();
500 factory_->DestroyAll(); 492 factory_->DestroyAll();
501 EXPECT_EQ(1u, execute_count); 493 EXPECT_EQ(1u, execute_count);
502 } 494 }
503 495
504 TEST_F(SurfaceFactoryTest, DestroySequence) { 496 TEST_F(SurfaceFactoryTest, DestroySequence) {
505 LocalFrameId local_frame_id2(5, 0); 497 LocalFrameId local_frame_id2(5, 0);
506 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 498 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
507 factory_->Create(local_frame_id2); 499 factory_->Create(local_frame_id2);
508 500
509 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 501 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
510 502
511 // Check that waiting before the sequence is satisfied works. 503 // Check that waiting before the sequence is satisfied works.
512 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 504 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
513 SurfaceSequence(kArbitraryFrameSinkId, 4)); 505 SurfaceSequence(kArbitraryFrameSinkId, 4));
514 factory_->Destroy(local_frame_id2); 506 factory_->Destroy(local_frame_id2);
515 507
516 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
517 CompositorFrame frame; 508 CompositorFrame frame;
518 frame.metadata.satisfies_sequences.push_back(6); 509 frame.metadata.satisfies_sequences.push_back(6);
519 frame.metadata.satisfies_sequences.push_back(4); 510 frame.metadata.satisfies_sequences.push_back(4);
520 frame.delegated_frame_data = std::move(frame_data);
521 DCHECK(manager_.GetSurfaceForId(id2)); 511 DCHECK(manager_.GetSurfaceForId(id2));
522 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 512 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
523 SurfaceFactory::DrawCallback()); 513 SurfaceFactory::DrawCallback());
524 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); 514 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
525 DCHECK(!manager_.GetSurfaceForId(id2)); 515 DCHECK(!manager_.GetSurfaceForId(id2));
526 516
527 // Check that waiting after the sequence is satisfied works. 517 // Check that waiting after the sequence is satisfied works.
528 factory_->Create(local_frame_id2); 518 factory_->Create(local_frame_id2);
529 DCHECK(manager_.GetSurfaceForId(id2)); 519 DCHECK(manager_.GetSurfaceForId(id2));
530 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 520 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 factory_->Create(local_frame_id2); 553 factory_->Create(local_frame_id2);
564 554
565 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); 555 manager_.RegisterFrameSinkId(FrameSinkId(0, 0));
566 556
567 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 557 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
568 SurfaceSequence(FrameSinkId(0, 0), 4)); 558 SurfaceSequence(FrameSinkId(0, 0), 4));
569 559
570 // Give id2 a frame that references local_frame_id_. 560 // Give id2 a frame that references local_frame_id_.
571 { 561 {
572 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 562 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
573 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
574 frame_data->render_pass_list.push_back(std::move(render_pass));
575 CompositorFrame frame; 563 CompositorFrame frame;
564 frame.render_pass_list.push_back(std::move(render_pass));
576 frame.metadata.referenced_surfaces.push_back( 565 frame.metadata.referenced_surfaces.push_back(
577 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 566 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
578 frame.delegated_frame_data = std::move(frame_data);
579 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), 567 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame),
580 SurfaceFactory::DrawCallback()); 568 SurfaceFactory::DrawCallback());
581 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); 569 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2);
582 } 570 }
583 factory_->Destroy(local_frame_id2); 571 factory_->Destroy(local_frame_id2);
584 572
585 // Give local_frame_id_ a frame that references id2. 573 // Give local_frame_id_ a frame that references id2.
586 { 574 {
587 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 575 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
588 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
589 frame_data->render_pass_list.push_back(std::move(render_pass));
590 CompositorFrame frame; 576 CompositorFrame frame;
577 frame.render_pass_list.push_back(std::move(render_pass));
591 frame.metadata.referenced_surfaces.push_back(id2); 578 frame.metadata.referenced_surfaces.push_back(id2);
592 frame.delegated_frame_data = std::move(frame_data);
593 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 579 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
594 SurfaceFactory::DrawCallback()); 580 SurfaceFactory::DrawCallback());
595 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); 581 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
596 } 582 }
597 factory_->Destroy(local_frame_id_); 583 factory_->Destroy(local_frame_id_);
598 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 584 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
599 // local_frame_id_ should be retained by reference from id2. 585 // local_frame_id_ should be retained by reference from id2.
600 EXPECT_TRUE(manager_.GetSurfaceForId( 586 EXPECT_TRUE(manager_.GetSurfaceForId(
601 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); 587 SurfaceId(factory_->frame_sink_id(), local_frame_id_)));
602 588
(...skipping 12 matching lines...) Expand all
615 } 601 }
616 602
617 void CopyRequestTestCallback(bool* called, 603 void CopyRequestTestCallback(bool* called,
618 std::unique_ptr<CopyOutputResult> result) { 604 std::unique_ptr<CopyOutputResult> result) {
619 *called = true; 605 *called = true;
620 } 606 }
621 607
622 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { 608 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) {
623 { 609 {
624 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 610 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
625 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
626 frame_data->render_pass_list.push_back(std::move(render_pass));
627 CompositorFrame frame; 611 CompositorFrame frame;
612 frame.render_pass_list.push_back(std::move(render_pass));
628 frame.metadata.referenced_surfaces.push_back( 613 frame.metadata.referenced_surfaces.push_back(
629 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 614 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
630 frame.delegated_frame_data = std::move(frame_data);
631 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 615 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
632 SurfaceFactory::DrawCallback()); 616 SurfaceFactory::DrawCallback());
633 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); 617 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
634 } 618 }
635 void* source1 = &source1; 619 void* source1 = &source1;
636 void* source2 = &source2; 620 void* source2 = &source2;
637 621
638 bool called1 = false; 622 bool called1 = false;
639 std::unique_ptr<CopyOutputRequest> request; 623 std::unique_ptr<CopyOutputRequest> request;
640 request = CopyOutputRequest::CreateRequest( 624 request = CopyOutputRequest::CreateRequest(
(...skipping 26 matching lines...) Expand all
667 651
668 factory_->Destroy(local_frame_id_); 652 factory_->Destroy(local_frame_id_);
669 local_frame_id_ = LocalFrameId(); 653 local_frame_id_ = LocalFrameId();
670 EXPECT_TRUE(called1); 654 EXPECT_TRUE(called1);
671 EXPECT_TRUE(called2); 655 EXPECT_TRUE(called2);
672 EXPECT_TRUE(called3); 656 EXPECT_TRUE(called3);
673 } 657 }
674 658
675 } // namespace 659 } // namespace
676 } // namespace cc 660 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698