Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 2908073003: Ensure that mask layer is of the same size as the owning layer. (Closed)
Patch Set: Compiling failure Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 1683
1684 // Test that when mask layers switches layers, this gets pushed onto impl. 1684 // Test that when mask layers switches layers, this gets pushed onto impl.
1685 // Also test that mask layer is in the layer update list even if its owning 1685 // Also test that mask layer is in the layer update list even if its owning
1686 // layer isn't. 1686 // layer isn't.
1687 class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest { 1687 class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest {
1688 protected: 1688 protected:
1689 void SetupTree() override { 1689 void SetupTree() override {
1690 scoped_refptr<Layer> root = Layer::Create(); 1690 scoped_refptr<Layer> root = Layer::Create();
1691 root->SetBounds(gfx::Size(10, 10)); 1691 root->SetBounds(gfx::Size(10, 10));
1692 child_layer_ = make_scoped_refptr(new UpdateCountingLayer); 1692 child_layer_ = make_scoped_refptr(new UpdateCountingLayer);
1693 child_layer_->SetBounds(gfx::Size(10, 10));
1693 mask_layer_ = make_scoped_refptr(new UpdateCountingLayer); 1694 mask_layer_ = make_scoped_refptr(new UpdateCountingLayer);
1694 mask_layer_->SetBounds(gfx::Size(10, 10)); 1695 mask_layer_->SetBounds(gfx::Size(10, 10));
1695 child_layer_->SetMaskLayer(mask_layer_.get()); 1696 child_layer_->SetMaskLayer(mask_layer_.get());
1696 root->AddChild(child_layer_); 1697 root->AddChild(child_layer_);
1697 layer_tree_host()->SetRootLayer(root); 1698 layer_tree_host()->SetRootLayer(root);
1698 LayerTreeHostTest::SetupTree(); 1699 LayerTreeHostTest::SetupTree();
1699 } 1700 }
1700 1701
1701 void BeginTest() override { 1702 void BeginTest() override {
1702 index_ = 0; 1703 index_ = 0;
(...skipping 5222 matching lines...) Expand 10 before | Expand all | Expand 10 after
6925 6926
6926 scoped_refptr<FakePictureLayer> content_layer = 6927 scoped_refptr<FakePictureLayer> content_layer =
6927 FakePictureLayer::Create(&client_); 6928 FakePictureLayer::Create(&client_);
6928 clipping_layer->AddChild(content_layer); 6929 clipping_layer->AddChild(content_layer);
6929 6930
6930 scoped_refptr<FakePictureLayer> content_child_layer = 6931 scoped_refptr<FakePictureLayer> content_child_layer =
6931 FakePictureLayer::Create(&client_); 6932 FakePictureLayer::Create(&client_);
6932 content_layer->AddChild(content_child_layer); 6933 content_layer->AddChild(content_child_layer);
6933 6934
6934 std::unique_ptr<RecordingSource> recording_source = 6935 std::unique_ptr<RecordingSource> recording_source =
6935 FakeRecordingSource::CreateFilledRecordingSource(gfx::Size(100, 100)); 6936 FakeRecordingSource::CreateFilledRecordingSource(gfx::Size(50, 50));
6936 PaintFlags paint1, paint2; 6937 PaintFlags paint1, paint2;
6937 static_cast<FakeRecordingSource*>(recording_source.get()) 6938 static_cast<FakeRecordingSource*>(recording_source.get())
6938 ->add_draw_rect_with_flags(gfx::Rect(0, 0, 100, 90), paint1); 6939 ->add_draw_rect_with_flags(gfx::Rect(0, 0, 50, 40), paint1);
6939 static_cast<FakeRecordingSource*>(recording_source.get()) 6940 static_cast<FakeRecordingSource*>(recording_source.get())
6940 ->add_draw_rect_with_flags(gfx::Rect(0, 90, 100, 10), paint2); 6941 ->add_draw_rect_with_flags(gfx::Rect(0, 40, 50, 10), paint2);
6941 client_.set_fill_with_nonsolid_color(true); 6942 client_.set_fill_with_nonsolid_color(true);
6942 static_cast<FakeRecordingSource*>(recording_source.get())->Rerecord(); 6943 static_cast<FakeRecordingSource*>(recording_source.get())->Rerecord();
6943 6944
6944 scoped_refptr<FakePictureLayer> mask_layer = 6945 scoped_refptr<FakePictureLayer> mask_layer =
6945 FakePictureLayer::CreateWithRecordingSource( 6946 FakePictureLayer::CreateWithRecordingSource(
6946 &client_, std::move(recording_source)); 6947 &client_, std::move(recording_source));
6947 content_layer->SetMaskLayer(mask_layer.get()); 6948 content_layer->SetMaskLayer(mask_layer.get());
6948 6949
6949 gfx::Size root_size(100, 100); 6950 gfx::Size root_size(100, 100);
6950 root->SetBounds(root_size); 6951 root->SetBounds(root_size);
6951 6952
6952 gfx::PointF clipping_origin(20.f, 10.f); 6953 gfx::PointF clipping_origin(20.f, 10.f);
6953 gfx::Size clipping_size(10, 20); 6954 gfx::Size clipping_size(10, 20);
6954 clipping_layer->SetBounds(clipping_size); 6955 clipping_layer->SetBounds(clipping_size);
6955 clipping_layer->SetPosition(clipping_origin); 6956 clipping_layer->SetPosition(clipping_origin);
6956 clipping_layer->SetMasksToBounds(true); 6957 clipping_layer->SetMasksToBounds(true);
6957 6958
6958 gfx::Size layer_size(50, 50); 6959 gfx::Size layer_size(50, 50);
6959 content_layer->SetBounds(layer_size); 6960 content_layer->SetBounds(layer_size);
6960 content_layer->SetPosition(gfx::PointF() - 6961 content_layer->SetPosition(gfx::PointF() -
6961 clipping_origin.OffsetFromOrigin()); 6962 clipping_origin.OffsetFromOrigin());
6962 6963
6963 gfx::Size child_size(50, 50); 6964 gfx::Size child_size(50, 50);
6964 content_child_layer->SetBounds(child_size); 6965 content_child_layer->SetBounds(child_size);
6965 content_child_layer->SetPosition(gfx::PointF(20.f, 0.f)); 6966 content_child_layer->SetPosition(gfx::PointF(20.f, 0.f));
6966 6967
6967 gfx::Size mask_size(100, 100); 6968 gfx::Size mask_size(50, 50);
6968 mask_layer->SetBounds(mask_size); 6969 mask_layer->SetBounds(mask_size);
6969 mask_layer->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); 6970 mask_layer->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK);
6970 mask_layer_id_ = mask_layer->id(); 6971 mask_layer_id_ = mask_layer->id();
6971 6972
6972 layer_tree_host()->SetRootLayer(root); 6973 layer_tree_host()->SetRootLayer(root);
6973 LayerTreeTest::SetupTree(); 6974 LayerTreeTest::SetupTree();
6974 client_.set_bounds(root->bounds()); 6975 client_.set_bounds(root->bounds());
6975 } 6976 }
6976 6977
6977 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 6978 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
7175 : public LayerTreeTestMaskLayerWithScaling { 7176 : public LayerTreeTestMaskLayerWithScaling {
7176 public: 7177 public:
7177 void InitializeSettings(LayerTreeSettings* settings) override { 7178 void InitializeSettings(LayerTreeSettings* settings) override {
7178 settings->enable_mask_tiling = true; 7179 settings->enable_mask_tiling = true;
7179 settings->layer_transforms_should_scale_layer_contents = true; 7180 settings->layer_transforms_should_scale_layer_contents = true;
7180 } 7181 }
7181 }; 7182 };
7182 7183
7183 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMultiTextureMaskLayerWithScaling); 7184 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMultiTextureMaskLayerWithScaling);
7184 7185
7185 class LayerTreeTestMaskLayerWithDifferentBounds : public LayerTreeTest {
7186 protected:
7187 void SetupTree() override {
7188 // The mask layer has bounds 100x100 but is attached to a layer with bounds
7189 // 50x50.
7190
7191 scoped_refptr<Layer> root = Layer::Create();
7192
7193 scoped_refptr<FakePictureLayer> content_layer =
7194 FakePictureLayer::Create(&client_);
7195 root->AddChild(content_layer);
7196
7197 std::unique_ptr<RecordingSource> recording_source =
7198 FakeRecordingSource::CreateFilledRecordingSource(gfx::Size(100, 100));
7199 PaintFlags paint1, paint2;
7200 static_cast<FakeRecordingSource*>(recording_source.get())
7201 ->add_draw_rect_with_flags(gfx::Rect(0, 0, 100, 90), paint1);
7202 static_cast<FakeRecordingSource*>(recording_source.get())
7203 ->add_draw_rect_with_flags(gfx::Rect(0, 90, 100, 10), paint2);
7204 client_.set_fill_with_nonsolid_color(true);
7205 static_cast<FakeRecordingSource*>(recording_source.get())->Rerecord();
7206
7207 scoped_refptr<FakePictureLayer> mask_layer =
7208 FakePictureLayer::CreateWithRecordingSource(
7209 &client_, std::move(recording_source));
7210 content_layer->SetMaskLayer(mask_layer.get());
7211
7212 gfx::Size root_size(100, 100);
7213 root->SetBounds(root_size);
7214
7215 gfx::Size layer_size(50, 50);
7216 content_layer->SetBounds(layer_size);
7217
7218 gfx::Size mask_size(100, 100);
7219 mask_layer->SetBounds(mask_size);
7220 mask_layer->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK);
7221
7222 layer_tree_host()->SetRootLayer(root);
7223 LayerTreeTest::SetupTree();
7224 client_.set_bounds(root->bounds());
7225 }
7226
7227 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
7228
7229 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
7230 LayerTreeHostImpl::FrameData* frame_data,
7231 DrawResult draw_result) override {
7232 EXPECT_EQ(2u, frame_data->render_passes.size());
7233 RenderPass* root_pass = frame_data->render_passes.back().get();
7234 EXPECT_EQ(2u, root_pass->quad_list.size());
7235
7236 // There's a solid color quad under everything.
7237 EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.back()->material);
7238
7239 EXPECT_EQ(DrawQuad::RENDER_PASS, root_pass->quad_list.front()->material);
7240 const RenderPassDrawQuad* render_pass_quad =
7241 RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
7242 switch (host_impl->active_tree()->source_frame_number()) {
7243 case 0:
7244 // Check that the mask fills the surface.
7245 EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
7246 render_pass_quad->rect.ToString());
7247 if (host_impl->settings().enable_mask_tiling) {
7248 EXPECT_EQ(gfx::RectF(0.f, 0.f, 50.f / 128.f, 50.f / 128.f).ToString(),
7249 render_pass_quad->mask_uv_rect.ToString());
7250 } else {
7251 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
7252 render_pass_quad->mask_uv_rect.ToString());
7253 }
7254 break;
7255 case 1:
7256 // Applying a DSF should change the render surface size, but won't
7257 // affect which part of the mask is used.
7258 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
7259 render_pass_quad->rect.ToString());
7260 if (host_impl->settings().enable_mask_tiling) {
7261 EXPECT_EQ(gfx::RectF(0.f, 0.f, 50.f / 128.f, 50.f / 128.f).ToString(),
7262 render_pass_quad->mask_uv_rect.ToString());
7263 } else {
7264 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(),
7265 render_pass_quad->mask_uv_rect.ToString());
7266 }
7267 EndTest();
7268 break;
7269 }
7270 return draw_result;
7271 }
7272
7273 void DidCommit() override {
7274 switch (layer_tree_host()->SourceFrameNumber()) {
7275 case 1:
7276 gfx::Size double_root_size(200, 200);
7277 layer_tree_host()->SetViewportSize(double_root_size);
7278 layer_tree_host()->SetDeviceScaleFactor(2.f);
7279 break;
7280 }
7281 }
7282
7283 void AfterTest() override {}
7284
7285 FakeContentLayerClient client_;
7286 };
7287
7288 class LayerTreeTestSingleTextureMaskLayerWithDifferentBounds
7289 : public LayerTreeTestMaskLayerWithDifferentBounds {
7290 public:
7291 void InitializeSettings(LayerTreeSettings* settings) override {
7292 settings->enable_mask_tiling = false;
7293 }
7294 };
7295
7296 SINGLE_AND_MULTI_THREAD_TEST_F(
7297 LayerTreeTestSingleTextureMaskLayerWithDifferentBounds);
7298
7299 class LayerTreeTestMultiTextureMaskLayerWithDifferentBounds
7300 : public LayerTreeTestMaskLayerWithDifferentBounds {
7301 public:
7302 void InitializeSettings(LayerTreeSettings* settings) override {
7303 settings->enable_mask_tiling = true;
7304 }
7305 };
7306
7307 SINGLE_AND_MULTI_THREAD_TEST_F(
7308 LayerTreeTestMultiTextureMaskLayerWithDifferentBounds);
7309
7310 class LayerTreeTestMaskWithNonExactTextureSize : public LayerTreeTest { 7186 class LayerTreeTestMaskWithNonExactTextureSize : public LayerTreeTest {
7311 protected: 7187 protected:
7312 void SetupTree() override { 7188 void SetupTree() override {
7313 // The masked layer has bounds 100x100, but is allocated a 120x150 texture. 7189 // The masked layer has bounds 100x100, but is allocated a 120x150 texture.
7314 7190
7315 scoped_refptr<Layer> root = Layer::Create(); 7191 scoped_refptr<Layer> root = Layer::Create();
7316 7192
7317 scoped_refptr<FakePictureLayer> content_layer = 7193 scoped_refptr<FakePictureLayer> content_layer =
7318 FakePictureLayer::Create(&client_); 7194 FakePictureLayer::Create(&client_);
7319 root->AddChild(content_layer); 7195 root->AddChild(content_layer);
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
8002 void AfterTest() override {} 7878 void AfterTest() override {}
8003 7879
8004 private: 7880 private:
8005 bool received_ack_ = false; 7881 bool received_ack_ = false;
8006 }; 7882 };
8007 7883
8008 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); 7884 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease);
8009 7885
8010 } // namespace 7886 } // namespace
8011 } // namespace cc 7887 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698