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

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

Issue 2098953003: Make cc::CompositorFrames movable [Part 2 of 2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed exo unittests 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.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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 87 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
88 size_t num_resource_ids) { 88 size_t num_resource_ids) {
89 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 89 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
90 for (size_t i = 0u; i < num_resource_ids; ++i) { 90 for (size_t i = 0u; i < num_resource_ids; ++i) {
91 TransferableResource resource; 91 TransferableResource resource;
92 resource.id = resource_ids[i]; 92 resource.id = resource_ids[i];
93 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 93 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
94 resource.mailbox_holder.sync_token = frame_sync_token_; 94 resource.mailbox_holder.sync_token = frame_sync_token_;
95 frame_data->resource_list.push_back(resource); 95 frame_data->resource_list.push_back(resource);
96 } 96 }
97 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 97 CompositorFrame frame;
98 frame->delegated_frame_data = std::move(frame_data); 98 frame.delegated_frame_data = std::move(frame_data);
99 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 99 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
100 SurfaceFactory::DrawCallback()); 100 SurfaceFactory::DrawCallback());
101 } 101 }
102 102
103 void UnrefResources(ResourceId* ids_to_unref, 103 void UnrefResources(ResourceId* ids_to_unref,
104 int* counts_to_unref, 104 int* counts_to_unref,
105 size_t num_ids_to_unref) { 105 size_t num_ids_to_unref) {
106 ReturnedResourceArray unref_array; 106 ReturnedResourceArray unref_array;
107 for (size_t i = 0; i < num_ids_to_unref; ++i) { 107 for (size_t i = 0; i < num_ids_to_unref; ++i) {
108 ReturnedResource resource; 108 ReturnedResource resource;
(...skipping 17 matching lines...) Expand all
126 EXPECT_EQ(expected_sync_token, resource.sync_token); 126 EXPECT_EQ(expected_sync_token, resource.sync_token);
127 EXPECT_EQ(expected_returned_ids[i], resource.id); 127 EXPECT_EQ(expected_returned_ids[i], resource.id);
128 EXPECT_EQ(expected_returned_counts[i], resource.count); 128 EXPECT_EQ(expected_returned_counts[i], resource.count);
129 } 129 }
130 client_.clear_returned_resources(); 130 client_.clear_returned_resources();
131 } 131 }
132 132
133 void RefCurrentFrameResources() { 133 void RefCurrentFrameResources() {
134 Surface* surface = manager_.GetSurfaceForId(surface_id_); 134 Surface* surface = manager_.GetSurfaceForId(surface_id_);
135 factory_->RefResources( 135 factory_->RefResources(
136 surface->GetEligibleFrame()->delegated_frame_data->resource_list); 136 surface->GetEligibleFrame().delegated_frame_data->resource_list);
137 } 137 }
138 138
139 protected: 139 protected:
140 SurfaceManager manager_; 140 SurfaceManager manager_;
141 TestSurfaceFactoryClient client_; 141 TestSurfaceFactoryClient client_;
142 std::unique_ptr<SurfaceFactory> factory_; 142 std::unique_ptr<SurfaceFactory> factory_;
143 SurfaceId surface_id_; 143 SurfaceId surface_id_;
144 144
145 // This is the sync token submitted with the frame. It should never be 145 // This is the sync token submitted with the frame. It should never be
146 // returned to the client. 146 // returned to the client.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 arraysize(expected_returned_counts), consumer_sync_token_); 417 arraysize(expected_returned_counts), consumer_sync_token_);
418 } 418 }
419 } 419 }
420 420
421 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 421 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
422 SurfaceId surface_id(0, 6, 0); 422 SurfaceId surface_id(0, 6, 0);
423 factory_->Create(surface_id); 423 factory_->Create(surface_id);
424 Surface* surface = manager_.GetSurfaceForId(surface_id); 424 Surface* surface = manager_.GetSurfaceForId(surface_id);
425 ASSERT_NE(nullptr, surface); 425 ASSERT_NE(nullptr, surface);
426 EXPECT_EQ(2, surface->frame_index()); 426 EXPECT_EQ(2, surface->frame_index());
427 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 427 CompositorFrame frame;
428 frame->delegated_frame_data.reset(new DelegatedFrameData); 428 frame.delegated_frame_data.reset(new DelegatedFrameData);
429 429
430 factory_->SubmitCompositorFrame(surface_id, std::move(frame), 430 factory_->SubmitCompositorFrame(surface_id, std::move(frame),
431 SurfaceFactory::DrawCallback()); 431 SurfaceFactory::DrawCallback());
432 EXPECT_EQ(2, surface->frame_index()); 432 EXPECT_EQ(2, surface->frame_index());
433 factory_->Destroy(surface_id); 433 factory_->Destroy(surface_id);
434 } 434 }
435 435
436 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 436 void CreateSurfaceDrawCallback(SurfaceFactory* factory,
437 uint32_t* execute_count, 437 uint32_t* execute_count,
438 SurfaceDrawStatus* result, 438 SurfaceDrawStatus* result,
439 SurfaceDrawStatus drawn) { 439 SurfaceDrawStatus drawn) {
440 SurfaceId new_id(0, 7, 0); 440 SurfaceId new_id(0, 7, 0);
441 factory->Create(new_id); 441 factory->Create(new_id);
442 factory->Destroy(new_id); 442 factory->Destroy(new_id);
443 *execute_count += 1; 443 *execute_count += 1;
444 *result = drawn; 444 *result = drawn;
445 } 445 }
446 446
447 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { 447 TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
448 SurfaceId surface_id(0, 6, 0); 448 SurfaceId surface_id(0, 6, 0);
449 factory_->Create(surface_id); 449 factory_->Create(surface_id);
450 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 450 CompositorFrame frame;
451 frame->delegated_frame_data.reset(new DelegatedFrameData); 451 frame.delegated_frame_data.reset(new DelegatedFrameData);
452 452
453 uint32_t execute_count = 0; 453 uint32_t execute_count = 0;
454 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; 454 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED;
455 factory_->SubmitCompositorFrame( 455 factory_->SubmitCompositorFrame(
456 surface_id, std::move(frame), 456 surface_id, std::move(frame),
457 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), 457 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
458 &execute_count, &drawn)); 458 &execute_count, &drawn));
459 EXPECT_EQ(0u, execute_count); 459 EXPECT_EQ(0u, execute_count);
460 factory_->Destroy(surface_id); 460 factory_->Destroy(surface_id);
461 EXPECT_EQ(1u, execute_count); 461 EXPECT_EQ(1u, execute_count);
(...skipping 10 matching lines...) Expand all
472 // Tests doing a DestroyAll before shutting down the factory; 472 // Tests doing a DestroyAll before shutting down the factory;
473 TEST_F(SurfaceFactoryTest, DestroyAll) { 473 TEST_F(SurfaceFactoryTest, DestroyAll) {
474 SurfaceId id(0, 7, 0); 474 SurfaceId id(0, 7, 0);
475 factory_->Create(id); 475 factory_->Create(id);
476 476
477 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 477 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
478 TransferableResource resource; 478 TransferableResource resource;
479 resource.id = 1; 479 resource.id = 1;
480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 480 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
481 frame_data->resource_list.push_back(resource); 481 frame_data->resource_list.push_back(resource);
482 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 482 CompositorFrame frame;
483 frame->delegated_frame_data = std::move(frame_data); 483 frame.delegated_frame_data = std::move(frame_data);
484 uint32_t execute_count = 0; 484 uint32_t execute_count = 0;
485 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; 485 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED;
486 486
487 factory_->SubmitCompositorFrame( 487 factory_->SubmitCompositorFrame(
488 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); 488 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn));
489 489
490 surface_id_ = SurfaceId(); 490 surface_id_ = SurfaceId();
491 factory_->DestroyAll(); 491 factory_->DestroyAll();
492 EXPECT_EQ(1u, execute_count); 492 EXPECT_EQ(1u, execute_count);
493 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); 493 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn);
494 } 494 }
495 495
496 TEST_F(SurfaceFactoryTest, DestroySequence) { 496 TEST_F(SurfaceFactoryTest, DestroySequence) {
497 SurfaceId id2(0, 5, 0); 497 SurfaceId id2(0, 5, 0);
498 factory_->Create(id2); 498 factory_->Create(id2);
499 499
500 manager_.RegisterSurfaceIdNamespace(0); 500 manager_.RegisterSurfaceIdNamespace(0);
501 501
502 // Check that waiting before the sequence is satisfied works. 502 // Check that waiting before the sequence is satisfied works.
503 manager_.GetSurfaceForId(id2) 503 manager_.GetSurfaceForId(id2)
504 ->AddDestructionDependency(SurfaceSequence(0, 4)); 504 ->AddDestructionDependency(SurfaceSequence(0, 4));
505 factory_->Destroy(id2); 505 factory_->Destroy(id2);
506 506
507 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 507 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
508 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 508 CompositorFrame frame;
509 frame->metadata.satisfies_sequences.push_back(6); 509 frame.metadata.satisfies_sequences.push_back(6);
510 frame->metadata.satisfies_sequences.push_back(4); 510 frame.metadata.satisfies_sequences.push_back(4);
511 frame->delegated_frame_data = std::move(frame_data); 511 frame.delegated_frame_data = std::move(frame_data);
512 DCHECK(manager_.GetSurfaceForId(id2)); 512 DCHECK(manager_.GetSurfaceForId(id2));
513 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 513 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
514 SurfaceFactory::DrawCallback()); 514 SurfaceFactory::DrawCallback());
515 DCHECK(!manager_.GetSurfaceForId(id2)); 515 DCHECK(!manager_.GetSurfaceForId(id2));
516 516
517 // Check that waiting after the sequence is satisfied works. 517 // Check that waiting after the sequence is satisfied works.
518 factory_->Create(id2); 518 factory_->Create(id2);
519 DCHECK(manager_.GetSurfaceForId(id2)); 519 DCHECK(manager_.GetSurfaceForId(id2));
520 manager_.GetSurfaceForId(id2) 520 manager_.GetSurfaceForId(id2)
521 ->AddDestructionDependency(SurfaceSequence(0, 6)); 521 ->AddDestructionDependency(SurfaceSequence(0, 6));
(...skipping 30 matching lines...) Expand all
552 manager_.RegisterSurfaceIdNamespace(0); 552 manager_.RegisterSurfaceIdNamespace(0);
553 553
554 manager_.GetSurfaceForId(id2) 554 manager_.GetSurfaceForId(id2)
555 ->AddDestructionDependency(SurfaceSequence(0, 4)); 555 ->AddDestructionDependency(SurfaceSequence(0, 4));
556 556
557 // Give id2 a frame that references surface_id_. 557 // Give id2 a frame that references surface_id_.
558 { 558 {
559 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 559 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
560 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 560 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
561 frame_data->render_pass_list.push_back(std::move(render_pass)); 561 frame_data->render_pass_list.push_back(std::move(render_pass));
562 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 562 CompositorFrame frame;
563 frame->metadata.referenced_surfaces.push_back(surface_id_); 563 frame.metadata.referenced_surfaces.push_back(surface_id_);
564 frame->delegated_frame_data = std::move(frame_data); 564 frame.delegated_frame_data = std::move(frame_data);
565 factory_->SubmitCompositorFrame(id2, std::move(frame), 565 factory_->SubmitCompositorFrame(id2, std::move(frame),
566 SurfaceFactory::DrawCallback()); 566 SurfaceFactory::DrawCallback());
567 } 567 }
568 factory_->Destroy(id2); 568 factory_->Destroy(id2);
569 569
570 // Give surface_id_ a frame that references id2. 570 // Give surface_id_ a frame that references id2.
571 { 571 {
572 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 572 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
573 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 573 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
574 frame_data->render_pass_list.push_back(std::move(render_pass)); 574 frame_data->render_pass_list.push_back(std::move(render_pass));
575 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 575 CompositorFrame frame;
576 frame->metadata.referenced_surfaces.push_back(id2); 576 frame.metadata.referenced_surfaces.push_back(id2);
577 frame->delegated_frame_data = std::move(frame_data); 577 frame.delegated_frame_data = std::move(frame_data);
578 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 578 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
579 SurfaceFactory::DrawCallback()); 579 SurfaceFactory::DrawCallback());
580 } 580 }
581 factory_->Destroy(surface_id_); 581 factory_->Destroy(surface_id_);
582 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 582 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
583 // surface_id_ should be retained by reference from id2. 583 // surface_id_ should be retained by reference from id2.
584 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_)); 584 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_));
585 585
586 // Satisfy last destruction dependency for id2. 586 // Satisfy last destruction dependency for id2.
587 std::vector<uint32_t> to_satisfy; 587 std::vector<uint32_t> to_satisfy;
(...skipping 11 matching lines...) Expand all
599 void CopyRequestTestCallback(bool* called, 599 void CopyRequestTestCallback(bool* called,
600 std::unique_ptr<CopyOutputResult> result) { 600 std::unique_ptr<CopyOutputResult> result) {
601 *called = true; 601 *called = true;
602 } 602 }
603 603
604 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { 604 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) {
605 { 605 {
606 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 606 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
607 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 607 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
608 frame_data->render_pass_list.push_back(std::move(render_pass)); 608 frame_data->render_pass_list.push_back(std::move(render_pass));
609 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 609 CompositorFrame frame;
610 frame->metadata.referenced_surfaces.push_back(surface_id_); 610 frame.metadata.referenced_surfaces.push_back(surface_id_);
611 frame->delegated_frame_data = std::move(frame_data); 611 frame.delegated_frame_data = std::move(frame_data);
612 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 612 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
613 SurfaceFactory::DrawCallback()); 613 SurfaceFactory::DrawCallback());
614 } 614 }
615 void* source1 = &source1; 615 void* source1 = &source1;
616 void* source2 = &source2; 616 void* source2 = &source2;
617 617
618 bool called1 = false; 618 bool called1 = false;
619 std::unique_ptr<CopyOutputRequest> request; 619 std::unique_ptr<CopyOutputRequest> request;
620 request = CopyOutputRequest::CreateRequest( 620 request = CopyOutputRequest::CreateRequest(
621 base::Bind(&CopyRequestTestCallback, &called1)); 621 base::Bind(&CopyRequestTestCallback, &called1));
(...skipping 25 matching lines...) Expand all
647 647
648 factory_->Destroy(surface_id_); 648 factory_->Destroy(surface_id_);
649 surface_id_ = SurfaceId(); 649 surface_id_ = SurfaceId();
650 EXPECT_TRUE(called1); 650 EXPECT_TRUE(called1);
651 EXPECT_TRUE(called2); 651 EXPECT_TRUE(called2);
652 EXPECT_TRUE(called3); 652 EXPECT_TRUE(called3);
653 } 653 }
654 654
655 } // namespace 655 } // namespace
656 } // namespace cc 656 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698