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

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

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