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

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

Issue 2379653006: Replaced cc::SurfaceId::nonce_ with base::UnguessableToken (Closed)
Patch Set: Changed comments in surface_id.h to reflect the change Created 4 years, 2 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 62 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
63 gpu::CommandBufferId::FromUnsafeValue(id), 1); 63 gpu::CommandBufferId::FromUnsafeValue(id), 1);
64 return token; 64 return token;
65 } 65 }
66 66
67 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver { 67 class SurfaceFactoryTest : public testing::Test, public SurfaceObserver {
68 public: 68 public:
69 SurfaceFactoryTest() 69 SurfaceFactoryTest()
70 : factory_( 70 : factory_(
71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)), 71 new SurfaceFactory(kArbitraryFrameSinkId, &manager_, &client_)),
72 local_frame_id_(3, 0), 72 local_frame_id_(3, base::UnguessableToken::Create()),
73 frame_sync_token_(GenTestSyncToken(4)), 73 frame_sync_token_(GenTestSyncToken(4)),
74 consumer_sync_token_(GenTestSyncToken(5)) { 74 consumer_sync_token_(GenTestSyncToken(5)) {
75 manager_.AddObserver(this); 75 manager_.AddObserver(this);
76 factory_->Create(local_frame_id_); 76 factory_->Create(local_frame_id_);
77 } 77 }
78 78
79 const SurfaceId& last_created_surface_id() const { 79 const SurfaceId& last_created_surface_id() const {
80 return last_created_surface_id_; 80 return last_created_surface_id_;
81 } 81 }
82 82
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 SCOPED_TRACE("fourth frame, second unref"); 429 SCOPED_TRACE("fourth frame, second unref");
430 ResourceId expected_returned_ids[] = {12, 13}; 430 ResourceId expected_returned_ids[] = {12, 13};
431 int expected_returned_counts[] = {2, 2}; 431 int expected_returned_counts[] = {2, 2};
432 CheckReturnedResourcesMatchExpected( 432 CheckReturnedResourcesMatchExpected(
433 expected_returned_ids, expected_returned_counts, 433 expected_returned_ids, expected_returned_counts,
434 arraysize(expected_returned_counts), consumer_sync_token_); 434 arraysize(expected_returned_counts), consumer_sync_token_);
435 } 435 }
436 } 436 }
437 437
438 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 438 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
439 LocalFrameId local_frame_id(6, 0); 439 LocalFrameId local_frame_id(6, base::UnguessableToken::Create());
440 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id); 440 SurfaceId surface_id(kArbitraryFrameSinkId, local_frame_id);
441 factory_->Create(local_frame_id); 441 factory_->Create(local_frame_id);
442 Surface* surface = manager_.GetSurfaceForId(surface_id); 442 Surface* surface = manager_.GetSurfaceForId(surface_id);
443 ASSERT_NE(nullptr, surface); 443 ASSERT_NE(nullptr, surface);
444 EXPECT_EQ(2, surface->frame_index()); 444 EXPECT_EQ(2, surface->frame_index());
445 CompositorFrame frame; 445 CompositorFrame frame;
446 frame.delegated_frame_data.reset(new DelegatedFrameData); 446 frame.delegated_frame_data.reset(new DelegatedFrameData);
447 447
448 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame), 448 factory_->SubmitCompositorFrame(local_frame_id, std::move(frame),
449 SurfaceFactory::DrawCallback()); 449 SurfaceFactory::DrawCallback());
450 EXPECT_EQ(2, surface->frame_index()); 450 EXPECT_EQ(2, surface->frame_index());
451 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id); 451 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id);
452 factory_->Destroy(local_frame_id); 452 factory_->Destroy(local_frame_id);
453 } 453 }
454 454
455 void CreateSurfaceDrawCallback(SurfaceFactory* factory, 455 void CreateSurfaceDrawCallback(SurfaceFactory* factory,
456 uint32_t* execute_count) { 456 uint32_t* execute_count) {
457 LocalFrameId new_id(7, 0); 457 LocalFrameId new_id(7, base::UnguessableToken::Create());
458 factory->Create(new_id); 458 factory->Create(new_id);
459 factory->Destroy(new_id); 459 factory->Destroy(new_id);
460 *execute_count += 1; 460 *execute_count += 1;
461 } 461 }
462 462
463 TEST_F(SurfaceFactoryTest, AddDuringDestroy) { 463 TEST_F(SurfaceFactoryTest, AddDuringDestroy) {
464 LocalFrameId local_frame_id(6, 0); 464 LocalFrameId local_frame_id(6, base::UnguessableToken::Create());
465 factory_->Create(local_frame_id); 465 factory_->Create(local_frame_id);
466 CompositorFrame frame; 466 CompositorFrame frame;
467 frame.delegated_frame_data.reset(new DelegatedFrameData); 467 frame.delegated_frame_data.reset(new DelegatedFrameData);
468 468
469 uint32_t execute_count = 0; 469 uint32_t execute_count = 0;
470 factory_->SubmitCompositorFrame( 470 factory_->SubmitCompositorFrame(
471 local_frame_id, std::move(frame), 471 local_frame_id, std::move(frame),
472 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()), 472 base::Bind(&CreateSurfaceDrawCallback, base::Unretained(factory_.get()),
473 &execute_count)); 473 &execute_count));
474 EXPECT_EQ(0u, execute_count); 474 EXPECT_EQ(0u, execute_count);
475 factory_->Destroy(local_frame_id); 475 factory_->Destroy(local_frame_id);
476 EXPECT_EQ(1u, execute_count); 476 EXPECT_EQ(1u, execute_count);
477 } 477 }
478 478
479 void DrawCallback(uint32_t* execute_count) { 479 void DrawCallback(uint32_t* execute_count) {
480 *execute_count += 1; 480 *execute_count += 1;
481 } 481 }
482 482
483 // Tests doing a DestroyAll before shutting down the factory; 483 // Tests doing a DestroyAll before shutting down the factory;
484 TEST_F(SurfaceFactoryTest, DestroyAll) { 484 TEST_F(SurfaceFactoryTest, DestroyAll) {
485 LocalFrameId id(7, 0); 485 LocalFrameId id(7, base::UnguessableToken::Create());
486 factory_->Create(id); 486 factory_->Create(id);
487 487
488 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 488 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
489 TransferableResource resource; 489 TransferableResource resource;
490 resource.id = 1; 490 resource.id = 1;
491 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 491 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
492 frame_data->resource_list.push_back(resource); 492 frame_data->resource_list.push_back(resource);
493 CompositorFrame frame; 493 CompositorFrame frame;
494 frame.delegated_frame_data = std::move(frame_data); 494 frame.delegated_frame_data = std::move(frame_data);
495 uint32_t execute_count = 0; 495 uint32_t execute_count = 0;
496 factory_->SubmitCompositorFrame(id, std::move(frame), 496 factory_->SubmitCompositorFrame(id, std::move(frame),
497 base::Bind(&DrawCallback, &execute_count)); 497 base::Bind(&DrawCallback, &execute_count));
498 EXPECT_EQ(last_created_surface_id().local_frame_id(), id); 498 EXPECT_EQ(last_created_surface_id().local_frame_id(), id);
499 local_frame_id_ = LocalFrameId(); 499 local_frame_id_ = LocalFrameId();
500 factory_->DestroyAll(); 500 factory_->DestroyAll();
501 EXPECT_EQ(1u, execute_count); 501 EXPECT_EQ(1u, execute_count);
502 } 502 }
503 503
504 TEST_F(SurfaceFactoryTest, DestroySequence) { 504 TEST_F(SurfaceFactoryTest, DestroySequence) {
505 LocalFrameId local_frame_id2(5, 0); 505 LocalFrameId local_frame_id2(5, base::UnguessableToken::Create());
506 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 506 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
507 factory_->Create(local_frame_id2); 507 factory_->Create(local_frame_id2);
508 508
509 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId); 509 manager_.RegisterFrameSinkId(kArbitraryFrameSinkId);
510 510
511 // Check that waiting before the sequence is satisfied works. 511 // Check that waiting before the sequence is satisfied works.
512 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 512 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
513 SurfaceSequence(kArbitraryFrameSinkId, 4)); 513 SurfaceSequence(kArbitraryFrameSinkId, 4));
514 factory_->Destroy(local_frame_id2); 514 factory_->Destroy(local_frame_id2);
515 515
(...skipping 15 matching lines...) Expand all
531 SurfaceSequence(FrameSinkId(0, 0), 6)); 531 SurfaceSequence(FrameSinkId(0, 0), 6));
532 factory_->Destroy(local_frame_id2); 532 factory_->Destroy(local_frame_id2);
533 DCHECK(!manager_.GetSurfaceForId(id2)); 533 DCHECK(!manager_.GetSurfaceForId(id2));
534 } 534 }
535 535
536 // Tests that Surface ID namespace invalidation correctly allows 536 // Tests that Surface ID namespace invalidation correctly allows
537 // Sequences to be ignored. 537 // Sequences to be ignored.
538 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) { 538 TEST_F(SurfaceFactoryTest, InvalidFrameSinkId) {
539 FrameSinkId frame_sink_id(1234, 5678); 539 FrameSinkId frame_sink_id(1234, 5678);
540 540
541 LocalFrameId local_frame_id(5, 0); 541 LocalFrameId local_frame_id(5, base::UnguessableToken::Create());
542 SurfaceId id(factory_->frame_sink_id(), local_frame_id); 542 SurfaceId id(factory_->frame_sink_id(), local_frame_id);
543 factory_->Create(local_frame_id); 543 factory_->Create(local_frame_id);
544 544
545 manager_.RegisterFrameSinkId(frame_sink_id); 545 manager_.RegisterFrameSinkId(frame_sink_id);
546 manager_.GetSurfaceForId(id)->AddDestructionDependency( 546 manager_.GetSurfaceForId(id)->AddDestructionDependency(
547 SurfaceSequence(frame_sink_id, 4)); 547 SurfaceSequence(frame_sink_id, 4));
548 factory_->Destroy(local_frame_id); 548 factory_->Destroy(local_frame_id);
549 549
550 // Verify the dependency has prevented the surface from getting destroyed. 550 // Verify the dependency has prevented the surface from getting destroyed.
551 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 551 EXPECT_TRUE(manager_.GetSurfaceForId(id));
552 552
553 manager_.InvalidateFrameSinkId(frame_sink_id); 553 manager_.InvalidateFrameSinkId(frame_sink_id);
554 554
555 // Verify that the invalidated namespace caused the unsatisfied sequence 555 // Verify that the invalidated namespace caused the unsatisfied sequence
556 // to be ignored. 556 // to be ignored.
557 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 557 EXPECT_FALSE(manager_.GetSurfaceForId(id));
558 } 558 }
559 559
560 TEST_F(SurfaceFactoryTest, DestroyCycle) { 560 TEST_F(SurfaceFactoryTest, DestroyCycle) {
561 LocalFrameId local_frame_id2(5, 0); 561 LocalFrameId local_frame_id2(5, base::UnguessableToken::Create());
562 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2); 562 SurfaceId id2(kArbitraryFrameSinkId, local_frame_id2);
563 factory_->Create(local_frame_id2); 563 factory_->Create(local_frame_id2);
564 564
565 manager_.RegisterFrameSinkId(FrameSinkId(0, 0)); 565 manager_.RegisterFrameSinkId(FrameSinkId(0, 0));
566 566
567 manager_.GetSurfaceForId(id2)->AddDestructionDependency( 567 manager_.GetSurfaceForId(id2)->AddDestructionDependency(
568 SurfaceSequence(FrameSinkId(0, 0), 4)); 568 SurfaceSequence(FrameSinkId(0, 0), 4));
569 569
570 // Give id2 a frame that references local_frame_id_. 570 // Give id2 a frame that references local_frame_id_.
571 { 571 {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 667
668 factory_->Destroy(local_frame_id_); 668 factory_->Destroy(local_frame_id_);
669 local_frame_id_ = LocalFrameId(); 669 local_frame_id_ = LocalFrameId();
670 EXPECT_TRUE(called1); 670 EXPECT_TRUE(called1);
671 EXPECT_TRUE(called2); 671 EXPECT_TRUE(called2);
672 EXPECT_TRUE(called3); 672 EXPECT_TRUE(called3);
673 } 673 }
674 674
675 } // namespace 675 } // namespace
676 } // namespace cc 676 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698