| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 | 1678 |
| 1679 // Test that when mask layers switches layers, this gets pushed onto impl. | 1679 // Test that when mask layers switches layers, this gets pushed onto impl. |
| 1680 // Also test that mask layer is in the layer update list even if its owning | 1680 // Also test that mask layer is in the layer update list even if its owning |
| 1681 // layer isn't. | 1681 // layer isn't. |
| 1682 class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest { | 1682 class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest { |
| 1683 protected: | 1683 protected: |
| 1684 void SetupTree() override { | 1684 void SetupTree() override { |
| 1685 scoped_refptr<Layer> root = Layer::Create(); | 1685 scoped_refptr<Layer> root = Layer::Create(); |
| 1686 root->SetBounds(gfx::Size(10, 10)); | 1686 root->SetBounds(gfx::Size(10, 10)); |
| 1687 child_layer_ = make_scoped_refptr(new UpdateCountingLayer); | 1687 child_layer_ = make_scoped_refptr(new UpdateCountingLayer); |
| 1688 child_layer_->SetBounds(gfx::Size(10, 10)); |
| 1688 mask_layer_ = make_scoped_refptr(new UpdateCountingLayer); | 1689 mask_layer_ = make_scoped_refptr(new UpdateCountingLayer); |
| 1689 mask_layer_->SetBounds(gfx::Size(10, 10)); | 1690 mask_layer_->SetBounds(gfx::Size(10, 10)); |
| 1690 child_layer_->SetMaskLayer(mask_layer_.get()); | 1691 child_layer_->SetMaskLayer(mask_layer_.get()); |
| 1691 root->AddChild(child_layer_); | 1692 root->AddChild(child_layer_); |
| 1692 layer_tree_host()->SetRootLayer(root); | 1693 layer_tree_host()->SetRootLayer(root); |
| 1693 LayerTreeHostTest::SetupTree(); | 1694 LayerTreeHostTest::SetupTree(); |
| 1694 } | 1695 } |
| 1695 | 1696 |
| 1696 void BeginTest() override { | 1697 void BeginTest() override { |
| 1697 index_ = 0; | 1698 index_ = 0; |
| (...skipping 5286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6984 | 6985 |
| 6985 scoped_refptr<FakePictureLayer> content_layer = | 6986 scoped_refptr<FakePictureLayer> content_layer = |
| 6986 FakePictureLayer::Create(&client_); | 6987 FakePictureLayer::Create(&client_); |
| 6987 clipping_layer->AddChild(content_layer); | 6988 clipping_layer->AddChild(content_layer); |
| 6988 | 6989 |
| 6989 scoped_refptr<FakePictureLayer> content_child_layer = | 6990 scoped_refptr<FakePictureLayer> content_child_layer = |
| 6990 FakePictureLayer::Create(&client_); | 6991 FakePictureLayer::Create(&client_); |
| 6991 content_layer->AddChild(content_child_layer); | 6992 content_layer->AddChild(content_child_layer); |
| 6992 | 6993 |
| 6993 std::unique_ptr<RecordingSource> recording_source = | 6994 std::unique_ptr<RecordingSource> recording_source = |
| 6994 FakeRecordingSource::CreateFilledRecordingSource(gfx::Size(100, 100)); | 6995 FakeRecordingSource::CreateFilledRecordingSource(gfx::Size(50, 50)); |
| 6995 PaintFlags paint1, paint2; | 6996 PaintFlags paint1, paint2; |
| 6996 static_cast<FakeRecordingSource*>(recording_source.get()) | 6997 static_cast<FakeRecordingSource*>(recording_source.get()) |
| 6997 ->add_draw_rect_with_flags(gfx::Rect(0, 0, 100, 90), paint1); | 6998 ->add_draw_rect_with_flags(gfx::Rect(0, 0, 50, 40), paint1); |
| 6998 static_cast<FakeRecordingSource*>(recording_source.get()) | 6999 static_cast<FakeRecordingSource*>(recording_source.get()) |
| 6999 ->add_draw_rect_with_flags(gfx::Rect(0, 90, 100, 10), paint2); | 7000 ->add_draw_rect_with_flags(gfx::Rect(0, 40, 50, 10), paint2); |
| 7000 client_.set_fill_with_nonsolid_color(true); | 7001 client_.set_fill_with_nonsolid_color(true); |
| 7001 static_cast<FakeRecordingSource*>(recording_source.get())->Rerecord(); | 7002 static_cast<FakeRecordingSource*>(recording_source.get())->Rerecord(); |
| 7002 | 7003 |
| 7003 scoped_refptr<FakePictureLayer> mask_layer = | 7004 scoped_refptr<FakePictureLayer> mask_layer = |
| 7004 FakePictureLayer::CreateWithRecordingSource( | 7005 FakePictureLayer::CreateWithRecordingSource( |
| 7005 &client_, std::move(recording_source)); | 7006 &client_, std::move(recording_source)); |
| 7006 content_layer->SetMaskLayer(mask_layer.get()); | 7007 content_layer->SetMaskLayer(mask_layer.get()); |
| 7007 | 7008 |
| 7008 gfx::Size root_size(100, 100); | 7009 gfx::Size root_size(100, 100); |
| 7009 root->SetBounds(root_size); | 7010 root->SetBounds(root_size); |
| 7010 | 7011 |
| 7011 gfx::PointF clipping_origin(20.f, 10.f); | 7012 gfx::PointF clipping_origin(20.f, 10.f); |
| 7012 gfx::Size clipping_size(10, 20); | 7013 gfx::Size clipping_size(10, 20); |
| 7013 clipping_layer->SetBounds(clipping_size); | 7014 clipping_layer->SetBounds(clipping_size); |
| 7014 clipping_layer->SetPosition(clipping_origin); | 7015 clipping_layer->SetPosition(clipping_origin); |
| 7015 clipping_layer->SetMasksToBounds(true); | 7016 clipping_layer->SetMasksToBounds(true); |
| 7016 | 7017 |
| 7017 gfx::Size layer_size(50, 50); | 7018 gfx::Size layer_size(50, 50); |
| 7018 content_layer->SetBounds(layer_size); | 7019 content_layer->SetBounds(layer_size); |
| 7019 content_layer->SetPosition(gfx::PointF() - | 7020 content_layer->SetPosition(gfx::PointF() - |
| 7020 clipping_origin.OffsetFromOrigin()); | 7021 clipping_origin.OffsetFromOrigin()); |
| 7021 | 7022 |
| 7022 gfx::Size child_size(50, 50); | 7023 gfx::Size child_size(50, 50); |
| 7023 content_child_layer->SetBounds(child_size); | 7024 content_child_layer->SetBounds(child_size); |
| 7024 content_child_layer->SetPosition(gfx::PointF(20.f, 0.f)); | 7025 content_child_layer->SetPosition(gfx::PointF(20.f, 0.f)); |
| 7025 | 7026 |
| 7026 gfx::Size mask_size(100, 100); | 7027 gfx::Size mask_size(50, 50); |
| 7027 mask_layer->SetBounds(mask_size); | 7028 mask_layer->SetBounds(mask_size); |
| 7028 mask_layer->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | 7029 mask_layer->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); |
| 7029 mask_layer_id_ = mask_layer->id(); | 7030 mask_layer_id_ = mask_layer->id(); |
| 7030 | 7031 |
| 7031 layer_tree_host()->SetRootLayer(root); | 7032 layer_tree_host()->SetRootLayer(root); |
| 7032 LayerTreeTest::SetupTree(); | 7033 LayerTreeTest::SetupTree(); |
| 7033 client_.set_bounds(root->bounds()); | 7034 client_.set_bounds(root->bounds()); |
| 7034 } | 7035 } |
| 7035 | 7036 |
| 7036 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 7037 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7234 : public LayerTreeTestMaskLayerWithScaling { | 7235 : public LayerTreeTestMaskLayerWithScaling { |
| 7235 public: | 7236 public: |
| 7236 void InitializeSettings(LayerTreeSettings* settings) override { | 7237 void InitializeSettings(LayerTreeSettings* settings) override { |
| 7237 settings->enable_mask_tiling = true; | 7238 settings->enable_mask_tiling = true; |
| 7238 settings->layer_transforms_should_scale_layer_contents = true; | 7239 settings->layer_transforms_should_scale_layer_contents = true; |
| 7239 } | 7240 } |
| 7240 }; | 7241 }; |
| 7241 | 7242 |
| 7242 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMultiTextureMaskLayerWithScaling); | 7243 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMultiTextureMaskLayerWithScaling); |
| 7243 | 7244 |
| 7244 class LayerTreeTestMaskLayerWithDifferentBounds : public LayerTreeTest { | |
| 7245 protected: | |
| 7246 void SetupTree() override { | |
| 7247 // The mask layer has bounds 100x100 but is attached to a layer with bounds | |
| 7248 // 50x50. | |
| 7249 | |
| 7250 scoped_refptr<Layer> root = Layer::Create(); | |
| 7251 | |
| 7252 scoped_refptr<FakePictureLayer> content_layer = | |
| 7253 FakePictureLayer::Create(&client_); | |
| 7254 root->AddChild(content_layer); | |
| 7255 | |
| 7256 std::unique_ptr<RecordingSource> recording_source = | |
| 7257 FakeRecordingSource::CreateFilledRecordingSource(gfx::Size(100, 100)); | |
| 7258 PaintFlags paint1, paint2; | |
| 7259 static_cast<FakeRecordingSource*>(recording_source.get()) | |
| 7260 ->add_draw_rect_with_flags(gfx::Rect(0, 0, 100, 90), paint1); | |
| 7261 static_cast<FakeRecordingSource*>(recording_source.get()) | |
| 7262 ->add_draw_rect_with_flags(gfx::Rect(0, 90, 100, 10), paint2); | |
| 7263 client_.set_fill_with_nonsolid_color(true); | |
| 7264 static_cast<FakeRecordingSource*>(recording_source.get())->Rerecord(); | |
| 7265 | |
| 7266 scoped_refptr<FakePictureLayer> mask_layer = | |
| 7267 FakePictureLayer::CreateWithRecordingSource( | |
| 7268 &client_, std::move(recording_source)); | |
| 7269 content_layer->SetMaskLayer(mask_layer.get()); | |
| 7270 | |
| 7271 gfx::Size root_size(100, 100); | |
| 7272 root->SetBounds(root_size); | |
| 7273 | |
| 7274 gfx::Size layer_size(50, 50); | |
| 7275 content_layer->SetBounds(layer_size); | |
| 7276 | |
| 7277 gfx::Size mask_size(100, 100); | |
| 7278 mask_layer->SetBounds(mask_size); | |
| 7279 mask_layer->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | |
| 7280 | |
| 7281 layer_tree_host()->SetRootLayer(root); | |
| 7282 LayerTreeTest::SetupTree(); | |
| 7283 client_.set_bounds(root->bounds()); | |
| 7284 } | |
| 7285 | |
| 7286 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
| 7287 | |
| 7288 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
| 7289 LayerTreeHostImpl::FrameData* frame_data, | |
| 7290 DrawResult draw_result) override { | |
| 7291 EXPECT_EQ(2u, frame_data->render_passes.size()); | |
| 7292 RenderPass* root_pass = frame_data->render_passes.back().get(); | |
| 7293 EXPECT_EQ(2u, root_pass->quad_list.size()); | |
| 7294 | |
| 7295 // There's a solid color quad under everything. | |
| 7296 EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.back()->material); | |
| 7297 | |
| 7298 EXPECT_EQ(DrawQuad::RENDER_PASS, root_pass->quad_list.front()->material); | |
| 7299 const RenderPassDrawQuad* render_pass_quad = | |
| 7300 RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front()); | |
| 7301 switch (host_impl->active_tree()->source_frame_number()) { | |
| 7302 case 0: | |
| 7303 // Check that the mask fills the surface. | |
| 7304 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(), | |
| 7305 render_pass_quad->rect.ToString()); | |
| 7306 if (host_impl->settings().enable_mask_tiling) { | |
| 7307 EXPECT_EQ(gfx::RectF(0.f, 0.f, 50.f / 128.f, 50.f / 128.f).ToString(), | |
| 7308 render_pass_quad->mask_uv_rect.ToString()); | |
| 7309 } else { | |
| 7310 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), | |
| 7311 render_pass_quad->mask_uv_rect.ToString()); | |
| 7312 } | |
| 7313 break; | |
| 7314 case 1: | |
| 7315 // Applying a DSF should change the render surface size, but won't | |
| 7316 // affect which part of the mask is used. | |
| 7317 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | |
| 7318 render_pass_quad->rect.ToString()); | |
| 7319 if (host_impl->settings().enable_mask_tiling) { | |
| 7320 EXPECT_EQ(gfx::RectF(0.f, 0.f, 50.f / 128.f, 50.f / 128.f).ToString(), | |
| 7321 render_pass_quad->mask_uv_rect.ToString()); | |
| 7322 } else { | |
| 7323 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), | |
| 7324 render_pass_quad->mask_uv_rect.ToString()); | |
| 7325 } | |
| 7326 EndTest(); | |
| 7327 break; | |
| 7328 } | |
| 7329 return draw_result; | |
| 7330 } | |
| 7331 | |
| 7332 void DidCommit() override { | |
| 7333 switch (layer_tree_host()->SourceFrameNumber()) { | |
| 7334 case 1: | |
| 7335 gfx::Size double_root_size(200, 200); | |
| 7336 layer_tree_host()->SetViewportSize(double_root_size); | |
| 7337 layer_tree_host()->SetDeviceScaleFactor(2.f); | |
| 7338 break; | |
| 7339 } | |
| 7340 } | |
| 7341 | |
| 7342 void AfterTest() override {} | |
| 7343 | |
| 7344 FakeContentLayerClient client_; | |
| 7345 }; | |
| 7346 | |
| 7347 class LayerTreeTestSingleTextureMaskLayerWithDifferentBounds | |
| 7348 : public LayerTreeTestMaskLayerWithDifferentBounds { | |
| 7349 public: | |
| 7350 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 7351 settings->enable_mask_tiling = false; | |
| 7352 } | |
| 7353 }; | |
| 7354 | |
| 7355 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 7356 LayerTreeTestSingleTextureMaskLayerWithDifferentBounds); | |
| 7357 | |
| 7358 class LayerTreeTestMultiTextureMaskLayerWithDifferentBounds | |
| 7359 : public LayerTreeTestMaskLayerWithDifferentBounds { | |
| 7360 public: | |
| 7361 void InitializeSettings(LayerTreeSettings* settings) override { | |
| 7362 settings->enable_mask_tiling = true; | |
| 7363 } | |
| 7364 }; | |
| 7365 | |
| 7366 SINGLE_AND_MULTI_THREAD_TEST_F( | |
| 7367 LayerTreeTestMultiTextureMaskLayerWithDifferentBounds); | |
| 7368 | |
| 7369 class LayerTreeTestMaskWithNonExactTextureSize : public LayerTreeTest { | 7245 class LayerTreeTestMaskWithNonExactTextureSize : public LayerTreeTest { |
| 7370 protected: | 7246 protected: |
| 7371 void SetupTree() override { | 7247 void SetupTree() override { |
| 7372 // The masked layer has bounds 100x100, but is allocated a 120x150 texture. | 7248 // The masked layer has bounds 100x100, but is allocated a 120x150 texture. |
| 7373 | 7249 |
| 7374 scoped_refptr<Layer> root = Layer::Create(); | 7250 scoped_refptr<Layer> root = Layer::Create(); |
| 7375 | 7251 |
| 7376 scoped_refptr<FakePictureLayer> content_layer = | 7252 scoped_refptr<FakePictureLayer> content_layer = |
| 7377 FakePictureLayer::Create(&client_); | 7253 FakePictureLayer::Create(&client_); |
| 7378 root->AddChild(content_layer); | 7254 root->AddChild(content_layer); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8061 void AfterTest() override {} | 7937 void AfterTest() override {} |
| 8062 | 7938 |
| 8063 private: | 7939 private: |
| 8064 bool received_ack_ = false; | 7940 bool received_ack_ = false; |
| 8065 }; | 7941 }; |
| 8066 | 7942 |
| 8067 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); | 7943 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); |
| 8068 | 7944 |
| 8069 } // namespace | 7945 } // namespace |
| 8070 } // namespace cc | 7946 } // namespace cc |
| OLD | NEW |