| // Copyright 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "cc/trees/layer_tree_host.h" |
| |
| #include <algorithm> |
| |
| #include "base/auto_reset.h" |
| #include "base/location.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/synchronization/lock.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "cc/animation/timing_function.h" |
| #include "cc/debug/frame_rate_counter.h" |
| #include "cc/layers/content_layer_client.h" |
| #include "cc/layers/io_surface_layer.h" |
| #include "cc/layers/layer_impl.h" |
| #include "cc/layers/painted_scrollbar_layer.h" |
| #include "cc/layers/picture_layer.h" |
| #include "cc/layers/solid_color_layer.h" |
| #include "cc/layers/video_layer.h" |
| #include "cc/output/begin_frame_args.h" |
| #include "cc/output/compositor_frame_ack.h" |
| #include "cc/output/copy_output_request.h" |
| #include "cc/output/copy_output_result.h" |
| #include "cc/output/output_surface.h" |
| #include "cc/output/swap_promise.h" |
| #include "cc/quads/draw_quad.h" |
| #include "cc/quads/io_surface_draw_quad.h" |
| #include "cc/quads/render_pass_draw_quad.h" |
| #include "cc/quads/tile_draw_quad.h" |
| #include "cc/test/fake_content_layer_client.h" |
| #include "cc/test/fake_layer_tree_host_client.h" |
| #include "cc/test/fake_output_surface.h" |
| #include "cc/test/fake_painted_scrollbar_layer.h" |
| #include "cc/test/fake_picture_layer.h" |
| #include "cc/test/fake_picture_layer_impl.h" |
| #include "cc/test/fake_picture_pile.h" |
| #include "cc/test/fake_proxy.h" |
| #include "cc/test/fake_scoped_ui_resource.h" |
| #include "cc/test/fake_video_frame_provider.h" |
| #include "cc/test/geometry_test_utils.h" |
| #include "cc/test/layer_tree_test.h" |
| #include "cc/test/test_shared_bitmap_manager.h" |
| #include "cc/test/test_web_graphics_context_3d.h" |
| #include "cc/trees/layer_tree_host_impl.h" |
| #include "cc/trees/layer_tree_impl.h" |
| #include "cc/trees/single_thread_proxy.h" |
| #include "cc/trees/thread_proxy.h" |
| #include "gpu/GLES2/gl2extchromium.h" |
| #include "skia/ext/refptr.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "third_party/khronos/GLES2/gl2.h" |
| #include "third_party/khronos/GLES2/gl2ext.h" |
| #include "third_party/skia/include/core/SkPicture.h" |
| #include "ui/gfx/geometry/point_conversions.h" |
| #include "ui/gfx/geometry/size_conversions.h" |
| #include "ui/gfx/geometry/vector2d_conversions.h" |
| |
| using testing::_; |
| using testing::AnyNumber; |
| using testing::AtLeast; |
| using testing::Mock; |
| |
| namespace cc { |
| namespace { |
| |
| class LayerTreeHostTest : public LayerTreeTest {}; |
| |
| class LayerTreeHostTestHasImplThreadTest : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestHasImplThreadTest() : threaded_(false) {} |
| |
| void RunTest(bool threaded, bool delegating_renderer) override { |
| threaded_ = threaded; |
| LayerTreeHostTest::RunTest(threaded, delegating_renderer); |
| } |
| |
| void BeginTest() override { |
| EXPECT_EQ(threaded_, HasImplThread()); |
| EndTest(); |
| } |
| |
| void AfterTest() override { EXPECT_EQ(threaded_, HasImplThread()); } |
| |
| private: |
| bool threaded_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHasImplThreadTest); |
| |
| class LayerTreeHostTestSetNeedsCommitInsideLayout : public LayerTreeHostTest { |
| protected: |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void Layout() override { |
| // This shouldn't cause a second commit to happen. |
| layer_tree_host()->SetNeedsCommit(); |
| } |
| |
| void DidCommit() override { |
| EXPECT_EQ(1, layer_tree_host()->source_frame_number()); |
| EndTest(); |
| } |
| |
| void AfterTest() override {} |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommitInsideLayout); |
| |
| class LayerTreeHostTestSetNeedsUpdateInsideLayout : public LayerTreeHostTest { |
| protected: |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void Layout() override { |
| // This shouldn't cause a second commit to happen. |
| layer_tree_host()->SetNeedsUpdateLayers(); |
| } |
| |
| void DidCommit() override { |
| EXPECT_EQ(1, layer_tree_host()->source_frame_number()); |
| EndTest(); |
| } |
| |
| void AfterTest() override {} |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsUpdateInsideLayout); |
| |
| // Test if the LTHI receives ReadyToActivate notifications from the TileManager |
| // when no raster tasks get scheduled. |
| class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestReadyToActivateEmpty() |
| : did_notify_ready_to_activate_(false), |
| all_tiles_required_for_activation_are_ready_to_draw_(false), |
| required_for_activation_count_(0) {} |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| const std::vector<PictureLayerImpl*>& layers = |
| impl->sync_tree()->picture_layers(); |
| required_for_activation_count_ = 0; |
| for (const auto& layer : layers) { |
| FakePictureLayerImpl* fake_layer = |
| static_cast<FakePictureLayerImpl*>(layer); |
| required_for_activation_count_ += |
| fake_layer->CountTilesRequiredForActivation(); |
| } |
| } |
| |
| void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { |
| did_notify_ready_to_activate_ = true; |
| all_tiles_required_for_activation_are_ready_to_draw_ = |
| impl->tile_manager()->IsReadyToActivate(); |
| EndTest(); |
| } |
| |
| void AfterTest() override { |
| EXPECT_TRUE(did_notify_ready_to_activate_); |
| EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); |
| EXPECT_EQ(size_t(0), required_for_activation_count_); |
| } |
| |
| protected: |
| bool did_notify_ready_to_activate_; |
| bool all_tiles_required_for_activation_are_ready_to_draw_; |
| size_t required_for_activation_count_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateEmpty); |
| |
| // Test if the LTHI receives ReadyToActivate notifications from the TileManager |
| // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled. |
| class LayerTreeHostTestReadyToActivateNonEmpty |
| : public LayerTreeHostTestReadyToActivateEmpty { |
| public: |
| void SetupTree() override { |
| client_.set_fill_with_nonsolid_color(true); |
| scoped_refptr<FakePictureLayer> root_layer = |
| FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer->SetBounds(gfx::Size(1024, 1024)); |
| root_layer->SetIsDrawable(true); |
| |
| layer_tree_host()->SetRootLayer(root_layer); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void AfterTest() override { |
| EXPECT_TRUE(did_notify_ready_to_activate_); |
| EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); |
| EXPECT_LE(size_t(1), required_for_activation_count_); |
| } |
| |
| private: |
| FakeContentLayerClient client_; |
| }; |
| |
| // Multi-thread only because in single thread the commit goes directly to the |
| // active tree, so notify ready to activate is skipped. |
| MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); |
| |
| // Test if the LTHI receives ReadyToDraw notifications from the TileManager when |
| // no raster tasks get scheduled. |
| class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestReadyToDrawEmpty() |
| : did_notify_ready_to_draw_(false), |
| all_tiles_required_for_draw_are_ready_to_draw_(false), |
| required_for_draw_count_(0) {} |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { |
| did_notify_ready_to_draw_ = true; |
| const std::vector<PictureLayerImpl*>& layers = |
| impl->active_tree()->picture_layers(); |
| all_tiles_required_for_draw_are_ready_to_draw_ = |
| impl->tile_manager()->IsReadyToDraw(); |
| for (const auto& layer : layers) { |
| FakePictureLayerImpl* fake_layer = |
| static_cast<FakePictureLayerImpl*>(layer); |
| required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw(); |
| } |
| |
| EndTest(); |
| } |
| |
| void AfterTest() override { |
| EXPECT_TRUE(did_notify_ready_to_draw_); |
| EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_); |
| EXPECT_EQ(size_t(0), required_for_draw_count_); |
| } |
| |
| protected: |
| bool did_notify_ready_to_draw_; |
| bool all_tiles_required_for_draw_are_ready_to_draw_; |
| size_t required_for_draw_count_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToDrawEmpty); |
| |
| // Test if the LTHI receives ReadyToDraw notifications from the TileManager when |
| // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled. |
| class LayerTreeHostTestReadyToDrawNonEmpty |
| : public LayerTreeHostTestReadyToDrawEmpty { |
| public: |
| void SetupTree() override { |
| client_.set_fill_with_nonsolid_color(true); |
| scoped_refptr<FakePictureLayer> root_layer = |
| FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer->SetBounds(gfx::Size(1024, 1024)); |
| root_layer->SetIsDrawable(true); |
| |
| layer_tree_host()->SetRootLayer(root_layer); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void AfterTest() override { |
| EXPECT_TRUE(did_notify_ready_to_draw_); |
| EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_); |
| EXPECT_LE(size_t(1), required_for_draw_count_); |
| } |
| |
| private: |
| FakeContentLayerClient client_; |
| }; |
| |
| // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in |
| // single threaded mode. |
| SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty); |
| |
| // This tests if we get the READY_TO_DRAW signal and draw if we become invisible |
| // and then become visible again. |
| class LayerTreeHostTestReadyToDrawVisibility : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestReadyToDrawVisibility() |
| : LayerTreeHostTest(), |
| toggled_visibility_(false), |
| did_notify_ready_to_draw_(false), |
| did_draw_(false) {} |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void SetupTree() override { |
| client_.set_fill_with_nonsolid_color(true); |
| scoped_refptr<FakePictureLayer> root_layer = |
| FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer->SetBounds(gfx::Size(1024, 1024)); |
| root_layer->SetIsDrawable(true); |
| |
| layer_tree_host()->SetRootLayer(root_layer); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| if (!toggled_visibility_) { |
| { |
| DebugScopedSetMainThread main(proxy()); |
| layer_tree_host()->SetVisible(false); |
| } |
| toggled_visibility_ = true; |
| EXPECT_FALSE(host_impl->visible()); |
| } |
| } |
| |
| void NotifyReadyToDrawOnThread(LayerTreeHostImpl* host_impl) override { |
| // Sometimes the worker thread posts NotifyReadyToDraw in the extremely |
| // short duration of time between PrepareTiles and SetVisible(false) so we |
| // might get two NotifyReadyToDraw signals for this test. |
| did_notify_ready_to_draw_ = true; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| EXPECT_FALSE(did_draw_); |
| did_draw_ = true; |
| EndTest(); |
| } |
| |
| void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override { |
| if (!host_impl->visible()) { |
| { |
| DebugScopedSetMainThread main(proxy()); |
| layer_tree_host()->SetVisible(true); |
| } |
| EXPECT_TRUE(host_impl->visible()); |
| } |
| } |
| |
| void AfterTest() override { |
| EXPECT_TRUE(did_notify_ready_to_draw_); |
| EXPECT_TRUE(did_draw_); |
| } |
| |
| private: |
| FakeContentLayerClient client_; |
| bool toggled_visibility_; |
| bool did_notify_ready_to_draw_; |
| bool did_draw_; |
| }; |
| |
| // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in |
| // single threaded mode. |
| SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawVisibility); |
| |
| class LayerTreeHostFreeWorkerContextResourcesTest : public LayerTreeHostTest { |
| public: |
| scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
| auto output_surface = make_scoped_ptr(new testing::StrictMock< |
| MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface>( |
| delegating_renderer())); |
| |
| // At init, we expect one call to set visibility to true. |
| testing::Expectation visibility_true = |
| EXPECT_CALL(*output_surface, |
| SetWorkerContextShouldAggressivelyFreeResources(false)) |
| .Times(1); |
| |
| // After running, we should get exactly one call to |
| // FreeWorkerContextGpuResources. |
| EXPECT_CALL(*output_surface, |
| SetWorkerContextShouldAggressivelyFreeResources(true)) |
| .After(visibility_true) |
| .WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); })); |
| return output_surface.Pass(); |
| } |
| |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->gpu_rasterization_enabled = true; |
| settings->gpu_rasterization_forced = true; |
| } |
| |
| void BeginTest() override { |
| // Logic is handled in InitializedRendererOnThread to ensure that our |
| // LTHI is fully set up. |
| } |
| |
| void AfterTest() override { |
| // Expectations handled via mock. |
| } |
| |
| private: |
| class MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface |
| : public FakeOutputSurface { |
| public: |
| ~MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface() {} |
| explicit MockSetWorkerContextShouldAggressivelyFreeResourcesOutputSurface( |
| bool delegated_rendering) |
| : FakeOutputSurface(TestContextProvider::Create(), |
| TestContextProvider::Create(), |
| delegated_rendering) {} |
| MOCK_METHOD1(SetWorkerContextShouldAggressivelyFreeResources, |
| void(bool is_visible)); |
| }; |
| }; |
| |
| // Test if the LTH successfully frees resources on the worker context when |
| // visibility is set to false. |
| class LayerTreeHostFreeWorkerContextResourcesOnInvisible |
| : public LayerTreeHostFreeWorkerContextResourcesTest { |
| public: |
| void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, |
| bool success) override { |
| PostSetVisibleToMainThread(false); |
| } |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostFreeWorkerContextResourcesOnInvisible); |
| |
| // Test if the LTH successfully frees resources on the worker context when |
| // hard memory limit is set to zero. |
| class LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit |
| : public LayerTreeHostFreeWorkerContextResourcesTest { |
| public: |
| void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, |
| bool success) override { |
| ManagedMemoryPolicy zero_policy( |
| 0, gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING, 0); |
| host_impl->SetMemoryPolicy(zero_policy); |
| } |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit); |
| |
| // Test if the LTH successfully frees resources on the worker context when |
| // hard memory limit is set to zero while using a synchronous compositor (like |
| // Android WebView). |
| class LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimitSynchronous |
| : public LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimit { |
| public: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| LayerTreeHostFreeWorkerContextResourcesTest::InitializeSettings(settings); |
| settings->use_external_begin_frame_source = true; |
| settings->using_synchronous_renderer_compositor = true; |
| } |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostFreeWorkerContextResourcesOnZeroMemoryLimitSynchronous); |
| |
| // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 |
| // draw with frame 0. |
| class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {} |
| |
| void BeginTest() override { |
| PostSetNeedsCommitToMainThread(); |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| num_draws_++; |
| if (!impl->active_tree()->source_frame_number()) |
| EndTest(); |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| num_commits_++; |
| } |
| |
| void AfterTest() override { |
| EXPECT_LE(1, num_commits_); |
| EXPECT_LE(1, num_draws_); |
| } |
| |
| private: |
| int num_commits_; |
| int num_draws_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1); |
| |
| // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that |
| // first committed frame draws should lead to another commit. |
| class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {} |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { ++num_draws_; } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| ++num_commits_; |
| switch (num_commits_) { |
| case 1: |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 2: |
| EndTest(); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| } |
| |
| void AfterTest() override { |
| EXPECT_EQ(2, num_commits_); |
| EXPECT_LE(1, num_draws_); |
| } |
| |
| private: |
| int num_commits_; |
| int num_draws_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); |
| |
| // Verify that we pass property values in PushPropertiesTo. |
| class LayerTreeHostTestPushPropertiesTo : public LayerTreeHostTest { |
| protected: |
| void SetupTree() override { |
| scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| root->CreateRenderSurface(); |
| root->SetBounds(gfx::Size(10, 10)); |
| layer_tree_host()->SetRootLayer(root); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| enum Properties { |
| STARTUP, |
| BOUNDS, |
| HIDE_LAYER_AND_SUBTREE, |
| DRAWS_CONTENT, |
| DONE, |
| }; |
| |
| void BeginTest() override { |
| index_ = STARTUP; |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| VerifyAfterValues(impl->active_tree()->root_layer()); |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| SetBeforeValues(layer_tree_host()->root_layer()); |
| VerifyBeforeValues(layer_tree_host()->root_layer()); |
| |
| ++index_; |
| if (index_ == DONE) { |
| EndTest(); |
| return; |
| } |
| |
| SetAfterValues(layer_tree_host()->root_layer()); |
| } |
| |
| void AfterTest() override {} |
| |
| void VerifyBeforeValues(Layer* layer) { |
| EXPECT_EQ(gfx::Size(10, 10).ToString(), layer->bounds().ToString()); |
| EXPECT_FALSE(layer->hide_layer_and_subtree()); |
| EXPECT_FALSE(layer->DrawsContent()); |
| } |
| |
| void SetBeforeValues(Layer* layer) { |
| layer->SetBounds(gfx::Size(10, 10)); |
| layer->SetHideLayerAndSubtree(false); |
| layer->SetIsDrawable(false); |
| } |
| |
| void VerifyAfterValues(LayerImpl* layer) { |
| switch (static_cast<Properties>(index_)) { |
| case STARTUP: |
| case DONE: |
| break; |
| case BOUNDS: |
| EXPECT_EQ(gfx::Size(20, 20).ToString(), layer->bounds().ToString()); |
| break; |
| case HIDE_LAYER_AND_SUBTREE: |
| EXPECT_TRUE(layer->hide_layer_and_subtree()); |
| break; |
| case DRAWS_CONTENT: |
| EXPECT_TRUE(layer->DrawsContent()); |
| break; |
| } |
| } |
| |
| void SetAfterValues(Layer* layer) { |
| switch (static_cast<Properties>(index_)) { |
| case STARTUP: |
| case DONE: |
| break; |
| case BOUNDS: |
| layer->SetBounds(gfx::Size(20, 20)); |
| break; |
| case HIDE_LAYER_AND_SUBTREE: |
| layer->SetHideLayerAndSubtree(true); |
| break; |
| case DRAWS_CONTENT: |
| layer->SetIsDrawable(true); |
| break; |
| } |
| } |
| |
| int index_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo); |
| |
| // 1 setNeedsRedraw after the first commit has completed should lead to 1 |
| // additional draw. |
| class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {} |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
| if (!num_draws_) { |
| // Redraw again to verify that the second redraw doesn't commit. |
| PostSetNeedsRedrawToMainThread(); |
| } else { |
| EndTest(); |
| } |
| num_draws_++; |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_EQ(0, num_draws_); |
| num_commits_++; |
| } |
| |
| void AfterTest() override { |
| EXPECT_GE(2, num_draws_); |
| EXPECT_EQ(1, num_commits_); |
| } |
| |
| private: |
| int num_commits_; |
| int num_draws_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); |
| |
| // After setNeedsRedrawRect(invalid_rect) the final damage_rect |
| // must contain invalid_rect. |
| class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNeedsRedrawRect() |
| : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {} |
| |
| void BeginTest() override { |
| root_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(bounds_); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| layer_tree_host()->SetViewportSize(bounds_); |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame_data, |
| DrawResult draw_result) override { |
| EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| |
| gfx::RectF root_damage_rect; |
| if (!frame_data->render_passes.empty()) |
| root_damage_rect = frame_data->render_passes.back()->damage_rect; |
| |
| if (!num_draws_) { |
| // If this is the first frame, expect full frame damage. |
| EXPECT_EQ(root_damage_rect, gfx::Rect(bounds_)); |
| } else { |
| // Check that invalid_rect_ is indeed repainted. |
| EXPECT_TRUE(root_damage_rect.Contains(invalid_rect_)); |
| } |
| |
| return draw_result; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| if (!num_draws_) { |
| PostSetNeedsRedrawRectToMainThread(invalid_rect_); |
| } else { |
| EndTest(); |
| } |
| num_draws_++; |
| } |
| |
| void AfterTest() override { EXPECT_EQ(2, num_draws_); } |
| |
| private: |
| int num_draws_; |
| const gfx::Size bounds_; |
| const gfx::Rect invalid_rect_; |
| FakeContentLayerClient client_; |
| scoped_refptr<FakePictureLayer> root_layer_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); |
| |
| // Ensure the texture size of the pending and active trees are identical when a |
| // layer is not in the viewport and a resize happens on the viewport |
| class LayerTreeHostTestGpuRasterDeviceSizeChanged : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestGpuRasterDeviceSizeChanged() |
| : num_draws_(0), bounds_(500, 64), invalid_rect_(10, 10, 20, 20) {} |
| |
| void BeginTest() override { |
| client_.set_fill_with_nonsolid_color(true); |
| root_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer_->SetIsDrawable(true); |
| gfx::Transform transform; |
| // Translate the layer out of the viewport to force it to not update its |
| // tile size via PushProperties. |
| transform.Translate(10000.0, 10000.0); |
| root_layer_->SetTransform(transform); |
| root_layer_->SetBounds(bounds_); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| layer_tree_host()->SetViewportSize(bounds_); |
| |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->gpu_rasterization_enabled = true; |
| settings->gpu_rasterization_forced = true; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| // Perform 2 commits. |
| if (!num_draws_) { |
| PostSetNeedsRedrawRectToMainThread(invalid_rect_); |
| } else { |
| EndTest(); |
| } |
| num_draws_++; |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| if (num_draws_ == 2) { |
| auto pending_tree = host_impl->pending_tree(); |
| auto pending_layer_impl = |
| static_cast<FakePictureLayerImpl*>(pending_tree->root_layer()); |
| EXPECT_NE(pending_layer_impl, nullptr); |
| |
| auto active_tree = host_impl->pending_tree(); |
| auto active_layer_impl = |
| static_cast<FakePictureLayerImpl*>(active_tree->root_layer()); |
| EXPECT_NE(pending_layer_impl, nullptr); |
| |
| auto active_tiling_set = active_layer_impl->picture_layer_tiling_set(); |
| auto active_tiling = active_tiling_set->tiling_at(0); |
| auto pending_tiling_set = pending_layer_impl->picture_layer_tiling_set(); |
| auto pending_tiling = pending_tiling_set->tiling_at(0); |
| EXPECT_EQ( |
| pending_tiling->TilingDataForTesting().max_texture_size().width(), |
| active_tiling->TilingDataForTesting().max_texture_size().width()); |
| } |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| // On the second commit, resize the viewport. |
| if (num_draws_ == 1) { |
| layer_tree_host()->SetViewportSize(gfx::Size(400, 64)); |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| int num_draws_; |
| const gfx::Size bounds_; |
| const gfx::Rect invalid_rect_; |
| FakeContentLayerClient client_; |
| scoped_refptr<FakePictureLayer> root_layer_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterDeviceSizeChanged); |
| |
| class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
| public: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->layer_transforms_should_scale_layer_contents = true; |
| } |
| |
| void SetupTree() override { |
| root_layer_ = Layer::Create(layer_settings()); |
| root_layer_->SetBounds(gfx::Size(10, 20)); |
| root_layer_->CreateRenderSurface(); |
| |
| scaled_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| scaled_layer_->SetBounds(gfx::Size(1, 1)); |
| root_layer_->AddChild(scaled_layer_); |
| |
| layer_tree_host()->SetRootLayer(root_layer_); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| if (host_impl->active_tree()->source_frame_number() == 1) |
| EndTest(); |
| } |
| |
| void DidCommit() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| case 1: |
| // SetBounds grows the layer and exposes new content. |
| scaled_layer_->SetBounds(gfx::Size(4, 4)); |
| break; |
| default: |
| // No extra commits. |
| EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
| } |
| } |
| |
| void AfterTest() override { |
| EXPECT_EQ(gfx::Size(4, 4).ToString(), scaled_layer_->bounds().ToString()); |
| } |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> root_layer_; |
| scoped_refptr<Layer> scaled_layer_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); |
| |
| class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate |
| : public LayerTreeHostTest { |
| public: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->layer_transforms_should_scale_layer_contents = true; |
| } |
| |
| void SetupTree() override { |
| root_layer_ = Layer::Create(layer_settings()); |
| root_layer_->SetBounds(gfx::Size(10, 20)); |
| root_layer_->CreateRenderSurface(); |
| |
| bool paint_scrollbar = true; |
| bool has_thumb = false; |
| scrollbar_ = FakePaintedScrollbarLayer::Create( |
| layer_settings(), paint_scrollbar, has_thumb, root_layer_->id()); |
| scrollbar_->SetPosition(gfx::Point(0, 10)); |
| scrollbar_->SetBounds(gfx::Size(10, 10)); |
| |
| root_layer_->AddChild(scrollbar_); |
| |
| layer_tree_host()->SetRootLayer(root_layer_); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| if (host_impl->active_tree()->source_frame_number() == 1) |
| EndTest(); |
| } |
| |
| void DidCommit() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| case 1: |
| // Changing the device scale factor causes a commit. It also changes |
| // the content bounds of |scrollbar_|, which should not generate |
| // a second commit as a result. |
| layer_tree_host()->SetDeviceScaleFactor(4.f); |
| break; |
| default: |
| // No extra commits. |
| EXPECT_EQ(2, layer_tree_host()->source_frame_number()); |
| break; |
| } |
| } |
| |
| void AfterTest() override { |
| } |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> root_layer_; |
| scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); |
| |
| class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNextCommitForcesRedraw() |
| : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {} |
| |
| void BeginTest() override { |
| root_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(bounds_); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| layer_tree_host()->SetViewportSize(bounds_); |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| if (num_draws_ == 3) |
| host_impl->SetNeedsRedrawRect(invalid_rect_); |
| } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame_data, |
| DrawResult draw_result) override { |
| EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| |
| gfx::RectF root_damage_rect; |
| if (!frame_data->render_passes.empty()) |
| root_damage_rect = frame_data->render_passes.back()->damage_rect; |
| |
| switch (num_draws_) { |
| case 0: |
| EXPECT_EQ(gfx::Rect(bounds_), root_damage_rect); |
| break; |
| case 1: |
| case 2: |
| EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root_damage_rect); |
| break; |
| case 3: |
| EXPECT_EQ(invalid_rect_, root_damage_rect); |
| break; |
| case 4: |
| EXPECT_EQ(gfx::Rect(bounds_), root_damage_rect); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| |
| return draw_result; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| switch (num_draws_) { |
| case 0: |
| case 1: |
| // Cycle through a couple of empty commits to ensure we're observing the |
| // right behavior |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 2: |
| // Should force full frame damage on the next commit |
| PostSetNextCommitForcesRedrawToMainThread(); |
| PostSetNeedsCommitToMainThread(); |
| host_impl->BlockNotifyReadyToActivateForTesting(true); |
| break; |
| case 3: |
| host_impl->BlockNotifyReadyToActivateForTesting(false); |
| break; |
| default: |
| EndTest(); |
| break; |
| } |
| num_draws_++; |
| } |
| |
| void AfterTest() override { EXPECT_EQ(5, num_draws_); } |
| |
| private: |
| int num_draws_; |
| const gfx::Size bounds_; |
| const gfx::Rect invalid_rect_; |
| FakeContentLayerClient client_; |
| scoped_refptr<FakePictureLayer> root_layer_; |
| }; |
| |
| // This test blocks activation which is not supported for single thread mode. |
| MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw); |
| |
| // Tests that if a layer is not drawn because of some reason in the parent then |
| // its damage is preserved until the next time it is drawn. |
| class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { |
| public: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| // If we don't set the minimum contents scale, it's harder to verify whether |
| // the damage we get is correct. For other scale amounts, please see |
| // LayerTreeHostTestDamageWithScale. |
| settings->minimum_contents_scale = 1.f; |
| } |
| |
| void SetupTree() override { |
| root_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(gfx::Size(50, 50)); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| |
| // The initially transparent layer has a larger child layer, which is |
| // not initially drawn because of the this (parent) layer. |
| parent_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| parent_layer_->SetBounds(gfx::Size(15, 15)); |
| parent_layer_->SetOpacity(0.0f); |
| root_layer_->AddChild(parent_layer_); |
| |
| child_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| child_layer_->SetBounds(gfx::Size(25, 25)); |
| parent_layer_->AddChild(child_layer_); |
| |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame_data, |
| DrawResult draw_result) override { |
| EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| |
| gfx::RectF root_damage_rect; |
| if (!frame_data->render_passes.empty()) |
| root_damage_rect = frame_data->render_passes.back()->damage_rect; |
| |
| // The first time, the whole view needs be drawn. |
| // Afterwards, just the opacity of surface_layer1 is changed a few times, |
| // and each damage should be the bounding box of it and its child. If this |
| // was working improperly, the damage might not include its childs bounding |
| // box. |
| switch (host_impl->active_tree()->source_frame_number()) { |
| case 0: |
| EXPECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); |
| break; |
| case 1: |
| case 2: |
| case 3: |
| EXPECT_EQ(gfx::Rect(child_layer_->bounds()), root_damage_rect); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| |
| return draw_result; |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| case 1: |
| // Test not owning the surface. |
| parent_layer_->SetOpacity(1.0f); |
| break; |
| case 2: |
| parent_layer_->SetOpacity(0.0f); |
| break; |
| case 3: |
| // Test owning the surface. |
| parent_layer_->SetOpacity(0.5f); |
| parent_layer_->SetForceRenderSurface(true); |
| break; |
| case 4: |
| EndTest(); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<FakePictureLayer> root_layer_; |
| scoped_refptr<FakePictureLayer> parent_layer_; |
| scoped_refptr<FakePictureLayer> child_layer_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); |
| |
| // Tests that if a layer is not drawn because of some reason in the parent then |
| // its damage is preserved until the next time it is drawn. |
| class LayerTreeHostTestDamageWithScale : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestDamageWithScale() {} |
| |
| void SetupTree() override { |
| client_.set_fill_with_nonsolid_color(true); |
| |
| scoped_ptr<FakePicturePile> pile( |
| new FakePicturePile(LayerTreeSettings().minimum_contents_scale, |
| LayerTreeSettings().default_tile_grid_size)); |
| root_layer_ = FakePictureLayer::CreateWithRecordingSource( |
| layer_settings(), &client_, pile.Pass()); |
| root_layer_->SetBounds(gfx::Size(50, 50)); |
| |
| pile.reset(new FakePicturePile(LayerTreeSettings().minimum_contents_scale, |
| LayerTreeSettings().default_tile_grid_size)); |
| child_layer_ = FakePictureLayer::CreateWithRecordingSource( |
| layer_settings(), &client_, pile.Pass()); |
| child_layer_->SetBounds(gfx::Size(25, 25)); |
| child_layer_->SetIsDrawable(true); |
| child_layer_->SetContentsOpaque(true); |
| root_layer_->AddChild(child_layer_); |
| |
| layer_tree_host()->SetRootLayer(root_layer_); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| // Force the layer to have a tiling at 1.3f scale. Note that if we simply |
| // add tiling, it will be gone by the time we draw because of aggressive |
| // cleanup. AddTilingUntilNextDraw ensures that it remains there during |
| // damage calculation. |
| FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>( |
| host_impl->active_tree()->LayerById(child_layer_->id())); |
| child_layer_impl->AddTilingUntilNextDraw(1.3f); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame_data, |
| DrawResult draw_result) override { |
| EXPECT_EQ(DRAW_SUCCESS, draw_result); |
| |
| gfx::RectF root_damage_rect; |
| if (!frame_data->render_passes.empty()) |
| root_damage_rect = frame_data->render_passes.back()->damage_rect; |
| |
| // The first time, the whole view needs be drawn. |
| // Afterwards, just the opacity of surface_layer1 is changed a few times, |
| // and each damage should be the bounding box of it and its child. If this |
| // was working improperly, the damage might not include its childs bounding |
| // box. |
| switch (host_impl->active_tree()->source_frame_number()) { |
| case 0: |
| EXPECT_EQ(gfx::Rect(root_layer_->bounds()), root_damage_rect); |
| break; |
| case 1: { |
| FakePictureLayerImpl* child_layer_impl = |
| static_cast<FakePictureLayerImpl*>( |
| host_impl->active_tree()->LayerById(child_layer_->id())); |
| // We remove tilings pretty aggressively if they are not ideal. Add this |
| // back in so that we can compare |
| // child_layer_impl->GetEnclosingRectInTargetSpace to the damage. |
| child_layer_impl->AddTilingUntilNextDraw(1.3f); |
| |
| EXPECT_EQ(gfx::Rect(26, 26), root_damage_rect); |
| EXPECT_EQ(child_layer_impl->GetEnclosingRectInTargetSpace(), |
| root_damage_rect); |
| EXPECT_TRUE(child_layer_impl->GetEnclosingRectInTargetSpace().Contains( |
| gfx::Rect(child_layer_->bounds()))); |
| break; |
| } |
| default: |
| NOTREACHED(); |
| } |
| |
| return draw_result; |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| case 1: { |
| // Test not owning the surface. |
| child_layer_->SetOpacity(0.5f); |
| break; |
| } |
| case 2: |
| EndTest(); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> root_layer_; |
| scoped_refptr<Layer> child_layer_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDamageWithScale); |
| |
| // This test verifies that properties on the layer tree host are commited |
| // to the impl side. |
| class LayerTreeHostTestCommit : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestCommit() {} |
| |
| void BeginTest() override { |
| layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
| layer_tree_host()->set_background_color(SK_ColorGRAY); |
| |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_EQ(gfx::Size(20, 20), impl->DrawViewportSize()); |
| EXPECT_EQ(SK_ColorGRAY, impl->active_tree()->background_color()); |
| |
| EndTest(); |
| } |
| |
| void AfterTest() override {} |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); |
| |
| // This test verifies that LayerTreeHostImpl's current frame time gets |
| // updated in consecutive frames when it doesn't draw due to tree |
| // activation failure. |
| class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails |
| : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestFrameTimeUpdatesAfterActivationFails() |
| : frame_count_with_pending_tree_(0) {} |
| |
| void BeginTest() override { |
| layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
| layer_tree_host()->set_background_color(SK_ColorGRAY); |
| |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void BeginCommitOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_EQ(frame_count_with_pending_tree_, 0); |
| impl->BlockNotifyReadyToActivateForTesting(true); |
| } |
| |
| void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl, |
| const BeginFrameArgs& args) override { |
| if (impl->pending_tree()) |
| frame_count_with_pending_tree_++; |
| |
| if (frame_count_with_pending_tree_ == 1) { |
| EXPECT_EQ(first_frame_time_.ToInternalValue(), 0); |
| first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time; |
| } else if (frame_count_with_pending_tree_ == 2) { |
| impl->BlockNotifyReadyToActivateForTesting(false); |
| } |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_GT(frame_count_with_pending_tree_, 1); |
| EXPECT_NE(first_frame_time_.ToInternalValue(), 0); |
| EXPECT_NE(first_frame_time_.ToInternalValue(), |
| impl->CurrentBeginFrameArgs().frame_time.ToInternalValue()); |
| EndTest(); |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_GT(frame_count_with_pending_tree_, 1); |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| int frame_count_with_pending_tree_; |
| base::TimeTicks first_frame_time_; |
| }; |
| |
| // This test blocks activation which is not supported for single thread mode. |
| MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
| LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); |
| |
| // This test verifies that LayerTreeHostImpl's current frame time gets |
| // updated in consecutive frames when it draws in each frame. |
| class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {} |
| |
| void BeginTest() override { |
| layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
| layer_tree_host()->set_background_color(SK_ColorGRAY); |
| |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| frame_++; |
| if (frame_ == 1) { |
| first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time; |
| impl->SetNeedsRedraw(); |
| |
| // Since we might use a low-resolution clock on Windows, we need to |
| // make sure that the clock has incremented past first_frame_time_. |
| while (first_frame_time_ == base::TimeTicks::Now()) { |
| } |
| |
| return; |
| } |
| |
| EXPECT_NE(first_frame_time_, impl->CurrentBeginFrameArgs().frame_time); |
| EndTest(); |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| // Ensure there isn't a commit between the two draws, to ensure that a |
| // commit isn't required for updating the current frame time. We can |
| // only check for this in the multi-threaded case, since in the single- |
| // threaded case there will always be a commit between consecutive draws. |
| if (HasImplThread()) |
| EXPECT_EQ(0, frame_); |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| int frame_; |
| base::TimeTicks first_frame_time_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw); |
| |
| // Verifies that StartPageScaleAnimation events propagate correctly |
| // from LayerTreeHost to LayerTreeHostImpl in the MT compositor. |
| class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestStartPageScaleAnimation() {} |
| |
| void SetupTree() override { |
| LayerTreeHostTest::SetupTree(); |
| |
| Layer* root_layer = layer_tree_host()->root_layer(); |
| |
| scoped_refptr<FakePictureLayer> layer = |
| FakePictureLayer::Create(layer_settings(), &client_); |
| layer->set_always_update_resources(true); |
| scroll_layer_ = layer; |
| |
| scroll_layer_->SetBounds(gfx::Size(2 * root_layer->bounds().width(), |
| 2 * root_layer->bounds().height())); |
| scroll_layer_->SetScrollOffset(gfx::ScrollOffset()); |
| |
| CreateVirtualViewportLayers(root_layer, |
| scroll_layer_, |
| root_layer->bounds(), |
| root_layer->bounds(), |
| layer_tree_host(), |
| layer_settings()); |
| |
| layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 2.f); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void ApplyViewportDeltas(const gfx::Vector2dF& scroll_delta, |
| const gfx::Vector2dF&, |
| const gfx::Vector2dF& elastic_overscroll_delta, |
| float scale, |
| float) override { |
| gfx::ScrollOffset offset = scroll_layer_->scroll_offset(); |
| scroll_layer_->SetScrollOffset(ScrollOffsetWithDelta(offset, |
| scroll_delta)); |
| layer_tree_host()->SetPageScaleFactorAndLimits(scale, 0.5f, 2.f); |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| // We get one commit before the first draw, and the animation doesn't happen |
| // until the second draw. |
| switch (impl->active_tree()->source_frame_number()) { |
| case 0: |
| EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor()); |
| // We'll start an animation when we get back to the main thread. |
| break; |
| case 1: |
| EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor()); |
| break; |
| case 2: |
| EXPECT_EQ(1.25f, impl->active_tree()->current_page_scale_factor()); |
| EndTest(); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| case 1: |
| layer_tree_host()->StartPageScaleAnimation( |
| gfx::Vector2d(), false, 1.25f, base::TimeDelta()); |
| break; |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> scroll_layer_; |
| }; |
| |
| // Single thread proxy does not support impl-side page scale changes. |
| MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation); |
| |
| class LayerTreeHostTestSetVisible : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetVisible() : num_draws_(0) {} |
| |
| void BeginTest() override { |
| PostSetNeedsCommitToMainThread(); |
| PostSetVisibleToMainThread(false); |
| // This is suppressed while we're invisible. |
| PostSetNeedsRedrawToMainThread(); |
| // Triggers the redraw. |
| PostSetVisibleToMainThread(true); |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| EXPECT_TRUE(impl->visible()); |
| ++num_draws_; |
| EndTest(); |
| } |
| |
| void AfterTest() override { EXPECT_EQ(1, num_draws_); } |
| |
| private: |
| int num_draws_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible); |
| |
| class TestOpacityChangeLayerDelegate : public ContentLayerClient { |
| public: |
| TestOpacityChangeLayerDelegate() : test_layer_(0) {} |
| |
| void SetTestLayer(Layer* test_layer) { test_layer_ = test_layer; } |
| |
| void PaintContents(SkCanvas* canvas, |
| const gfx::Rect& clip, |
| PaintingControlSetting picture_control) override { |
| // Set layer opacity to 0. |
| if (test_layer_) |
| test_layer_->SetOpacity(0.f); |
| } |
| scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| const gfx::Rect& clip, |
| PaintingControlSetting picture_control) override { |
| NOTIMPLEMENTED(); |
| return nullptr; |
| } |
| bool FillsBoundsCompletely() const override { return false; } |
| size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
| |
| private: |
| Layer* test_layer_; |
| }; |
| |
| // Layer opacity change during paint should not prevent compositor resources |
| // from being updated during commit. |
| class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestOpacityChange() : test_opacity_change_delegate_() {} |
| |
| void SetupTree() override { |
| LayerTreeHostTest::SetupTree(); |
| |
| update_check_picture_layer_ = FakePictureLayer::Create( |
| layer_settings(), &test_opacity_change_delegate_); |
| test_opacity_change_delegate_.SetTestLayer( |
| update_check_picture_layer_.get()); |
| layer_tree_host()->root_layer()->AddChild(update_check_picture_layer_); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { EndTest(); } |
| |
| void AfterTest() override { |
| // Update() should have been called once. |
| EXPECT_EQ(1, update_check_picture_layer_->update_count()); |
| } |
| |
| private: |
| TestOpacityChangeLayerDelegate test_opacity_change_delegate_; |
| scoped_refptr<FakePictureLayer> update_check_picture_layer_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange); |
| |
| class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() {} |
| |
| void BeginTest() override { |
| client_.set_fill_with_nonsolid_color(true); |
| root_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| child_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| |
| layer_tree_host()->SetViewportSize(gfx::Size(60, 60)); |
| layer_tree_host()->SetDeviceScaleFactor(1.5); |
| EXPECT_EQ(gfx::Size(60, 60), layer_tree_host()->device_viewport_size()); |
| |
| root_layer_->AddChild(child_layer_); |
| |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(gfx::Size(30, 30)); |
| |
| child_layer_->SetIsDrawable(true); |
| child_layer_->SetPosition(gfx::Point(2, 2)); |
| child_layer_->SetBounds(gfx::Size(10, 10)); |
| |
| layer_tree_host()->SetRootLayer(root_layer_); |
| |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| // Should only do one commit. |
| EXPECT_EQ(0, impl->active_tree()->source_frame_number()); |
| // Device scale factor should come over to impl. |
| EXPECT_NEAR(impl->device_scale_factor(), 1.5f, 0.00001f); |
| |
| // Both layers are on impl. |
| ASSERT_EQ(1u, impl->active_tree()->root_layer()->children().size()); |
| |
| // Device viewport is scaled. |
| EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); |
| |
| FakePictureLayerImpl* root = |
| static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer()); |
| FakePictureLayerImpl* child = static_cast<FakePictureLayerImpl*>( |
| impl->active_tree()->root_layer()->children()[0]); |
| |
| // Positions remain in layout pixels. |
| EXPECT_EQ(gfx::Point(0, 0), root->position()); |
| EXPECT_EQ(gfx::Point(2, 2), child->position()); |
| |
| // Compute all the layer transforms for the frame. |
| LayerTreeHostImpl::FrameData frame_data; |
| impl->PrepareToDraw(&frame_data); |
| impl->DidDrawAllLayers(frame_data); |
| |
| const LayerImplList& render_surface_layer_list = |
| *frame_data.render_surface_layer_list; |
| |
| // Both layers should be drawing into the root render surface. |
| ASSERT_EQ(1u, render_surface_layer_list.size()); |
| ASSERT_EQ(root->render_surface(), |
| render_surface_layer_list[0]->render_surface()); |
| ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| |
| // The root render surface is the size of the viewport. |
| EXPECT_EQ(gfx::Rect(0, 0, 60, 60), root->render_surface()->content_rect()); |
| |
| // The max tiling scale of the child should be scaled. |
| EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale()); |
| |
| gfx::Transform scale_transform; |
| scale_transform.Scale(impl->device_scale_factor(), |
| impl->device_scale_factor()); |
| |
| // The root layer is scaled by 2x. |
| gfx::Transform root_screen_space_transform = scale_transform; |
| gfx::Transform root_draw_transform = scale_transform; |
| |
| EXPECT_EQ(root_draw_transform, root->draw_transform()); |
| EXPECT_EQ(root_screen_space_transform, root->screen_space_transform()); |
| |
| // The child is at position 2,2, which is transformed to 3,3 after the scale |
| gfx::Transform child_transform; |
| child_transform.Translate(3.f, 3.f); |
| child_transform.Scale(child->MaximumTilingContentsScale(), |
| child->MaximumTilingContentsScale()); |
| |
| EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform, child->draw_transform()); |
| EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform, |
| child->screen_space_transform()); |
| |
| EndTest(); |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<FakePictureLayer> root_layer_; |
| scoped_refptr<FakePictureLayer> child_layer_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); |
| |
| class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestContinuousInvalidate() |
| : num_commit_complete_(0), num_draw_layers_(0) {} |
| |
| void BeginTest() override { |
| layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
| layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| |
| layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| layer_->SetBounds(gfx::Size(10, 10)); |
| layer_->SetPosition(gfx::PointF(0.f, 0.f)); |
| layer_->SetIsDrawable(true); |
| layer_tree_host()->root_layer()->AddChild(layer_); |
| |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| if (num_draw_layers_ == 2) |
| return; |
| layer_->SetNeedsDisplay(); |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| if (num_draw_layers_ == 1) |
| num_commit_complete_++; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| num_draw_layers_++; |
| if (num_draw_layers_ == 2) |
| EndTest(); |
| } |
| |
| void AfterTest() override { |
| // Check that we didn't commit twice between first and second draw. |
| EXPECT_EQ(1, num_commit_complete_); |
| } |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> layer_; |
| int num_commit_complete_; |
| int num_draw_layers_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); |
| |
| class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestDeferCommits() |
| : num_will_begin_impl_frame_(0), |
| num_send_begin_main_frame_(0) {} |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
| const BeginFrameArgs& args) override { |
| num_will_begin_impl_frame_++; |
| switch (num_will_begin_impl_frame_) { |
| case 1: |
| break; |
| case 2: |
| case 3: |
| case 4: |
| // Post a number of frames to increase the chance that, if there exist |
| // bugs, an unexpected BeginMainFrame will be issued. |
| PostSetNeedsCommitToMainThread(); |
| PostSetNeedsRedrawToMainThread(); |
| break; |
| case 5: |
| PostSetDeferCommitsToMainThread(false); |
| break; |
| default: |
| // Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the |
| // main thread is slow to respond. |
| break; |
| } |
| } |
| |
| void ScheduledActionSendBeginMainFrame() override { |
| num_send_begin_main_frame_++; |
| switch (num_send_begin_main_frame_) { |
| case 1: |
| PostSetDeferCommitsToMainThread(true); |
| break; |
| case 2: |
| EndTest(); |
| break; |
| default: |
| NOTREACHED(); |
| break; |
| } |
| } |
| |
| void AfterTest() override { |
| EXPECT_GE(num_will_begin_impl_frame_, 5); |
| EXPECT_EQ(2, num_send_begin_main_frame_); |
| } |
| |
| private: |
| int num_will_begin_impl_frame_; |
| int num_send_begin_main_frame_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); |
| |
| class LayerTreeHostTestCompositeImmediatelyStateTransitions |
| : public LayerTreeHostTest { |
| public: |
| enum { |
| kInvalid, |
| kStartedTest, |
| kStartedImplFrame, |
| kStartedMainFrame, |
| kStartedCommit, |
| kCompletedCommit, |
| kCompletedMainFrame, |
| kCompletedImplFrame, |
| }; |
| |
| LayerTreeHostTestCompositeImmediatelyStateTransitions() |
| : current_state_(kInvalid), current_begin_frame_args_() {} |
| |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->single_thread_proxy_scheduler = false; |
| settings->use_zero_copy = true; |
| settings->use_one_copy = false; |
| } |
| |
| void BeginTest() override { |
| current_state_ = kStartedTest; |
| PostCompositeImmediatelyToMainThread(); |
| } |
| |
| void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
| const BeginFrameArgs& args) override { |
| EXPECT_EQ(current_state_, kStartedTest); |
| current_state_ = kStartedImplFrame; |
| |
| EXPECT_FALSE(current_begin_frame_args_.IsValid()); |
| EXPECT_TRUE(args.IsValid()); |
| current_begin_frame_args_ = args; |
| } |
| void WillBeginMainFrame() override { |
| EXPECT_EQ(current_state_, kStartedImplFrame); |
| current_state_ = kStartedMainFrame; |
| } |
| void BeginMainFrame(const BeginFrameArgs& args) override { |
| EXPECT_EQ(current_state_, kStartedMainFrame); |
| EXPECT_EQ(args.frame_time, current_begin_frame_args_.frame_time); |
| } |
| void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| EXPECT_EQ(current_state_, kStartedMainFrame); |
| current_state_ = kStartedCommit; |
| } |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| EXPECT_EQ(current_state_, kStartedCommit); |
| current_state_ = kCompletedCommit; |
| } |
| void DidBeginMainFrame() override { |
| EXPECT_EQ(current_state_, kCompletedCommit); |
| current_state_ = kCompletedMainFrame; |
| } |
| void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override { |
| EXPECT_EQ(current_state_, kCompletedMainFrame); |
| current_state_ = kCompletedImplFrame; |
| EndTest(); |
| } |
| void AfterTest() override { EXPECT_EQ(current_state_, kCompletedImplFrame); } |
| |
| private: |
| int current_state_; |
| BeginFrameArgs current_begin_frame_args_; |
| }; |
| |
| SINGLE_THREAD_TEST_F(LayerTreeHostTestCompositeImmediatelyStateTransitions); |
| |
| class LayerTreeHostTestLCDChange : public LayerTreeHostTest { |
| public: |
| void SetupTree() override { |
| num_tiles_rastered_ = 0; |
| |
| scoped_refptr<Layer> root_layer = |
| PictureLayer::Create(layer_settings(), &client_); |
| client_.set_fill_with_nonsolid_color(true); |
| root_layer->SetIsDrawable(true); |
| root_layer->SetBounds(gfx::Size(10, 10)); |
| root_layer->SetContentsOpaque(true); |
| |
| layer_tree_host()->SetRootLayer(root_layer); |
| |
| // The expectations are based on the assumption that the default |
| // LCD settings are: |
| EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |
| |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DidCommitAndDrawFrame() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| case 1: |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 2: |
| // Change layer opacity that should trigger lcd change. |
| layer_tree_host()->root_layer()->SetOpacity(.5f); |
| break; |
| case 3: |
| // Change layer opacity that should not trigger lcd change. |
| layer_tree_host()->root_layer()->SetOpacity(1.f); |
| break; |
| case 4: |
| EndTest(); |
| break; |
| } |
| } |
| |
| void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, |
| const Tile* tile) override { |
| ++num_tiles_rastered_; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| PictureLayerImpl* root_layer = |
| static_cast<PictureLayerImpl*>(host_impl->active_tree()->root_layer()); |
| bool can_use_lcd_text = |
| host_impl->active_tree()->root_layer()->can_use_lcd_text(); |
| switch (host_impl->active_tree()->source_frame_number()) { |
| case 0: |
| // The first draw. |
| EXPECT_EQ(1, num_tiles_rastered_); |
| EXPECT_TRUE(can_use_lcd_text); |
| EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); |
| break; |
| case 1: |
| // Nothing changed on the layer. |
| EXPECT_EQ(1, num_tiles_rastered_); |
| EXPECT_TRUE(can_use_lcd_text); |
| EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); |
| break; |
| case 2: |
| // LCD text was disabled; it should be re-rastered with LCD text off. |
| EXPECT_EQ(2, num_tiles_rastered_); |
| EXPECT_FALSE(can_use_lcd_text); |
| EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); |
| break; |
| case 3: |
| // LCD text was enabled, but it's sticky and stays off. |
| EXPECT_EQ(2, num_tiles_rastered_); |
| EXPECT_TRUE(can_use_lcd_text); |
| EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); |
| break; |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| FakeContentLayerClient client_; |
| int num_tiles_rastered_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDChange); |
| |
| // Verify that the BeginFrame notification is used to initiate rendering. |
| class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |
| public: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->use_external_begin_frame_source = true; |
| } |
| |
| void BeginTest() override { |
| // This will trigger a SetNeedsBeginFrame which will trigger a |
| // BeginFrame. |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame, |
| DrawResult draw_result) override { |
| EndTest(); |
| return DRAW_SUCCESS; |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| base::TimeTicks frame_time_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFrameNotification); |
| |
| class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled |
| : public LayerTreeHostTest { |
| public: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->use_external_begin_frame_source = true; |
| settings->using_synchronous_renderer_compositor = true; |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| // The BeginFrame notification is turned off now but will get enabled |
| // once we return. End test while it's enabled. |
| ImplThreadTaskRunner()->PostTask( |
| FROM_HERE, |
| base::Bind(&LayerTreeHostTestBeginFrameNotification::EndTest, |
| base::Unretained(this))); |
| } |
| |
| void AfterTest() override {} |
| }; |
| |
| MULTI_THREAD_TEST_F( |
| LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); |
| |
| class LayerTreeHostTestAbortedCommitDoesntStall : public LayerTreeHostTest { |
| protected: |
| LayerTreeHostTestAbortedCommitDoesntStall() |
| : commit_count_(0), commit_abort_count_(0), commit_complete_count_(0) {} |
| |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->use_external_begin_frame_source = true; |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DidCommit() override { |
| commit_count_++; |
| if (commit_count_ == 4) { |
| // After two aborted commits, request a real commit now to make sure a |
| // real commit following an aborted commit will still complete and |
| // end the test even when the Impl thread is idle. |
| layer_tree_host()->SetNeedsCommit(); |
| } |
| } |
| |
| void BeginMainFrameAbortedOnThread(LayerTreeHostImpl* host_impl, |
| CommitEarlyOutReason reason) override { |
| commit_abort_count_++; |
| // Initiate another abortable commit. |
| host_impl->SetNeedsCommit(); |
| } |
| |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| commit_complete_count_++; |
| if (commit_complete_count_ == 1) { |
| // Initiate an abortable commit after the first commit. |
| host_impl->SetNeedsCommit(); |
| } else { |
| EndTest(); |
| } |
| } |
| |
| void AfterTest() override { |
| EXPECT_EQ(commit_count_, 5); |
| EXPECT_EQ(commit_abort_count_, 3); |
| EXPECT_EQ(commit_complete_count_, 2); |
| } |
| |
| int commit_count_; |
| int commit_abort_count_; |
| int commit_complete_count_; |
| }; |
| |
| class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor |
| : public LayerTreeHostTestAbortedCommitDoesntStall { |
| protected: |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings); |
| settings->using_synchronous_renderer_compositor = true; |
| } |
| |
| void ScheduledActionInvalidateOutputSurface() override { |
| ImplThreadTaskRunner()->PostTask( |
| FROM_HERE, |
| base::Bind( |
| &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor:: |
| CallOnDraw, |
| base::Unretained(this))); |
| } |
| |
| void CallOnDraw() { |
| // Synchronous compositor does not draw unless told to do so by the output |
| // surface. |
| output_surface()->client()->OnDraw(); |
| } |
| }; |
| |
| MULTI_THREAD_TEST_F( |
| LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor); |
| |
| class LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync |
| : public LayerTreeHostTestAbortedCommitDoesntStall { |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings); |
| settings->wait_for_beginframe_interval = false; |
| settings->renderer_settings.disable_display_vsync = true; |
| } |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestAbortedCommitDoesntStallDisabledVsync); |
| |
| class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation |
| : public LayerTreeHostTest { |
| protected: |
| void SetupTree() override { |
| LayerTreeHostTest::SetupTree(); |
| |
| scoped_refptr<Layer> layer = |
| PictureLayer::Create(layer_settings(), &client_); |
| layer->SetTransform(gfx::Transform(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); |
| layer->SetBounds(gfx::Size(10, 10)); |
| layer_tree_host()->root_layer()->AddChild(layer); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| EndTest(); |
| } |
| |
| void AfterTest() override {} |
| |
| FakeContentLayerClient client_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); |
| |
| class LayerTreeHostTestChangeLayerPropertiesInPaintContents |
| : public LayerTreeHostTest { |
| public: |
| class SetBoundsClient : public ContentLayerClient { |
| public: |
| SetBoundsClient() : layer_(0) {} |
| |
| void set_layer(Layer* layer) { layer_ = layer; } |
| |
| void PaintContents(SkCanvas* canvas, |
| const gfx::Rect& clip, |
| PaintingControlSetting picture_control) override { |
| layer_->SetBounds(gfx::Size(2, 2)); |
| } |
| |
| scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| const gfx::Rect& clip, |
| PaintingControlSetting picture_control) override { |
| NOTIMPLEMENTED(); |
| return nullptr; |
| } |
| |
| bool FillsBoundsCompletely() const override { return false; } |
| size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
| |
| private: |
| Layer* layer_; |
| }; |
| |
| LayerTreeHostTestChangeLayerPropertiesInPaintContents() : num_commits_(0) {} |
| |
| void SetupTree() override { |
| scoped_refptr<PictureLayer> root_layer = |
| PictureLayer::Create(layer_settings(), &client_); |
| root_layer->SetIsDrawable(true); |
| root_layer->SetBounds(gfx::Size(1, 1)); |
| client_.set_layer(root_layer.get()); |
| |
| layer_tree_host()->SetRootLayer(root_layer); |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| void AfterTest() override {} |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| num_commits_++; |
| if (num_commits_ == 1) { |
| LayerImpl* root_layer = host_impl->active_tree()->root_layer(); |
| EXPECT_EQ(gfx::Size(1, 1), root_layer->bounds()); |
| } else { |
| LayerImpl* root_layer = host_impl->active_tree()->root_layer(); |
| EXPECT_EQ(gfx::Size(2, 2), root_layer->bounds()); |
| EndTest(); |
| } |
| } |
| |
| private: |
| SetBoundsClient client_; |
| int num_commits_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostTestChangeLayerPropertiesInPaintContents); |
| |
| class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { |
| public: |
| MockIOSurfaceWebGraphicsContext3D() { |
| test_capabilities_.gpu.iosurface = true; |
| test_capabilities_.gpu.texture_rectangle = true; |
| } |
| |
| GLuint createTexture() override { return 1; } |
| MOCK_METHOD1(activeTexture, void(GLenum texture)); |
| MOCK_METHOD2(bindTexture, void(GLenum target, |
| GLuint texture_id)); |
| MOCK_METHOD3(texParameteri, void(GLenum target, |
| GLenum pname, |
| GLint param)); |
| MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(GLenum target, |
| GLint width, |
| GLint height, |
| GLuint ioSurfaceId, |
| GLuint plane)); |
| MOCK_METHOD4(drawElements, void(GLenum mode, |
| GLsizei count, |
| GLenum type, |
| GLintptr offset)); |
| MOCK_METHOD1(deleteTexture, void(GLenum texture)); |
| MOCK_METHOD3(produceTextureDirectCHROMIUM, |
| void(GLuint texture, GLenum target, const GLbyte* mailbox)); |
| }; |
| |
| class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { |
| protected: |
| scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
| scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned( |
| new MockIOSurfaceWebGraphicsContext3D); |
| mock_context_ = mock_context_owned.get(); |
| |
| if (delegating_renderer()) |
| return FakeOutputSurface::CreateDelegating3d(mock_context_owned.Pass()); |
| else |
| return FakeOutputSurface::Create3d(mock_context_owned.Pass()); |
| } |
| |
| void SetupTree() override { |
| LayerTreeHostTest::SetupTree(); |
| |
| layer_tree_host()->root_layer()->SetIsDrawable(false); |
| |
| io_surface_id_ = 9; |
| io_surface_size_ = gfx::Size(6, 7); |
| |
| scoped_refptr<IOSurfaceLayer> io_surface_layer = |
| IOSurfaceLayer::Create(layer_settings()); |
| io_surface_layer->SetBounds(gfx::Size(10, 10)); |
| io_surface_layer->SetIsDrawable(true); |
| io_surface_layer->SetContentsOpaque(true); |
| io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); |
| layer_tree_host()->root_layer()->AddChild(io_surface_layer); |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| EXPECT_EQ(0u, host_impl->resource_provider()->num_resources()); |
| // In WillDraw, the IOSurfaceLayer sets up the io surface texture. |
| |
| EXPECT_CALL(*mock_context_, activeTexture(_)).Times(0); |
| EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) |
| .Times(AtLeast(1)); |
| EXPECT_CALL(*mock_context_, |
| texParameteri( |
| GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR)) |
| .Times(1); |
| EXPECT_CALL(*mock_context_, |
| texParameteri( |
| GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR)) |
| .Times(1); |
| EXPECT_CALL(*mock_context_, |
| texParameteri(GL_TEXTURE_RECTANGLE_ARB, |
| GL_TEXTURE_POOL_CHROMIUM, |
| GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)).Times(1); |
| EXPECT_CALL(*mock_context_, |
| texParameteri(GL_TEXTURE_RECTANGLE_ARB, |
| GL_TEXTURE_WRAP_S, |
| GL_CLAMP_TO_EDGE)).Times(1); |
| EXPECT_CALL(*mock_context_, |
| texParameteri(GL_TEXTURE_RECTANGLE_ARB, |
| GL_TEXTURE_WRAP_T, |
| GL_CLAMP_TO_EDGE)).Times(1); |
| |
| EXPECT_CALL(*mock_context_, |
| texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, |
| io_surface_size_.width(), |
| io_surface_size_.height(), |
| io_surface_id_, |
| 0)).Times(1); |
| |
| EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); |
| } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame, |
| DrawResult draw_result) override { |
| Mock::VerifyAndClearExpectations(&mock_context_); |
| ResourceProvider* resource_provider = host_impl->resource_provider(); |
| EXPECT_EQ(1u, resource_provider->num_resources()); |
| CHECK_EQ(1u, frame->render_passes.size()); |
| CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); |
| const DrawQuad* quad = frame->render_passes[0]->quad_list.front(); |
| CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); |
| const IOSurfaceDrawQuad* io_surface_draw_quad = |
| IOSurfaceDrawQuad::MaterialCast(quad); |
| EXPECT_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); |
| EXPECT_NE(0u, io_surface_draw_quad->io_surface_resource_id()); |
| EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB), |
| resource_provider->TargetForTesting( |
| io_surface_draw_quad->io_surface_resource_id())); |
| |
| if (delegating_renderer()) { |
| // The io surface layer's resource should be sent to the parent. |
| EXPECT_CALL(*mock_context_, produceTextureDirectCHROMIUM( |
| _, GL_TEXTURE_RECTANGLE_ARB, _)).Times(1); |
| } else { |
| // The io surface layer's texture is drawn. |
| EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1)); |
| EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) |
| .Times(AtLeast(1)); |
| } |
| |
| return draw_result; |
| } |
| |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| Mock::VerifyAndClearExpectations(&mock_context_); |
| |
| EXPECT_CALL(*mock_context_, deleteTexture(1)).Times(AtLeast(1)); |
| EndTest(); |
| } |
| |
| void AfterTest() override {} |
| |
| int io_surface_id_; |
| MockIOSurfaceWebGraphicsContext3D* mock_context_; |
| gfx::Size io_surface_size_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing); |
| |
| class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { |
| public: |
| void BeginTest() override { |
| frame_ = 0; |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| // Round 1: commit + draw |
| // Round 2: commit only (no draw/swap) |
| // Round 3: draw only (no commit) |
| |
| void DidCommit() override { |
| int commit = layer_tree_host()->source_frame_number(); |
| switch (commit) { |
| case 2: |
| // Round 2 done. |
| EXPECT_EQ(1, frame_); |
| layer_tree_host()->SetNeedsRedraw(); |
| break; |
| } |
| } |
| |
| void DidCompleteSwapBuffers() override { |
| int commit = layer_tree_host()->source_frame_number(); |
| ++frame_; |
| switch (frame_) { |
| case 1: |
| // Round 1 done. |
| EXPECT_EQ(1, commit); |
| layer_tree_host()->SetNeedsCommit(); |
| break; |
| case 2: |
| // Round 3 done. |
| EXPECT_EQ(2, commit); |
| EndTest(); |
| break; |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| protected: |
| int frame_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending); |
| |
| class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { |
| public: |
| void SetupTree() override { |
| root_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(gfx::Size(50, 50)); |
| |
| parent_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| parent_layer_->SetIsDrawable(true); |
| parent_layer_->SetBounds(gfx::Size(50, 50)); |
| parent_layer_->SetForceRenderSurface(true); |
| |
| child_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| child_layer_->SetIsDrawable(true); |
| child_layer_->SetBounds(gfx::Size(50, 50)); |
| |
| root_layer_->AddChild(parent_layer_); |
| parent_layer_->AddChild(child_layer_); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
| if (delegating_renderer()) { |
| return FakeOutputSurface::CreateDelegatingSoftware( |
| make_scoped_ptr(new SoftwareOutputDevice)); |
| } else { |
| return FakeOutputSurface::CreateSoftware( |
| make_scoped_ptr(new SoftwareOutputDevice)); |
| } |
| } |
| |
| void BeginTest() override { |
| PostSetNeedsCommitToMainThread(); |
| swap_count_ = 0; |
| } |
| |
| DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| LayerTreeHostImpl::FrameData* frame_data, |
| DrawResult draw_result) override { |
| if (host_impl->GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
| EXPECT_EQ(1u, frame_data->render_passes.size()); |
| // Has at least 3 quads for each layer. |
| RenderPass* render_pass = frame_data->render_passes[0]; |
| EXPECT_GE(render_pass->quad_list.size(), 3u); |
| } else { |
| EXPECT_EQ(2u, frame_data->render_passes.size()); |
| |
| // At least root layer quad in root render pass. |
| EXPECT_GE(frame_data->render_passes[0]->quad_list.size(), 1u); |
| // At least parent and child layer quads in parent render pass. |
| EXPECT_GE(frame_data->render_passes[1]->quad_list.size(), 2u); |
| } |
| return draw_result; |
| } |
| |
| void SwapBuffersCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| swap_count_++; |
| switch (swap_count_) { |
| case 1: { |
| gfx::Transform identity; |
| gfx::Rect empty_rect; |
| bool resourceless_software_draw = true; |
| host_impl->SetExternalDrawConstraints(identity, empty_rect, empty_rect, |
| empty_rect, identity, |
| resourceless_software_draw); |
| host_impl->SetFullRootLayerDamage(); |
| host_impl->SetNeedsRedraw(); |
| break; |
| } |
| case 2: |
| EndTest(); |
| break; |
| default: |
| NOTREACHED(); |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> root_layer_; |
| scoped_refptr<Layer> parent_layer_; |
| scoped_refptr<Layer> child_layer_; |
| int swap_count_; |
| }; |
| |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw); |
| |
| // Test for UI Resource management. |
| class LayerTreeHostTestUIResource : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestUIResource() : num_ui_resources_(0) {} |
| |
| void InitializeSettings(LayerTreeSettings* settings) override { |
| settings->renderer_settings.texture_id_allocation_chunk_size = 1; |
| } |
| |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| |
| void DidCommit() override { |
| int frame = layer_tree_host()->source_frame_number(); |
| switch (frame) { |
| case 1: |
| CreateResource(); |
| CreateResource(); |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 2: |
| // Usually ScopedUIResource are deleted from the manager in their |
| // destructor. Here we just want to test that a direct call to |
| // DeleteUIResource works. |
| layer_tree_host()->DeleteUIResource(ui_resources_[0]->id()); |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 3: |
| // DeleteUIResource can be called with an invalid id. |
| layer_tree_host()->DeleteUIResource(ui_resources_[0]->id()); |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 4: |
| CreateResource(); |
| CreateResource(); |
| PostSetNeedsCommitToMainThread(); |
| break; |
| case 5: |
| ClearResources(); |
| EndTest(); |
| break; |
| } |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| TestWebGraphicsContext3D* context = TestContext(); |
| |
| int frame = impl->active_tree()->source_frame_number(); |
| switch (frame) { |
| case 0: |
| ASSERT_EQ(0u, context->NumTextures()); |
| break; |
| case 1: |
| // Created two textures. |
| ASSERT_EQ(2u, context->NumTextures()); |
| break; |
| case 2: |
| // One texture left after one deletion. |
| ASSERT_EQ(1u, context->NumTextures()); |
| break; |
| case 3: |
| // Resource manager state should not change when delete is called on an |
| // invalid id. |
| ASSERT_EQ(1u, context->NumTextures()); |
| break; |
| case 4: |
| // Creation after deletion: two more creates should total up to |
| // three textures. |
| ASSERT_EQ(3u, context->NumTextures()); |
| break; |
| } |
| } |
| |
| void AfterTest() override {} |
| |
| private: |
| // Must clear all resources before exiting. |
| void ClearResources() { |
| for (int i = 0; i < num_ui_resources_; i++) |
| ui_resources_[i] = nullptr; |
| } |
| |
| void CreateResource() { |
| ui_resources_[num_ui_resources_++] = |
| FakeScopedUIResource::Create(layer_tree_host()); |
| } |
| |
| scoped_ptr<FakeScopedUIResource> ui_resources_[5]; |
| int num_ui_resources_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource); |
| |
| class PushPropertiesCountingLayerImpl : public LayerImpl { |
| public: |
| static scoped_ptr<PushPropertiesCountingLayerImpl> Create( |
| LayerTreeImpl* tree_impl, int id) { |
| return make_scoped_ptr(new PushPropertiesCountingLayerImpl(tree_impl, id)); |
| } |
| |
| ~PushPropertiesCountingLayerImpl() override {} |
| |
| void PushPropertiesTo(LayerImpl* layer) override { |
| LayerImpl::PushPropertiesTo(layer); |
| push_properties_count_++; |
| // Push state to the active tree because we can only access it from there. |
| static_cast<PushPropertiesCountingLayerImpl*>( |
| layer)->push_properties_count_ = push_properties_count_; |
| } |
| |
| scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override { |
| return PushPropertiesCountingLayerImpl::Create(tree_impl, id()); |
| } |
| |
| size_t push_properties_count() const { return push_properties_count_; } |
| void reset_push_properties_count() { push_properties_count_ = 0; } |
| |
| private: |
| size_t push_properties_count_; |
| |
| PushPropertiesCountingLayerImpl(LayerTreeImpl* tree_impl, int id) |
| : LayerImpl(tree_impl, id), |
| push_properties_count_(0) { |
| SetBounds(gfx::Size(1, 1)); |
| } |
| }; |
| |
| class PushPropertiesCountingLayer : public Layer { |
| public: |
| static scoped_refptr<PushPropertiesCountingLayer> Create( |
| const LayerSettings& settings) { |
| return new PushPropertiesCountingLayer(settings); |
| } |
| |
| void PushPropertiesTo(LayerImpl* layer) override { |
| Layer::PushPropertiesTo(layer); |
| push_properties_count_++; |
| if (persist_needs_push_properties_) |
| needs_push_properties_ = true; |
| } |
| |
| // Something to make this layer push properties, but no other layer. |
| void MakePushProperties() { SetContentsOpaque(!contents_opaque()); } |
| |
| scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override { |
| return PushPropertiesCountingLayerImpl::Create(tree_impl, id()); |
| } |
| |
| void SetDrawsContent(bool draws_content) { SetIsDrawable(draws_content); } |
| |
| size_t push_properties_count() const { return push_properties_count_; } |
| void reset_push_properties_count() { push_properties_count_ = 0; } |
| |
| void set_persist_needs_push_properties(bool persist) { |
| persist_needs_push_properties_ = persist; |
| } |
| |
| private: |
| explicit PushPropertiesCountingLayer(const LayerSettings& settings) |
| : Layer(settings), |
| push_properties_count_(0), |
| persist_needs_push_properties_(false) { |
| SetBounds(gfx::Size(1, 1)); |
| } |
| ~PushPropertiesCountingLayer() override {} |
| |
| size_t push_properties_count_; |
| bool persist_needs_push_properties_; |
| }; |
| |
| class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest { |
| protected: |
| void BeginTest() override { |
| num_commits_ = 0; |
| expected_push_properties_root_ = 0; |
| expected_push_properties_child_ = 0; |
| expected_push_properties_grandchild_ = 0; |
| expected_push_properties_child2_ = 0; |
| expected_push_properties_other_root_ = 0; |
| expected_push_properties_leaf_layer_ = 0; |
| PostSetNeedsCommitToMainThread(); |
| } |
| |
| void SetupTree() override { |
| root_ = PushPropertiesCountingLayer::Create(layer_settings()); |
| root_->CreateRenderSurface(); |
| child_ = PushPropertiesCountingLayer::Create(layer_settings()); |
| child2_ = PushPropertiesCountingLayer::Create(layer_settings()); |
| grandchild_ = PushPropertiesCountingLayer::Create(layer_settings()); |
| leaf_always_pushing_layer_ = |
| PushPropertiesCountingLayer::Create(layer_settings()); |
| leaf_always_pushing_layer_->set_persist_needs_push_properties(true); |
| |
| root_->AddChild(child_); |
| root_->AddChild(child2_); |
| child_->AddChild(grandchild_); |
| child2_->AddChild(leaf_always_pushing_layer_); |
| |
| other_root_ = PushPropertiesCountingLayer::Create(layer_settings()); |
| other_root_->CreateRenderSurface(); |
| |
| // Don't set the root layer here. |
| LayerTreeHostTest::SetupTree(); |
| } |
| |
| void DidCommitAndDrawFrame() override { |
| EXPECT_EQ(expected_push_properties_root_, root_->push_properties_count()) |
| << "num_commits: " << num_commits_; |
| EXPECT_EQ(expected_push_properties_child_, child_->push_properties_count()) |
| << "num_commits: " << num_commits_; |
| EXPECT_EQ(expected_push_properties_grandchild_, |
| grandchild_->push_properties_count()) |
| << "num_commits: " << num_commits_; |
| EXPECT_EQ(expected_push_properties_child2_, |
| child2_->push_properties_count()) |
| << "num_commits: " << num_commits_; |
| EXPECT_EQ(expected_push_properties_other_root_, |
| other_root_->push_properties_count()) |
| << "num_commits: " << num_commits_; |
| EXPECT_EQ(expected_push_properties_leaf_layer_, |
| leaf_always_pushing_layer_->push_properties_count()) |
| << "num_commits: " << num_commits_; |
| |
| ++num_commits_; |
| |
| // The scrollbar layer always needs to be pushed. |
| if (root_->layer_tree_host()) { |
| EXPECT_TRUE(root_->descendant_needs_push_properties()); |
| EXPECT_FALSE(root_->needs_push_properties()); |
| } |
| if (child2_->layer_tree_host()) { |
| EXPECT_TRUE(child2_->descendant_needs_push_properties()); |
| EXPECT_FALSE(child2_->needs_push_properties()); |
| } |
| if (leaf_always_pushing_layer_->layer_tree_host()) { |
| EXPECT_FALSE( |
| leaf_always_pushing_layer_->descendant_needs_push_properties()); |
| EXPECT_TRUE(leaf_always_pushing_layer_->needs_push_properties()); |
| } |
| |
| // child_ and grandchild_ don't persist their need to push properties. |
| if (child_->layer_tree_host()) { |
| EXPECT_FALSE(child_->descendant_needs_push_properties()); |
| EXPECT_FALSE(child_->needs_push_properties()); |
| } |
| if (grandchild_->layer_tree_host()) { |
| EXPECT_FALSE(grandchild_->descendant_needs_push_properties()); |
| EXPECT_FALSE(grandchild_->needs_push_properties()); |
| } |
| |
| if (other_root_->layer_tree_host()) { |
| EXPECT_FALSE(other_root_->descendant_needs_push_properties()); |
| EXPECT_FALSE(other_root_->needs_push_properties()); |
| } |
| |
| switch (num_commits_) { |
| case 1: |
| layer_tree_host()->SetRootLayer(root_); |
| // Layers added to the tree get committed. |
| ++expected_push_properties_root_; |
| ++expected_push_properties_child_; |
| ++expected_push_properties_grandchild_; |
| ++expected_push_properties_child2_; |
| break; |
| case 2: |
| layer_tree_host()->SetNeedsCommit(); |
| // No layers need commit. |
| break; |
| case 3: |
| layer_tree_host()->SetRootLayer(other_root_); |
| // Layers added to the tree get committed. |
| ++expected_push_properties_other_root_; |
| break; |
| case 4: |
| layer_tree_host()->SetRootLayer(root_); |
| // Layers added to the tree get committed. |
| ++expected_push_properties_root_; |
| ++expected_push_properties_child_; |
| ++expected_push_properties_grandchild_; |
| ++expected_push_properties_child2_; |
| break; |
| case 5: |
| layer_tree_host()->SetNeedsCommit(); |
| // No layers need commit. |
| break; |
| case 6: |
| child_->RemoveFromParent(); |
| // No layers need commit. |
| break; |
| case 7: |
| root_->AddChild(child_); |
| // Layers added to the tree get committed. |
| ++expected_push_properties_child_; |
| ++expected_push_properties_grandchild_; |
| break; |
| case 8: |
| grandchild_->RemoveFromParent(); |
| // No layers need commit. |
| break; |
| case 9: |
| child_->AddChild(grandchild_); |
| // Layers added to the tree get committed. |
| ++expected_push_properties_grandchild_; |
| break; |
| case 10: |
| layer_tree_host()->SetViewportSize(gfx::Size(20, 20)); |
| // No layers need commit. |
| break; |
| case 11: |
| layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.8f, 1.1f); |
| // No layers need commit. |
| break; |
| case 12: |
| child_->MakePushProperties(); |
| // The modified layer needs commit |
| ++expected_push_properties_child_; |
| break; |
| case 13: |
| child2_->MakePushProperties(); |
| // The modified layer needs commit |
| ++expected_push_properties_child2_; |
| break; |
| case 14: |
| child_->RemoveFromParent(); |
| root_->AddChild(child_); |
| // Layers added to the tree get committed. |
| ++expected_push_properties_child_; |
| ++expected_push_properties_grandchild_; |
| break; |
| case 15: |
| grandchild_->MakePushProperties(); |
| // The modified layer needs commit |
| ++expected_push_properties_grandchild_; |
| break; |
| case 16: |
| // SetNeedsDisplay does not always set needs commit (so call it |
| // explicitly), but is a property change. |
| child_->SetNeedsDisplay(); |
| ++expected_push_properties_child_; |
| layer_tree_host()->SetNeedsCommit(); |
| break; |
| case 17: |
| EndTest(); |
| break; |
| } |
| |
| // The leaf layer always pushes. |
| if (leaf_always_pushing_layer_->layer_tree_host()) |
| ++expected_push_properties_leaf_layer_; |
| } |
| |
| void AfterTest() override {} |
| |
| int num_commits_; |
| FakeContentLayerClient client_; |
| scoped_refptr<PushPropertiesCountingLayer> root_; |
| scoped_refptr<PushPropertiesCountingLayer> child_; |
| scoped_refptr<PushPropertiesCountingLayer> child2_; |
| scoped_refptr<PushPropertiesCountingLayer> grandchild_; |
| scoped_refptr<PushPropertiesCountingLayer> other_root_; |
| scoped_refptr<PushPropertiesCountingLayer> leaf_always_pushing_layer_; |
| size_t expected_push_properties_root_; |
| size_t expected_push_properties_child_; |
| size_t expected_push_properties_child2_; |
| size_t expected_push_properties_grandchild_; |
| size_t expected_push_properties_other_root_; |
| size_t expected_push_properties_leaf_layer_; |
| }; |
| |
| MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties); |
| |
| class LayerTreeHostTestImplLayersPushProperties |
| : public LayerTreeHostTestLayersPushProperties { |
| protected: |
| void BeginTest() override { |
| expected_push_properties_root_impl_ = 0; |
| expected_push_properties_child_impl_ = 0; |
| expected_push_properties_grandchild_impl_ = 0; |
| expected_push_properties_child2_impl_ = 0; |
| expected_push_properties_grandchild2_impl_ = 0; |
| LayerTreeHostTestLayersPushProperties::BeginTest(); |
| } |
| |
| void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| // These commits are in response to the changes made in |
| // LayerTreeHostTestLayersPushProperties::DidCommitAndDrawFrame() |
| switch (num_commits_) { |
| case 0: |
| // Tree hasn't been setup yet don't bother to check anything. |
| return; |
| case 1: |
| // Root gets set up, Everyone is initialized. |
| ++expected_push_properties_root_impl_; |
| ++expected_push_properties_child_impl_; |
| ++expected_push_properties_grandchild_impl_; |
| ++expected_push_properties_child2_impl_; |
| ++expected_push_properties_grandchild2_impl_; |
| break; |
| case 2: |
| // Tree doesn't change but the one leaf that always pushes is pushed. |
| ++expected_push_properties_grandchild2_impl_; |
| break; |
| case 3: |
| // Root is swapped here. |
| // Clear the expected push properties the tree will be rebuilt. |
| expected_push_properties_root_impl_ = 0; |
| expected_push_properties_child_impl_ = 0; |
| expected_push_properties_grandchild_impl_ = 0; |
| expected_push_properties_child2_impl_ = 0; |
| expected_push_properties_grandchild2_impl_ = 0; |
| |
| // Make sure the new root is pushed. |
| EXPECT_EQ(1u, static_cast<PushPropertiesCountingLayerImpl*>( |
| host_impl->RootLayer())->push_properties_count()); |
| return; |
| case 4: |
| // Root is swapped back all of the layers in the tree get pushed. |
| ++expected_push_properties_root_impl_; |
| ++expected_push_properties_child_impl_; |
| ++expected_push_properties_grandchild_impl_; |
| ++expected_push_properties_child2_impl_; |
| ++expected_push_properties_grandchild2_impl_; |
| break; |
| case 5: |
| // Tree doesn't change but the one leaf that always pushes is pushed. |
| ++expected_push_properties_grandchild2_impl_; |
| break; |
| case 6: |
| // First child is removed. Structure of the tree changes here so swap |
| // some of the values. child_impl becomes child2_impl. |
| expected_push_properties_child_impl_ = |
| expected_push_properties_child2_impl_; |
| expected_push_properties_child2_impl_ = 0; |
| // grandchild_impl becomes grandchild2_impl. |
| expected_push_properties_grandchild_impl_ = |
| expected_push_properties_grandchild2_impl_; |
| expected_push_properties_grandchild2_impl_ = 0; |
| |
| // grandchild_impl is now the leaf that always pushes. It is pushed. |
| ++expected_push_properties_grandchild_impl_; |
| |