| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "cc/animation/animation_host.h" | 24 #include "cc/animation/animation_host.h" |
| 25 #include "cc/layers/solid_color_layer.h" | 25 #include "cc/layers/solid_color_layer.h" |
| 26 #include "cc/layers/texture_layer_client.h" | 26 #include "cc/layers/texture_layer_client.h" |
| 27 #include "cc/layers/texture_layer_impl.h" | 27 #include "cc/layers/texture_layer_impl.h" |
| 28 #include "cc/output/context_provider.h" | 28 #include "cc/output/context_provider.h" |
| 29 #include "cc/resources/returned_resource.h" | 29 #include "cc/resources/returned_resource.h" |
| 30 #include "cc/test/fake_compositor_frame_sink.h" |
| 30 #include "cc/test/fake_impl_task_runner_provider.h" | 31 #include "cc/test/fake_impl_task_runner_provider.h" |
| 31 #include "cc/test/fake_layer_tree_host_client.h" | 32 #include "cc/test/fake_layer_tree_host_client.h" |
| 32 #include "cc/test/fake_layer_tree_host_impl.h" | 33 #include "cc/test/fake_layer_tree_host_impl.h" |
| 33 #include "cc/test/fake_output_surface.h" | |
| 34 #include "cc/test/layer_test_common.h" | 34 #include "cc/test/layer_test_common.h" |
| 35 #include "cc/test/layer_tree_test.h" | 35 #include "cc/test/layer_tree_test.h" |
| 36 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 36 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 37 #include "cc/test/test_delegating_output_surface.h" | 37 #include "cc/test/test_compositor_frame_sink.h" |
| 38 #include "cc/test/test_task_graph_runner.h" | 38 #include "cc/test/test_task_graph_runner.h" |
| 39 #include "cc/test/test_web_graphics_context_3d.h" | 39 #include "cc/test/test_web_graphics_context_3d.h" |
| 40 #include "cc/trees/blocking_task_runner.h" | 40 #include "cc/trees/blocking_task_runner.h" |
| 41 #include "cc/trees/layer_tree_host.h" | 41 #include "cc/trees/layer_tree_host.h" |
| 42 #include "cc/trees/layer_tree_impl.h" | 42 #include "cc/trees/layer_tree_impl.h" |
| 43 #include "cc/trees/single_thread_proxy.h" | 43 #include "cc/trees/single_thread_proxy.h" |
| 44 #include "gpu/GLES2/gl2extchromium.h" | 44 #include "gpu/GLES2/gl2extchromium.h" |
| 45 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 47 | 47 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 TextureMailbox mailbox2_; | 202 TextureMailbox mailbox2_; |
| 203 TextureMailbox mailbox3_; | 203 TextureMailbox mailbox3_; |
| 204 gpu::SyncToken sync_token1_; | 204 gpu::SyncToken sync_token1_; |
| 205 gpu::SyncToken sync_token2_; | 205 gpu::SyncToken sync_token2_; |
| 206 std::unique_ptr<SharedBitmap> shared_bitmap_; | 206 std::unique_ptr<SharedBitmap> shared_bitmap_; |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 class TextureLayerTest : public testing::Test { | 209 class TextureLayerTest : public testing::Test { |
| 210 public: | 210 public: |
| 211 TextureLayerTest() | 211 TextureLayerTest() |
| 212 : output_surface_(FakeOutputSurface::CreateDelegating3d()), | 212 : compositor_frame_sink_(FakeCompositorFrameSink::Create3d()), |
| 213 host_impl_(&task_runner_provider_, | 213 host_impl_(&task_runner_provider_, |
| 214 &shared_bitmap_manager_, | 214 &shared_bitmap_manager_, |
| 215 &task_graph_runner_), | 215 &task_graph_runner_), |
| 216 test_data_(&shared_bitmap_manager_) {} | 216 test_data_(&shared_bitmap_manager_) {} |
| 217 | 217 |
| 218 protected: | 218 protected: |
| 219 void SetUp() override { | 219 void SetUp() override { |
| 220 layer_tree_host_ = | 220 layer_tree_host_ = |
| 221 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); | 221 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); |
| 222 layer_tree_ = layer_tree_host_->GetLayerTree(); | 222 layer_tree_ = layer_tree_host_->GetLayerTree(); |
| 223 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 223 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 224 layer_tree_->SetViewportSize(gfx::Size(10, 10)); | 224 layer_tree_->SetViewportSize(gfx::Size(10, 10)); |
| 225 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 225 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void TearDown() override { | 228 void TearDown() override { |
| 229 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 229 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 230 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 230 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 231 | 231 |
| 232 layer_tree_->SetRootLayer(nullptr); | 232 layer_tree_->SetRootLayer(nullptr); |
| 233 layer_tree_host_ = nullptr; | 233 layer_tree_host_ = nullptr; |
| 234 } | 234 } |
| 235 | 235 |
| 236 std::unique_ptr<MockLayerTreeHost> layer_tree_host_; | 236 std::unique_ptr<MockLayerTreeHost> layer_tree_host_; |
| 237 LayerTree* layer_tree_; | 237 LayerTree* layer_tree_; |
| 238 FakeImplTaskRunnerProvider task_runner_provider_; | 238 FakeImplTaskRunnerProvider task_runner_provider_; |
| 239 FakeLayerTreeHostClient fake_client_; | 239 FakeLayerTreeHostClient fake_client_; |
| 240 TestSharedBitmapManager shared_bitmap_manager_; | 240 TestSharedBitmapManager shared_bitmap_manager_; |
| 241 TestTaskGraphRunner task_graph_runner_; | 241 TestTaskGraphRunner task_graph_runner_; |
| 242 std::unique_ptr<OutputSurface> output_surface_; | 242 std::unique_ptr<CompositorFrameSink> compositor_frame_sink_; |
| 243 FakeLayerTreeHostImpl host_impl_; | 243 FakeLayerTreeHostImpl host_impl_; |
| 244 CommonMailboxObjects test_data_; | 244 CommonMailboxObjects test_data_; |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 247 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
| 248 scoped_refptr<TextureLayer> test_layer = | 248 scoped_refptr<TextureLayer> test_layer = |
| 249 TextureLayer::CreateForMailbox(nullptr); | 249 TextureLayer::CreateForMailbox(nullptr); |
| 250 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer)); | 250 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer)); |
| 251 | 251 |
| 252 // Test properties that should call SetNeedsCommit. All properties need to | 252 // Test properties that should call SetNeedsCommit. All properties need to |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 stop_capture.Signal(); | 628 stop_capture.Signal(); |
| 629 Wait(main_thread_); | 629 Wait(main_thread_); |
| 630 | 630 |
| 631 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 631 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 632 } | 632 } |
| 633 | 633 |
| 634 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { | 634 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| 635 public: | 635 public: |
| 636 TextureLayerImplWithMailboxThreadedCallback() = default; | 636 TextureLayerImplWithMailboxThreadedCallback() = default; |
| 637 | 637 |
| 638 std::unique_ptr<TestDelegatingOutputSurface> CreateDelegatingOutputSurface( | 638 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( |
| 639 scoped_refptr<ContextProvider> compositor_context_provider, | 639 scoped_refptr<ContextProvider> compositor_context_provider, |
| 640 scoped_refptr<ContextProvider> worker_context_provider) override { | 640 scoped_refptr<ContextProvider> worker_context_provider) override { |
| 641 bool synchronous_composite = | 641 bool synchronous_composite = |
| 642 !HasImplThread() && | 642 !HasImplThread() && |
| 643 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler; | 643 !layer_tree_host()->GetSettings().single_thread_proxy_scheduler; |
| 644 // Allow relaim resources for this test so that mailboxes in the display | 644 // Allow relaim resources for this test so that mailboxes in the display |
| 645 // will be returned inside the commit that replaces them. | 645 // will be returned inside the commit that replaces them. |
| 646 bool force_disable_reclaim_resources = false; | 646 bool force_disable_reclaim_resources = false; |
| 647 return base::MakeUnique<TestDelegatingOutputSurface>( | 647 return base::MakeUnique<TestCompositorFrameSink>( |
| 648 compositor_context_provider, std::move(worker_context_provider), | 648 compositor_context_provider, std::move(worker_context_provider), |
| 649 CreateDisplayOutputSurface(compositor_context_provider), | 649 CreateDisplayOutputSurface(compositor_context_provider), |
| 650 shared_bitmap_manager(), gpu_memory_buffer_manager(), | 650 shared_bitmap_manager(), gpu_memory_buffer_manager(), |
| 651 layer_tree_host()->GetSettings().renderer_settings, | 651 layer_tree_host()->GetSettings().renderer_settings, |
| 652 ImplThreadTaskRunner(), synchronous_composite, | 652 ImplThreadTaskRunner(), synchronous_composite, |
| 653 force_disable_reclaim_resources); | 653 force_disable_reclaim_resources); |
| 654 } | 654 } |
| 655 | 655 |
| 656 // Make sure callback is received on main and doesn't block the impl thread. | 656 // Make sure callback is received on main and doesn't block the impl thread. |
| 657 void ReleaseCallback(char mailbox_char, | 657 void ReleaseCallback(char mailbox_char, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 #endif | 850 #endif |
| 851 | 851 |
| 852 class TextureLayerImplWithMailboxTest : public TextureLayerTest { | 852 class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
| 853 protected: | 853 protected: |
| 854 void SetUp() override { | 854 void SetUp() override { |
| 855 TextureLayerTest::SetUp(); | 855 TextureLayerTest::SetUp(); |
| 856 layer_tree_host_ = | 856 layer_tree_host_ = |
| 857 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); | 857 MockLayerTreeHost::Create(&fake_client_, &task_graph_runner_); |
| 858 layer_tree_ = layer_tree_host_->GetLayerTree(); | 858 layer_tree_ = layer_tree_host_->GetLayerTree(); |
| 859 host_impl_.SetVisible(true); | 859 host_impl_.SetVisible(true); |
| 860 EXPECT_TRUE(host_impl_.InitializeRenderer(output_surface_.get())); | 860 EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get())); |
| 861 } | 861 } |
| 862 | 862 |
| 863 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { | 863 bool WillDraw(TextureLayerImpl* layer, DrawMode mode) { |
| 864 bool will_draw = layer->WillDraw( | 864 bool will_draw = layer->WillDraw( |
| 865 mode, host_impl_.active_tree()->resource_provider()); | 865 mode, host_impl_.active_tree()->resource_provider()); |
| 866 if (will_draw) | 866 if (will_draw) |
| 867 layer->DidDraw(host_impl_.active_tree()->resource_provider()); | 867 layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
| 868 return will_draw; | 868 return will_draw; |
| 869 } | 869 } |
| 870 | 870 |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 base::ThreadChecker main_thread_; | 1453 base::ThreadChecker main_thread_; |
| 1454 int callback_count_; | 1454 int callback_count_; |
| 1455 scoped_refptr<Layer> root_; | 1455 scoped_refptr<Layer> root_; |
| 1456 scoped_refptr<TextureLayer> layer_; | 1456 scoped_refptr<TextureLayer> layer_; |
| 1457 }; | 1457 }; |
| 1458 | 1458 |
| 1459 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); | 1459 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerWithMailboxImplThreadDeleted); |
| 1460 | 1460 |
| 1461 } // namespace | 1461 } // namespace |
| 1462 } // namespace cc | 1462 } // namespace cc |
| OLD | NEW |