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