Chromium Code Reviews| Index: cc/trees/layer_tree_host_unittest.cc |
| diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc |
| index fa97e9d163c5a254dffa8c1b3ad66b6d4dc255a1..cb65d729454bbc8c42203fd482068bda1c188a9c 100644 |
| --- a/cc/trees/layer_tree_host_unittest.cc |
| +++ b/cc/trees/layer_tree_host_unittest.cc |
| @@ -417,12 +417,13 @@ MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); |
| class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNeedsRedrawRect() |
| - : num_draws_(0), |
| - bounds_(50, 50), |
| - invalid_rect_(10, 10, 20, 20), |
| - root_layer_(ContentLayer::Create(&client_)) {} |
| + : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {} |
| void BeginTest() override { |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + root_layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + root_layer_ = ContentLayer::Create(&client_); |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(bounds_); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| @@ -466,7 +467,7 @@ class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { |
| const gfx::Size bounds_; |
| const gfx::Rect invalid_rect_; |
| FakeContentLayerClient client_; |
| - scoped_refptr<ContentLayer> root_layer_; |
| + scoped_refptr<Layer> root_layer_; |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); |
| @@ -481,7 +482,10 @@ class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
| root_layer_ = Layer::Create(); |
| root_layer_->SetBounds(gfx::Size(10, 20)); |
| - scaled_layer_ = FakeContentLayer::Create(&client_); |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + scaled_layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + scaled_layer_ = FakeContentLayer::Create(&client_); |
| scaled_layer_->SetBounds(gfx::Size(1, 1)); |
| root_layer_->AddChild(scaled_layer_); |
| @@ -499,10 +503,15 @@ class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
| 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 |scaled_layer_|, which should not generate |
| - // a second commit as a result. |
| - layer_tree_host()->SetDeviceScaleFactor(4.f); |
| + // SetBounds grows the layer and exposes new content. |
| + if (layer_tree_host()->settings().impl_side_painting) { |
| + scaled_layer_->SetBounds(gfx::Size(4, 4)); |
| + } else { |
| + // Changing the device scale factor causes a commit. It also changes |
| + // the content bounds of |scaled_layer_|, which should not generate |
| + // a second commit as a result. |
| + layer_tree_host()->SetDeviceScaleFactor(4.f); |
| + } |
| break; |
| default: |
| // No extra commits. |
| @@ -518,7 +527,7 @@ class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { |
| private: |
| FakeContentLayerClient client_; |
| scoped_refptr<Layer> root_layer_; |
| - scoped_refptr<FakeContentLayer> scaled_layer_; |
| + scoped_refptr<Layer> scaled_layer_; |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); |
| @@ -585,12 +594,13 @@ SINGLE_AND_MULTI_THREAD_TEST_F( |
| class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { |
| public: |
| LayerTreeHostTestSetNextCommitForcesRedraw() |
| - : num_draws_(0), |
| - bounds_(50, 50), |
| - invalid_rect_(10, 10, 20, 20), |
| - root_layer_(ContentLayer::Create(&client_)) {} |
| + : num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {} |
| void BeginTest() override { |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + root_layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + root_layer_ = ContentLayer::Create(&client_); |
| root_layer_->SetIsDrawable(true); |
| root_layer_->SetBounds(bounds_); |
| layer_tree_host()->SetRootLayer(root_layer_); |
| @@ -667,7 +677,7 @@ class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { |
| const gfx::Size bounds_; |
| const gfx::Rect invalid_rect_; |
| FakeContentLayerClient client_; |
| - scoped_refptr<ContentLayer> root_layer_; |
| + scoped_refptr<Layer> root_layer_; |
| }; |
| SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
| @@ -677,22 +687,31 @@ SINGLE_AND_MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
| // its damage is preserved until the next time it is drawn. |
| class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { |
| public: |
| - LayerTreeHostTestUndrawnLayersDamageLater() |
| - : root_layer_(ContentLayer::Create(&client_)) {} |
| + LayerTreeHostTestUndrawnLayersDamageLater() {} |
| void SetupTree() override { |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + root_layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + root_layer_ = ContentLayer::Create(&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_ = FakeContentLayer::Create(&client_); |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + parent_layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + parent_layer_ = FakeContentLayer::Create(&client_); |
| parent_layer_->SetBounds(gfx::Size(15, 15)); |
| parent_layer_->SetOpacity(0.0f); |
| root_layer_->AddChild(parent_layer_); |
| - child_layer_ = FakeContentLayer::Create(&client_); |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + child_layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + child_layer_ = FakeContentLayer::Create(&client_); |
| child_layer_->SetBounds(gfx::Size(25, 25)); |
| parent_layer_->AddChild(child_layer_); |
| @@ -757,9 +776,9 @@ class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { |
| private: |
| FakeContentLayerClient client_; |
| - scoped_refptr<ContentLayer> root_layer_; |
| - scoped_refptr<FakeContentLayer> parent_layer_; |
| - scoped_refptr<FakeContentLayer> child_layer_; |
| + scoped_refptr<Layer> root_layer_; |
| + scoped_refptr<Layer> parent_layer_; |
| + scoped_refptr<Layer> child_layer_; |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); |
| @@ -1132,16 +1151,27 @@ class ContentLayerWithUpdateTracking : public ContentLayer { |
| // from being updated during commit. |
| class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { |
| public: |
| - LayerTreeHostTestOpacityChange() |
| - : test_opacity_change_delegate_(), |
| - update_check_layer_(ContentLayerWithUpdateTracking::Create( |
| - &test_opacity_change_delegate_)) { |
| - test_opacity_change_delegate_.SetTestLayer(update_check_layer_.get()); |
| - } |
| + LayerTreeHostTestOpacityChange() : test_opacity_change_delegate_() {} |
| void BeginTest() override { |
| + if (layer_tree_host()->settings().impl_side_painting) { |
| + update_check_picture_layer_ = |
| + FakePictureLayer::Create(&test_opacity_change_delegate_); |
| + test_opacity_change_delegate_.SetTestLayer( |
| + update_check_picture_layer_.get()); |
| + is_impl_paint_ = true; |
| + } else { |
| + update_check_content_layer_ = ContentLayerWithUpdateTracking::Create( |
| + &test_opacity_change_delegate_); |
| + test_opacity_change_delegate_.SetTestLayer( |
| + update_check_content_layer_.get()); |
| + is_impl_paint_ = false; |
| + } |
| layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
| - layer_tree_host()->root_layer()->AddChild(update_check_layer_); |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + layer_tree_host()->root_layer()->AddChild(update_check_picture_layer_); |
| + else |
| + layer_tree_host()->root_layer()->AddChild(update_check_content_layer_); |
| PostSetNeedsCommitToMainThread(); |
| } |
| @@ -1150,47 +1180,37 @@ class LayerTreeHostTestOpacityChange : public LayerTreeHostTest { |
| void AfterTest() override { |
| // Update() should have been called once. |
| - EXPECT_EQ(1, update_check_layer_->PaintContentsCount()); |
| + if (is_impl_paint_) |
| + EXPECT_EQ(1u, update_check_picture_layer_->update_count()); |
| + else |
| + EXPECT_EQ(1, update_check_content_layer_->PaintContentsCount()); |
| } |
| private: |
| TestOpacityChangeLayerDelegate test_opacity_change_delegate_; |
| - scoped_refptr<ContentLayerWithUpdateTracking> update_check_layer_; |
| + scoped_refptr<ContentLayerWithUpdateTracking> update_check_content_layer_; |
| + scoped_refptr<FakePictureLayer> update_check_picture_layer_; |
| + bool is_impl_paint_; |
| }; |
| MULTI_THREAD_TEST_F(LayerTreeHostTestOpacityChange); |
| -class NoScaleContentLayer : public ContentLayer { |
| - public: |
| - static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| - return make_scoped_refptr(new NoScaleContentLayer(client)); |
| - } |
| - |
| - void CalculateContentsScale(float ideal_contents_scale, |
| - float* contents_scale_x, |
| - float* contents_scale_y, |
| - gfx::Size* contentBounds) override { |
| - // Skip over the ContentLayer's method to the base Layer class. |
| - Layer::CalculateContentsScale(ideal_contents_scale, |
| - contents_scale_x, |
| - contents_scale_y, |
| - contentBounds); |
| - } |
| - |
| - private: |
| - explicit NoScaleContentLayer(ContentLayerClient* client) |
| - : ContentLayer(client) {} |
| - ~NoScaleContentLayer() override {} |
| -}; |
| - |
| class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| : public LayerTreeHostTest { |
| public: |
| - LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() |
| - : root_layer_(NoScaleContentLayer::Create(&client_)), |
| - child_layer_(ContentLayer::Create(&client_)) {} |
| + LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() {} |
| + |
| + void InitializeSettings(LayerTreeSettings* settings) override { |
| + // PictureLayer can only be used with impl side painting enabled. |
| + settings->impl_side_painting = true; |
| + } |
| void BeginTest() override { |
| + // Paint non-solid color. |
|
danakj
2014/11/13 18:14:22
drop this comment
|
| + client_.set_fill_with_nonsolid_color(true); |
| + root_layer_ = FakePictureLayer::Create(&client_); |
| + child_layer_ = FakePictureLayer::Create(&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()); |
| @@ -1221,8 +1241,10 @@ class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| // Device viewport is scaled. |
| EXPECT_EQ(gfx::Size(60, 60), impl->DrawViewportSize()); |
| - LayerImpl* root = impl->active_tree()->root_layer(); |
| - LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; |
| + 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()); |
| @@ -1246,10 +1268,8 @@ class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| EXPECT_RECT_EQ(gfx::Rect(0, 0, 60, 60), |
| root->render_surface()->content_rect()); |
| - // The content bounds of the child should be scaled. |
| - gfx::Size child_bounds_scaled = |
| - gfx::ToCeiledSize(gfx::ScaleSize(child->bounds(), 1.5)); |
| - EXPECT_EQ(child_bounds_scaled, child->content_bounds()); |
| + // 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(), |
| @@ -1263,13 +1283,13 @@ class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| 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_screen_space_transform; |
| - child_screen_space_transform.Translate(3.f, 3.f); |
| - gfx::Transform child_draw_transform = child_screen_space_transform; |
| + gfx::Transform child_transform; |
| + child_transform.Translate(3.f, 3.f); |
| + child_transform.Scale(child->MaximumTilingContentsScale(), |
| + child->MaximumTilingContentsScale()); |
| - EXPECT_TRANSFORMATION_MATRIX_EQ(child_draw_transform, |
| - child->draw_transform()); |
| - EXPECT_TRANSFORMATION_MATRIX_EQ(child_screen_space_transform, |
| + EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform, child->draw_transform()); |
| + EXPECT_TRANSFORMATION_MATRIX_EQ(child_transform, |
| child->screen_space_transform()); |
| EndTest(); |
| @@ -1279,12 +1299,13 @@ class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers |
| private: |
| FakeContentLayerClient client_; |
| - scoped_refptr<NoScaleContentLayer> root_layer_; |
| - scoped_refptr<ContentLayer> child_layer_; |
| + scoped_refptr<FakePictureLayer> root_layer_; |
| + scoped_refptr<FakePictureLayer> child_layer_; |
| }; |
| MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); |
| +// TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| // Verify atomicity of commits and reuse of textures. |
| class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |
| public: |
| @@ -1393,6 +1414,7 @@ class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |
| MULTI_THREAD_DIRECT_RENDERER_NOIMPL_TEST_F( |
| LayerTreeHostTestDirectRendererAtomicCommit); |
| +// TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| class LayerTreeHostTestDelegatingRendererAtomicCommit |
| : public LayerTreeHostTestDirectRendererAtomicCommit { |
| public: |
| @@ -1460,6 +1482,7 @@ static void SetLayerPropertiesForTesting(Layer* layer, |
| layer->SetContentsOpaque(opaque); |
| } |
| +// TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| class LayerTreeHostTestAtomicCommitWithPartialUpdate |
| : public LayerTreeHostTest { |
| public: |
| @@ -1633,6 +1656,7 @@ class LayerTreeHostTestAtomicCommitWithPartialUpdate |
| SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| LayerTreeHostTestAtomicCommitWithPartialUpdate); |
| +// TODO(sohanjg) : Make it work with impl-side painting. |
| class LayerTreeHostTestSurfaceNotAllocatedForLayersOutsideMemoryLimit |
| : public LayerTreeHostTest { |
| protected: |
| @@ -1953,11 +1977,15 @@ class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| layer_tree_host()->SetViewportSize(gfx::Size(10, 10)); |
| layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10)); |
| - content_layer_ = ContentLayer::Create(&client_); |
| - content_layer_->SetBounds(gfx::Size(10, 10)); |
| - content_layer_->SetPosition(gfx::PointF(0.f, 0.f)); |
| - content_layer_->SetIsDrawable(true); |
| - layer_tree_host()->root_layer()->AddChild(content_layer_); |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + layer_ = FakePictureLayer::Create(&client_); |
| + else |
| + layer_ = FakeContentLayer::Create(&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(); |
| } |
| @@ -1965,7 +1993,7 @@ class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| void DidCommitAndDrawFrame() override { |
| if (num_draw_layers_ == 2) |
| return; |
| - content_layer_->SetNeedsDisplay(); |
| + layer_->SetNeedsDisplay(); |
| } |
| void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| @@ -1986,12 +2014,12 @@ class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { |
| private: |
| FakeContentLayerClient client_; |
| - scoped_refptr<Layer> content_layer_; |
| + scoped_refptr<Layer> layer_; |
| int num_commit_complete_; |
| int num_draw_layers_; |
| }; |
| -MULTI_THREAD_NOIMPL_TEST_F(LayerTreeHostTestContinuousInvalidate); |
| +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); |
| class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { |
| public: |
| @@ -2194,6 +2222,7 @@ TEST(LayerTreeHostTest, |
| EXPECT_EQ(0u, host->MaxPartialTextureUpdates()); |
| } |
| +// TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |
| class LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted |
| : public LayerTreeHostTest { |
| public: |
| @@ -2598,9 +2627,7 @@ class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { |
| test_capabilities_.gpu.texture_rectangle = true; |
| } |
| - virtual GLuint createTexture() override { |
| - return 1; |
| - } |
| + GLuint createTexture() override { return 1; } |
| MOCK_METHOD1(activeTexture, void(GLenum texture)); |
| MOCK_METHOD2(bindTexture, void(GLenum target, |
| GLuint texture_id)); |
| @@ -4506,7 +4533,10 @@ class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface |
| } |
| void SetupTree() override { |
| - root_ = FakeContentLayer::Create(&client_); |
| + if (layer_tree_host()->settings().impl_side_painting) |
| + root_ = FakePictureLayer::Create(&client_); |
| + else |
| + root_ = FakeContentLayer::Create(&client_); |
| root_->SetBounds(gfx::Size(20, 20)); |
| layer_tree_host()->SetRootLayer(root_); |
| LayerTreeHostTest::SetupTree(); |
| @@ -4548,10 +4578,9 @@ class LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface |
| size_t first_output_surface_memory_limit_; |
| size_t second_output_surface_memory_limit_; |
| FakeContentLayerClient client_; |
| - scoped_refptr<FakeContentLayer> root_; |
| + scoped_refptr<Layer> root_; |
| }; |
| -// No output to copy for delegated renderers. |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| LayerTreeHostTestSetMemoryPolicyOnLostOutputSurface); |