| OLD | NEW |
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "cc/output/compositor_frame.h" | 6 #include "cc/output/compositor_frame.h" |
| 7 #include "cc/output/delegated_frame_data.h" | 7 #include "cc/output/delegated_frame_data.h" |
| 8 #include "cc/resources/resource_provider.h" | 8 #include "cc/resources/resource_provider.h" |
| 9 #include "cc/surfaces/surface.h" | 9 #include "cc/surfaces/surface.h" |
| 10 #include "cc/surfaces/surface_factory.h" | 10 #include "cc/surfaces/surface_factory.h" |
| 11 #include "cc/surfaces/surface_factory_client.h" | 11 #include "cc/surfaces/surface_factory_client.h" |
| 12 #include "cc/surfaces/surface_manager.h" | 12 #include "cc/surfaces/surface_manager.h" |
| 13 #include "cc/test/scheduler_test_common.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 15 | 16 |
| 16 namespace cc { | 17 namespace cc { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class TestSurfaceFactoryClient : public SurfaceFactoryClient { | 20 class TestSurfaceFactoryClient : public SurfaceFactoryClient { |
| 20 public: | 21 public: |
| 21 TestSurfaceFactoryClient() {} | 22 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} |
| 22 ~TestSurfaceFactoryClient() override {} | 23 ~TestSurfaceFactoryClient() override {} |
| 23 | 24 |
| 24 void ReturnResources(const ReturnedResourceArray& resources) override { | 25 void ReturnResources(const ReturnedResourceArray& resources) override { |
| 25 returned_resources_.insert( | 26 returned_resources_.insert( |
| 26 returned_resources_.end(), resources.begin(), resources.end()); | 27 returned_resources_.end(), resources.begin(), resources.end()); |
| 27 } | 28 } |
| 28 | 29 |
| 30 void SetBeginFrameSource(SurfaceId surface_id, |
| 31 BeginFrameSource* begin_frame_source) override { |
| 32 begin_frame_source_ = begin_frame_source; |
| 33 } |
| 34 |
| 29 const ReturnedResourceArray& returned_resources() const { | 35 const ReturnedResourceArray& returned_resources() const { |
| 30 return returned_resources_; | 36 return returned_resources_; |
| 31 } | 37 } |
| 32 | 38 |
| 33 void clear_returned_resources() { returned_resources_.clear(); } | 39 void clear_returned_resources() { returned_resources_.clear(); } |
| 34 | 40 |
| 41 BeginFrameSource* begin_frame_source() const { return begin_frame_source_; } |
| 42 |
| 35 private: | 43 private: |
| 36 ReturnedResourceArray returned_resources_; | 44 ReturnedResourceArray returned_resources_; |
| 45 BeginFrameSource* begin_frame_source_; |
| 37 | 46 |
| 38 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); | 47 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); |
| 39 }; | 48 }; |
| 40 | 49 |
| 41 class SurfaceFactoryTest : public testing::Test { | 50 class SurfaceFactoryTest : public testing::Test { |
| 42 public: | 51 public: |
| 43 SurfaceFactoryTest() : factory_(&manager_, &client_), surface_id_(3) { | 52 SurfaceFactoryTest() |
| 44 factory_.Create(surface_id_); | 53 : factory_(new SurfaceFactory(&manager_, &client_)), surface_id_(3) { |
| 54 factory_->Create(surface_id_); |
| 45 } | 55 } |
| 46 | 56 |
| 47 ~SurfaceFactoryTest() override { | 57 ~SurfaceFactoryTest() override { |
| 48 if (!surface_id_.is_null()) | 58 if (!surface_id_.is_null()) |
| 49 factory_.Destroy(surface_id_); | 59 factory_->Destroy(surface_id_); |
| 50 } | 60 } |
| 51 | 61 |
| 52 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 62 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 53 size_t num_resource_ids) { | 63 size_t num_resource_ids) { |
| 54 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 64 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 55 for (size_t i = 0u; i < num_resource_ids; ++i) { | 65 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 56 TransferableResource resource; | 66 TransferableResource resource; |
| 57 resource.id = resource_ids[i]; | 67 resource.id = resource_ids[i]; |
| 58 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 68 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 59 frame_data->resource_list.push_back(resource); | 69 frame_data->resource_list.push_back(resource); |
| 60 } | 70 } |
| 61 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 71 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 62 frame->delegated_frame_data = frame_data.Pass(); | 72 frame->delegated_frame_data = frame_data.Pass(); |
| 63 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), | 73 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(), |
| 64 SurfaceFactory::DrawCallback()); | 74 SurfaceFactory::DrawCallback()); |
| 65 } | 75 } |
| 66 | 76 |
| 67 void UnrefResources(ResourceId* ids_to_unref, | 77 void UnrefResources(ResourceId* ids_to_unref, |
| 68 int* counts_to_unref, | 78 int* counts_to_unref, |
| 69 size_t num_ids_to_unref) { | 79 size_t num_ids_to_unref) { |
| 70 ReturnedResourceArray unref_array; | 80 ReturnedResourceArray unref_array; |
| 71 for (size_t i = 0; i < num_ids_to_unref; ++i) { | 81 for (size_t i = 0; i < num_ids_to_unref; ++i) { |
| 72 ReturnedResource resource; | 82 ReturnedResource resource; |
| 73 resource.id = ids_to_unref[i]; | 83 resource.id = ids_to_unref[i]; |
| 74 resource.count = counts_to_unref[i]; | 84 resource.count = counts_to_unref[i]; |
| 75 unref_array.push_back(resource); | 85 unref_array.push_back(resource); |
| 76 } | 86 } |
| 77 factory_.UnrefResources(unref_array); | 87 factory_->UnrefResources(unref_array); |
| 78 } | 88 } |
| 79 | 89 |
| 80 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids, | 90 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids, |
| 81 int* expected_returned_counts, | 91 int* expected_returned_counts, |
| 82 size_t expected_resources) { | 92 size_t expected_resources) { |
| 83 const ReturnedResourceArray& actual_resources = | 93 const ReturnedResourceArray& actual_resources = |
| 84 client_.returned_resources(); | 94 client_.returned_resources(); |
| 85 ASSERT_EQ(expected_resources, actual_resources.size()); | 95 ASSERT_EQ(expected_resources, actual_resources.size()); |
| 86 for (size_t i = 0; i < expected_resources; ++i) { | 96 for (size_t i = 0; i < expected_resources; ++i) { |
| 87 ReturnedResource resource = actual_resources[i]; | 97 ReturnedResource resource = actual_resources[i]; |
| 88 EXPECT_EQ(expected_returned_ids[i], resource.id); | 98 EXPECT_EQ(expected_returned_ids[i], resource.id); |
| 89 EXPECT_EQ(expected_returned_counts[i], resource.count); | 99 EXPECT_EQ(expected_returned_counts[i], resource.count); |
| 90 } | 100 } |
| 91 client_.clear_returned_resources(); | 101 client_.clear_returned_resources(); |
| 92 } | 102 } |
| 93 | 103 |
| 94 void RefCurrentFrameResources() { | 104 void RefCurrentFrameResources() { |
| 95 Surface* surface = manager_.GetSurfaceForId(surface_id_); | 105 Surface* surface = manager_.GetSurfaceForId(surface_id_); |
| 96 factory_.RefResources( | 106 factory_->RefResources( |
| 97 surface->GetEligibleFrame()->delegated_frame_data->resource_list); | 107 surface->GetEligibleFrame()->delegated_frame_data->resource_list); |
| 98 } | 108 } |
| 99 | 109 |
| 100 protected: | 110 protected: |
| 101 SurfaceManager manager_; | 111 SurfaceManager manager_; |
| 102 TestSurfaceFactoryClient client_; | 112 TestSurfaceFactoryClient client_; |
| 103 SurfaceFactory factory_; | 113 scoped_ptr<SurfaceFactory> factory_; |
| 104 SurfaceId surface_id_; | 114 SurfaceId surface_id_; |
| 105 }; | 115 }; |
| 106 | 116 |
| 107 // Tests submitting a frame with resources followed by one with no resources | 117 // Tests submitting a frame with resources followed by one with no resources |
| 108 // with no resource provider action in between. | 118 // with no resource provider action in between. |
| 109 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) { | 119 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) { |
| 110 ResourceId first_frame_ids[] = {1, 2, 3}; | 120 ResourceId first_frame_ids[] = {1, 2, 3}; |
| 111 SubmitCompositorFrameWithResources(first_frame_ids, | 121 SubmitCompositorFrameWithResources(first_frame_ids, |
| 112 arraysize(first_frame_ids)); | 122 arraysize(first_frame_ids)); |
| 113 | 123 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 ResourceId expected_returned_ids[] = {12, 13}; | 375 ResourceId expected_returned_ids[] = {12, 13}; |
| 366 int expected_returned_counts[] = {2, 2}; | 376 int expected_returned_counts[] = {2, 2}; |
| 367 CheckReturnedResourcesMatchExpected(expected_returned_ids, | 377 CheckReturnedResourcesMatchExpected(expected_returned_ids, |
| 368 expected_returned_counts, | 378 expected_returned_counts, |
| 369 arraysize(expected_returned_counts)); | 379 arraysize(expected_returned_counts)); |
| 370 } | 380 } |
| 371 } | 381 } |
| 372 | 382 |
| 373 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { | 383 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { |
| 374 SurfaceId surface_id(6); | 384 SurfaceId surface_id(6); |
| 375 factory_.Create(surface_id); | 385 factory_->Create(surface_id); |
| 376 Surface* surface = manager_.GetSurfaceForId(surface_id); | 386 Surface* surface = manager_.GetSurfaceForId(surface_id); |
| 377 ASSERT_NE(nullptr, surface); | 387 ASSERT_NE(nullptr, surface); |
| 378 EXPECT_EQ(2, surface->frame_index()); | 388 EXPECT_EQ(2, surface->frame_index()); |
| 379 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 389 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 380 frame->delegated_frame_data.reset(new DelegatedFrameData); | 390 frame->delegated_frame_data.reset(new DelegatedFrameData); |
| 381 | 391 |
| 382 factory_.SubmitCompositorFrame(surface_id, frame.Pass(), | 392 factory_->SubmitCompositorFrame(surface_id, frame.Pass(), |
| 383 SurfaceFactory::DrawCallback()); | 393 SurfaceFactory::DrawCallback()); |
| 384 EXPECT_EQ(2, surface->frame_index()); | 394 EXPECT_EQ(2, surface->frame_index()); |
| 385 factory_.Destroy(surface_id); | 395 factory_->Destroy(surface_id); |
| 386 } | 396 } |
| 387 | 397 |
| 388 void DrawCallback(uint32* execute_count, | 398 void DrawCallback(uint32* execute_count, |
| 389 SurfaceDrawStatus* result, | 399 SurfaceDrawStatus* result, |
| 390 SurfaceDrawStatus drawn) { | 400 SurfaceDrawStatus drawn) { |
| 391 *execute_count += 1; | 401 *execute_count += 1; |
| 392 *result = drawn; | 402 *result = drawn; |
| 393 } | 403 } |
| 394 | 404 |
| 395 // Tests doing a DestroyAll before shutting down the factory; | 405 // Tests doing a DestroyAll before shutting down the factory; |
| 396 TEST_F(SurfaceFactoryTest, DestroyAll) { | 406 TEST_F(SurfaceFactoryTest, DestroyAll) { |
| 397 SurfaceId id(7); | 407 SurfaceId id(7); |
| 398 factory_.Create(id); | 408 factory_->Create(id); |
| 399 | 409 |
| 400 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 410 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 401 TransferableResource resource; | 411 TransferableResource resource; |
| 402 resource.id = 1; | 412 resource.id = 1; |
| 403 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; | 413 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; |
| 404 frame_data->resource_list.push_back(resource); | 414 frame_data->resource_list.push_back(resource); |
| 405 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 415 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 406 frame->delegated_frame_data = frame_data.Pass(); | 416 frame->delegated_frame_data = frame_data.Pass(); |
| 407 uint32 execute_count = 0; | 417 uint32 execute_count = 0; |
| 408 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; | 418 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; |
| 409 | 419 |
| 410 factory_.SubmitCompositorFrame( | 420 factory_->SubmitCompositorFrame( |
| 411 id, frame.Pass(), base::Bind(&DrawCallback, &execute_count, &drawn)); | 421 id, frame.Pass(), base::Bind(&DrawCallback, &execute_count, &drawn)); |
| 412 | 422 |
| 413 surface_id_ = SurfaceId(); | 423 surface_id_ = SurfaceId(); |
| 414 factory_.DestroyAll(); | 424 factory_->DestroyAll(); |
| 415 EXPECT_EQ(1u, execute_count); | 425 EXPECT_EQ(1u, execute_count); |
| 416 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); | 426 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); |
| 417 } | 427 } |
| 418 | 428 |
| 419 TEST_F(SurfaceFactoryTest, DestroySequence) { | 429 TEST_F(SurfaceFactoryTest, DestroySequence) { |
| 420 SurfaceId id2(5); | 430 SurfaceId id2(5); |
| 421 factory_.Create(id2); | 431 factory_->Create(id2); |
| 422 | 432 |
| 423 manager_.RegisterSurfaceIdNamespace(0); | 433 manager_.RegisterSurfaceIdNamespace(0); |
| 424 | 434 |
| 425 // Check that waiting before the sequence is satisfied works. | 435 // Check that waiting before the sequence is satisfied works. |
| 426 manager_.GetSurfaceForId(id2) | 436 manager_.GetSurfaceForId(id2) |
| 427 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 437 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
| 428 factory_.Destroy(id2); | 438 factory_->Destroy(id2); |
| 429 | 439 |
| 430 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 440 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 431 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 441 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 432 frame->metadata.satisfies_sequences.push_back(6); | 442 frame->metadata.satisfies_sequences.push_back(6); |
| 433 frame->metadata.satisfies_sequences.push_back(4); | 443 frame->metadata.satisfies_sequences.push_back(4); |
| 434 frame->delegated_frame_data = frame_data.Pass(); | 444 frame->delegated_frame_data = frame_data.Pass(); |
| 435 DCHECK(manager_.GetSurfaceForId(id2)); | 445 DCHECK(manager_.GetSurfaceForId(id2)); |
| 436 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), | 446 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(), |
| 437 SurfaceFactory::DrawCallback()); | 447 SurfaceFactory::DrawCallback()); |
| 438 DCHECK(!manager_.GetSurfaceForId(id2)); | 448 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 439 | 449 |
| 440 // Check that waiting after the sequence is satisfied works. | 450 // Check that waiting after the sequence is satisfied works. |
| 441 factory_.Create(id2); | 451 factory_->Create(id2); |
| 442 DCHECK(manager_.GetSurfaceForId(id2)); | 452 DCHECK(manager_.GetSurfaceForId(id2)); |
| 443 manager_.GetSurfaceForId(id2) | 453 manager_.GetSurfaceForId(id2) |
| 444 ->AddDestructionDependency(SurfaceSequence(0, 6)); | 454 ->AddDestructionDependency(SurfaceSequence(0, 6)); |
| 445 factory_.Destroy(id2); | 455 factory_->Destroy(id2); |
| 446 DCHECK(!manager_.GetSurfaceForId(id2)); | 456 DCHECK(!manager_.GetSurfaceForId(id2)); |
| 447 } | 457 } |
| 448 | 458 |
| 449 // Tests that Surface ID namespace invalidation correctly allows | 459 // Tests that Surface ID namespace invalidation correctly allows |
| 450 // Sequences to be ignored. | 460 // Sequences to be ignored. |
| 451 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { | 461 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { |
| 452 uint32_t id_namespace = 9u; | 462 uint32_t id_namespace = 9u; |
| 453 SurfaceId id(5); | 463 SurfaceId id(5); |
| 454 factory_.Create(id); | 464 factory_->Create(id); |
| 455 | 465 |
| 456 manager_.RegisterSurfaceIdNamespace(id_namespace); | 466 manager_.RegisterSurfaceIdNamespace(id_namespace); |
| 457 manager_.GetSurfaceForId(id) | 467 manager_.GetSurfaceForId(id) |
| 458 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); | 468 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); |
| 459 factory_.Destroy(id); | 469 factory_->Destroy(id); |
| 460 | 470 |
| 461 // Verify the dependency has prevented the surface from getting destroyed. | 471 // Verify the dependency has prevented the surface from getting destroyed. |
| 462 EXPECT_TRUE(manager_.GetSurfaceForId(id)); | 472 EXPECT_TRUE(manager_.GetSurfaceForId(id)); |
| 463 | 473 |
| 464 manager_.InvalidateSurfaceIdNamespace(id_namespace); | 474 manager_.InvalidateSurfaceIdNamespace(id_namespace); |
| 465 | 475 |
| 466 // Verify that the invalidated namespace caused the unsatisfied sequence | 476 // Verify that the invalidated namespace caused the unsatisfied sequence |
| 467 // to be ignored. | 477 // to be ignored. |
| 468 EXPECT_FALSE(manager_.GetSurfaceForId(id)); | 478 EXPECT_FALSE(manager_.GetSurfaceForId(id)); |
| 469 } | 479 } |
| 470 | 480 |
| 471 TEST_F(SurfaceFactoryTest, DestroyCycle) { | 481 TEST_F(SurfaceFactoryTest, DestroyCycle) { |
| 472 SurfaceId id2(5); | 482 SurfaceId id2(5); |
| 473 factory_.Create(id2); | 483 factory_->Create(id2); |
| 474 | 484 |
| 475 manager_.RegisterSurfaceIdNamespace(0); | 485 manager_.RegisterSurfaceIdNamespace(0); |
| 476 | 486 |
| 477 manager_.GetSurfaceForId(id2) | 487 manager_.GetSurfaceForId(id2) |
| 478 ->AddDestructionDependency(SurfaceSequence(0, 4)); | 488 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
| 479 | 489 |
| 480 // Give id2 a frame that references surface_id_. | 490 // Give id2 a frame that references surface_id_. |
| 481 { | 491 { |
| 482 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); | 492 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 483 render_pass->referenced_surfaces.push_back(surface_id_); | 493 render_pass->referenced_surfaces.push_back(surface_id_); |
| 484 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 494 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 485 frame_data->render_pass_list.push_back(render_pass.Pass()); | 495 frame_data->render_pass_list.push_back(render_pass.Pass()); |
| 486 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 496 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 487 frame->delegated_frame_data = frame_data.Pass(); | 497 frame->delegated_frame_data = frame_data.Pass(); |
| 488 factory_.SubmitCompositorFrame(id2, frame.Pass(), | 498 factory_->SubmitCompositorFrame(id2, frame.Pass(), |
| 489 SurfaceFactory::DrawCallback()); | 499 SurfaceFactory::DrawCallback()); |
| 490 } | 500 } |
| 491 factory_.Destroy(id2); | 501 factory_->Destroy(id2); |
| 492 | 502 |
| 493 // Give surface_id_ a frame that references id2. | 503 // Give surface_id_ a frame that references id2. |
| 494 { | 504 { |
| 495 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); | 505 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); |
| 496 render_pass->referenced_surfaces.push_back(id2); | 506 render_pass->referenced_surfaces.push_back(id2); |
| 497 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 507 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 498 frame_data->render_pass_list.push_back(render_pass.Pass()); | 508 frame_data->render_pass_list.push_back(render_pass.Pass()); |
| 499 scoped_ptr<CompositorFrame> frame(new CompositorFrame); | 509 scoped_ptr<CompositorFrame> frame(new CompositorFrame); |
| 500 frame->delegated_frame_data = frame_data.Pass(); | 510 frame->delegated_frame_data = frame_data.Pass(); |
| 501 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), | 511 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(), |
| 502 SurfaceFactory::DrawCallback()); | 512 SurfaceFactory::DrawCallback()); |
| 503 } | 513 } |
| 504 factory_.Destroy(surface_id_); | 514 factory_->Destroy(surface_id_); |
| 505 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); | 515 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); |
| 506 // surface_id_ should be retained by reference from id2. | 516 // surface_id_ should be retained by reference from id2. |
| 507 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_)); | 517 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_)); |
| 508 | 518 |
| 509 // Satisfy last destruction dependency for id2. | 519 // Satisfy last destruction dependency for id2. |
| 510 std::vector<uint32_t> to_satisfy; | 520 std::vector<uint32_t> to_satisfy; |
| 511 to_satisfy.push_back(4); | 521 to_satisfy.push_back(4); |
| 512 manager_.DidSatisfySequences(0, &to_satisfy); | 522 manager_.DidSatisfySequences(0, &to_satisfy); |
| 513 | 523 |
| 514 // id2 and surface_id_ are in a reference cycle that has no surface | 524 // id2 and surface_id_ are in a reference cycle that has no surface |
| 515 // sequences holding on to it, so they should be destroyed. | 525 // sequences holding on to it, so they should be destroyed. |
| 516 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); | 526 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); |
| 517 EXPECT_TRUE(!manager_.GetSurfaceForId(surface_id_)); | 527 EXPECT_TRUE(!manager_.GetSurfaceForId(surface_id_)); |
| 518 | 528 |
| 519 surface_id_ = SurfaceId(); | 529 surface_id_ = SurfaceId(); |
| 520 } | 530 } |
| 521 | 531 |
| 532 // Verifies BFS is forwarded to the client. |
| 533 TEST_F(SurfaceFactoryTest, SetBeginFrameSource) { |
| 534 FakeBeginFrameSource bfs1; |
| 535 FakeBeginFrameSource bfs2; |
| 536 EXPECT_EQ(nullptr, client_.begin_frame_source()); |
| 537 factory_->SetBeginFrameSource(surface_id_, &bfs1); |
| 538 EXPECT_EQ(&bfs1, client_.begin_frame_source()); |
| 539 factory_->SetBeginFrameSource(surface_id_, &bfs2); |
| 540 EXPECT_EQ(&bfs2, client_.begin_frame_source()); |
| 541 factory_->SetBeginFrameSource(surface_id_, nullptr); |
| 542 EXPECT_EQ(nullptr, client_.begin_frame_source()); |
| 543 } |
| 544 |
| 545 TEST_F(SurfaceFactoryTest, BeginFrameSourceRemovedOnFactoryDestruction) { |
| 546 FakeBeginFrameSource bfs; |
| 547 factory_->SetBeginFrameSource(surface_id_, &bfs); |
| 548 EXPECT_EQ(&bfs, client_.begin_frame_source()); |
| 549 |
| 550 // Prevent the Surface from being destroyed when we destroy the factory. |
| 551 manager_.RegisterSurfaceIdNamespace(0); |
| 552 manager_.GetSurfaceForId(surface_id_) |
| 553 ->AddDestructionDependency(SurfaceSequence(0, 4)); |
| 554 |
| 555 surface_id_ = SurfaceId(); |
| 556 factory_->DestroyAll(); |
| 557 |
| 558 EXPECT_EQ(&bfs, client_.begin_frame_source()); |
| 559 factory_.reset(); |
| 560 EXPECT_EQ(nullptr, client_.begin_frame_source()); |
| 561 } |
| 562 |
| 522 } // namespace | 563 } // namespace |
| 523 } // namespace cc | 564 } // namespace cc |
| OLD | NEW |