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

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 more build targets Created 4 years, 7 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 private: 51 private:
52 ReturnedResourceArray returned_resources_; 52 ReturnedResourceArray returned_resources_;
53 BeginFrameSource* begin_frame_source_; 53 BeginFrameSource* begin_frame_source_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); 55 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient);
56 }; 56 };
57 57
58 class SurfaceFactoryTest : public testing::Test { 58 class SurfaceFactoryTest : public testing::Test {
59 public: 59 public:
60 SurfaceFactoryTest() 60 SurfaceFactoryTest()
61 : factory_(new SurfaceFactory(&manager_, &client_)), surface_id_(3) { 61 : factory_(new SurfaceFactory(&manager_, &client_)), surface_id_(0, 3) {
62 factory_->Create(surface_id_); 62 factory_->Create(surface_id_);
63 } 63 }
64 64
65 ~SurfaceFactoryTest() override { 65 ~SurfaceFactoryTest() override {
66 if (!surface_id_.is_null()) 66 if (!surface_id_.is_null())
67 factory_->Destroy(surface_id_); 67 factory_->Destroy(surface_id_);
68 } 68 }
69 69
70 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 70 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
71 size_t num_resource_ids) { 71 size_t num_resource_ids) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 SCOPED_TRACE("fourth frame, second unref"); 382 SCOPED_TRACE("fourth frame, second unref");
383 ResourceId expected_returned_ids[] = {12, 13}; 383 ResourceId expected_returned_ids[] = {12, 13};
384 int expected_returned_counts[] = {2, 2}; 384 int expected_returned_counts[] = {2, 2};
385 CheckReturnedResourcesMatchExpected(expected_returned_ids, 385 CheckReturnedResourcesMatchExpected(expected_returned_ids,
386 expected_returned_counts, 386 expected_returned_counts,
387 arraysize(expected_returned_counts)); 387 arraysize(expected_returned_counts));
388 } 388 }
389 } 389 }
390 390
391 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 391 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
392 SurfaceId surface_id(6); 392 SurfaceId surface_id(0, 6);
393 factory_->Create(surface_id); 393 factory_->Create(surface_id);
394 Surface* surface = manager_.GetSurfaceForId(surface_id); 394 Surface* surface = manager_.GetSurfaceForId(surface_id);
395 ASSERT_NE(nullptr, surface); 395 ASSERT_NE(nullptr, surface);
396 EXPECT_EQ(2, surface->frame_index()); 396 EXPECT_EQ(2, surface->frame_index());
397 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 397 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
398 frame->delegated_frame_data.reset(new DelegatedFrameData); 398 frame->delegated_frame_data.reset(new DelegatedFrameData);
399 399
400 factory_->SubmitCompositorFrame(surface_id, std::move(frame), 400 factory_->SubmitCompositorFrame(surface_id, std::move(frame),
401 SurfaceFactory::DrawCallback()); 401 SurfaceFactory::DrawCallback());
402 EXPECT_EQ(2, surface->frame_index()); 402 EXPECT_EQ(2, surface->frame_index());
403 factory_->Destroy(surface_id); 403 factory_->Destroy(surface_id);
404 } 404 }
405 405
406 void DrawCallback(uint32_t* execute_count, 406 void DrawCallback(uint32_t* execute_count,
407 SurfaceDrawStatus* result, 407 SurfaceDrawStatus* result,
408 SurfaceDrawStatus drawn) { 408 SurfaceDrawStatus drawn) {
409 *execute_count += 1; 409 *execute_count += 1;
410 *result = drawn; 410 *result = drawn;
411 } 411 }
412 412
413 // Tests doing a DestroyAll before shutting down the factory; 413 // Tests doing a DestroyAll before shutting down the factory;
414 TEST_F(SurfaceFactoryTest, DestroyAll) { 414 TEST_F(SurfaceFactoryTest, DestroyAll) {
415 SurfaceId id(7); 415 SurfaceId id(0, 7);
416 factory_->Create(id); 416 factory_->Create(id);
417 417
418 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 418 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
419 TransferableResource resource; 419 TransferableResource resource;
420 resource.id = 1; 420 resource.id = 1;
421 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 421 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
422 frame_data->resource_list.push_back(resource); 422 frame_data->resource_list.push_back(resource);
423 std::unique_ptr<CompositorFrame> frame(new CompositorFrame); 423 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
424 frame->delegated_frame_data = std::move(frame_data); 424 frame->delegated_frame_data = std::move(frame_data);
425 uint32_t execute_count = 0; 425 uint32_t execute_count = 0;
426 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; 426 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED;
427 427
428 factory_->SubmitCompositorFrame( 428 factory_->SubmitCompositorFrame(
429 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); 429 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn));
430 430
431 surface_id_ = SurfaceId(); 431 surface_id_ = SurfaceId();
432 factory_->DestroyAll(); 432 factory_->DestroyAll();
433 EXPECT_EQ(1u, execute_count); 433 EXPECT_EQ(1u, execute_count);
434 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); 434 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn);
435 } 435 }
436 436
437 TEST_F(SurfaceFactoryTest, DestroySequence) { 437 TEST_F(SurfaceFactoryTest, DestroySequence) {
438 SurfaceId id2(5); 438 SurfaceId id2(0, 5);
439 factory_->Create(id2); 439 factory_->Create(id2);
440 440
441 manager_.RegisterSurfaceIdNamespace(0); 441 manager_.RegisterSurfaceIdNamespace(0);
442 442
443 // Check that waiting before the sequence is satisfied works. 443 // Check that waiting before the sequence is satisfied works.
444 manager_.GetSurfaceForId(id2) 444 manager_.GetSurfaceForId(id2)
445 ->AddDestructionDependency(SurfaceSequence(0, 4)); 445 ->AddDestructionDependency(SurfaceSequence(0, 4));
446 factory_->Destroy(id2); 446 factory_->Destroy(id2);
447 447
448 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 448 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
(...skipping 12 matching lines...) Expand all
461 manager_.GetSurfaceForId(id2) 461 manager_.GetSurfaceForId(id2)
462 ->AddDestructionDependency(SurfaceSequence(0, 6)); 462 ->AddDestructionDependency(SurfaceSequence(0, 6));
463 factory_->Destroy(id2); 463 factory_->Destroy(id2);
464 DCHECK(!manager_.GetSurfaceForId(id2)); 464 DCHECK(!manager_.GetSurfaceForId(id2));
465 } 465 }
466 466
467 // Tests that Surface ID namespace invalidation correctly allows 467 // Tests that Surface ID namespace invalidation correctly allows
468 // Sequences to be ignored. 468 // Sequences to be ignored.
469 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { 469 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) {
470 uint32_t id_namespace = 9u; 470 uint32_t id_namespace = 9u;
471 SurfaceId id(5); 471 SurfaceId id(id_namespace, 5);
472 factory_->Create(id); 472 factory_->Create(id);
473 473
474 manager_.RegisterSurfaceIdNamespace(id_namespace); 474 manager_.RegisterSurfaceIdNamespace(id_namespace);
475 manager_.GetSurfaceForId(id) 475 manager_.GetSurfaceForId(id)
476 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); 476 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4));
477 factory_->Destroy(id); 477 factory_->Destroy(id);
478 478
479 // Verify the dependency has prevented the surface from getting destroyed. 479 // Verify the dependency has prevented the surface from getting destroyed.
480 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 480 EXPECT_TRUE(manager_.GetSurfaceForId(id));
481 481
482 manager_.InvalidateSurfaceIdNamespace(id_namespace); 482 manager_.InvalidateSurfaceIdNamespace(id_namespace);
483 483
484 // Verify that the invalidated namespace caused the unsatisfied sequence 484 // Verify that the invalidated namespace caused the unsatisfied sequence
485 // to be ignored. 485 // to be ignored.
486 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 486 EXPECT_FALSE(manager_.GetSurfaceForId(id));
487 } 487 }
488 488
489 TEST_F(SurfaceFactoryTest, DestroyCycle) { 489 TEST_F(SurfaceFactoryTest, DestroyCycle) {
490 SurfaceId id2(5); 490 SurfaceId id2(0, 5);
491 factory_->Create(id2); 491 factory_->Create(id2);
492 492
493 manager_.RegisterSurfaceIdNamespace(0); 493 manager_.RegisterSurfaceIdNamespace(0);
494 494
495 manager_.GetSurfaceForId(id2) 495 manager_.GetSurfaceForId(id2)
496 ->AddDestructionDependency(SurfaceSequence(0, 4)); 496 ->AddDestructionDependency(SurfaceSequence(0, 4));
497 497
498 // Give id2 a frame that references surface_id_. 498 // Give id2 a frame that references surface_id_.
499 { 499 {
500 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 500 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 588
589 factory_->Destroy(surface_id_); 589 factory_->Destroy(surface_id_);
590 surface_id_ = SurfaceId(); 590 surface_id_ = SurfaceId();
591 EXPECT_TRUE(called1); 591 EXPECT_TRUE(called1);
592 EXPECT_TRUE(called2); 592 EXPECT_TRUE(called2);
593 EXPECT_TRUE(called3); 593 EXPECT_TRUE(called3);
594 } 594 }
595 595
596 } // namespace 596 } // namespace
597 } // namespace cc 597 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698