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

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

Issue 2379653006: Replaced cc::SurfaceId::nonce_ with base::UnguessableToken (Closed)
Patch Set: Changed SurfaceManager::kRootSurfaceId to a private field to avoid static initialization 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
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.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>
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/resources/resource_provider.h" 17 #include "cc/resources/resource_provider.h"
18 #include "cc/surfaces/surface.h" 18 #include "cc/surfaces/surface.h"
19 #include "cc/surfaces/surface_factory_client.h" 19 #include "cc/surfaces/surface_factory_client.h"
20 #include "cc/surfaces/surface_manager.h" 20 #include "cc/surfaces/surface_manager.h"
21 #include "cc/test/scheduler_test_common.h" 21 #include "cc/test/scheduler_test_common.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
24 24
25 namespace cc { 25 namespace cc {
26 namespace { 26 namespace {
27 27
28 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); 28 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1);
29 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); 29 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2);
30 static const base::UnguessableToken kArbitraryToken =
31 base::UnguessableToken::Create();
30 32
31 class TestSurfaceFactoryClient : public SurfaceFactoryClient { 33 class TestSurfaceFactoryClient : public SurfaceFactoryClient {
32 public: 34 public:
33 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} 35 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
34 ~TestSurfaceFactoryClient() override {} 36 ~TestSurfaceFactoryClient() override {}
35 37
36 void ReturnResources(const ReturnedResourceArray& resources) override { 38 void ReturnResources(const ReturnedResourceArray& resources) override {
37 returned_resources_.insert( 39 returned_resources_.insert(
38 returned_resources_.end(), resources.begin(), resources.end()); 40 returned_resources_.end(), resources.begin(), resources.end());
39 } 41 }
(...skipping 22 matching lines...) Expand all
62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 64 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
63 gpu::CommandBufferId::FromUnsafeValue(id), 1); 65 gpu::CommandBufferId::FromUnsafeValue(id), 1);
64 return token; 66 return token;
65 } 67 }
66 68
67 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { 69 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver {
68 public: 70 public:
69 SurfaceFactoryTest() 71 SurfaceFactoryTest()
70 : factory_( 72 : factory_(
71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), 73 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)),
72 local_frame_id_(3, 1), 74 local_frame_id_(3, kArbitraryToken),
73 frame_sync_token_(GenTestSyncToken(4)), 75 frame_sync_token_(GenTestSyncToken(4)),
74 consumer_sync_token_(GenTestSyncToken(5)) { 76 consumer_sync_token_(GenTestSyncToken(5)) {
75 manager_.AddObserver(this); 77 manager_.AddObserver(this);
76 factory_->Create(local_frame_id_); 78 factory_->Create(local_frame_id_);
77 } 79 }
78 80
79 const SurfaceId& last_created_surface_id() const { 81 const SurfaceId& last_created_surface_id() const {
80 return last_created_surface_id_; 82 return last_created_surface_id_;
81 } 83 }
82 84
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 SCOPED_TRACE("fourth frame, second unref"); 428 SCOPED_TRACE("fourth frame, second unref");
427 ResourceId expected_returned_ids[] = {12, 13}; 429 ResourceId expected_returned_ids[] = {12, 13};
428 int expected_returned_counts[] = {2, 2}; 430 int expected_returned_counts[] = {2, 2};
429 CheckReturnedResourcesMatchExpected( 431 CheckReturnedResourcesMatchExpected(
430 expected_returned_ids, expected_returned_counts, 432 expected_returned_ids, expected_returned_counts,
431 arraysize(expected_returned_counts), consumer_sync_token_); 433 arraysize(expected_returned_counts), consumer_sync_token_);
432 } 434 }
433 } 435 }
434 436
435 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 437 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
436 LocalFrameId local_frame_id(6, 1); 438 LocalFrameId local_frame_id(6, kArbitraryToken);
437 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 439 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
438 factory_->Create(local_frame_id); 440 factory_->Create(local_frame_id);
439 Surface* surface = manager_.GetSurfaceForId(surface_id); 441 Surface* surface = manager_.GetSurfaceForId(surface_id);
440 ASSERT_NE(nullptr, surface); 442 ASSERT_NE(nullptr, surface);
441 EXPECT_EQ(2, surface->frame_index()); 443 EXPECT_EQ(2, surface->frame_index());
442 444
443 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(), 445 factory_->SubmitCompositorFrame(local_frame_id, CompositorFrame(),
444 SurfaceFactory::DrawCallback()); 446 SurfaceFactory::DrawCallback());
445 EXPECT_EQ(2, surface->frame_index()); 447 EXPECT_EQ(2, surface->frame_index());
446 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); 448 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id);
447 factory_->Destroy(local_frame_id); 449 factory_->Destroy(local_frame_id);
448 } 450 }
449 451
450 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 452 void CreateSurfaceDrawCallback(SurfaceFactory* factory,
451 uint32_t* execute_count) { 453 uint32_t* execute_count) {
452 LocalFrameId new_id(7, 0); 454 LocalFrameId new_id(7, base::UnguessableToken::Create());
453 factory->Create(new_id); 455 factory->Create(new_id);
454 factory->Destroy(new_id); 456 factory->Destroy(new_id);
455 *execute_count += 1; 457 *execute_count += 1;
456 } 458 }
457 459
458 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { 460 TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
459 LocalFrameId local_frame_id(6, 1); 461 LocalFrameId local_frame_id(6, kArbitraryToken);
460 factory_->Create(local_frame_id); 462 factory_->Create(local_frame_id);
461 463
462 uint32_t execute_count = 0; 464 uint32_t execute_count = 0;
463 factory_->SubmitCompositorFrame( 465 factory_->SubmitCompositorFrame(
464 local_frame_id, CompositorFrame(), 466 local_frame_id, CompositorFrame(),
465 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), 467 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
466 &execute_count)); 468 &execute_count));
467 EXPECT_EQ(0u, execute_count); 469 EXPECT_EQ(0u, execute_count);
468 factory_->Destroy(local_frame_id); 470 factory_->Destroy(local_frame_id);
469 EXPECT_EQ(1u, execute_count); 471 EXPECT_EQ(1u, execute_count);
470 } 472 }
471 473
472 void DrawCallback(uint32_t* execute_count) { 474 void DrawCallback(uint32_t* execute_count) {
473 *execute_count += 1; 475 *execute_count += 1;
474 } 476 }
475 477
476 // Tests doing a DestroyAll before shutting down the factory; 478 // Tests doing a DestroyAll before shutting down the factory;
477 TEST_F(SurfaceFactoryTest, DestroyAll) { 479 TEST_F(SurfaceFactoryTest, DestroyAll) {
478 LocalFrameId id(7, 1); 480 LocalFrameId id(7, kArbitraryToken);
479 factory_->Create(id); 481 factory_->Create(id);
480 482
481 TransferableResource resource; 483 TransferableResource resource;
482 resource.id = 1; 484 resource.id = 1;
483 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 485 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
484 CompositorFrame frame; 486 CompositorFrame frame;
485 frame.resource_list.push_back(resource); 487 frame.resource_list.push_back(resource);
486 uint32_t execute_count = 0; 488 uint32_t execute_count = 0;
487 factory_->SubmitCompositorFrame(id, std::move(frame), 489 factory_->SubmitCompositorFrame(id, std::move(frame),
488 base::Bind(&DrawCallback, &execute_count)); 490 base::Bind(&DrawCallback, &execute_count));
489 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); 491 EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
490 local_frame_id_ = LocalFrameId(); 492 local_frame_id_ = LocalFrameId();
491 factory_->DestroyAll(); 493 factory_->DestroyAll();
492 EXPECT_EQ(1u, execute_count); 494 EXPECT_EQ(1u, execute_count);
493 } 495 }
494 496
495 // Tests that SurfaceFactory doesn't return resources after Reset(). 497 // Tests that SurfaceFactory doesn't return resources after Reset().
496 TEST_F(SurfaceFactoryTest, Reset) { 498 TEST_F(SurfaceFactoryTest, Reset) {
497 LocalFrameId id(7, 0); 499 LocalFrameId id(7, kArbitraryToken);
498 factory_->Create(id); 500 factory_->Create(id);
499 501
500 TransferableResource resource; 502 TransferableResource resource;
501 resource.id = 1; 503 resource.id = 1;
502 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 504 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
503 CompositorFrame frame; 505 CompositorFrame frame;
504 frame.resource_list.push_back(resource); 506 frame.resource_list.push_back(resource);
505 uint32_t execute_count = 0; 507 uint32_t execute_count = 0;
506 factory_->SubmitCompositorFrame(id, std::move(frame), 508 factory_->SubmitCompositorFrame(id, std::move(frame),
507 base::Bind(&DrawCallback, &execute_count)); 509 base::Bind(&DrawCallback, &execute_count));
508 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); 510 EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
509 511
510 SurfaceId surface_id(kArbitraryFrameSinkId, id); 512 SurfaceId surface_id(kArbitraryFrameSinkId, id);
511 manager_.AddSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); 513 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id);
512 factory_->Reset(); 514 factory_->Reset();
513 EXPECT_TRUE(client_.returned_resources().empty()); 515 EXPECT_TRUE(client_.returned_resources().empty());
514 manager_.RemoveSurfaceReference(SurfaceManager::kRootSurfaceId, surface_id); 516 manager_.RemoveSurfaceReference(manager_.GetRootSurfaceId(), surface_id);
515 EXPECT_TRUE(client_.returned_resources().empty()); 517 EXPECT_TRUE(client_.returned_resources().empty());
516 local_frame_id_ = LocalFrameId(); 518 local_frame_id_ = LocalFrameId();
517 } 519 }
518 520
519 TEST_F(SurfaceFactoryTest, DestroySequence) { 521 TEST_F(SurfaceFactoryTest, DestroySequence) {
520 LocalFrameId local_frame_id2(5, 1); 522 LocalFrameId local_frame_id2(5, kArbitraryToken);
521 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 523 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
522 factory_->Create(local_frame_id2); 524 factory_->Create(local_frame_id2);
523 525
524 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 526 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
525 527
526 // Check that waiting before the sequence is satisfied works. 528 // Check that waiting before the sequence is satisfied works.
527 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 529 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
528 SurfaceSequence(kArbitraryFrameSinkId, 4)); 530 SurfaceSequence(kArbitraryFrameSinkId, 4));
529 factory_->Destroy(local_frame_id2); 531 factory_->Destroy(local_frame_id2);
530 532
(...skipping 13 matching lines...) Expand all
544 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6)); 546 SurfaceSequence(kAnotherArbitraryFrameSinkId, 6));
545 factory_->Destroy(local_frame_id2); 547 factory_->Destroy(local_frame_id2);
546 DCHECK(!manager_.GetSurfaceForId(id2)); 548 DCHECK(!manager_.GetSurfaceForId(id2));
547 } 549 }
548 550
549 // Tests that Surface ID namespace invalidation correctly allows 551 // Tests that Surface ID namespace invalidation correctly allows
550 // Sequences to be ignored. 552 // Sequences to be ignored.
551 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { 553 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
552 FrameSinkId frame_sink_id(1234, 5678); 554 FrameSinkId frame_sink_id(1234, 5678);
553 555
554 LocalFrameId local_frame_id(5, 1); 556 LocalFrameId local_frame_id(5, kArbitraryToken);
555 SurfaceId id(factory_->frame_sink_id(), local_frame_id); 557 SurfaceId id(factory_->frame_sink_id(), local_frame_id);
556 factory_->Create(local_frame_id); 558 factory_->Create(local_frame_id);
557 559
558 manager_.RegisterFrameSinkId(frame_sink_id); 560 manager_.RegisterFrameSinkId(frame_sink_id);
559 manager_.GetSurfaceForId(id)->AddDestructionDependency( 561 manager_.GetSurfaceForId(id)->AddDestructionDependency(
560 SurfaceSequence(frame_sink_id, 4)); 562 SurfaceSequence(frame_sink_id, 4));
561 factory_->Destroy(local_frame_id); 563 factory_->Destroy(local_frame_id);
562 564
563 // Verify the dependency has prevented the surface from getting destroyed. 565 // Verify the dependency has prevented the surface from getting destroyed.
564 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 566 EXPECT_TRUE(manager_.GetSurfaceForId(id));
565 567
566 manager_.InvalidateFrameSinkId(frame_sink_id); 568 manager_.InvalidateFrameSinkId(frame_sink_id);
567 569
568 // Verify that the invalidated namespace caused the unsatisfied sequence 570 // Verify that the invalidated namespace caused the unsatisfied sequence
569 // to be ignored. 571 // to be ignored.
570 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 572 EXPECT_FALSE(manager_.GetSurfaceForId(id));
571 } 573 }
572 574
573 TEST_F(SurfaceFactoryTest, DestroyCycle) { 575 TEST_F(SurfaceFactoryTest, DestroyCycle) {
574 LocalFrameId local_frame_id2(5, 1); 576 LocalFrameId local_frame_id2(5, kArbitraryToken);
575 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 577 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
576 factory_->Create(local_frame_id2); 578 factory_->Create(local_frame_id2);
577 579
578 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId); 580 manager_.RegisterFrameSinkId(kAnotherArbitraryFrameSinkId);
579 581
580 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 582 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
581 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4)); 583 SurfaceSequence(kAnotherArbitraryFrameSinkId, 4));
582 584
583 // Give id2 a frame that references local_frame_id_. 585 // Give id2 a frame that references local_frame_id_.
584 { 586 {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 676
675 factory_->Destroy(local_frame_id_); 677 factory_->Destroy(local_frame_id_);
676 local_frame_id_ = LocalFrameId(); 678 local_frame_id_ = LocalFrameId();
677 EXPECT_TRUE(called1); 679 EXPECT_TRUE(called1);
678 EXPECT_TRUE(called2); 680 EXPECT_TRUE(called2);
679 EXPECT_TRUE(called3); 681 EXPECT_TRUE(called3);
680 } 682 }
681 683
682 } // namespace 684 } // namespace
683 } // namespace cc 685 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_aggregator_unittest.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698