| 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 "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 Loading... |
| 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, 1), |
| 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 |
| 83 // SurfaceObserver implementation. | 83 // SurfaceObserver implementation. |
| 84 void OnSurfaceCreated(const SurfaceId& surface_id, | 84 void OnSurfaceCreated(const SurfaceId& surface_id, |
| 85 const gfx::Size& frame, | 85 const gfx::Size& frame, |
| 86 float device_scale_factor) override { | 86 float device_scale_factor) override { |
| 87 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id()); | 87 EXPECT_EQ(kArbitraryFrameSinkId, surface_id.frame_sink_id()); |
| 88 last_created_surface_id_ = surface_id; | 88 last_created_surface_id_ = surface_id; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { | 91 void OnSurfaceDamaged(const SurfaceId& id, bool* changed) override { |
| 92 *changed = true; | 92 *changed = true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 ~SurfaceFactoryTest() override { | 95 ~SurfaceFactoryTest() override { |
| 96 if (!local_frame_id_.is_null()) | 96 if (local_frame_id_.is_valid()) |
| 97 factory_->Destroy(local_frame_id_); | 97 factory_->Destroy(local_frame_id_); |
| 98 manager_.RemoveObserver(this); | 98 manager_.RemoveObserver(this); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, | 101 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, |
| 102 size_t num_resource_ids) { | 102 size_t num_resource_ids) { |
| 103 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 103 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 104 for (size_t i = 0u; i < num_resource_ids; ++i) { | 104 for (size_t i = 0u; i < num_resource_ids; ++i) { |
| 105 TransferableResource resource; | 105 TransferableResource resource; |
| 106 resource.id = resource_ids[i]; | 106 resource.id = resource_ids[i]; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, 1); |
| 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, 0); |
| 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, 1); |
| 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, 1); |
| 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 factory_->DestroyAll(); |
| 499 local_frame_id_ = LocalFrameId(); | 500 local_frame_id_ = LocalFrameId(); |
| 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, 0); |
| 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 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |