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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: up 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>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { 66 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver {
67 public: 67 public:
68 SurfaceFactoryTest() 68 SurfaceFactoryTest()
69 : factory_( 69 : factory_(
70 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), 70 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)),
71 local_frame_id_(3, 0), 71 local_frame_id_(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(local_frame_id_); 75 factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(),
76 SurfaceFactory::DrawCallback());
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 factory_->Destroy(local_frame_id_);
97 manager_.RemoveObserver(this); 96 manager_.RemoveObserver(this);
98 } 97 }
99 98
100 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 99 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
101 size_t num_resource_ids) { 100 size_t num_resource_ids) {
102 CompositorFrame frame; 101 CompositorFrame frame;
103 for (size_t i = 0u; i < num_resource_ids; ++i) { 102 for (size_t i = 0u; i < num_resource_ids; ++i) {
104 TransferableResource resource; 103 TransferableResource resource;
105 resource.id = resource_ids[i]; 104 resource.id = resource_ids[i];
106 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 105 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 int expected_returned_counts[] = {2, 2}; 426 int expected_returned_counts[] = {2, 2};
428 CheckReturnedResourcesMatchExpected( 427 CheckReturnedResourcesMatchExpected(
429 expected_returned_ids, expected_returned_counts, 428 expected_returned_ids, expected_returned_counts,
430 arraysize(expected_returned_counts), consumer_sync_token_); 429 arraysize(expected_returned_counts), consumer_sync_token_);
431 } 430 }
432 } 431 }
433 432
434 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 433 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
435 LocalFrameId local_frame_id(6, 0); 434 LocalFrameId local_frame_id(6, 0);
436 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 435 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
437 factory_->Create(local_frame_id); 436 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
437 SurfaceFactory::DrawCallback());
438 Surface* surface = manager_.GetSurfaceForId(surface_id); 438 Surface* surface = manager_.GetSurfaceForId(surface_id);
439 ASSERT_NE(nullptr, surface); 439 ASSERT_NE(nullptr, surface);
440 EXPECT_EQ(2, surface->frame_index()); 440 EXPECT_EQ(2, surface->frame_index());
441
442 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
443 SurfaceFactory::DrawCallback());
444 EXPECT_EQ(2, surface->frame_index());
445 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); 441 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id);
446 factory_->Destroy(local_frame_id);
447 } 442 }
448 443
449 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 444 // Tests that SurfaceFactory doesn't return resources after Reset().
450 uint32_t* execute_count) { 445 TEST_F(SurfaceFactoryTest, Reset) {
451 LocalFrameId new_id(7, 0);
452 factory->Create(new_id);
453 factory->Destroy(new_id);
454 *execute_count += 1;
455 }
456
457 TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
458 LocalFrameId local_frame_id(6, 0);
459 factory_->Create(local_frame_id);
460
461 uint32_t execute_count = 0;
462 factory_->SubmitCompositorFrame(
463 local_frame_id, CompositorFrame(),
464 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
465 &execute_count));
466 EXPECT_EQ(0u, execute_count);
467 factory_->Destroy(local_frame_id);
468 EXPECT_EQ(1u, execute_count);
469 }
470
471 void DrawCallback(uint32_t* execute_count) {
472 *execute_count += 1;
473 }
474
475 // Tests doing a DestroyAll before shutting down the factory;
476 TEST_F(SurfaceFactoryTest, DestroyAll) {
477 LocalFrameId id(7, 0); 446 LocalFrameId id(7, 0);
478 factory_->Create(id);
479 447
480 TransferableResource resource; 448 TransferableResource resource;
481 resource.id = 1; 449 resource.id = 1;
482 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 450 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
483 CompositorFrame frame; 451 CompositorFrame frame;
484 frame.resource_list.push_back(resource); 452 frame.resource_list.push_back(resource);
485 uint32_t execute_count = 0;
486 factory_->SubmitCompositorFrame(id, std::move(frame), 453 factory_->SubmitCompositorFrame(id, std::move(frame),
487 base::Bind(&DrawCallback, &execute_count)); 454 SurfaceFactory::DrawCallback());
488 EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
489 local_frame_id_ = LocalFrameId();
490 factory_->DestroyAll();
491 EXPECT_EQ(1u, execute_count);
492 }
493
494 // Tests that SurfaceFactory doesn't return resources after Reset().
495 TEST_F(SurfaceFactoryTest, Reset) {
496 LocalFrameId id(7, 0);
497 factory_->Create(id);
498
499 TransferableResource resource;
500 resource.id = 1;
501 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
502 CompositorFrame frame;
503 frame.resource_list.push_back(resource);
504 uint32_t execute_count = 0;
505 factory_->SubmitCompositorFrame(id, std::move(frame),
506 base::Bind(&DrawCallback, &execute_count));
507 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); 455 EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
508 456
509 SurfaceId surface_id(kArbitraryFrameSinkId, id); 457 SurfaceId surface_id(kArbitraryFrameSinkId, id);
510 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); 458 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id);
511 factory_->Reset(); 459 factory_->Reset();
512 EXPECT_TRUE(client_.returned_resources().empty()); 460 EXPECT_TRUE(client_.returned_resources().empty());
513 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); 461 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id);
514 EXPECT_TRUE(client_.returned_resources().empty()); 462 EXPECT_TRUE(client_.returned_resources().empty());
515 local_frame_id_ = LocalFrameId(); 463 local_frame_id_ = LocalFrameId();
516 } 464 }
517 465
518 TEST_F(SurfaceFactoryTest, DestroySequence) { 466 TEST_F(SurfaceFactoryTest, DestroySequence) {
467 SurfaceFactory* factory2 =
468 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_);
519 LocalFrameId local_frame_id2(5, 0); 469 LocalFrameId local_frame_id2(5, 0);
520 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 470 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
521 factory_->Create(local_frame_id2); 471 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
472 SurfaceFactory::DrawCallback());
522 473
523 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 474 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
524 475
525 // Check that waiting before the sequence is satisfied works. 476 // Check that waiting before the sequence is satisfied works.
526 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 477 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
527 SurfaceSequence(kArbitraryFrameSinkId, 4)); 478 SurfaceSequence(kArbitraryFrameSinkId, 4));
528 factory_->Destroy(local_frame_id2); 479 factory2->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(),
480 SurfaceFactory::DrawCallback());
529 481
530 CompositorFrame frame; 482 CompositorFrame frame;
531 frame.metadata.satisfies_sequences.push_back(6); 483 frame.metadata.satisfies_sequences.push_back(6);
532 frame.metadata.satisfies_sequences.push_back(4); 484 frame.metadata.satisfies_sequences.push_back(4);
533 DCHECK(manager_.GetSurfaceForId(id2)); 485 DCHECK(manager_.GetSurfaceForId(id2));
534 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 486 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
535 SurfaceFactory::DrawCallback()); 487 SurfaceFactory::DrawCallback());
536 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); 488 // EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
537 DCHECK(!manager_.GetSurfaceForId(id2)); 489 DCHECK(!manager_.GetSurfaceForId(id2));
538 490
539 // Check that waiting after the sequence is satisfied works. 491 // Check that waiting after the sequence is satisfied works.
540 factory_->Create(local_frame_id2); 492 factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
493 SurfaceFactory::DrawCallback());
541 DCHECK(manager_.GetSurfaceForId(id2)); 494 DCHECK(manager_.GetSurfaceForId(id2));
542 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 495 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
543 SurfaceSequence(FrameSinkId(0, 0), 6)); 496 SurfaceSequence(FrameSinkId(0, 0), 6));
544 factory_->Destroy(local_frame_id2); 497 factory2->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(),
498 SurfaceFactory::DrawCallback());
545 DCHECK(!manager_.GetSurfaceForId(id2)); 499 DCHECK(!manager_.GetSurfaceForId(id2));
546 } 500 }
547 501
548 // Tests that Surface ID namespace invalidation correctly allows 502 // Tests that Surface ID namespace invalidation correctly allows
549 // Sequences to be ignored. 503 // Sequences to be ignored.
550 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { 504 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
551 FrameSinkId frame_sink_id(1234, 5678); 505 FrameSinkId frame_sink_id(1234, 5678);
552 506
553 LocalFrameId local_frame_id(5, 0); 507 LocalFrameId local_frame_id(5, 0);
554 SurfaceId id(factory_->frame_sink_id(), local_frame_id); 508 SurfaceId id(factory_->frame_sink_id(), local_frame_id);
555 factory_->Create(local_frame_id); 509 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
510 SurfaceFactory::DrawCallback());
556 511
557 manager_.RegisterFrameSinkId(frame_sink_id); 512 manager_.RegisterFrameSinkId(frame_sink_id);
558 manager_.GetSurfaceForId(id)->AddDestructionDependency( 513 manager_.GetSurfaceForId(id)->AddDestructionDependency(
559 SurfaceSequence(frame_sink_id, 4)); 514 SurfaceSequence(frame_sink_id, 4));
560 factory_->Destroy(local_frame_id); 515
516 LocalFrameId local_frame_id_2(6, 0);
517 factory_->SubmitCompositorFrame(local_frame_id_2, CompositorFrame(),
518 SurfaceFactory::DrawCallback());
561 519
562 // Verify the dependency has prevented the surface from getting destroyed. 520 // Verify the dependency has prevented the surface from getting destroyed.
563 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 521 EXPECT_TRUE(manager_.GetSurfaceForId(id));
564 522
565 manager_.InvalidateFrameSinkId(frame_sink_id); 523 manager_.InvalidateFrameSinkId(frame_sink_id);
566 524
567 // Verify that the invalidated namespace caused the unsatisfied sequence 525 // Verify that the invalidated namespace caused the unsatisfied sequence
568 // to be ignored. 526 // to be ignored.
569 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 527 EXPECT_FALSE(manager_.GetSurfaceForId(id));
570 } 528 }
571 529
572 TEST_F(SurfaceFactoryTest, DestroyCycle) { 530 TEST_F(SurfaceFactoryTest, DestroyCycle) {
573 LocalFrameId local_frame_id2(5, 0); 531 LocalFrameId local_frame_id2(5, 0);
574 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 532 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
575 factory_->Create(local_frame_id2); 533 SurfaceFactory* factory2 =
534 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_);
535 // factory2->SubmitCompositorFrame(local_frame_id2, CompositorFrame(),
536 // SurfaceFactory::DrawCallback());
576 537
577 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); 538 manager_.RegisterFrameSinkId(FrameSinkId(0, 0));
578 539
579 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
580 SurfaceSequence(FrameSinkId(0, 0), 4));
581 540
582 // Give id2 a frame that references local_frame_id_. 541 // Give id2 a frame that references local_frame_id_.
583 { 542 {
584 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 543 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
585 CompositorFrame frame; 544 CompositorFrame frame;
586 frame.render_pass_list.push_back(std::move(render_pass)); 545 frame.render_pass_list.push_back(std::move(render_pass));
587 frame.metadata.referenced_surfaces.push_back( 546 frame.metadata.referenced_surfaces.push_back(
588 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 547 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
589 factory_->SubmitCompositorFrame(local_frame_id2, std::move(frame), 548 factory2->SubmitCompositorFrame(local_frame_id2, std::move(frame),
590 SurfaceFactory::DrawCallback()); 549 SurfaceFactory::DrawCallback());
591 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2); 550 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id2);
592 } 551 }
593 factory_->Destroy(local_frame_id2); 552 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
594 553 SurfaceSequence(FrameSinkId(0, 0), 4));
554 factory2->SubmitCompositorFrame(LocalFrameId(0, 0), CompositorFrame(),
555 SurfaceFactory::DrawCallback());
556 LOG(ERROR) << manager_.GetSurfaceForId(id2)->referenced_surfaces().size();
595 // Give local_frame_id_ a frame that references id2. 557 // Give local_frame_id_ a frame that references id2.
596 { 558 {
597 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 559 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
598 CompositorFrame frame; 560 CompositorFrame frame;
599 frame.render_pass_list.push_back(std::move(render_pass)); 561 frame.render_pass_list.push_back(std::move(render_pass));
600 frame.metadata.referenced_surfaces.push_back(id2); 562 frame.metadata.referenced_surfaces.push_back(id2);
601 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 563 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
602 SurfaceFactory::DrawCallback()); 564 SurfaceFactory::DrawCallback());
603 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
604 } 565 }
605 factory_->Destroy(local_frame_id_); 566 factory_->SubmitCompositorFrame(LocalFrameId(0, 1), CompositorFrame(),
567 SurfaceFactory::DrawCallback());
606 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 568 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
607 // local_frame_id_ should be retained by reference from id2. 569 // local_frame_id_ should be retained by reference from id2.
608 EXPECT_TRUE(manager_.GetSurfaceForId( 570 EXPECT_TRUE(manager_.GetSurfaceForId(
609 SurfaceId(factory_->frame_sink_id(), local_frame_id_))); 571 SurfaceId(factory_->frame_sink_id(), local_frame_id_)));
610 572
611 // Satisfy last destruction dependency for id2. 573 // Satisfy last destruction dependency for id2.
612 std::vector<uint32_t> to_satisfy; 574 std::vector<uint32_t> to_satisfy;
613 to_satisfy.push_back(4); 575 to_satisfy.push_back(4);
614 manager_.DidSatisfySequences(FrameSinkId(0, 0), &to_satisfy); 576 manager_.DidSatisfySequences(FrameSinkId(0, 0), &to_satisfy);
615 577
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 request = CopyOutputRequest::CreateRequest( 626 request = CopyOutputRequest::CreateRequest(
665 base::Bind(&CopyRequestTestCallback, &called3)); 627 base::Bind(&CopyRequestTestCallback, &called3));
666 request->set_source(source1); 628 request->set_source(source1);
667 629
668 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request)); 630 factory_->RequestCopyOfSurface(local_frame_id_, std::move(request));
669 // Two callbacks are from source1, so the first should be called. 631 // Two callbacks are from source1, so the first should be called.
670 EXPECT_TRUE(called1); 632 EXPECT_TRUE(called1);
671 EXPECT_FALSE(called2); 633 EXPECT_FALSE(called2);
672 EXPECT_FALSE(called3); 634 EXPECT_FALSE(called3);
673 635
674 factory_->Destroy(local_frame_id_);
675 local_frame_id_ = LocalFrameId(); 636 local_frame_id_ = LocalFrameId();
637 factory_->SubmitCompositorFrame(local_frame_id_, CompositorFrame(),
638 SurfaceFactory::DrawCallback());
676 EXPECT_TRUE(called1); 639 EXPECT_TRUE(called1);
677 EXPECT_TRUE(called2); 640 EXPECT_TRUE(called2);
678 EXPECT_TRUE(called3); 641 EXPECT_TRUE(called3);
679 } 642 }
680 643
681 } // namespace 644 } // namespace
682 } // namespace cc 645 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698