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

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

Issue 1996783002: Make cc::SurfaceId unguessable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests Created 4 years, 6 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 gpu::SyncToken token; 59 gpu::SyncToken token;
60 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0, 60 token.Set(gpu::CommandBufferNamespace::GPU_IO, 0,
61 gpu::CommandBufferId::FromUnsafeValue(id), 1); 61 gpu::CommandBufferId::FromUnsafeValue(id), 1);
62 return token; 62 return token;
63 } 63 }
64 64
65 class SurfaceFactoryTest : public testing::Test { 65 class SurfaceFactoryTest : public testing::Test {
66 public: 66 public:
67 SurfaceFactoryTest() 67 SurfaceFactoryTest()
68 : factory_(new SurfaceFactory(&manager_, &client_)), 68 : factory_(new SurfaceFactory(&manager_, &client_)),
69 surface_id_(3), 69 surface_id_(0, 0, 3),
70 frame_sync_token_(GenTestSyncToken(4)), 70 frame_sync_token_(GenTestSyncToken(4)),
71 consumer_sync_token_(GenTestSyncToken(5)) { 71 consumer_sync_token_(GenTestSyncToken(5)) {
72 factory_->Create(surface_id_); 72 factory_->Create(surface_id_);
73 } 73 }
74 74
75 ~SurfaceFactoryTest() override { 75 ~SurfaceFactoryTest() override {
76 if (!surface_id_.is_null()) 76 if (!surface_id_.is_null())
77 factory_->Destroy(surface_id_); 77 factory_->Destroy(surface_id_);
78 } 78 }
79 79
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 SCOPED_TRACE("fourth frame, second unref"); 405 SCOPED_TRACE("fourth frame, second unref");
406 ResourceId expected_returned_ids[] = {12, 13}; 406 ResourceId expected_returned_ids[] = {12, 13};
407 int expected_returned_counts[] = {2, 2}; 407 int expected_returned_counts[] = {2, 2};
408 CheckReturnedResourcesMatchExpected( 408 CheckReturnedResourcesMatchExpected(
409 expected_returned_ids, expected_returned_counts, 409 expected_returned_ids, expected_returned_counts,
410 arraysize(expected_returned_counts), consumer_sync_token_); 410 arraysize(expected_returned_counts), consumer_sync_token_);
411 } 411 }
412 } 412 }
413 413
414 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 414 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
415 SurfaceId surface_id(6); 415 SurfaceId surface_id(0, 0, 6);
416 factory_->Create(surface_id); 416 factory_->Create(surface_id);
417 Surface* surface = manager_.GetSurfaceForId(surface_id); 417 Surface* surface = manager_.GetSurfaceForId(surface_id);
418 ASSERT_NE(nullptr, surface); 418 ASSERT_NE(nullptr, surface);
419 EXPECT_EQ(2, surface->frame_index()); 419 EXPECT_EQ(2, surface->frame_index());
420 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 420 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
421 frame->delegated_frame_data.reset(new DelegatedFrameData); 421 frame->delegated_frame_data.reset(new DelegatedFrameData);
422 422
423 factory_->SubmitCompositorFrame(surface_id, std::move(frame), 423 factory_->SubmitCompositorFrame(surface_id, std::move(frame),
424 SurfaceFactory::DrawCallback()); 424 SurfaceFactory::DrawCallback());
425 EXPECT_EQ(2, surface->frame_index()); 425 EXPECT_EQ(2, surface->frame_index());
426 factory_->Destroy(surface_id); 426 factory_->Destroy(surface_id);
427 } 427 }
428 428
429 void DrawCallback(uint32_t* execute_count, 429 void DrawCallback(uint32_t* execute_count,
430 SurfaceDrawStatus* result, 430 SurfaceDrawStatus* result,
431 SurfaceDrawStatus drawn) { 431 SurfaceDrawStatus drawn) {
432 *execute_count += 1; 432 *execute_count += 1;
433 *result = drawn; 433 *result = drawn;
434 } 434 }
435 435
436 // Tests doing a DestroyAll before shutting down the factory; 436 // Tests doing a DestroyAll before shutting down the factory;
437 TEST_F(SurfaceFactoryTest, DestroyAll) { 437 TEST_F(SurfaceFactoryTest, DestroyAll) {
438 SurfaceId id(7); 438 SurfaceId id(0, 0, 7);
439 factory_->Create(id); 439 factory_->Create(id);
440 440
441 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 441 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
442 TransferableResource resource; 442 TransferableResource resource;
443 resource.id = 1; 443 resource.id = 1;
444 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 444 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
445 frame_data->resource_list.push_back(resource); 445 frame_data->resource_list.push_back(resource);
446 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 446 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
447 frame->delegated_frame_data = std::move(frame_data); 447 frame->delegated_frame_data = std::move(frame_data);
448 uint32_t execute_count = 0; 448 uint32_t execute_count = 0;
449 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; 449 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED;
450 450
451 factory_->SubmitCompositorFrame( 451 factory_->SubmitCompositorFrame(
452 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); 452 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn));
453 453
454 surface_id_ = SurfaceId(); 454 surface_id_ = SurfaceId();
455 factory_->DestroyAll(); 455 factory_->DestroyAll();
456 EXPECT_EQ(1u, execute_count); 456 EXPECT_EQ(1u, execute_count);
457 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); 457 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn);
458 } 458 }
459 459
460 TEST_F(SurfaceFactoryTest, DestroySequence) { 460 TEST_F(SurfaceFactoryTest, DestroySequence) {
461 SurfaceId id2(5); 461 SurfaceId id2(0, 0, 5);
462 factory_->Create(id2); 462 factory_->Create(id2);
463 463
464 manager_.RegisterSurfaceIdNamespace(0); 464 manager_.RegisterSurfaceIdNamespace(0);
465 465
466 // Check that waiting before the sequence is satisfied works. 466 // Check that waiting before the sequence is satisfied works.
467 manager_.GetSurfaceForId(id2) 467 manager_.GetSurfaceForId(id2)
468 ->AddDestructionDependency(SurfaceSequence(0, 4)); 468 ->AddDestructionDependency(SurfaceSequence(0, 4));
469 factory_->Destroy(id2); 469 factory_->Destroy(id2);
470 470
471 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 471 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
(...skipping 12 matching lines...) Expand all
484 manager_.GetSurfaceForId(id2) 484 manager_.GetSurfaceForId(id2)
485 ->AddDestructionDependency(SurfaceSequence(0, 6)); 485 ->AddDestructionDependency(SurfaceSequence(0, 6));
486 factory_->Destroy(id2); 486 factory_->Destroy(id2);
487 DCHECK(!manager_.GetSurfaceForId(id2)); 487 DCHECK(!manager_.GetSurfaceForId(id2));
488 } 488 }
489 489
490 // Tests that Surface ID namespace invalidation correctly allows 490 // Tests that Surface ID namespace invalidation correctly allows
491 // Sequences to be ignored. 491 // Sequences to be ignored.
492 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { 492 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) {
493 uint32_t id_namespace = 9u; 493 uint32_t id_namespace = 9u;
494 SurfaceId id(5); 494 SurfaceId id(id_namespace, 0, 5);
495 factory_->Create(id); 495 factory_->Create(id);
496 496
497 manager_.RegisterSurfaceIdNamespace(id_namespace); 497 manager_.RegisterSurfaceIdNamespace(id_namespace);
498 manager_.GetSurfaceForId(id) 498 manager_.GetSurfaceForId(id)
499 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); 499 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4));
500 factory_->Destroy(id); 500 factory_->Destroy(id);
501 501
502 // Verify the dependency has prevented the surface from getting destroyed. 502 // Verify the dependency has prevented the surface from getting destroyed.
503 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 503 EXPECT_TRUE(manager_.GetSurfaceForId(id));
504 504
505 manager_.InvalidateSurfaceIdNamespace(id_namespace); 505 manager_.InvalidateSurfaceIdNamespace(id_namespace);
506 506
507 // Verify that the invalidated namespace caused the unsatisfied sequence 507 // Verify that the invalidated namespace caused the unsatisfied sequence
508 // to be ignored. 508 // to be ignored.
509 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 509 EXPECT_FALSE(manager_.GetSurfaceForId(id));
510 } 510 }
511 511
512 TEST_F(SurfaceFactoryTest, DestroyCycle) { 512 TEST_F(SurfaceFactoryTest, DestroyCycle) {
513 SurfaceId id2(5); 513 SurfaceId id2(0, 0, 5);
514 factory_->Create(id2); 514 factory_->Create(id2);
515 515
516 manager_.RegisterSurfaceIdNamespace(0); 516 manager_.RegisterSurfaceIdNamespace(0);
517 517
518 manager_.GetSurfaceForId(id2) 518 manager_.GetSurfaceForId(id2)
519 ->AddDestructionDependency(SurfaceSequence(0, 4)); 519 ->AddDestructionDependency(SurfaceSequence(0, 4));
520 520
521 // Give id2 a frame that references surface_id_. 521 // Give id2 a frame that references surface_id_.
522 { 522 {
523 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 523 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 611
612 factory_->Destroy(surface_id_); 612 factory_->Destroy(surface_id_);
613 surface_id_ = SurfaceId(); 613 surface_id_ = SurfaceId();
614 EXPECT_TRUE(called1); 614 EXPECT_TRUE(called1);
615 EXPECT_TRUE(called2); 615 EXPECT_TRUE(called2);
616 EXPECT_TRUE(called3); 616 EXPECT_TRUE(called3);
617 } 617 }
618 618
619 } // namespace 619 } // namespace
620 } // namespace cc 620 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698