blob: 4c8c45946b5a0dea64e008a6e5ae45e183d6776e [file] [log] [blame]
ajumae2b7a5c2015-09-30 21:41:421// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_common.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj6496cba2014-10-16 01:31:089#include <algorithm>
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]995708c52013-10-17 20:52:5911#include <set>
vmpstra370ef52015-11-18 10:41:2812#include <vector>
[email protected]995708c52013-10-17 20:52:5913
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
loyso968163c92016-01-04 23:18:4815#include "cc/animation/animation_host.h"
16#include "cc/animation/animation_id_provider.h"
sunxd71aea3e2016-04-01 23:48:0517#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3418#include "cc/animation/keyframed_animation_curve.h"
[email protected]1c3626e2014-04-09 17:49:2219#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5220#include "cc/base/math_util.h"
sunxd29f17bf422016-02-03 02:47:4821#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/content_layer_client.h"
ajuma956219582017-04-04 19:58:1423#include "cc/layers/effect_tree_layer_list_iterator.h"
[email protected]cc3cfaa2013-03-18 09:05:5224#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5925#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5226#include "cc/layers/layer_impl.h"
[email protected]50761e92013-03-29 20:51:2827#include "cc/layers/render_surface_impl.h"
jaydasika69c77aa2016-07-14 22:48:4828#include "cc/layers/texture_layer_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4529#include "cc/output/copy_output_request.h"
30#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0331#include "cc/test/animation_test_common.h"
vollick2175fae82015-04-27 21:18:1232#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1633#include "cc/test/fake_impl_task_runner_provider.h"
danakjc7afae52017-06-20 21:12:4134#include "cc/test/fake_layer_tree_frame_sink.h"
[email protected]d600df7d2013-08-03 02:34:2835#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4536#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5937#include "cc/test/fake_picture_layer.h"
38#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0339#include "cc/test/geometry_test_utils.h"
danakj59931942016-07-26 22:11:2940#include "cc/test/layer_test_common.h"
reveman34b7a1522015-03-23 20:27:4741#include "cc/test/test_task_graph_runner.h"
trchendba8b1502016-07-08 09:47:0142#include "cc/trees/clip_node.h"
ennef6903532015-08-18 05:10:1543#include "cc/trees/draw_property_utils.h"
trchendba8b1502016-07-08 09:47:0144#include "cc/trees/effect_node.h"
danakj59931942016-07-26 22:11:2945#include "cc/trees/property_tree_builder.h"
trchendba8b1502016-07-08 09:47:0146#include "cc/trees/scroll_node.h"
[email protected]556fd292013-03-18 08:03:0447#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1648#include "cc/trees/task_runner_provider.h"
trchendba8b1502016-07-08 09:47:0149#include "cc/trees/transform_node.h"
[email protected]7f0c53db2012-10-02 00:23:1850#include "testing/gtest/include/gtest/gtest.h"
ajumae947a352017-01-10 19:17:4951#include "third_party/skia/include/core/SkImageFilter.h"
jbroman1c44d5b52016-06-06 21:19:3052#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
ajumae947a352017-01-10 19:17:4953#include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2054#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3755#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0056#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1457
[email protected]ba565742012-11-10 09:29:4858namespace cc {
[email protected]94f206c12012-08-25 00:09:1459namespace {
60
danakj59931942016-07-26 22:11:2961class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings {
62 public:
63 VerifyTreeCalcsLayerTreeSettings() {
danakj59931942016-07-26 22:11:2964 }
65};
66
67class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest {
68 public:
69 LayerTreeHostCommonTestBase()
70 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {}
71 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings)
72 : LayerTestCommon::LayerImplTest(settings) {}
73
74 static void SetScrollOffsetDelta(LayerImpl* layer_impl,
75 const gfx::Vector2dF& delta) {
76 if (layer_impl->layer_tree_impl()
77 ->property_trees()
pdr54d038192017-06-08 22:44:1378 ->scroll_tree.SetScrollOffsetDeltaForTesting(
79 layer_impl->element_id(), delta))
80 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(
81 layer_impl->element_id());
danakj59931942016-07-26 22:11:2982 }
83
84 static float GetMaximumAnimationScale(LayerImpl* layer_impl) {
85 return layer_impl->layer_tree_impl()
86 ->property_trees()
87 ->GetAnimationScales(layer_impl->transform_tree_index(),
88 layer_impl->layer_tree_impl())
89 .maximum_animation_scale;
90 }
91
92 static float GetStartingAnimationScale(LayerImpl* layer_impl) {
93 return layer_impl->layer_tree_impl()
94 ->property_trees()
95 ->GetAnimationScales(layer_impl->transform_tree_index(),
96 layer_impl->layer_tree_impl())
97 .starting_animation_scale;
98 }
99
100 void ExecuteCalculateDrawProperties(Layer* root_layer,
101 float device_scale_factor,
102 float page_scale_factor,
flackre310f292016-10-12 21:09:28103 Layer* page_scale_layer,
flackra283bed2016-10-31 14:49:42104 Layer* inner_viewport_scroll_layer,
105 Layer* outer_viewport_scroll_layer) {
danakj59931942016-07-26 22:11:29106 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
107 gfx::Size device_viewport_size =
108 gfx::Size(root_layer->bounds().width() * device_scale_factor,
109 root_layer->bounds().height() * device_scale_factor);
110
111 // We are probably not testing what is intended if the root_layer bounds are
112 // empty.
113 DCHECK(!root_layer->bounds().IsEmpty());
114 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
115 root_layer, device_viewport_size);
116 inputs.device_scale_factor = device_scale_factor;
117 inputs.page_scale_factor = page_scale_factor;
118 inputs.page_scale_layer = page_scale_layer;
flackre310f292016-10-12 21:09:28119 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
flackra283bed2016-10-31 14:49:42120 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer;
danakj59931942016-07-26 22:11:29121 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
122 }
123
jaydasika3a6b14432017-03-21 23:11:19124 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
125 float device_scale_factor,
126 float page_scale_factor,
127 LayerImpl* page_scale_layer,
128 LayerImpl* inner_viewport_scroll_layer,
129 LayerImpl* outer_viewport_scroll_layer) {
danakj59931942016-07-26 22:11:29130 if (device_scale_factor !=
131 root_layer->layer_tree_impl()->device_scale_factor())
132 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
133
134 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
135
136 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
137
138 gfx::Size device_viewport_size =
139 gfx::Size(root_layer->bounds().width() * device_scale_factor,
140 root_layer->bounds().height() * device_scale_factor);
141
ajumab784ef42017-04-28 23:01:52142 render_surface_list_impl_.reset(new RenderSurfaceList);
danakj59931942016-07-26 22:11:29143
144 // We are probably not testing what is intended if the root_layer bounds are
145 // empty.
146 DCHECK(!root_layer->bounds().IsEmpty());
147 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:52148 root_layer, device_viewport_size, render_surface_list_impl_.get());
danakj59931942016-07-26 22:11:29149 inputs.device_scale_factor = device_scale_factor;
150 inputs.page_scale_factor = page_scale_factor;
151 inputs.page_scale_layer = page_scale_layer;
flackre310f292016-10-12 21:09:28152 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
flackra283bed2016-10-31 14:49:42153 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer;
danakj59931942016-07-26 22:11:29154 inputs.can_adjust_raster_scales = true;
155
156 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
157 }
158
159 template <class LayerType>
160 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
161 LayerType* page_scale_application_layer = nullptr;
flackre310f292016-10-12 21:09:28162 LayerType* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:42163 LayerType* outer_viewport_scroll_layer = nullptr;
164 ExecuteCalculateDrawProperties(
165 root_layer, 1.f, 1.f, page_scale_application_layer,
166 inner_viewport_scroll_layer, outer_viewport_scroll_layer);
danakj59931942016-07-26 22:11:29167 }
168
169 template <class LayerType>
170 void ExecuteCalculateDrawProperties(LayerType* root_layer,
171 float device_scale_factor) {
172 LayerType* page_scale_application_layer = nullptr;
flackre310f292016-10-12 21:09:28173 LayerType* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:42174 LayerType* outer_viewport_scroll_layer = nullptr;
175 ExecuteCalculateDrawProperties(
176 root_layer, device_scale_factor, 1.f, page_scale_application_layer,
177 inner_viewport_scroll_layer, outer_viewport_scroll_layer);
danakj59931942016-07-26 22:11:29178 }
179
sunxd713aedbd2016-08-10 22:22:14180 const LayerList* GetUpdateLayerList() { return &update_layer_list_; }
181
jaydasika6ed869662016-09-21 14:29:59182 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) {
khushalsagarb69ba9452017-01-27 22:20:07183 DCHECK(root_layer->layer_tree_host());
danakj59931942016-07-26 22:11:29184 const Layer* page_scale_layer =
khushalsagarb69ba9452017-01-27 22:20:07185 root_layer->layer_tree_host()->page_scale_layer();
danakj59931942016-07-26 22:11:29186 Layer* inner_viewport_scroll_layer =
khushalsagarb69ba9452017-01-27 22:20:07187 root_layer->layer_tree_host()->inner_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29188 Layer* outer_viewport_scroll_layer =
khushalsagarb69ba9452017-01-27 22:20:07189 root_layer->layer_tree_host()->outer_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29190 const Layer* overscroll_elasticity_layer =
khushalsagarb69ba9452017-01-27 22:20:07191 root_layer->layer_tree_host()->overscroll_elasticity_layer();
danakj59931942016-07-26 22:11:29192 gfx::Vector2dF elastic_overscroll =
khushalsagarb69ba9452017-01-27 22:20:07193 root_layer->layer_tree_host()->elastic_overscroll();
danakj59931942016-07-26 22:11:29194 float page_scale_factor = 1.f;
195 float device_scale_factor = 1.f;
196 gfx::Size device_viewport_size =
197 gfx::Size(root_layer->bounds().width() * device_scale_factor,
198 root_layer->bounds().height() * device_scale_factor);
199 PropertyTrees* property_trees =
khushalsagarb69ba9452017-01-27 22:20:07200 root_layer->layer_tree_host()->property_trees();
danakj59931942016-07-26 22:11:29201 update_layer_list_.clear();
202 PropertyTreeBuilder::BuildPropertyTrees(
203 root_layer, page_scale_layer, inner_viewport_scroll_layer,
204 outer_viewport_scroll_layer, overscroll_elasticity_layer,
205 elastic_overscroll, page_scale_factor, device_scale_factor,
206 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees);
weiliangc1c0802c32017-03-21 19:53:17207 draw_property_utils::UpdatePropertyTrees(root_layer->layer_tree_host(),
danakjdc24211f22017-05-09 18:58:25208 property_trees);
danakj59931942016-07-26 22:11:29209 draw_property_utils::FindLayersThatNeedUpdates(
khushalsagarb69ba9452017-01-27 22:20:07210 root_layer->layer_tree_host(), property_trees, &update_layer_list_);
danakj59931942016-07-26 22:11:29211 }
212
jaydasika6ed869662016-09-21 14:29:59213 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
jaydasika3a6b14432017-03-21 23:11:19214 LayerImpl* root_layer) {
danakj59931942016-07-26 22:11:29215 DCHECK(root_layer->layer_tree_impl());
revemanb2b99a3b2017-04-06 23:39:08216 bool can_adjust_raster_scales = true;
danakj59931942016-07-26 22:11:29217
jaydasika3a6b14432017-03-21 23:11:19218 const LayerImpl* page_scale_layer = nullptr;
danakj59931942016-07-26 22:11:29219 LayerImpl* inner_viewport_scroll_layer =
220 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
221 LayerImpl* outer_viewport_scroll_layer =
222 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
jaydasika3a6b14432017-03-21 23:11:19223 const LayerImpl* overscroll_elasticity_layer =
danakj59931942016-07-26 22:11:29224 root_layer->layer_tree_impl()->OverscrollElasticityLayer();
225 gfx::Vector2dF elastic_overscroll =
226 root_layer->layer_tree_impl()->elastic_overscroll()->Current(
227 root_layer->layer_tree_impl()->IsActiveTree());
228 float page_scale_factor = 1.f;
229 float device_scale_factor = 1.f;
230 gfx::Size device_viewport_size =
231 gfx::Size(root_layer->bounds().width() * device_scale_factor,
232 root_layer->bounds().height() * device_scale_factor);
233 update_layer_list_impl_.reset(new LayerImplList);
234 root_layer->layer_tree_impl()->BuildLayerListForTesting();
jaydasika6ed869662016-09-21 14:29:59235 PropertyTrees* property_trees =
236 root_layer->layer_tree_impl()->property_trees();
jaydasika3a6b14432017-03-21 23:11:19237 PropertyTreeBuilder::BuildPropertyTrees(
danakj59931942016-07-26 22:11:29238 root_layer, page_scale_layer, inner_viewport_scroll_layer,
239 outer_viewport_scroll_layer, overscroll_elasticity_layer,
240 elastic_overscroll, page_scale_factor, device_scale_factor,
jaydasika3a6b14432017-03-21 23:11:19241 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees);
242 draw_property_utils::UpdatePropertyTreesAndRenderSurfaces(
danakjdc24211f22017-05-09 18:58:25243 root_layer, property_trees, can_adjust_raster_scales);
jaydasika3a6b14432017-03-21 23:11:19244 draw_property_utils::FindLayersThatNeedUpdates(
245 root_layer->layer_tree_impl(), property_trees,
danakj59931942016-07-26 22:11:29246 update_layer_list_impl_.get());
jaydasika3a6b14432017-03-21 23:11:19247 draw_property_utils::ComputeDrawPropertiesOfVisibleLayers(
248 update_layer_list_impl(), property_trees);
danakj59931942016-07-26 22:11:29249 }
250
revemanb2b99a3b2017-04-06 23:39:08251 void ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(
252 LayerImpl* root_layer) {
253 gfx::Size device_viewport_size =
254 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height());
ajumab784ef42017-04-28 23:01:52255 render_surface_list_impl_.reset(new RenderSurfaceList);
revemanb2b99a3b2017-04-06 23:39:08256
257 DCHECK(!root_layer->bounds().IsEmpty());
258 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:52259 root_layer, device_viewport_size, render_surface_list_impl_.get());
revemanb2b99a3b2017-04-06 23:39:08260 inputs.can_adjust_raster_scales = false;
261
262 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
263 }
264
danakj59931942016-07-26 22:11:29265 bool UpdateLayerListImplContains(int id) const {
266 for (auto* layer : *update_layer_list_impl_) {
267 if (layer->id() == id)
268 return true;
269 }
270 return false;
271 }
272
273 bool UpdateLayerListContains(int id) const {
274 for (const auto& layer : update_layer_list_) {
275 if (layer->id() == id)
276 return true;
277 }
278 return false;
279 }
280
ajumab784ef42017-04-28 23:01:52281 const RenderSurfaceList* render_surface_list_impl() const {
282 return render_surface_list_impl_.get();
danakj59931942016-07-26 22:11:29283 }
284 const LayerImplList* update_layer_list_impl() const {
285 return update_layer_list_impl_.get();
286 }
287 const LayerList& update_layer_list() const { return update_layer_list_; }
288
sunxd713aedbd2016-08-10 22:22:14289 bool VerifyLayerInList(scoped_refptr<Layer> layer,
290 const LayerList* layer_list) {
291 return std::find(layer_list->begin(), layer_list->end(), layer) !=
292 layer_list->end();
293 }
294
danakj59931942016-07-26 22:11:29295 private:
ajumab784ef42017-04-28 23:01:52296 std::unique_ptr<RenderSurfaceList> render_surface_list_impl_;
danakj59931942016-07-26 22:11:29297 LayerList update_layer_list_;
298 std::unique_ptr<LayerImplList> update_layer_list_impl_;
299};
300
301class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
302 public testing::Test {};
303
[email protected]96baf3e2012-10-22 23:09:55304class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32305 public:
loyso0940d412016-03-14 01:30:31306 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14307
danakj59931942016-07-26 22:11:29308 bool DrawsContent() const override { return true; }
[email protected]d58499a2012-10-09 22:27:47309
[email protected]fb661802013-03-25 01:59:32310 private:
dcheng716bedf2014-10-21 09:51:08311 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:14312};
313
danakj59931942016-07-26 22:11:29314class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings {
enne637715732015-07-07 02:05:26315 public:
316 LayerTreeSettingsScaleContent() {
317 layer_transforms_should_scale_layer_contents = true;
318 }
319};
320
danakj59931942016-07-26 22:11:29321class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase,
322 public testing::Test {
enne637715732015-07-07 02:05:26323 public:
324 LayerTreeHostCommonScalingTest()
danakj59931942016-07-26 22:11:29325 : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {}
enne637715732015-07-07 02:05:26326};
327
weiliangc6da32862016-04-20 16:40:11328class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
329 public:
330 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
331
332 LayerImpl* TestVisibleRectAndDrawableContentRect(
333 const gfx::Rect& target_rect,
334 const gfx::Transform& layer_transform,
335 const gfx::Rect& layer_rect) {
jaydasikabf1875a2016-06-28 03:39:59336 LayerImpl* root = root_layer_for_testing();
weiliangc6da32862016-04-20 16:40:11337 LayerImpl* target = AddChild<LayerImpl>(root);
338 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
339
340 root->SetDrawsContent(true);
341 target->SetDrawsContent(true);
342 target->SetMasksToBounds(true);
343 drawing_layer->SetDrawsContent(true);
344
danakje4fa7b72016-07-25 22:00:06345 root->SetBounds(gfx::Size(500, 500));
346 root->test_properties()->force_render_surface = true;
347 target->SetPosition(gfx::PointF(target_rect.origin()));
348 target->SetBounds(target_rect.size());
349 target->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:04350 drawing_layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06351 drawing_layer->SetPosition(gfx::PointF(layer_rect.origin()));
352 drawing_layer->SetBounds(layer_rect.size());
353 drawing_layer->test_properties()->should_flatten_transform = false;
weiliangc6da32862016-04-20 16:40:11354
355 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
356 ExecuteCalculateDrawProperties(root);
357
358 return drawing_layer;
359 }
360};
361
[email protected]989386c2013-07-18 21:37:23362TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32363 // Sanity check: For layers positioned at zero, with zero size,
364 // and with identity transforms, then the draw transform,
365 // screen space transform, and the hierarchy passed on to children
366 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14367
jaydasikabf1875a2016-06-28 03:39:59368 LayerImpl* parent = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51369 LayerImpl* child = AddChild<LayerImpl>(parent);
370 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28371
danakje4fa7b72016-07-25 22:00:06372 parent->SetBounds(gfx::Size(100, 100));
[email protected]94f206c12012-08-25 00:09:14373
sunxdfd920f3f2016-04-05 16:17:51374 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14375
danakjf78fb272016-07-26 19:06:15376 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
377 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51378 child->ScreenSpaceTransform());
danakjf78fb272016-07-26 19:06:15379 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51380 grand_child->DrawTransform());
danakjf78fb272016-07-26 19:06:15381 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51382 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14383}
384
jaydasika322436372015-12-16 23:42:38385TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
386 // Tests that effect tree node gets a valid transform id when a layer
387 // has opacity but doesn't create a render surface.
jaydasikabf1875a2016-06-28 03:39:59388 LayerImpl* parent = root_layer_for_testing();
jaydasika322436372015-12-16 23:42:38389 LayerImpl* child = AddChild<LayerImpl>(parent);
390 child->SetDrawsContent(true);
391
danakje4fa7b72016-07-25 22:00:06392 parent->SetBounds(gfx::Size(100, 100));
393 child->SetPosition(gfx::PointF(10, 10));
394 child->SetBounds(gfx::Size(100, 100));
jaydasikaab317e02016-06-01 00:53:18395 child->test_properties()->opacity = 0.f;
jaydasika322436372015-12-16 23:42:38396 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04397 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38398 parent->layer_tree_impl()->property_trees()->effect_tree;
399 EffectNode* node = effect_tree.Node(child->effect_tree_index());
400 const int transform_tree_size = parent->layer_tree_impl()
401 ->property_trees()
402 ->transform_tree.next_available_id();
trchendba8b1502016-07-08 09:47:01403 EXPECT_LT(node->transform_id, transform_tree_size);
jaydasika322436372015-12-16 23:42:38404}
405
[email protected]989386c2013-07-18 21:37:23406TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
jaydasikabf1875a2016-06-28 03:39:59407 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51408 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14409
jaydasikabaede2d92016-07-20 00:34:32410 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51411 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32412 EffectTree& effect_tree =
413 host_impl()->active_tree()->property_trees()->effect_tree;
enne826452722015-08-18 22:22:31414
danakje4fa7b72016-07-25 22:00:06415 root->SetBounds(gfx::Size(1, 2));
416
417 // Case 1: Setting the bounds of the layer should not affect either the draw
[email protected]fb661802013-03-25 01:59:32418 // transform or the screenspace transform.
danakje4fa7b72016-07-25 22:00:06419 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51420 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31421 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15422 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32423 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31424 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15425 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32426 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14427
danakje4fa7b72016-07-25 22:00:06428 // Case 2: The anchor point by itself (without a layer transform) should have
[email protected]fb661802013-03-25 01:59:32429 // no effect on the transforms.
danakje4fa7b72016-07-25 22:00:06430 layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
431 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51432 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
433 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31434 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15435 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32436 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31437 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15438 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32439 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14440
danakje4fa7b72016-07-25 22:00:06441 // Case 3: A change in actual position affects both the draw transform and
[email protected]fb661802013-03-25 01:59:32442 // screen space transform.
443 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05444 position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06445 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51446 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
447 ExecuteCalculateDrawProperties(root);
448 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32449 position_transform,
450 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31451 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27452 position_transform,
jaydasikabaede2d92016-07-20 00:34:32453 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14454
danakje4fa7b72016-07-25 22:00:06455 // Case 4: In the correct sequence of transforms, the layer transform should
456 // pre-multiply the translation-to-center. This is easily tested by using a
[email protected]fb661802013-03-25 01:59:32457 // scale transform, because scale and translation are not commutative.
458 gfx::Transform layer_transform;
459 layer_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:04460 layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06461 layer->test_properties()->transform_origin = gfx::Point3F();
462 layer->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51463 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
464 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31465 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32466 layer_transform,
467 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31468 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32469 layer_transform,
470 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14471
danakje4fa7b72016-07-25 22:00:06472 // Case 5: The layer transform should occur with respect to the anchor point.
[email protected]fb661802013-03-25 01:59:32473 gfx::Transform translation_to_anchor;
474 translation_to_anchor.Translate(5.0, 0.0);
475 gfx::Transform expected_result =
476 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06477 layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f);
sunxdfd920f3f2016-04-05 16:17:51478 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
479 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31480 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32481 expected_result,
482 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31483 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32484 expected_result,
485 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14486
danakje4fa7b72016-07-25 22:00:06487 // Case 6: Verify that position pre-multiplies the layer transform. The
[email protected]fb661802013-03-25 01:59:32488 // current implementation of CalculateDrawProperties does this implicitly, but
489 // it is still worth testing to detect accidental regressions.
490 expected_result = position_transform * translation_to_anchor *
491 layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06492 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51493 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
494 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31495 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32496 expected_result,
497 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31498 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32499 expected_result,
500 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14501}
502
[email protected]989386c2013-07-18 21:37:23503TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13504 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32505 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01506 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32507 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
508 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16509 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32510 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20511
khushalsagarb64b360d2015-10-21 19:25:16512 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:56513 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:22514 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20515
danakj60bc3bc2016-04-09 00:24:48516 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32517 LayerImpl::Create(host_impl.active_tree(), 1));
518 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28519 sublayer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:06520 sublayer->SetBounds(gfx::Size(500, 500));
[email protected]657b24c2013-03-06 09:01:20521
danakj60bc3bc2016-04-09 00:24:48522 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32523 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47524 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
danakje4fa7b72016-07-25 22:00:06525 scroll_layer->SetBounds(gfx::Size(10, 20));
[email protected]adeda572014-01-31 00:49:47526
pdr54d038192017-06-08 22:44:13527 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id()));
pdrbbfd8822017-06-27 22:44:52528 scroll_layer->SetScrollable(
[email protected]adeda572014-01-31 00:49:47529 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
530 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
pdr80d5a3e2017-07-17 19:04:07531
jaydasika89f7b5a2016-06-22 02:08:39532 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
[email protected]657b24c2013-03-06 09:01:20533
danakj60bc3bc2016-04-09 00:24:48534 std::unique_ptr<LayerImpl> root(
535 LayerImpl::Create(host_impl.active_tree(), 3));
danakje4fa7b72016-07-25 22:00:06536 root->SetBounds(gfx::Size(3, 4));
pdrbbfd8822017-06-27 22:44:52537 root->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
jaydasika2411692c2016-03-23 01:56:09538 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59539 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
pdr80d5a3e2017-07-17 19:04:07540 host_impl.active_tree()->BuildPropertyTreesForTesting();
541 auto& scroll_tree = host_impl.active_tree()->property_trees()->scroll_tree;
542 scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->element_id(),
543 kScrollOffset);
544 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]657b24c2013-03-06 09:01:20545
jaydasikaa534a472016-03-31 01:12:16546 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28547 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42548 nullptr, nullptr);
danakjf78fb272016-07-26 19:06:15549 gfx::Transform expected_transform;
[email protected]fb661802013-03-25 01:59:32550 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33551 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16552 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33553 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16554 page_scale * kDeviceScale));
555 expected_transform.Scale(page_scale * kDeviceScale,
556 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32557 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44558 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32559 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10560 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20561
[email protected]fb661802013-03-25 01:59:32562 gfx::Transform arbitrary_translate;
563 const float kTranslateX = 10.6f;
564 const float kTranslateY = 20.6f;
565 arbitrary_translate.Translate(kTranslateX, kTranslateY);
jaydasika10d43fc2016-08-18 04:06:04566 scroll_layer->test_properties()->transform = arbitrary_translate;
jaydasika2411692c2016-03-23 01:56:09567 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16568 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28569 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42570 nullptr, nullptr);
[email protected]fb661802013-03-25 01:59:32571 expected_transform.MakeIdentity();
572 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16573 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
574 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33575 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16576 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
577 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33578 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16579 expected_transform.Scale(page_scale * kDeviceScale,
580 page_scale * kDeviceScale);
581 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
582 sublayer->DrawTransform());
583
584 // Test that page scale is updated even when we don't rebuild property trees.
585 page_scale = 1.888f;
pdr53abb452017-05-19 01:59:42586
587 LayerTreeImpl::ViewportLayerIds viewport_ids;
588 viewport_ids.page_scale = scroll_layer->test_properties()->parent->id();
589 root_layer->layer_tree_impl()->SetViewportLayersFromIds(viewport_ids);
jaydasikaa534a472016-03-31 01:12:16590 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
591 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
592 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28593 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42594 nullptr, nullptr);
jaydasikaa534a472016-03-31 01:12:16595
596 expected_transform.MakeIdentity();
597 expected_transform.Translate(
598 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
599 sub_layer_screen_position.x() * page_scale *
600 kDeviceScale),
601 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
602 sub_layer_screen_position.y() * page_scale *
603 kDeviceScale));
604 expected_transform.Scale(page_scale * kDeviceScale,
605 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32606 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44607 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20608}
609
[email protected]989386c2013-07-18 21:37:23610TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
jaydasikabf1875a2016-06-28 03:39:59611 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51612 LayerImpl* parent = AddChild<LayerImpl>(root);
613 LayerImpl* child = AddChild<LayerImpl>(parent);
614 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28615
[email protected]fb661802013-03-25 01:59:32616 // One-time setup of root layer
danakje4fa7b72016-07-25 22:00:06617 root->SetBounds(gfx::Size(1, 2));
enne826452722015-08-18 22:22:31618
jaydasikabaede2d92016-07-20 00:34:32619 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51620 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32621 EffectTree& effect_tree =
622 host_impl()->active_tree()->property_trees()->effect_tree;
[email protected]ecc12622012-10-30 20:45:42623
[email protected]fb661802013-03-25 01:59:32624 // Case 1: parent's anchor point should not affect child or grand_child.
danakje4fa7b72016-07-25 22:00:06625 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
626 parent->SetBounds(gfx::Size(10, 12));
627 child->SetBounds(gfx::Size(16, 18));
628 grand_child->SetBounds(gfx::Size(76, 78));
sunxdfd920f3f2016-04-05 16:17:51629 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31630
631 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15632 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32633 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31634 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15635 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32636 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
637 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15638 gfx::Transform(), draw_property_utils::DrawTransform(
639 grand_child, transform_tree, effect_tree));
jaydasikabaede2d92016-07-20 00:34:32640 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15641 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32642 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14643
[email protected]fb661802013-03-25 01:59:32644 // Case 2: parent's position affects child and grand_child.
645 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05646 parent_position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06647 parent->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51648 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
649 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31650 EXPECT_TRANSFORMATION_MATRIX_EQ(
651 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32652 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31653 EXPECT_TRANSFORMATION_MATRIX_EQ(
654 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32655 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
656 EXPECT_TRANSFORMATION_MATRIX_EQ(
657 parent_position_transform, draw_property_utils::DrawTransform(
658 grand_child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31659 EXPECT_TRANSFORMATION_MATRIX_EQ(
660 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32661 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14662
[email protected]fb661802013-03-25 01:59:32663 // Case 3: parent's local transform affects child and grandchild
664 gfx::Transform parent_layer_transform;
665 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
666 gfx::Transform parent_translation_to_anchor;
667 parent_translation_to_anchor.Translate(2.5, 3.0);
668 gfx::Transform parent_composite_transform =
669 parent_translation_to_anchor * parent_layer_transform *
670 Inverse(parent_translation_to_anchor);
jaydasika10d43fc2016-08-18 04:06:04671 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06672 parent->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51673 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
674 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31675 EXPECT_TRANSFORMATION_MATRIX_EQ(
676 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32677 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31678 EXPECT_TRANSFORMATION_MATRIX_EQ(
679 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32680 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
enne826452722015-08-18 22:22:31681 EXPECT_TRANSFORMATION_MATRIX_EQ(
682 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32683 draw_property_utils::DrawTransform(grand_child, transform_tree,
684 effect_tree));
enne826452722015-08-18 22:22:31685 EXPECT_TRANSFORMATION_MATRIX_EQ(
686 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32687 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14688}
689
[email protected]989386c2013-07-18 21:37:23690TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:59691 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28692 LayerImpl* parent = AddChildToRoot<LayerImpl>();
693 LayerImpl* child = AddChild<LayerImpl>(parent);
694 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]94f206c12012-08-25 00:09:14695
[email protected]fb661802013-03-25 01:59:32696 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05697 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32698 gfx::Transform parent_translation_to_anchor;
699 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44700
[email protected]fb661802013-03-25 01:59:32701 gfx::Transform parent_composite_transform =
702 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39703 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32704 gfx::Vector2dF parent_composite_scale =
705 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
706 1.f);
707 gfx::Transform surface_sublayer_transform;
708 surface_sublayer_transform.Scale(parent_composite_scale.x(),
709 parent_composite_scale.y());
710 gfx::Transform surface_sublayer_composite_transform =
711 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14712
danakje4fa7b72016-07-25 22:00:06713 root->SetBounds(gfx::Size(1, 2));
jaydasika10d43fc2016-08-18 04:06:04714 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06715 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
716 parent->SetBounds(gfx::Size(100, 120));
717 child->SetBounds(gfx::Size(16, 18));
718 child->test_properties()->force_render_surface = true;
719 grand_child->SetBounds(gfx::Size(8, 10));
720 grand_child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28721 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14722
[email protected]fb661802013-03-25 01:59:32723 // Render surface should have been created now.
chrishtr7e3aaf22017-05-04 15:04:01724 ASSERT_TRUE(GetRenderSurface(child));
725 ASSERT_EQ(GetRenderSurface(child), child->render_target());
[email protected]94f206c12012-08-25 00:09:14726
[email protected]fb661802013-03-25 01:59:32727 // The child layer's draw transform should refer to its new render surface.
728 // The screen-space transform, however, should still refer to the root.
729 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44730 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32731 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10732 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14733
[email protected]fb661802013-03-25 01:59:32734 // Because the grand_child is the only drawable content, the child's render
735 // surface will tighten its bounds to the grand_child. The scale at which the
736 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25737 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
738 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14739
[email protected]fb661802013-03-25 01:59:32740 // The screen space is the same as the target since the child surface draws
741 // into the root.
742 EXPECT_TRANSFORMATION_MATRIX_EQ(
743 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25744 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14745}
746
[email protected]989386c2013-07-18 21:37:23747TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32748 // This test creates a more complex tree and verifies it all at once. This
749 // covers the following cases:
750 // - layers that are described w.r.t. a render surface: should have draw
751 // transforms described w.r.t. that surface
752 // - A render surface described w.r.t. an ancestor render surface: should
753 // have a draw transform described w.r.t. that ancestor surface
[email protected]fb661802013-03-25 01:59:32754 // - Sanity check on recursion: verify transforms of layers described w.r.t.
755 // a render surface that is described w.r.t. an ancestor render surface.
756 // - verifying that each layer has a reference to the correct render surface
757 // and render target values.
758
jaydasikabf1875a2016-06-28 03:39:59759 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28760 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36761 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28762 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36763 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28764 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36765 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28766 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36767 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28768 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36769 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28770 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36771 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28772 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36773 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28774 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
775 grand_child_of_rs1->SetDrawsContent(true);
776 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
777 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32778
779 // In combination with descendant draws content, opacity != 1 forces the layer
780 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18781 render_surface1->test_properties()->opacity = 0.5f;
782 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32783
[email protected]fb661802013-03-25 01:59:32784 // All layers in the tree are initialized with an anchor at .25 and a size of
wangxianzhu932d7f12016-09-30 05:47:00785 // (10,10). Matrix "A" is the composite layer transform used in all layers.
[email protected]fb661802013-03-25 01:59:32786 gfx::Transform translation_to_anchor;
787 translation_to_anchor.Translate(2.5, 0.0);
788 gfx::Transform layer_transform;
789 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32790
791 gfx::Transform A =
792 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32793
794 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39795 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32796 gfx::Transform surface1_sublayer_transform;
797 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
798 surface1_parent_transform_scale.y());
799
800 // SS1 = transform given to the subtree of render_surface1
801 gfx::Transform SS1 = surface1_sublayer_transform;
802 // S1 = transform to move from render_surface1 pixels to the layer space of
803 // the owning layer
804 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
805
806 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39807 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32808 gfx::Transform surface2_sublayer_transform;
809 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
810 surface2_parent_transform_scale.y());
811
812 // SS2 = transform given to the subtree of render_surface2
813 gfx::Transform SS2 = surface2_sublayer_transform;
814 // S2 = transform to move from render_surface2 pixels to the layer space of
815 // the owning layer
816 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
817
danakje4fa7b72016-07-25 22:00:06818 root->SetBounds(gfx::Size(1, 2));
819 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04820 parent->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06821 parent->SetBounds(gfx::Size(10, 10));
822 render_surface1->test_properties()->transform_origin =
823 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04824 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06825 render_surface1->SetBounds(gfx::Size(10, 10));
826 render_surface1->test_properties()->force_render_surface = true;
827 render_surface2->test_properties()->transform_origin =
828 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04829 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06830 render_surface2->SetBounds(gfx::Size(10, 10));
831 render_surface2->test_properties()->force_render_surface = true;
832 child_of_root->test_properties()->transform_origin =
833 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04834 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06835 child_of_root->SetBounds(gfx::Size(10, 10));
836 child_of_rs1->test_properties()->transform_origin =
837 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04838 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06839 child_of_rs1->SetBounds(gfx::Size(10, 10));
840 child_of_rs2->test_properties()->transform_origin =
841 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04842 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06843 child_of_rs2->SetBounds(gfx::Size(10, 10));
844 grand_child_of_root->test_properties()->transform_origin =
845 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04846 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06847 grand_child_of_root->SetBounds(gfx::Size(10, 10));
848 grand_child_of_rs1->test_properties()->transform_origin =
849 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04850 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06851 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
852 grand_child_of_rs2->test_properties()->transform_origin =
853 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04854 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06855 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:32856
enne25dea3f2015-07-27 16:44:28857 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32858
859 // Only layers that are associated with render surfaces should have an actual
860 // RenderSurface() value.
chrishtr7e3aaf22017-05-04 15:04:01861 ASSERT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:49862 ASSERT_EQ(GetRenderSurface(child_of_root), GetRenderSurface(root));
863 ASSERT_EQ(GetRenderSurface(grand_child_of_root), GetRenderSurface(root));
[email protected]fb661802013-03-25 01:59:32864
chrishtr5f60ca02017-05-11 23:09:49865 ASSERT_NE(GetRenderSurface(render_surface1), GetRenderSurface(root));
866 ASSERT_EQ(GetRenderSurface(child_of_rs1), GetRenderSurface(render_surface1));
867 ASSERT_EQ(GetRenderSurface(grand_child_of_rs1),
868 GetRenderSurface(render_surface1));
[email protected]fb661802013-03-25 01:59:32869
chrishtr5f60ca02017-05-11 23:09:49870 ASSERT_NE(GetRenderSurface(render_surface2), GetRenderSurface(root));
871 ASSERT_NE(GetRenderSurface(render_surface2),
872 GetRenderSurface(render_surface1));
873 ASSERT_EQ(GetRenderSurface(child_of_rs2), GetRenderSurface(render_surface2));
874 ASSERT_EQ(GetRenderSurface(grand_child_of_rs2),
875 GetRenderSurface(render_surface2));
[email protected]fb661802013-03-25 01:59:32876
877 // Verify all render target accessors
chrishtr7e3aaf22017-05-04 15:04:01878 EXPECT_EQ(GetRenderSurface(root), parent->render_target());
879 EXPECT_EQ(GetRenderSurface(root), child_of_root->render_target());
880 EXPECT_EQ(GetRenderSurface(root), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32881
chrishtr7e3aaf22017-05-04 15:04:01882 EXPECT_EQ(GetRenderSurface(render_surface1),
weiliangc189c1a12016-04-11 16:16:25883 render_surface1->render_target());
chrishtr7e3aaf22017-05-04 15:04:01884 EXPECT_EQ(GetRenderSurface(render_surface1), child_of_rs1->render_target());
885 EXPECT_EQ(GetRenderSurface(render_surface1),
weiliangc189c1a12016-04-11 16:16:25886 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32887
chrishtr7e3aaf22017-05-04 15:04:01888 EXPECT_EQ(GetRenderSurface(render_surface2),
weiliangc189c1a12016-04-11 16:16:25889 render_surface2->render_target());
chrishtr7e3aaf22017-05-04 15:04:01890 EXPECT_EQ(GetRenderSurface(render_surface2), child_of_rs2->render_target());
891 EXPECT_EQ(GetRenderSurface(render_surface2),
weiliangc189c1a12016-04-11 16:16:25892 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32893
894 // Verify layer draw transforms note that draw transforms are described with
895 // respect to the nearest ancestor render surface but screen space transforms
896 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44897 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
898 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39899 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44900 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32901
ajumad9432e32015-11-30 19:43:44902 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
903 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39904 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44905 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32906
ajumad9432e32015-11-30 19:43:44907 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
908 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39909 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44910 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32911
912 // Verify layer screen-space transforms
913 //
ajumab6aa1c62015-12-01 21:01:10914 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
915 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
916 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
917 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32918
[email protected]baf64d062014-02-16 22:10:39919 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10920 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39921 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10922 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39923 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10924 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32925
[email protected]baf64d062014-02-16 22:10:39926 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10927 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39928 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10929 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39930 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10931 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32932
933 // Verify render surface transforms.
934 //
935 // Draw transform of render surface 1 is described with respect to root.
936 EXPECT_TRANSFORMATION_MATRIX_EQ(
chrishtr7e3aaf22017-05-04 15:04:01937 A * A * S1, GetRenderSurface(render_surface1)->draw_transform());
[email protected]fb661802013-03-25 01:59:32938 EXPECT_TRANSFORMATION_MATRIX_EQ(
chrishtr7e3aaf22017-05-04 15:04:01939 A * A * S1, GetRenderSurface(render_surface1)->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32940 // Draw transform of render surface 2 is described with respect to render
941 // surface 1.
942 EXPECT_TRANSFORMATION_MATRIX_EQ(
chrishtr7e3aaf22017-05-04 15:04:01943 SS1 * A * S2, GetRenderSurface(render_surface2)->draw_transform());
[email protected]fb661802013-03-25 01:59:32944 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39945 A * A * A * S2,
chrishtr7e3aaf22017-05-04 15:04:01946 GetRenderSurface(render_surface2)->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32947
948 // Sanity check. If these fail there is probably a bug in the test itself. It
949 // is expected that we correctly set up transforms so that the y-component of
950 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:10951 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:26952 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10953 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32954 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10955 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32956
[email protected]803f6b52013-09-12 00:51:26957 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10958 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
959 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32960 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10961 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32962
[email protected]803f6b52013-09-12 00:51:26963 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:10964 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
965 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32966 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10967 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32968}
969
[email protected]989386c2013-07-18 21:37:23970TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:32971 // For layers that flatten their subtree, there should be an orthographic
972 // projection (for x and y values) in the middle of the transform sequence.
973 // Note that the way the code is currently implemented, it is not expected to
974 // use a canonical orthographic projection.
975
jaydasikabf1875a2016-06-28 03:39:59976 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28977 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36978 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28979 LayerImpl* grand_child = AddChild<LayerImpl>(child);
980 grand_child->SetDrawsContent(true);
981 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
982 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32983
984 gfx::Transform rotation_about_y_axis;
985 rotation_about_y_axis.RotateAboutYAxis(30.0);
986
danakje4fa7b72016-07-25 22:00:06987 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:04988 child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:06989 child->SetBounds(gfx::Size(10, 10));
990 child->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:04991 grand_child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:06992 grand_child->SetBounds(gfx::Size(10, 10));
993 great_grand_child->SetBounds(gfx::Size(10, 10));
[email protected]d600df7d2013-08-03 02:34:28994
[email protected]fb661802013-03-25 01:59:32995 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:52996 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
997 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
998 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
999 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:321000
1001 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1002 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1003 gfx::Transform expected_grand_child_draw_transform =
1004 rotation_about_y_axis; // draws onto child's render surface
1005 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1006 flattened_rotation_about_y.FlattenTo2d();
1007 gfx::Transform expected_grand_child_screen_space_transform =
1008 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081009 gfx::Transform expected_great_grand_child_draw_transform =
1010 flattened_rotation_about_y;
1011 gfx::Transform expected_great_grand_child_screen_space_transform =
1012 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321013
enne25dea3f2015-07-27 16:44:281014 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321015
1016 // The child's draw transform should have been taken by its surface.
chrishtr7e3aaf22017-05-04 15:04:011017 ASSERT_TRUE(GetRenderSurface(child));
[email protected]fb661802013-03-25 01:59:321018 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
chrishtr7e3aaf22017-05-04 15:04:011019 GetRenderSurface(child)->draw_transform());
[email protected]fb661802013-03-25 01:59:321020 EXPECT_TRANSFORMATION_MATRIX_EQ(
1021 expected_child_screen_space_transform,
chrishtr7e3aaf22017-05-04 15:04:011022 GetRenderSurface(child)->screen_space_transform());
danakje4fa7b72016-07-25 22:00:061023 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321024 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101025 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321026 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441027 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321028 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101029 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081030 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441031 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081032 EXPECT_TRANSFORMATION_MATRIX_EQ(
1033 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101034 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321035}
1036
ajumadbd92cb2015-07-16 13:47:061037TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasikabf1875a2016-06-28 03:39:591038 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:141039 LayerImpl* child = AddChild<LayerImpl>(root);
1040 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061041
1042 gfx::Transform child_transform;
1043 child_transform.Translate(50.0, 50.0);
1044 child_transform.RotateAboutZAxis(30.0);
1045
1046 gfx::Transform grand_child_transform;
1047 grand_child_transform.RotateAboutYAxis(90.0);
1048
danakje4fa7b72016-07-25 22:00:061049 root->SetBounds(gfx::Size(200, 200));
jaydasika10d43fc2016-08-18 04:06:041050 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:061051 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:041052 grand_child->test_properties()->transform = grand_child_transform;
danakje4fa7b72016-07-25 22:00:061053 grand_child->SetBounds(gfx::Size(100, 100));
jaydasikaca2605e2016-04-23 02:52:521054 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141055 grand_child->SetDrawsContent(true);
jaydasika6ed869662016-09-21 14:29:591056 float device_scale_factor = 1.f;
1057 float page_scale_factor = 1.f;
1058 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:281059 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:421060 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika6ed869662016-09-21 14:29:591061 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:281062 page_scale_layer, inner_viewport_scroll_layer,
jaydasika3a6b14432017-03-21 23:11:191063 outer_viewport_scroll_layer);
ajumadbd92cb2015-07-16 13:47:061064
petermayo9711f032017-03-30 19:17:261065 // Mapping grand_child's bounds to screen space produces an empty rect, but
1066 // only because it is turned sideways. The entire rect is contained inside
1067 // the clip, and is only empty so long as the numerical precision of the
1068 // transform is effectively perfect. Currently we do the calculation the
1069 // other way around, and the Projection of the screen space clip into layer
1070 // space includes the entire bounds.
1071 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
1072 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061073}
1074
[email protected]989386c2013-07-18 21:37:231075TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321076 // A layer that is empty in one axis, but not the other, was accidentally
1077 // skipping a necessary translation. Without that translation, the coordinate
1078 // space of the layer's draw transform is incorrect.
1079 //
1080 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1081 // but if that layer becomes a render surface, then its draw transform is
1082 // implicitly inherited by the rest of the subtree, which then is positioned
1083 // incorrectly as a result.
1084
jaydasikabf1875a2016-06-28 03:39:591085 LayerImpl* root = root_layer_for_testing();
ennec1332992015-08-24 19:45:091086 LayerImpl* child = AddChild<LayerImpl>(root);
1087 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1088 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321089
danakje4fa7b72016-07-25 22:00:061090 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:321091 // The child height is zero, but has non-zero width that should be accounted
1092 // for while computing draw transforms.
danakje4fa7b72016-07-25 22:00:061093 child->SetBounds(gfx::Size(10, 0));
1094 child->test_properties()->force_render_surface = true;
1095 grand_child->SetBounds(gfx::Size(10, 10));
ennec1332992015-08-24 19:45:091096 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321097
chrishtr7e3aaf22017-05-04 15:04:011098 ASSERT_TRUE(GetRenderSurface(child));
[email protected]fb661802013-03-25 01:59:321099 // This is the real test, the rest are sanity checks.
danakje4fa7b72016-07-25 22:00:061100 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011101 GetRenderSurface(child)->draw_transform());
danakje4fa7b72016-07-25 22:00:061102 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1103 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441104 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321105}
1106
jaydasika9bbee9b2016-01-13 00:36:481107TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
jaydasikabf1875a2016-06-28 03:39:591108 LayerImpl* root = root_layer_for_testing();
jaydasika9bbee9b2016-01-13 00:36:481109 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1110 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1111 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1112
jaydasika9bbee9b2016-01-13 00:36:481113 gfx::Transform translate;
1114 translate.Translate3d(5, 5, 5);
danakje4fa7b72016-07-25 22:00:061115
1116 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041117 render_surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061118 render_surface->SetBounds(gfx::Size(100, 100));
1119 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041120 child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061121 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041122 grand_child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061123 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika9bbee9b2016-01-13 00:36:481124 grand_child->SetDrawsContent(true);
1125
1126 // render_surface will have a sublayer scale because of device scale factor.
1127 float device_scale_factor = 2.0f;
ajumab784ef42017-04-28 23:01:521128 RenderSurfaceList render_surface_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481129 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521130 root, root->bounds(), translate, &render_surface_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481131 inputs.device_scale_factor = device_scale_factor;
1132 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571133 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481134
1135 // Between grand_child and render_surface, we translate by (10, 10) and scale
1136 // by a factor of 2.
1137 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1138 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1139 expected_translation);
1140}
1141
[email protected]989386c2013-07-18 21:37:231142TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321143 // Transformations applied at the root of the tree should be forwarded
1144 // to child layers instead of applied to the root RenderSurface.
jaydasikabf1875a2016-06-28 03:39:591145 LayerImpl* root = root_layer_for_testing();
enned3f61fb02015-08-18 22:54:391146 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061147
1148 root->SetDrawsContent(true);
jaydasikab874eddc2016-11-02 22:34:281149 root->SetBounds(gfx::Size(100, 100));
enned3f61fb02015-08-18 22:54:391150 child->SetDrawsContent(true);
jaydasikab874eddc2016-11-02 22:34:281151 child->SetBounds(gfx::Size(100, 100));
1152 child->SetMasksToBounds(true);
[email protected]f224cc92013-06-06 23:23:321153
[email protected]f224cc92013-06-06 23:23:321154 gfx::Transform translate;
1155 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231156 {
ajumab784ef42017-04-28 23:01:521157 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391158 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521159 root, root->bounds(), translate, &render_surface_list_impl);
vollick5057e1e2015-04-17 19:12:321160 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571161 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021162 EXPECT_TRANSFORMATION_MATRIX_EQ(
1163 translate, root->draw_properties().target_space_transform);
1164 EXPECT_TRANSFORMATION_MATRIX_EQ(
1165 translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151166 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011167 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281168 EXPECT_TRANSFORMATION_MATRIX_EQ(translate, child->ScreenSpaceTransform());
1169 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231170 }
[email protected]f224cc92013-06-06 23:23:321171
1172 gfx::Transform scale;
1173 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231174 {
ajumab784ef42017-04-28 23:01:521175 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391176 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521177 root, root->bounds(), scale, &render_surface_list_impl);
vollick5057e1e2015-04-17 19:12:321178 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571179 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021180 EXPECT_TRANSFORMATION_MATRIX_EQ(
1181 scale, root->draw_properties().target_space_transform);
1182 EXPECT_TRANSFORMATION_MATRIX_EQ(
1183 scale, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151184 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011185 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281186 EXPECT_TRANSFORMATION_MATRIX_EQ(scale, child->ScreenSpaceTransform());
1187 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231188 }
[email protected]f224cc92013-06-06 23:23:321189
1190 gfx::Transform rotate;
1191 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231192 {
ajumab784ef42017-04-28 23:01:521193 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391194 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521195 root, root->bounds(), rotate, &render_surface_list_impl);
vollick5057e1e2015-04-17 19:12:321196 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571197 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021198 EXPECT_TRANSFORMATION_MATRIX_EQ(
1199 rotate, root->draw_properties().target_space_transform);
1200 EXPECT_TRANSFORMATION_MATRIX_EQ(
1201 rotate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151202 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011203 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281204 EXPECT_TRANSFORMATION_MATRIX_EQ(rotate, child->ScreenSpaceTransform());
1205 EXPECT_EQ(gfx::Rect(-4, 0, 104, 104), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231206 }
[email protected]f224cc92013-06-06 23:23:321207
1208 gfx::Transform composite;
1209 composite.ConcatTransform(translate);
1210 composite.ConcatTransform(scale);
1211 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231212 {
ajumab784ef42017-04-28 23:01:521213 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391214 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521215 root, root->bounds(), composite, &render_surface_list_impl);
vollick5057e1e2015-04-17 19:12:321216 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571217 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021218 EXPECT_TRANSFORMATION_MATRIX_EQ(
1219 composite, root->draw_properties().target_space_transform);
1220 EXPECT_TRANSFORMATION_MATRIX_EQ(
1221 composite, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151222 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011223 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281224 EXPECT_TRANSFORMATION_MATRIX_EQ(composite, child->ScreenSpaceTransform());
1225 EXPECT_EQ(gfx::Rect(89, 103, 208, 208), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231226 }
[email protected]f224cc92013-06-06 23:23:321227
[email protected]9781afa2013-07-17 23:15:321228 // Verify it composes correctly with device scale.
1229 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231230
1231 {
ajumab784ef42017-04-28 23:01:521232 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391233 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521234 root, root->bounds(), translate, &render_surface_list_impl);
[email protected]7aad55f2013-07-26 11:25:531235 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321236 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571237 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231238 gfx::Transform device_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101239 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
weiliangcc3517722016-06-28 22:52:021240 EXPECT_TRANSFORMATION_MATRIX_EQ(
1241 device_scaled_translate,
1242 root->draw_properties().target_space_transform);
1243 EXPECT_TRANSFORMATION_MATRIX_EQ(
1244 device_scaled_translate,
1245 child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151246 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011247 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281248 EXPECT_TRANSFORMATION_MATRIX_EQ(device_scaled_translate,
1249 child->ScreenSpaceTransform());
1250 EXPECT_EQ(gfx::Rect(50, 50, 150, 150), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231251 }
[email protected]9781afa2013-07-17 23:15:321252
1253 // Verify it composes correctly with page scale.
1254 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231255
1256 {
ajumab784ef42017-04-28 23:01:521257 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391258 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521259 root, root->bounds(), translate, &render_surface_list_impl);
[email protected]7aad55f2013-07-26 11:25:531260 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391261 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321262 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571263 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231264 gfx::Transform page_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101265 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
weiliangcc3517722016-06-28 22:52:021266 EXPECT_TRANSFORMATION_MATRIX_EQ(
1267 page_scaled_translate, root->draw_properties().target_space_transform);
1268 EXPECT_TRANSFORMATION_MATRIX_EQ(
1269 page_scaled_translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151270 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011271 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281272 EXPECT_TRANSFORMATION_MATRIX_EQ(page_scaled_translate,
1273 child->ScreenSpaceTransform());
1274 EXPECT_EQ(gfx::Rect(50, 50, 200, 200), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231275 }
[email protected]9781afa2013-07-17 23:15:321276
[email protected]f224cc92013-06-06 23:23:321277 // Verify that it composes correctly with transforms directly on root layer.
jaydasika10d43fc2016-08-18 04:06:041278 root->test_properties()->transform = composite;
[email protected]989386c2013-07-18 21:37:231279
1280 {
ajumab784ef42017-04-28 23:01:521281 RenderSurfaceList render_surface_list_impl;
enned3f61fb02015-08-18 22:54:391282 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521283 root, root->bounds(), composite, &render_surface_list_impl);
enned3f61fb02015-08-18 22:54:391284 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571285 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231286 gfx::Transform compositeSquared = composite;
1287 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261288 EXPECT_TRANSFORMATION_MATRIX_EQ(
1289 compositeSquared, root->draw_properties().target_space_transform);
1290 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391291 compositeSquared, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151292 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:011293 GetRenderSurface(root)->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281294 EXPECT_TRANSFORMATION_MATRIX_EQ(compositeSquared,
1295 child->ScreenSpaceTransform());
1296 EXPECT_EQ(gfx::Rect(254, 316, 428, 428), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231297 }
[email protected]f224cc92013-06-06 23:23:321298}
1299
jaydasika2cde7b512017-05-16 23:45:571300TEST_F(LayerTreeHostCommonTest, RenderSurfaceForNonAxisAlignedClipping) {
1301 LayerImpl* root = root_layer_for_testing();
1302 LayerImpl* rotated_and_transparent = AddChildToRoot<LayerImpl>();
1303 LayerImpl* clips_subtree = AddChild<LayerImpl>(rotated_and_transparent);
1304 LayerImpl* draws_content = AddChild<LayerImpl>(clips_subtree);
1305
1306 root->SetBounds(gfx::Size(10, 10));
1307 rotated_and_transparent->SetBounds(gfx::Size(10, 10));
1308 rotated_and_transparent->test_properties()->opacity = 0.5f;
1309 gfx::Transform rotate;
1310 rotate.Rotate(2);
1311 rotated_and_transparent->test_properties()->transform = rotate;
1312 clips_subtree->SetBounds(gfx::Size(10, 10));
1313 clips_subtree->SetMasksToBounds(true);
1314 draws_content->SetBounds(gfx::Size(10, 10));
1315 draws_content->SetDrawsContent(true);
1316
1317 ExecuteCalculateDrawProperties(root);
1318 EffectTree& effect_tree =
1319 root->layer_tree_impl()->property_trees()->effect_tree;
1320 EffectNode* node = effect_tree.Node(clips_subtree->effect_tree_index());
1321 EXPECT_TRUE(node->has_render_surface);
1322}
1323
jaydasikafbc951d2017-05-24 04:22:521324TEST_F(LayerTreeHostCommonTest, EffectNodesForNonAxisAlignedClips) {
1325 LayerImpl* root = root_layer_for_testing();
1326 LayerImpl* rotate_and_clip = AddChildToRoot<LayerImpl>();
1327 LayerImpl* only_clip = AddChild<LayerImpl>(rotate_and_clip);
1328 LayerImpl* rotate_and_clip2 = AddChild<LayerImpl>(only_clip);
1329
1330 gfx::Transform rotate;
1331 rotate.Rotate(2);
1332 root->SetBounds(gfx::Size(10, 10));
1333 rotate_and_clip->SetBounds(gfx::Size(10, 10));
1334 rotate_and_clip->test_properties()->transform = rotate;
1335 rotate_and_clip->SetMasksToBounds(true);
1336 only_clip->SetBounds(gfx::Size(10, 10));
1337 only_clip->SetMasksToBounds(true);
1338 rotate_and_clip2->SetBounds(gfx::Size(10, 10));
1339 rotate_and_clip2->test_properties()->transform = rotate;
1340 rotate_and_clip2->SetMasksToBounds(true);
1341
1342 ExecuteCalculateDrawProperties(root);
1343 // non-axis aligned clip should create an effect node
1344 EXPECT_NE(root->effect_tree_index(), rotate_and_clip->effect_tree_index());
1345 // Since only_clip's clip is in the same non-axis aligned space as
1346 // rotate_and_clip's clip, no new effect node should be created.
1347 EXPECT_EQ(rotate_and_clip->effect_tree_index(),
1348 only_clip->effect_tree_index());
1349 // rotate_and_clip2's clip and only_clip's clip are in different non-axis
1350 // aligned spaces. So, new effect node should be created.
1351 EXPECT_NE(rotate_and_clip2->effect_tree_index(),
1352 only_clip->effect_tree_index());
1353}
1354
[email protected]989386c2013-07-18 21:37:231355TEST_F(LayerTreeHostCommonTest,
1356 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
danakje4fa7b72016-07-25 22:00:061357 LayerImpl* root = root_layer_for_testing();
enneea850232015-07-27 16:43:121358 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1359 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
danakje4fa7b72016-07-25 22:00:061360
1361 root->SetBounds(gfx::Size(10, 10));
1362 root->SetMasksToBounds(true);
1363 render_surface1->SetBounds(gfx::Size(10, 10));
1364 render_surface1->test_properties()->force_render_surface = true;
enneea850232015-07-27 16:43:121365 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061366 child->SetPosition(gfx::PointF(30.f, 30.f));
1367 child->SetBounds(gfx::Size(10, 10));
1368 ExecuteCalculateDrawProperties(root);
[email protected]d600df7d2013-08-03 02:34:281369
danakje4fa7b72016-07-25 22:00:061370 // The child layer's content is entirely outside the root's clip rect, so
[email protected]fb661802013-03-25 01:59:321371 // the intermediate render surface should not be listed here, even if it was
1372 // forced to be created. Render surfaces without children or visible content
1373 // are unexpected at draw time (e.g. we might try to create a content texture
1374 // of size 0).
chrishtr7e3aaf22017-05-04 15:04:011375 ASSERT_TRUE(GetRenderSurface(root));
ajumab784ef42017-04-28 23:01:521376 EXPECT_EQ(1U, render_surface_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321377}
1378
[email protected]989386c2013-07-18 21:37:231379TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
danakje4fa7b72016-07-25 22:00:061380 LayerImpl* root = root_layer_for_testing();
1381 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
enne03b0e9a2015-06-19 00:08:021382 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
[email protected]d600df7d2013-08-03 02:34:281383
danakje4fa7b72016-07-25 22:00:061384 render_surface1->SetBounds(gfx::Size(10, 10));
1385 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181386 render_surface1->test_properties()->opacity = 0.f;
danakje4fa7b72016-07-25 22:00:061387 child->SetBounds(gfx::Size(10, 10));
1388 child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321389
ajumab784ef42017-04-28 23:01:521390 RenderSurfaceList render_surface_list;
enne03b0e9a2015-06-19 00:08:021391 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521392 root, root->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:531393 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571394 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321395
ajumaac2d30792017-02-24 23:00:311396 // Since the layer is transparent, render_surface1->GetRenderSurface() should
[email protected]fb661802013-03-25 01:59:321397 // not have gotten added anywhere. Also, the drawable content rect should not
1398 // have been extended by the children.
chrishtr7e3aaf22017-05-04 15:04:011399 ASSERT_TRUE(GetRenderSurface(root));
1400 EXPECT_EQ(0, GetRenderSurface(root)->num_contributors());
ajumab784ef42017-04-28 23:01:521401 EXPECT_EQ(1U, render_surface_list.size());
Chris Harrelson9bdbcce2017-06-02 03:12:141402 EXPECT_EQ(static_cast<RenderPassId>(root->id()),
1403 render_surface_list.at(0)->id());
danakje4fa7b72016-07-25 22:00:061404 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321405}
1406
hendrikwc266f7b2015-08-21 23:41:341407TEST_F(LayerTreeHostCommonTest,
1408 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
danakje4fa7b72016-07-25 22:00:061409 LayerImpl* root = root_layer_for_testing();
1410 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
hendrikwc266f7b2015-08-21 23:41:341411 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
hendrikwc266f7b2015-08-21 23:41:341412
danakje4fa7b72016-07-25 22:00:061413 root->SetBounds(gfx::Size(10, 10));
1414 render_surface1->SetBounds(gfx::Size(10, 10));
1415 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181416 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071417 render_surface1->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341418 FilterOperations filters;
1419 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
ajuma50bce7e2016-06-24 20:56:041420 render_surface1->test_properties()->background_filters = filters;
danakje4fa7b72016-07-25 22:00:061421 child->SetBounds(gfx::Size(10, 10));
1422 child->SetDrawsContent(true);
weiliangcea09f3372017-03-29 16:43:241423 root->layer_tree_impl()->SetElementIdsForTesting();
hendrikwc266f7b2015-08-21 23:41:341424
jaydasika369c24b2016-04-06 23:44:161425 {
ajumab784ef42017-04-28 23:01:521426 RenderSurfaceList render_surface_list;
jaydasika369c24b2016-04-06 23:44:161427 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521428 root, root->bounds(), &render_surface_list);
jaydasika369c24b2016-04-06 23:44:161429 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571430 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
ajumab784ef42017-04-28 23:01:521431 EXPECT_EQ(2U, render_surface_list.size());
jaydasika369c24b2016-04-06 23:44:161432 }
hendrikwc266f7b2015-08-21 23:41:341433 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161434 // shouldn't be skipped and should be drawn.
chrishtr7e3aaf22017-05-04 15:04:011435 ASSERT_TRUE(GetRenderSurface(root));
1436 EXPECT_EQ(1, GetRenderSurface(root)->num_contributors());
jaydasika8640f9f2015-11-10 01:34:361437 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
chrishtr7e3aaf22017-05-04 15:04:011438 GetRenderSurface(root)->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161439 EffectTree& effect_tree =
danakje4fa7b72016-07-25 22:00:061440 root->layer_tree_impl()->property_trees()->effect_tree;
jaydasika369c24b2016-04-06 23:44:161441 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011442 EXPECT_TRUE(node->is_drawn);
jaydasika369c24b2016-04-06 23:44:161443
danakje4fa7b72016-07-25 22:00:061444 // When root is transparent, the layer should not be drawn.
weiliangcea09f3372017-03-29 16:43:241445 root->layer_tree_impl()->SetOpacityMutated(root->element_id(), 0.f);
1446 root->layer_tree_impl()->SetOpacityMutated(render_surface1->element_id(),
1447 1.f);
jaydasika8185d302016-04-14 15:20:061448 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161449 {
ajumab784ef42017-04-28 23:01:521450 RenderSurfaceList render_surface_list;
jaydasika369c24b2016-04-06 23:44:161451 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521452 root, root->bounds(), &render_surface_list);
jaydasika369c24b2016-04-06 23:44:161453 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571454 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161455 }
1456
1457 node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011458 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:061459 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341460}
1461
senorblanco38858c52016-01-20 23:15:001462TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
jaydasikabf1875a2016-06-28 03:39:591463 LayerImpl* root = root_layer_for_testing();
senorblanco38858c52016-01-20 23:15:001464 LayerImpl* parent = AddChild<LayerImpl>(root);
1465 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1466 LayerImpl* child2 = AddChild<LayerImpl>(parent);
senorblanco38858c52016-01-20 23:15:001467
senorblanco38858c52016-01-20 23:15:001468 gfx::Transform scale_matrix;
1469 scale_matrix.Scale(2.0f, 2.0f);
danakje4fa7b72016-07-25 22:00:061470
1471 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041472 parent->test_properties()->transform = scale_matrix;
senorblanco38858c52016-01-20 23:15:001473 FilterOperations filters;
1474 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
ajumacb2b74432016-07-21 19:11:151475 parent->test_properties()->filters = filters;
danakje4fa7b72016-07-25 22:00:061476 parent->test_properties()->force_render_surface = true;
1477 child1->SetBounds(gfx::Size(25, 25));
1478 child1->SetDrawsContent(true);
1479 child1->test_properties()->force_render_surface = true;
1480 child2->SetPosition(gfx::PointF(25, 25));
1481 child2->SetBounds(gfx::Size(25, 25));
1482 child2->SetDrawsContent(true);
1483 child2->test_properties()->force_render_surface = true;
senorblanco38858c52016-01-20 23:15:001484
ajumab784ef42017-04-28 23:01:521485 RenderSurfaceList render_surface_list;
senorblanco38858c52016-01-20 23:15:001486 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:521487 root, root->bounds(), &render_surface_list);
senorblanco38858c52016-01-20 23:15:001488 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571489 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001490
chrishtr7e3aaf22017-05-04 15:04:011491 ASSERT_TRUE(GetRenderSurface(parent));
1492 EXPECT_EQ(2, GetRenderSurface(parent)->num_contributors());
ajumab784ef42017-04-28 23:01:521493 EXPECT_EQ(4U, render_surface_list.size());
jbroman1c44d5b52016-06-06 21:19:301494
1495 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1496 // blur (-30,-30 110x110), and then scaled by the scale matrix
1497 // (-60,-60 220x220).
1498 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
chrishtr7e3aaf22017-05-04 15:04:011499 GetRenderSurface(parent)->DrawableContentRect());
senorblanco38858c52016-01-20 23:15:001500}
1501
jbroman1c44d5b52016-06-06 21:19:301502TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
jaydasikabf1875a2016-06-28 03:39:591503 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301504 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061505
1506 root->SetBounds(gfx::Size(100, 100));
1507 child->SetBounds(gfx::Size(25, 25));
jbroman1c44d5b52016-06-06 21:19:301508 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061509 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301510 FilterOperations filters;
1511 filters.Append(FilterOperation::CreateReferenceFilter(
1512 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151513 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301514 ExecuteCalculateDrawProperties(root);
1515
1516 // The render surface's size should be unaffected by the offset image filter;
1517 // it need only have a drawable content rect large enough to contain the
1518 // contents (at the new offset).
chrishtr7e3aaf22017-05-04 15:04:011519 ASSERT_TRUE(GetRenderSurface(child));
jbroman1c44d5b52016-06-06 21:19:301520 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
chrishtr7e3aaf22017-05-04 15:04:011521 GetRenderSurface(child)->DrawableContentRect());
jbroman1c44d5b52016-06-06 21:19:301522}
1523
1524TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1525 const float device_scale_factor = 2.0f;
1526
jaydasikabf1875a2016-06-28 03:39:591527 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301528 LayerImpl* child = AddChild<LayerImpl>(root);
jbroman1c44d5b52016-06-06 21:19:301529
danakje4fa7b72016-07-25 22:00:061530 root->SetBounds(gfx::Size(100, 100));
1531 child->SetBounds(gfx::Size(25, 25));
1532 child->SetDrawsContent(true);
1533 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301534
1535 FilterOperations filters;
1536 filters.Append(FilterOperation::CreateReferenceFilter(
1537 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151538 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301539
1540 ExecuteCalculateDrawProperties(root, device_scale_factor);
1541
1542 // The render surface's size should be unaffected by the offset image filter;
1543 // it need only have a drawable content rect large enough to contain the
1544 // contents (at the new offset). All coordinates should be scaled by 2,
1545 // corresponding to the device scale factor.
chrishtr7e3aaf22017-05-04 15:04:011546 ASSERT_TRUE(GetRenderSurface(child));
jbroman1c44d5b52016-06-06 21:19:301547 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
chrishtr7e3aaf22017-05-04 15:04:011548 GetRenderSurface(child)->DrawableContentRect());
jbroman1c44d5b52016-06-06 21:19:301549}
1550
rosca948d29d2014-11-09 10:25:131551TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
danakje4fa7b72016-07-25 22:00:061552 LayerImpl* root = root_layer_for_testing();
1553 LayerImpl* child = AddChild<LayerImpl>(root);
1554
1555 root->SetBounds(gfx::Size(10, 10));
1556 child->SetBounds(gfx::Size(10, 10));
enned5f4ddd2015-08-18 16:50:061557 child->SetDrawsContent(true);
reedcc9c70f2016-11-22 04:26:011558 child->test_properties()->blend_mode = SkBlendMode::kMultiply;
jaydasikaab317e02016-06-01 00:53:181559 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061560 child->test_properties()->force_render_surface = true;
1561 ExecuteCalculateDrawProperties(root);
rosca948d29d2014-11-09 10:25:131562
1563 // Since the child layer has a blend mode other than normal, it should get
jaydasika815ffdb82017-04-10 18:19:461564 // its own render surface.
chrishtr7e3aaf22017-05-04 15:04:011565 ASSERT_TRUE(GetRenderSurface(child));
weiliangc451b818f2015-07-24 17:52:291566 EXPECT_EQ(1.0f, child->draw_opacity());
chrishtr7e3aaf22017-05-04 15:04:011567 EXPECT_EQ(0.5f, GetRenderSurface(child)->draw_opacity());
1568 EXPECT_EQ(SkBlendMode::kMultiply, GetRenderSurface(child)->BlendMode());
rosca948d29d2014-11-09 10:25:131569}
1570
jaydasikafbdb86e2016-01-21 18:57:511571TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
jaydasikabf1875a2016-06-28 03:39:591572 LayerImpl* root = root_layer_for_testing();
jaydasikafbdb86e2016-01-21 18:57:511573 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1574 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1575 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1576
danakje4fa7b72016-07-25 22:00:061577 root->SetBounds(gfx::Size(10, 10));
1578 surface1->SetBounds(gfx::Size(10, 10));
jaydasikafbdb86e2016-01-21 18:57:511579 surface1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181580 surface1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061581 surface1->test_properties()->force_render_surface = true;
1582 not_surface->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:181583 not_surface->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061584 surface2->SetBounds(gfx::Size(10, 10));
1585 surface2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181586 surface2->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061587 surface2->test_properties()->force_render_surface = true;
jaydasikafbdb86e2016-01-21 18:57:511588 ExecuteCalculateDrawProperties(root);
1589
chrishtr7e3aaf22017-05-04 15:04:011590 ASSERT_TRUE(GetRenderSurface(surface1));
chrishtr5f60ca02017-05-11 23:09:491591 ASSERT_EQ(GetRenderSurface(not_surface), GetRenderSurface(surface1));
chrishtr7e3aaf22017-05-04 15:04:011592 ASSERT_TRUE(GetRenderSurface(surface2));
1593 EXPECT_EQ(0.5f, GetRenderSurface(surface1)->draw_opacity());
jaydasikafbdb86e2016-01-21 18:57:511594 // surface2's draw opacity should include the opacity of not-surface and
1595 // itself, but not the opacity of surface1.
chrishtr7e3aaf22017-05-04 15:04:011596 EXPECT_EQ(0.25f, GetRenderSurface(surface2)->draw_opacity());
jaydasikafbdb86e2016-01-21 18:57:511597}
1598
[email protected]989386c2013-07-18 21:37:231599TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
danakje4fa7b72016-07-25 22:00:061600 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:261601 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1602 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261603
danakje4fa7b72016-07-25 22:00:061604 root->SetBounds(gfx::Size(10, 10));
1605 render_surface1->SetBounds(gfx::Size(10, 10));
jaydasika6b5a32bf2016-04-22 21:56:361606 render_surface1->test_properties()->force_render_surface = true;
danakje4fa7b72016-07-25 22:00:061607 child->SetBounds(gfx::Size(10, 10));
1608 child->SetDrawsContent(true);
weiliangceffae0462015-12-08 23:17:261609
[email protected]989386c2013-07-18 21:37:231610 {
jaydasika6ed869662016-09-21 14:29:591611 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:321612
[email protected]989386c2013-07-18 21:37:231613 // The root layer always creates a render surface
chrishtr7e3aaf22017-05-04 15:04:011614 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:491615 EXPECT_NE(GetRenderSurface(render_surface1), GetRenderSurface(root));
[email protected]989386c2013-07-18 21:37:231616 }
[email protected]fb661802013-03-25 01:59:321617
[email protected]989386c2013-07-18 21:37:231618 {
jaydasika6b5a32bf2016-04-22 21:56:361619 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261620 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:591621 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
chrishtr7e3aaf22017-05-04 15:04:011622 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:491623 EXPECT_EQ(GetRenderSurface(render_surface1), GetRenderSurface(root));
[email protected]989386c2013-07-18 21:37:231624 }
[email protected]fb661802013-03-25 01:59:321625}
1626
ajuma246190a2015-03-11 20:56:031627TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1628 // Render surfaces act as a flattening point for their subtree, so should
1629 // always flatten the target-to-screen space transform seen by descendants.
jaydasikabf1875a2016-06-28 03:39:591630 LayerImpl* root = root_layer_for_testing();
enne1a79c5542015-08-18 19:43:571631 LayerImpl* parent = AddChild<LayerImpl>(root);
1632 LayerImpl* child = AddChild<LayerImpl>(parent);
1633 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1634
ajuma246190a2015-03-11 20:56:031635 gfx::Transform rotation_about_y_axis;
1636 rotation_about_y_axis.RotateAboutYAxis(30.0);
ajuma246190a2015-03-11 20:56:031637
danakje4fa7b72016-07-25 22:00:061638 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041639 parent->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061640 parent->SetBounds(gfx::Size(10, 10));
1641 parent->test_properties()->force_render_surface = true;
1642 child->SetBounds(gfx::Size(10, 10));
1643 child->SetDrawsContent(true);
1644 grand_child->SetBounds(gfx::Size(10, 10));
1645 grand_child->SetDrawsContent(true);
jaydasikaca2605e2016-04-23 02:52:521646 grand_child->test_properties()->should_flatten_transform = false;
enne1a79c5542015-08-18 19:43:571647 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031648
chrishtr7e3aaf22017-05-04 15:04:011649 EXPECT_TRUE(GetRenderSurface(parent));
chrishtr5f60ca02017-05-11 23:09:491650 EXPECT_EQ(GetRenderSurface(child), GetRenderSurface(parent));
1651 EXPECT_EQ(GetRenderSurface(grand_child), GetRenderSurface(parent));
ajuma246190a2015-03-11 20:56:031652
danakje4fa7b72016-07-25 22:00:061653 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1654 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441655 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031656
1657 // The screen-space transform inherited by |child| and |grand_child| should
1658 // have been flattened at their render target. In particular, the fact that
1659 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
danakje4fa7b72016-07-25 22:00:061660 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1661 flattened_rotation_about_y.FlattenTo2d();
ajuma246190a2015-03-11 20:56:031662 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101663 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031664 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101665 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031666}
1667
[email protected]989386c2013-07-18 21:37:231668TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321669 // The entire subtree of layers that are outside the clip rect should be
ajumab784ef42017-04-28 23:01:521670 // culled away, and should not affect the render_surface_list.
[email protected]fb661802013-03-25 01:59:321671 //
1672 // The test tree is set up as follows:
1673 // - all layers except the leaf_nodes are forced to be a new render surface
1674 // that have something to draw.
1675 // - parent is a large container layer.
danakje4fa7b72016-07-25 22:00:061676 // - child has MasksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321677 // - grand_child is positioned outside of the child's bounds
1678 // - great_grand_child is also kept outside child's bounds.
1679 //
1680 // In this configuration, grand_child and great_grand_child are completely
1681 // outside the clip rect, and they should never get scheduled on the list of
1682 // render surfaces.
[email protected]fb661802013-03-25 01:59:321683
danakje4fa7b72016-07-25 22:00:061684 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571685 LayerImpl* child = AddChildToRoot<LayerImpl>();
1686 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1687 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281688
ajumab784ef42017-04-28 23:01:521689 // leaf_node1 ensures that root and child are kept on the render_surface_list,
1690 // even though grand_child and great_grand_child should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571691 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
weiliangcfb3d5eaa2015-07-28 23:54:571692 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
[email protected]fb661802013-03-25 01:59:321693
danakje4fa7b72016-07-25 22:00:061694 root->SetBounds(gfx::Size(500, 500));
1695 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321696 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061697 child->test_properties()->force_render_surface = true;
1698 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1699 grand_child->SetBounds(gfx::Size(10, 10));
1700 great_grand_child->SetBounds(gfx::Size(10, 10));
1701 leaf_node1->SetBounds(gfx::Size(500, 500));
1702 leaf_node1->SetDrawsContent(true);
1703 leaf_node1->SetBounds(gfx::Size(20, 20));
1704 leaf_node2->SetDrawsContent(true);
1705 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321706
ajumab784ef42017-04-28 23:01:521707 ASSERT_EQ(2U, render_surface_list_impl()->size());
Chris Harrelson9bdbcce2017-06-02 03:12:141708 EXPECT_EQ(static_cast<uint64_t>(root->id()),
1709 render_surface_list_impl()->at(0)->id());
1710 EXPECT_EQ(static_cast<uint64_t>(child->id()),
1711 render_surface_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321712}
1713
[email protected]989386c2013-07-18 21:37:231714TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321715 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571716 // of the surface.
[email protected]fb661802013-03-25 01:59:321717
1718 // The test tree is set up as follows:
danakje4fa7b72016-07-25 22:00:061719 // - root is a container layer that masksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321720 // - child is a render surface, which has a clip rect set to the bounds of
danakje4fa7b72016-07-25 22:00:061721 // the root.
[email protected]fb661802013-03-25 01:59:321722 // - grand_child is a render surface, and the only visible content in child.
danakje4fa7b72016-07-25 22:00:061723 // It is positioned outside of the clip rect from root.
[email protected]fb661802013-03-25 01:59:321724
1725 // In this configuration, grand_child should be outside the clipped
1726 // content rect of the child, making grand_child not appear in the
ajumab784ef42017-04-28 23:01:521727 // render_surface_list.
weiliangcfb3d5eaa2015-07-28 23:54:571728
danakje4fa7b72016-07-25 22:00:061729 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571730 LayerImpl* child = AddChildToRoot<LayerImpl>();
1731 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1732 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
[email protected]fb661802013-03-25 01:59:321733
danakje4fa7b72016-07-25 22:00:061734 root->SetMasksToBounds(true);
1735 root->SetBounds(gfx::Size(100, 100));
1736 child->SetBounds(gfx::Size(20, 20));
1737 child->test_properties()->force_render_surface = true;
1738 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1739 grand_child->SetBounds(gfx::Size(10, 10));
1740 grand_child->test_properties()->force_render_surface = true;
1741 leaf_node->SetBounds(gfx::Size(10, 10));
1742 leaf_node->SetDrawsContent(true);
1743 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321744
weiliangcfb3d5eaa2015-07-28 23:54:571745 // We should cull child and grand_child from the
ajumab784ef42017-04-28 23:01:521746 // render_surface_list.
1747 ASSERT_EQ(1U, render_surface_list_impl()->size());
Chris Harrelson9bdbcce2017-06-02 03:12:141748 EXPECT_EQ(static_cast<uint64_t>(root->id()),
1749 render_surface_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321750}
1751
ajumae2b7a5c2015-09-30 21:41:421752TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1753 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321754 // - the layer clips its subtree, e.g. masks to bounds,
1755 // - the layer is clipped by an ancestor that contributes to the same
1756 // render target,
1757 // - a surface is clipped by an ancestor that contributes to the same
1758 // render target.
1759 //
1760 // In particular, for a layer that owns a render surface:
1761 // - the render surface inherits any clip from ancestors, and does NOT
1762 // pass that clipped status to the layer itself.
1763 // - but if the layer itself masks to bounds, it is considered clipped
1764 // and propagates the clip to the subtree.
1765
jaydasikabf1875a2016-06-28 03:39:591766 LayerImpl* root = root_layer_for_testing();
enne76bf8982015-08-18 17:55:331767 LayerImpl* parent = AddChild<LayerImpl>(root);
1768 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1769 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1770 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1771 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
enne76bf8982015-08-18 17:55:331772 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
enne76bf8982015-08-18 17:55:331773
danakje4fa7b72016-07-25 22:00:061774 root->SetBounds(gfx::Size(100, 100));
1775 parent->SetBounds(gfx::Size(100, 100));
1776 parent->SetDrawsContent(true);
1777 child1->SetBounds(gfx::Size(100, 100));
1778 child1->SetDrawsContent(true);
1779 child2->SetBounds(gfx::Size(100, 100));
1780 child2->SetDrawsContent(true);
1781 child2->test_properties()->force_render_surface = true;
1782 grand_child->SetBounds(gfx::Size(100, 100));
1783 grand_child->SetDrawsContent(true);
1784 leaf_node1->SetBounds(gfx::Size(100, 100));
1785 leaf_node1->SetDrawsContent(true);
1786 leaf_node2->SetBounds(gfx::Size(100, 100));
1787 leaf_node2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331788
1789 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521790 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331791
chrishtr7e3aaf22017-05-04 15:04:011792 ASSERT_TRUE(GetRenderSurface(root));
1793 ASSERT_TRUE(GetRenderSurface(child2));
enne76bf8982015-08-18 17:55:331794
weiliangce3f09a612016-03-16 17:02:521795 EXPECT_FALSE(root->is_clipped());
chrishtr7e3aaf22017-05-04 15:04:011796 EXPECT_TRUE(GetRenderSurface(root)->is_clipped());
weiliangce3f09a612016-03-16 17:02:521797 EXPECT_FALSE(parent->is_clipped());
1798 EXPECT_FALSE(child1->is_clipped());
1799 EXPECT_FALSE(child2->is_clipped());
chrishtr7e3aaf22017-05-04 15:04:011800 EXPECT_FALSE(GetRenderSurface(child2)->is_clipped());
weiliangce3f09a612016-03-16 17:02:521801 EXPECT_FALSE(grand_child->is_clipped());
1802 EXPECT_FALSE(leaf_node1->is_clipped());
1803 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331804
danakje4fa7b72016-07-25 22:00:061805 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
enne76bf8982015-08-18 17:55:331806 // surface are clipped. But layers that contribute to child2's surface are
1807 // not clipped explicitly because child2's surface already accounts for
1808 // that clip.
weiliangce3f09a612016-03-16 17:02:521809 parent->SetMasksToBounds(true);
1810 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331811
weiliangce3f09a612016-03-16 17:02:521812 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331813
chrishtr7e3aaf22017-05-04 15:04:011814 ASSERT_TRUE(GetRenderSurface(root));
1815 ASSERT_TRUE(GetRenderSurface(child2));
enne76bf8982015-08-18 17:55:331816
weiliangce3f09a612016-03-16 17:02:521817 EXPECT_FALSE(root->is_clipped());
chrishtr7e3aaf22017-05-04 15:04:011818 EXPECT_TRUE(GetRenderSurface(root)->is_clipped());
weiliangce3f09a612016-03-16 17:02:521819 EXPECT_TRUE(parent->is_clipped());
1820 EXPECT_TRUE(child1->is_clipped());
1821 EXPECT_FALSE(child2->is_clipped());
chrishtr7e3aaf22017-05-04 15:04:011822 EXPECT_TRUE(GetRenderSurface(child2)->is_clipped());
weiliangce3f09a612016-03-16 17:02:521823 EXPECT_TRUE(grand_child->is_clipped());
1824 EXPECT_TRUE(leaf_node1->is_clipped());
1825 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331826
weiliangce3f09a612016-03-16 17:02:521827 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331828
danakje4fa7b72016-07-25 22:00:061829 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
enne76bf8982015-08-18 17:55:331830 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521831 child2->SetMasksToBounds(true);
1832 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331833
weiliangce3f09a612016-03-16 17:02:521834 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331835
chrishtr7e3aaf22017-05-04 15:04:011836 ASSERT_TRUE(GetRenderSurface(root));
1837 ASSERT_TRUE(GetRenderSurface(child2));
enne76bf8982015-08-18 17:55:331838
weiliangce3f09a612016-03-16 17:02:521839 EXPECT_FALSE(root->is_clipped());
chrishtr7e3aaf22017-05-04 15:04:011840 EXPECT_TRUE(GetRenderSurface(root)->is_clipped());
weiliangce3f09a612016-03-16 17:02:521841 EXPECT_FALSE(parent->is_clipped());
1842 EXPECT_FALSE(child1->is_clipped());
1843 EXPECT_TRUE(child2->is_clipped());
chrishtr7e3aaf22017-05-04 15:04:011844 EXPECT_FALSE(GetRenderSurface(child2)->is_clipped());
weiliangce3f09a612016-03-16 17:02:521845 EXPECT_FALSE(grand_child->is_clipped());
1846 EXPECT_FALSE(leaf_node1->is_clipped());
1847 EXPECT_TRUE(leaf_node2->is_clipped());
1848}
1849
1850TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1851 // Tests that when as long as layer is clipped, it's clip rect is set to
1852 // correct value.
jaydasikabf1875a2016-06-28 03:39:591853 LayerImpl* root = root_layer_for_testing();
weiliangce3f09a612016-03-16 17:02:521854 LayerImpl* parent = AddChild<LayerImpl>(root);
1855 LayerImpl* child = AddChild<LayerImpl>(parent);
1856
danakje4fa7b72016-07-25 22:00:061857 root->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521858 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061859 parent->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521860 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061861 child->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521862 child->SetDrawsContent(true);
weiliangce3f09a612016-03-16 17:02:521863 child->SetMasksToBounds(true);
1864
1865 ExecuteCalculateDrawProperties(root);
1866
1867 EXPECT_FALSE(root->is_clipped());
1868 EXPECT_FALSE(parent->is_clipped());
1869 EXPECT_TRUE(child->is_clipped());
1870 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1871
1872 parent->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061873 child->SetPosition(gfx::PointF(100.f, 100.f));
weiliangce3f09a612016-03-16 17:02:521874 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1875
1876 ExecuteCalculateDrawProperties(root);
1877
1878 EXPECT_FALSE(root->is_clipped());
1879 EXPECT_TRUE(parent->is_clipped());
1880 EXPECT_TRUE(child->is_clipped());
1881 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321882}
1883
[email protected]fd9a3b6d2013-08-03 00:46:171884TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321885 // Verify that layers get the appropriate DrawableContentRect when their
danakje4fa7b72016-07-25 22:00:061886 // parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:321887 //
1888 // grand_child1 - completely inside the region; DrawableContentRect should
1889 // be the layer rect expressed in target space.
danakje4fa7b72016-07-25 22:00:061890 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
[email protected]fb661802013-03-25 01:59:321891 // will be the intersection of layer bounds and the mask region.
danakje4fa7b72016-07-25 22:00:061892 // grand_child3 - partially clipped and MasksToBounds; the
[email protected]fb661802013-03-25 01:59:321893 // DrawableContentRect will still be the intersection of layer bounds and
1894 // the mask region.
1895 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1896 // be empty.
[email protected]fb661802013-03-25 01:59:321897
jaydasikabf1875a2016-06-28 03:39:591898 LayerImpl* parent = root_layer_for_testing();
enne07405c772015-08-18 17:56:451899 LayerImpl* child = AddChild<LayerImpl>(parent);
1900 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
1901 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
1902 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
1903 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:321904
danakje4fa7b72016-07-25 22:00:061905 parent->SetBounds(gfx::Size(500, 500));
[email protected]fb661802013-03-25 01:59:321906 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061907 child->SetBounds(gfx::Size(20, 20));
1908 child->test_properties()->force_render_surface = true;
1909 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
1910 grand_child1->SetBounds(gfx::Size(10, 10));
1911 grand_child1->SetDrawsContent(true);
1912 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
1913 grand_child2->SetBounds(gfx::Size(10, 10));
1914 grand_child2->SetDrawsContent(true);
1915 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
[email protected]fb661802013-03-25 01:59:321916 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061917 grand_child3->SetBounds(gfx::Size(10, 10));
1918 grand_child3->SetDrawsContent(true);
1919 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
1920 grand_child4->SetBounds(gfx::Size(10, 10));
1921 grand_child4->SetDrawsContent(true);
enne07405c772015-08-18 17:56:451922 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321923
hush6b614212014-12-04 22:37:321924 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
1925 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1926 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321927 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1928}
1929
[email protected]989386c2013-07-18 21:37:231930TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:321931 // Verify that render surfaces (and their layers) get the appropriate
danakje4fa7b72016-07-25 22:00:061932 // clip rects when their parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:321933 //
1934 // Layers that own render surfaces (at least for now) do not inherit any
1935 // clipping; instead the surface will enforce the clip for the entire subtree.
1936 // They may still have a clip rect of their own layer bounds, however, if
danakje4fa7b72016-07-25 22:00:061937 // MasksToBounds was true.
jaydasikabf1875a2016-06-28 03:39:591938 LayerImpl* parent = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571939 LayerImpl* child = AddChildToRoot<LayerImpl>();
1940 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
1941 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
1942 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
1943 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:061944 // The leaf nodes ensure that these grand_children become render surfaces for
[email protected]fb661802013-03-25 01:59:321945 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:571946 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
weiliangcfb3d5eaa2015-07-28 23:54:571947 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
weiliangcfb3d5eaa2015-07-28 23:54:571948 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
weiliangcfb3d5eaa2015-07-28 23:54:571949 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
[email protected]fb661802013-03-25 01:59:321950
danakje4fa7b72016-07-25 22:00:061951 parent->SetBounds(gfx::Size(500, 500));
1952 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321953 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061954 child->test_properties()->force_render_surface = true;
1955 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
1956 grand_child1->SetBounds(gfx::Size(10, 10));
1957 grand_child1->test_properties()->force_render_surface = true;
1958 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
1959 grand_child2->SetBounds(gfx::Size(10, 10));
1960 grand_child2->test_properties()->force_render_surface = true;
1961 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
1962 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:321963 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061964 grand_child3->test_properties()->force_render_surface = true;
1965 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
1966 grand_child4->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:321967 grand_child4->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061968 grand_child4->test_properties()->force_render_surface = true;
1969 leaf_node1->SetBounds(gfx::Size(10, 10));
1970 leaf_node1->SetDrawsContent(true);
1971 leaf_node2->SetBounds(gfx::Size(10, 10));
1972 leaf_node2->SetDrawsContent(true);
1973 leaf_node3->SetBounds(gfx::Size(10, 10));
1974 leaf_node3->SetDrawsContent(true);
1975 leaf_node4->SetBounds(gfx::Size(10, 10));
1976 leaf_node4->SetDrawsContent(true);
weiliangcfb3d5eaa2015-07-28 23:54:571977 ExecuteCalculateDrawProperties(parent);
1978
chrishtr7e3aaf22017-05-04 15:04:011979 ASSERT_TRUE(GetRenderSurface(grand_child1));
1980 ASSERT_TRUE(GetRenderSurface(grand_child2));
1981 ASSERT_TRUE(GetRenderSurface(grand_child3));
[email protected]fb661802013-03-25 01:59:321982
1983 // Surfaces are clipped by their parent, but un-affected by the owning layer's
danakje4fa7b72016-07-25 22:00:061984 // MasksToBounds.
hush6b614212014-12-04 22:37:321985 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
chrishtr7e3aaf22017-05-04 15:04:011986 GetRenderSurface(grand_child1)->clip_rect());
hush6b614212014-12-04 22:37:321987 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
chrishtr7e3aaf22017-05-04 15:04:011988 GetRenderSurface(grand_child2)->clip_rect());
hush6b614212014-12-04 22:37:321989 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
chrishtr7e3aaf22017-05-04 15:04:011990 GetRenderSurface(grand_child3)->clip_rect());
[email protected]fb661802013-03-25 01:59:321991}
1992
[email protected]989386c2013-07-18 21:37:231993TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
danakje4fa7b72016-07-25 22:00:061994 LayerImpl* root = root_layer_for_testing();
enneab0fee42015-07-07 17:36:421995 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1996 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
1997 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
1998 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
1999 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2000 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2001 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2002 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322003
danakje4fa7b72016-07-25 22:00:062004 root->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362005 render_surface1->SetDrawsContent(true);
2006 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422007 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362008 render_surface2->SetDrawsContent(true);
2009 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422010 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362011 child_of_root->SetDrawsContent(true);
2012 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322013
2014 gfx::Transform layer_transform;
2015 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322016
jaydasika10d43fc2016-08-18 04:06:042017 root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062018 root->SetPosition(gfx::PointF(2.5f, 0.f));
2019 root->SetBounds(gfx::Size(10, 10));
2020 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042021 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062022 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2023 render_surface1->SetBounds(gfx::Size(10, 10));
2024 render_surface1->test_properties()->transform_origin =
2025 gfx::Point3F(0.25f, 0.f, 0.f);
2026 render_surface1->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042027 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062028 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2029 render_surface2->SetBounds(gfx::Size(10, 10));
2030 render_surface2->test_properties()->transform_origin =
2031 gfx::Point3F(0.25f, 0.f, 0.f);
2032 render_surface2->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042033 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062034 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2035 child_of_root->SetBounds(gfx::Size(10, 10));
2036 child_of_root->test_properties()->transform_origin =
2037 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042038 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062039 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2040 child_of_rs1->SetBounds(gfx::Size(10, 10));
2041 child_of_rs1->test_properties()->transform_origin =
2042 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042043 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062044 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2045 child_of_rs2->SetBounds(gfx::Size(10, 10));
2046 child_of_rs2->test_properties()->transform_origin =
2047 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042048 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062049 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2050 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2051 grand_child_of_root->test_properties()->transform_origin =
2052 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042053 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062054 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2055 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2056 grand_child_of_rs1->test_properties()->transform_origin =
2057 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042058 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062059 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2060 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2061 grand_child_of_rs2->test_properties()->transform_origin =
2062 gfx::Point3F(0.25f, 0.f, 0.f);
[email protected]fb661802013-03-25 01:59:322063
danakje4fa7b72016-07-25 22:00:062064 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
jaydasika9cb21c772016-05-10 22:37:082065
loyso9556c732016-03-11 07:54:582066 // Put an animated opacity on the render surface.
vollickef2ae922016-06-29 17:54:272067 AddOpacityTransitionToElementWithPlayer(
2068 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322069
loyso9556c732016-03-11 07:54:582070 // Also put an animated opacity on a layer without descendants.
vollickef2ae922016-06-29 17:54:272071 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2072 timeline_impl(), 10.0, 1.f, 0.f,
2073 false);
[email protected]fb661802013-03-25 01:59:322074
loyso9556c732016-03-11 07:54:582075 // Put a transform animation on the render surface.
vollickef2ae922016-06-29 17:54:272076 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2077 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322078
loyso9556c732016-03-11 07:54:582079 // Also put transform animations on grand_child_of_root, and
2080 // grand_child_of_rs2
vollickef2ae922016-06-29 17:54:272081 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2082 timeline_impl(), 10.0, 30, 0);
2083 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2084 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322085
danakje4fa7b72016-07-25 22:00:062086 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2087 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322088
2089 // Only layers that are associated with render surfaces should have an actual
2090 // RenderSurface() value.
chrishtr7e3aaf22017-05-04 15:04:012091 ASSERT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:492092 ASSERT_EQ(GetRenderSurface(child_of_root), GetRenderSurface(root));
2093 ASSERT_EQ(GetRenderSurface(grand_child_of_root), GetRenderSurface(root));
[email protected]fb661802013-03-25 01:59:322094
chrishtr5f60ca02017-05-11 23:09:492095 ASSERT_NE(GetRenderSurface(render_surface1), GetRenderSurface(root));
2096 ASSERT_EQ(GetRenderSurface(child_of_rs1), GetRenderSurface(render_surface1));
2097 ASSERT_EQ(GetRenderSurface(grand_child_of_rs1),
2098 GetRenderSurface(render_surface1));
[email protected]fb661802013-03-25 01:59:322099
chrishtr5f60ca02017-05-11 23:09:492100 ASSERT_NE(GetRenderSurface(render_surface2), GetRenderSurface(root));
2101 ASSERT_NE(GetRenderSurface(render_surface2),
2102 GetRenderSurface(render_surface1));
2103 ASSERT_EQ(GetRenderSurface(child_of_rs2), GetRenderSurface(render_surface2));
2104 ASSERT_EQ(GetRenderSurface(grand_child_of_rs2),
2105 GetRenderSurface(render_surface2));
[email protected]fb661802013-03-25 01:59:322106
2107 // Verify all render target accessors
chrishtr7e3aaf22017-05-04 15:04:012108 EXPECT_EQ(GetRenderSurface(root), root->render_target());
2109 EXPECT_EQ(GetRenderSurface(root), child_of_root->render_target());
2110 EXPECT_EQ(GetRenderSurface(root), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322111
chrishtr7e3aaf22017-05-04 15:04:012112 EXPECT_EQ(GetRenderSurface(render_surface1),
weiliangc189c1a12016-04-11 16:16:252113 render_surface1->render_target());
chrishtr7e3aaf22017-05-04 15:04:012114 EXPECT_EQ(GetRenderSurface(render_surface1), child_of_rs1->render_target());
2115 EXPECT_EQ(GetRenderSurface(render_surface1),
weiliangc189c1a12016-04-11 16:16:252116 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322117
chrishtr7e3aaf22017-05-04 15:04:012118 EXPECT_EQ(GetRenderSurface(render_surface2),
weiliangc189c1a12016-04-11 16:16:252119 render_surface2->render_target());
chrishtr7e3aaf22017-05-04 15:04:012120 EXPECT_EQ(GetRenderSurface(render_surface2), child_of_rs2->render_target());
2121 EXPECT_EQ(GetRenderSurface(render_surface2),
weiliangc189c1a12016-04-11 16:16:252122 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322123
[email protected]fb661802013-03-25 01:59:322124 // Verify screen_space_transform_is_animating values
danakje4fa7b72016-07-25 22:00:062125 EXPECT_FALSE(root->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322126 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2127 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2128 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322129 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2130 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2131 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322132 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2133 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2134
2135 // Sanity check. If these fail there is probably a bug in the test itself.
2136 // It is expected that we correctly set up transforms so that the y-component
2137 // of the screen-space transform encodes the "depth" of the layer in the tree.
danakje4fa7b72016-07-25 22:00:062138 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262139 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102140 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322141 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102142 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322143
[email protected]803f6b52013-09-12 00:51:262144 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102145 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2146 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322147 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102148 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322149
[email protected]803f6b52013-09-12 00:51:262150 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102151 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2152 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322153 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102154 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322155}
2156
ajuma9384b9c22015-09-17 20:35:032157TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
danakje4fa7b72016-07-25 22:00:062158 LayerImpl* root = root_layer_for_testing();
ajuma9384b9c22015-09-17 20:35:032159 LayerImpl* child = AddChildToRoot<LayerImpl>();
2160 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2161
ajuma9384b9c22015-09-17 20:35:032162 gfx::Transform large_transform;
2163 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2164
danakje4fa7b72016-07-25 22:00:062165 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042166 child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062167 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042168 grand_child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062169 grand_child->SetBounds(gfx::Size(10, 10));
2170 grand_child->SetDrawsContent(true);
2171 ExecuteCalculateDrawProperties(root);
ajuma9384b9c22015-09-17 20:35:032172
2173 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2174}
2175
wkorman15d86862017-05-12 18:18:242176static bool TransformIsAnimating(LayerImpl* layer) {
2177 return layer->GetMutatorHost()->IsAnimatingTransformProperty(
2178 layer->element_id(), layer->GetElementTypeForAnimation());
2179}
2180
ajuma315a4782015-07-24 21:16:342181TEST_F(LayerTreeHostCommonTest,
2182 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
danakje4fa7b72016-07-25 22:00:062183 LayerImpl* root = root_layer_for_testing();
2184 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma315a4782015-07-24 21:16:342185 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2186 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2187
danakje4fa7b72016-07-25 22:00:062188 root->SetDrawsContent(true);
ajuma315a4782015-07-24 21:16:342189 child->SetDrawsContent(true);
2190 grand_child->SetDrawsContent(true);
2191 great_grand_child->SetDrawsContent(true);
2192
danakje4fa7b72016-07-25 22:00:062193 root->SetBounds(gfx::Size(10, 10));
2194 child->SetBounds(gfx::Size(10, 10));
2195 grand_child->SetBounds(gfx::Size(10, 10));
2196 great_grand_child->SetBounds(gfx::Size(10, 10));
ajuma315a4782015-07-24 21:16:342197
vollickef2ae922016-06-29 17:54:272198 SetElementIdsForTesting();
2199
ajuma315a4782015-07-24 21:16:342200 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482201 std::unique_ptr<Animation> animation = Animation::Create(
2202 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302203 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552204 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342205 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:272206 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2207 std::move(animation));
danakje4fa7b72016-07-25 22:00:062208 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:342209
danakje4fa7b72016-07-25 22:00:062210 EXPECT_FALSE(root->screen_space_transform_is_animating());
ajuma315a4782015-07-24 21:16:342211 EXPECT_FALSE(child->screen_space_transform_is_animating());
2212
wkorman15d86862017-05-12 18:18:242213 EXPECT_FALSE(TransformIsAnimating(grand_child));
ajuma315a4782015-07-24 21:16:342214 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2215 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2216 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2217}
2218
weiliangc6da32862016-04-20 16:40:112219TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2220 // Test visible layer rect and drawable content rect are calculated correctly
2221 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322222
[email protected]2c7c6702013-03-26 03:14:052223 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322224 gfx::Transform layer_to_surface_transform;
2225
2226 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232227 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112228 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2229 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2230 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2231 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2232 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2233 EXPECT_EQ(expected_drawable_content_rect,
2234 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322235
2236 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052237 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112238 expected_visible_layer_rect = gfx::Rect();
2239 expected_drawable_content_rect = gfx::Rect();
2240 drawing_layer = TestVisibleRectAndDrawableContentRect(
2241 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2242 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2243 EXPECT_EQ(expected_drawable_content_rect,
2244 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322245
2246 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052247 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112248 expected_visible_layer_rect = gfx::Rect(20, 20);
2249 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2250 drawing_layer = TestVisibleRectAndDrawableContentRect(
2251 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2252 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2253 EXPECT_EQ(expected_drawable_content_rect,
2254 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322255}
2256
weiliangc6da32862016-04-20 16:40:112257TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2258 // Test visible layer rect and drawable content rect are calculated correctly
2259 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322260
[email protected]2c7c6702013-03-26 03:14:052261 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2262 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322263 gfx::Transform layer_to_surface_transform;
2264
2265 // Case 1: Layer is contained within the surface.
2266 layer_to_surface_transform.MakeIdentity();
2267 layer_to_surface_transform.Translate(50.0, 50.0);
2268 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112269 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2270 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2271 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2272 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2273 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2274 EXPECT_EQ(expected_drawable_content_rect,
2275 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322276
2277 // Case 2: Layer is outside the surface rect.
2278 layer_to_surface_transform.MakeIdentity();
2279 layer_to_surface_transform.Translate(-50.0, 0.0);
2280 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112281 expected_visible_layer_rect = gfx::Rect();
2282 expected_drawable_content_rect = gfx::Rect();
2283 drawing_layer = TestVisibleRectAndDrawableContentRect(
2284 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2285 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2286 EXPECT_EQ(expected_drawable_content_rect,
2287 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322288
2289 // Case 3: The layer is rotated about its top-left corner. In surface space,
2290 // the layer is oriented diagonally, with the left half outside of the render
2291 // surface. In this case, the g should still be the entire layer
2292 // (remember the g is computed in layer space); both the top-left
2293 // and bottom-right corners of the layer are still visible.
2294 layer_to_surface_transform.MakeIdentity();
2295 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112296 expected_visible_layer_rect = gfx::Rect(30, 30);
2297 expected_drawable_content_rect = gfx::Rect(22, 43);
2298 drawing_layer = TestVisibleRectAndDrawableContentRect(
2299 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2300 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2301 EXPECT_EQ(expected_drawable_content_rect,
2302 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322303
2304 // Case 4: The layer is rotated about its top-left corner, and translated
2305 // upwards. In surface space, the layer is oriented diagonally, with only the
2306 // top corner of the surface overlapping the layer. In layer space, the render
2307 // surface overlaps the right side of the layer. The g should be
2308 // the layer's right half.
2309 layer_to_surface_transform.MakeIdentity();
2310 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2311 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112312 // Right half of layer bounds.
2313 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2314 expected_drawable_content_rect = gfx::Rect(22, 22);
2315 drawing_layer = TestVisibleRectAndDrawableContentRect(
2316 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2317 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2318 EXPECT_EQ(expected_drawable_content_rect,
2319 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322320}
2321
weiliangc6da32862016-04-20 16:40:112322TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2323 // Test visible layer rect and drawable content rect are calculated correctly
2324 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322325
[email protected]2c7c6702013-03-26 03:14:052326 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2327 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322328 gfx::Transform layer_to_surface_transform;
2329
2330 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2331 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112332 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322333 layer_to_surface_transform.MakeIdentity();
2334 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112335 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2336 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2337 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2338 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2339 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2340 EXPECT_EQ(expected_drawable_content_rect,
2341 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322342
2343 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2344 // degrees, but shifted to the side so only the right-half the layer would be
2345 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112346 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262347 SkMScalar half_width_of_rotated_layer =
2348 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322349 layer_to_surface_transform.MakeIdentity();
2350 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232351 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2352 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112353 // Tight half of the layer.
2354 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2355 expected_drawable_content_rect = gfx::Rect(36, 100);
2356 drawing_layer = TestVisibleRectAndDrawableContentRect(
2357 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2358 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2359 EXPECT_EQ(expected_drawable_content_rect,
2360 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322361}
2362
weiliangc6da32862016-04-20 16:40:112363TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2364 // Test visible layer rect and drawable content rect are calculated correctly
2365 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322366
[email protected]2c7c6702013-03-26 03:14:052367 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2368 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322369 gfx::Transform layer_to_surface_transform;
2370
2371 // Case 1: Even though the layer is twice as large as the surface, due to
2372 // perspective foreshortening, the layer will fit fully in the surface when
2373 // its translated more than the perspective amount.
2374 layer_to_surface_transform.MakeIdentity();
2375
2376 // The following sequence of transforms applies the perspective about the
2377 // center of the surface.
2378 layer_to_surface_transform.Translate(50.0, 50.0);
2379 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2380 layer_to_surface_transform.Translate(-50.0, -50.0);
2381
2382 // This translate places the layer in front of the surface's projection plane.
2383 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2384
weiliangc6da32862016-04-20 16:40:112385 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2386 // offset by layer position.
2387 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2388 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2389 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2390 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2391 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2392 EXPECT_EQ(expected_drawable_content_rect,
2393 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322394
2395 // Case 2: same projection as before, except that the layer is also translated
2396 // to the side, so that only the right half of the layer should be visible.
2397 //
2398 // Explanation of expected result: The perspective ratio is (z distance
2399 // between layer and camera origin) / (z distance between projection plane and
2400 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112401 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322402 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112403 // -25 == -100 in the layer's units.
2404 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2405 // Visible layer rect is moved by 100, and drawable content rect is in target
2406 // space and is moved by 25.
2407 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2408 expected_drawable_content_rect = gfx::Rect(13, 38);
2409 drawing_layer = TestVisibleRectAndDrawableContentRect(
2410 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2411 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2412 EXPECT_EQ(expected_drawable_content_rect,
2413 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322414}
2415
weiliangc6da32862016-04-20 16:40:112416TEST_F(LayerTreeHostCommonDrawRectsTest,
2417 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322418 // There is currently no explicit concept of an orthographic projection plane
2419 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2420 // are technically behind the surface in an orthographic world should not be
2421 // clipped when they are flattened to the surface.
2422
[email protected]2c7c6702013-03-26 03:14:052423 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2424 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322425 gfx::Transform layer_to_surface_transform;
2426
2427 // This sequence of transforms effectively rotates the layer about the y-axis
2428 // at the center of the layer.
2429 layer_to_surface_transform.MakeIdentity();
2430 layer_to_surface_transform.Translate(50.0, 0.0);
2431 layer_to_surface_transform.RotateAboutYAxis(45.0);
2432 layer_to_surface_transform.Translate(-50.0, 0.0);
2433
weiliangc6da32862016-04-20 16:40:112434 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2435 // space.
2436 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2437 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2438 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2439 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2440 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2441 EXPECT_EQ(expected_drawable_content_rect,
2442 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322443}
2444
weiliangc6da32862016-04-20 16:40:112445TEST_F(LayerTreeHostCommonDrawRectsTest,
2446 DrawRectsFor3dPerspectiveWhenClippedByW) {
2447 // Test visible layer rect and drawable content rect are calculated correctly
2448 // when projecting a surface onto a layer, but the layer is partially behind
2449 // the camera (not just behind the projection plane). In this case, the
2450 // cartesian coordinates may seem to be valid, but actually they are not. The
2451 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2452 // coordinates before converting to cartesian coordinates. The drawable
2453 // content rect would be entire surface rect because layer is rotated at the
2454 // camera position.
[email protected]fb661802013-03-25 01:59:322455
weiliangc6da32862016-04-20 16:40:112456 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2457 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322458 gfx::Transform layer_to_surface_transform;
2459
2460 // The layer is positioned so that the right half of the layer should be in
2461 // front of the camera, while the other half is behind the surface's
2462 // projection plane. The following sequence of transforms applies the
2463 // perspective and rotation about the center of the layer.
2464 layer_to_surface_transform.MakeIdentity();
2465 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112466 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2467 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2468 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322469
2470 // Sanity check that this transform does indeed cause w < 0 when applying the
2471 // transform, otherwise this code is not testing the intended scenario.
2472 bool clipped;
2473 MathUtil::MapQuad(layer_to_surface_transform,
2474 gfx::QuadF(gfx::RectF(layer_content_rect)),
2475 &clipped);
2476 ASSERT_TRUE(clipped);
2477
weiliangc6da32862016-04-20 16:40:112478 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2479 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2480 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2481 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2482 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2483 EXPECT_EQ(expected_drawable_content_rect,
2484 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322485}
2486
petermayoca9b8202017-03-17 18:54:102487static bool ProjectionClips(const gfx::Transform& map_transform,
2488 const gfx::RectF& mapped_rect) {
2489 gfx::Transform inverse(Inverse(map_transform));
2490 bool clipped = false;
2491 if (!clipped)
2492 MathUtil::ProjectPoint(inverse, mapped_rect.top_right(), &clipped);
2493 if (!clipped)
2494 MathUtil::ProjectPoint(inverse, mapped_rect.origin(), &clipped);
2495 if (!clipped)
2496 MathUtil::ProjectPoint(inverse, mapped_rect.bottom_right(), &clipped);
2497 if (!clipped)
2498 MathUtil::ProjectPoint(inverse, mapped_rect.bottom_left(), &clipped);
2499 return clipped;
2500}
2501
weiliangc6da32862016-04-20 16:40:112502TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322503 // To determine visible rect in layer space, there needs to be an
2504 // un-projection from surface space to layer space. When the original
2505 // transform was a perspective projection that was clipped, it returns a rect
2506 // that encloses the clipped bounds. Un-projecting this new rect may require
2507 // clipping again.
2508
2509 // This sequence of transforms causes one corner of the layer to protrude
2510 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:112511 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
2512 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322513 gfx::Transform layer_to_surface_transform;
2514 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:112515 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:322516 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2517 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2518 layer_to_surface_transform.RotateAboutYAxis(45.0);
2519 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:112520 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:322521
2522 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2523 // code is not testing the intended scenario.
danakj5e6ff6d2015-09-05 04:43:442524 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2525 layer_to_surface_transform, gfx::RectF(layer_content_rect));
petermayoca9b8202017-03-17 18:54:102526 ASSERT_TRUE(ProjectionClips(layer_to_surface_transform, clipped_rect));
[email protected]fb661802013-03-25 01:59:322527
2528 // Only the corner of the layer is not visible on the surface because of being
2529 // clipped. But, the net result of rounding visible region to an axis-aligned
2530 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:112531 gfx::Rect expected_visible_layer_rect = layer_content_rect;
2532 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2533 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2534 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2535 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2536 EXPECT_EQ(expected_drawable_content_rect,
2537 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322538}
2539
miletus9d3da522015-06-05 19:45:072540TEST_F(LayerTreeHostCommonTest,
2541 VisibleRectsForPositionedRootLayerClippedByViewport) {
jaydasikabf1875a2016-06-28 03:39:592542 LayerImpl* root = root_layer_for_testing();
miletus9d3da522015-06-05 19:45:072543
danakje4fa7b72016-07-25 22:00:062544 root->SetPosition(gfx::PointF(60, 70));
2545 root->SetBounds(gfx::Size(100, 100));
2546 root->SetDrawsContent(true);
enne6c281f6e2015-08-18 23:23:002547 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:072548
danakj5e6ff6d2015-09-05 04:43:442549 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:012550 GetRenderSurface(root)->DrawableContentRect());
miletus9d3da522015-06-05 19:45:072551 // In target space, not clipped.
2552 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2553 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:442554 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:072555}
2556
[email protected]989386c2013-07-18 21:37:232557TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
jaydasikabf1875a2016-06-28 03:39:592558 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:172559 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:172560 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:172561 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:062562
2563 root->SetBounds(gfx::Size(100, 100));
2564 child1_layer->SetBounds(gfx::Size(50, 50));
2565 child1_layer->SetDrawsContent(true);
2566 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
2567 child2_layer->SetBounds(gfx::Size(50, 50));
2568 child2_layer->SetDrawsContent(true);
2569 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
2570 child3_layer->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:172571 child3_layer->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:172572 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322573
danakj5e6ff6d2015-09-05 04:43:442574 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:012575 GetRenderSurface(root)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322576
danakj64767d902015-06-19 00:10:432577 // Layers that do not draw content should have empty visible_layer_rects.
2578 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322579
danakj64767d902015-06-19 00:10:432580 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:172581 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
2582 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
2583 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:322584
2585 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:172586 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
2587 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
2588 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322589}
2590
[email protected]989386c2013-07-18 21:37:232591TEST_F(LayerTreeHostCommonTest,
2592 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
jaydasikabf1875a2016-06-28 03:39:592593 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:172594 LayerImpl* child = AddChildToRoot<LayerImpl>();
2595 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:172596 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:172597 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:282598
danakje4fa7b72016-07-25 22:00:062599 root->SetBounds(gfx::Size(100, 100));
2600 child->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:322601 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062602 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2603 grand_child1->SetBounds(gfx::Size(50, 50));
2604 grand_child1->SetDrawsContent(true);
2605 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
2606 grand_child2->SetBounds(gfx::Size(50, 50));
2607 grand_child2->SetDrawsContent(true);
2608 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
2609 grand_child3->SetBounds(gfx::Size(50, 50));
2610 grand_child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:172611 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322612
danakj5e6ff6d2015-09-05 04:43:442613 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:012614 GetRenderSurface(root)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322615
2616 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:432617 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2618 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322619
2620 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:432621 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
2622 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
2623 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:322624
2625 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322626 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2627 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322628 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2629}
2630
ajuma27442dd2015-03-30 19:19:482631TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasikabf1875a2016-06-28 03:39:592632 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:142633 LayerImpl* child = AddChild<LayerImpl>(root);
2634 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:482635
ajuma27442dd2015-03-30 19:19:482636 gfx::Transform child_scale_matrix;
2637 child_scale_matrix.Scale(0.25f, 0.25f);
2638 gfx::Transform grand_child_scale_matrix;
2639 grand_child_scale_matrix.Scale(0.246f, 0.246f);
ajuma27442dd2015-03-30 19:19:482640
danakje4fa7b72016-07-25 22:00:062641 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:042642 child->test_properties()->transform = child_scale_matrix;
danakje4fa7b72016-07-25 22:00:062643 child->SetBounds(gfx::Size(10, 10));
ajuma27442dd2015-03-30 19:19:482644 child->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:042645 grand_child->test_properties()->transform = grand_child_scale_matrix;
danakje4fa7b72016-07-25 22:00:062646 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:142647 grand_child->SetDrawsContent(true);
2648 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:482649
weiliangcd15784432016-06-07 17:57:332650 // The visible rect is expanded to integer coordinates.
2651 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:482652}
2653
ajumae947a352017-01-10 19:17:492654TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) {
2655 LayerImpl* root = root_layer_for_testing();
2656 LayerImpl* clip = AddChild<LayerImpl>(root);
2657 LayerImpl* filter = AddChild<LayerImpl>(clip);
2658 LayerImpl* filter_child = AddChild<LayerImpl>(filter);
2659
2660 root->SetBounds(gfx::Size(100, 100));
2661 clip->SetBounds(gfx::Size(10, 10));
2662 filter->test_properties()->force_render_surface = true;
2663 filter_child->SetBounds(gfx::Size(2000, 2000));
2664 filter_child->SetPosition(gfx::PointF(-50, -50));
2665 filter_child->SetDrawsContent(true);
2666
2667 clip->SetMasksToBounds(true);
2668
2669 ExecuteCalculateDrawProperties(root);
2670 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
chrishtr7e3aaf22017-05-04 15:04:012671 EXPECT_EQ(gfx::Rect(10, 10), GetRenderSurface(filter)->content_rect());
ajumae947a352017-01-10 19:17:492672
2673 FilterOperations blur_filter;
2674 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
2675 filter->test_properties()->filters = blur_filter;
2676 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2677
2678 ExecuteCalculateDrawProperties(root);
2679
2680 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
2681 EXPECT_EQ(gfx::Rect(-12, -12, 34, 34),
chrishtr7e3aaf22017-05-04 15:04:012682 GetRenderSurface(filter)->content_rect());
ajumae947a352017-01-10 19:17:492683
2684 gfx::Transform vertical_flip;
2685 vertical_flip.Scale(1, -1);
2686 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
2687 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
2688 FilterOperations reflection_filter;
2689 reflection_filter.Append(
2690 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
2691 SkBlendMode::kSrcOver, std::move(flip_filter))));
2692 filter->test_properties()->filters = reflection_filter;
2693 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2694
2695 ExecuteCalculateDrawProperties(root);
2696
2697 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
2698 EXPECT_EQ(gfx::Rect(0, -10, 10, 20),
chrishtr7e3aaf22017-05-04 15:04:012699 GetRenderSurface(filter)->content_rect());
ajumae947a352017-01-10 19:17:492700}
2701
2702TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) {
2703 LayerImpl* root = root_layer_for_testing();
2704 LayerImpl* scale = AddChild<LayerImpl>(root);
2705 LayerImpl* clip = AddChild<LayerImpl>(scale);
2706 LayerImpl* filter = AddChild<LayerImpl>(clip);
2707 LayerImpl* filter_child = AddChild<LayerImpl>(filter);
2708
2709 root->SetBounds(gfx::Size(100, 100));
2710 clip->SetBounds(gfx::Size(10, 10));
2711 filter->test_properties()->force_render_surface = true;
2712 filter_child->SetBounds(gfx::Size(2000, 2000));
2713 filter_child->SetPosition(gfx::PointF(-50, -50));
2714 filter_child->SetDrawsContent(true);
2715
2716 clip->SetMasksToBounds(true);
2717
2718 gfx::Transform scale_transform;
2719 scale_transform.Scale(3, 3);
2720 scale->test_properties()->transform = scale_transform;
2721
2722 ExecuteCalculateDrawProperties(root);
2723 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
chrishtr7e3aaf22017-05-04 15:04:012724 EXPECT_EQ(gfx::Rect(30, 30), GetRenderSurface(filter)->content_rect());
ajumae947a352017-01-10 19:17:492725
2726 FilterOperations blur_filter;
2727 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
2728 filter->test_properties()->filters = blur_filter;
2729 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2730
2731 ExecuteCalculateDrawProperties(root);
2732
2733 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
2734 EXPECT_EQ(gfx::Rect(-36, -36, 102, 102),
chrishtr7e3aaf22017-05-04 15:04:012735 GetRenderSurface(filter)->content_rect());
ajumae947a352017-01-10 19:17:492736
2737 gfx::Transform vertical_flip;
2738 vertical_flip.Scale(1, -1);
2739 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
2740 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
2741 FilterOperations reflection_filter;
2742 reflection_filter.Append(
2743 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
2744 SkBlendMode::kSrcOver, std::move(flip_filter))));
2745 filter->test_properties()->filters = reflection_filter;
2746 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2747
2748 ExecuteCalculateDrawProperties(root);
2749
2750 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
2751 EXPECT_EQ(gfx::Rect(0, -30, 30, 60),
chrishtr7e3aaf22017-05-04 15:04:012752 GetRenderSurface(filter)->content_rect());
ajumae947a352017-01-10 19:17:492753}
2754
2755TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) {
2756 LayerImpl* root = root_layer_for_testing();
2757 LayerImpl* clip = AddChild<LayerImpl>(root);
2758 LayerImpl* filter = AddChild<LayerImpl>(clip);
2759 LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter);
2760 LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter);
2761
2762 root->SetBounds(gfx::Size(100, 100));
2763 clip->SetBounds(gfx::Size(10, 10));
2764 filter->test_properties()->force_render_surface = true;
2765
2766 filter_child_1->SetBounds(gfx::Size(20, 20));
2767 filter_child_1->SetDrawsContent(true);
2768 filter_child_2->SetBounds(gfx::Size(20, 20));
2769 filter_child_2->SetDrawsContent(true);
2770
2771 root->SetMasksToBounds(true);
2772 clip->SetMasksToBounds(true);
2773
2774 root->test_properties()->clip_children =
2775 base::MakeUnique<std::set<LayerImpl*>>();
2776 root->test_properties()->clip_children->insert(filter_child_1);
2777 filter_child_1->test_properties()->clip_parent = root;
2778
2779 ExecuteCalculateDrawProperties(root);
2780 EXPECT_TRUE(filter_child_1->is_clipped());
2781 EXPECT_TRUE(filter_child_2->is_clipped());
2782 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
2783 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
2784
2785 FilterOperations blur_filter;
2786 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
2787 filter->test_properties()->filters = blur_filter;
2788 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2789
2790 ExecuteCalculateDrawProperties(root);
2791
2792 EXPECT_TRUE(filter_child_1->is_clipped());
2793 EXPECT_TRUE(filter_child_2->is_clipped());
2794 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
2795 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
2796}
2797
2798TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) {
2799 LayerImpl* root = root_layer_for_testing();
2800 LayerImpl* filter = AddChild<LayerImpl>(root);
2801 LayerImpl* clip = AddChild<LayerImpl>(filter);
2802 LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip);
2803
2804 root->SetBounds(gfx::Size(100, 100));
2805 filter->test_properties()->force_render_surface = true;
2806
2807 clip->SetBounds(gfx::Size(10, 10));
2808 clip->SetMasksToBounds(true);
2809
2810 filter_grand_child->SetBounds(gfx::Size(20, 20));
2811 filter_grand_child->SetDrawsContent(true);
2812
2813 ExecuteCalculateDrawProperties(root);
2814 EXPECT_TRUE(filter_grand_child->is_clipped());
2815 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
2816
2817 FilterOperations blur_filter;
2818 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
2819 filter->test_properties()->filters = blur_filter;
2820 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2821
2822 ExecuteCalculateDrawProperties(root);
2823
2824 EXPECT_TRUE(filter_grand_child->is_clipped());
2825 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
2826}
2827
[email protected]989386c2013-07-18 21:37:232828TEST_F(LayerTreeHostCommonTest,
2829 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:592830 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:172831 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2832 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:172833 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:172834 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
danakje4fa7b72016-07-25 22:00:062835
2836 root->SetBounds(gfx::Size(100, 100));
2837 render_surface->SetBounds(gfx::Size(3, 4));
2838 render_surface->test_properties()->force_render_surface = true;
2839 child1->SetPosition(gfx::PointF(5.f, 5.f));
2840 child1->SetBounds(gfx::Size(50, 50));
2841 child1->SetDrawsContent(true);
2842 child2->SetPosition(gfx::PointF(75.f, 75.f));
2843 child2->SetBounds(gfx::Size(50, 50));
2844 child2->SetDrawsContent(true);
2845 child3->SetPosition(gfx::PointF(125.f, 125.f));
2846 child3->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:172847 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:172848 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322849
chrishtr7e3aaf22017-05-04 15:04:012850 ASSERT_TRUE(GetRenderSurface(render_surface));
[email protected]fb661802013-03-25 01:59:322851
danakj5e6ff6d2015-09-05 04:43:442852 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:012853 GetRenderSurface(root)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322854
2855 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:432856 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:172857 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322858
2859 // An unclipped surface grows its DrawableContentRect to include all drawable
2860 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:442861 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
chrishtr7e3aaf22017-05-04 15:04:012862 GetRenderSurface(render_surface)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322863
2864 // All layers that draw content into the unclipped surface are also unclipped.
jaydasika94bebdd2016-09-16 22:11:182865 // Only the viewport clip should apply
danakj64767d902015-06-19 00:10:432866 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:182867 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
2868 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322869
hush6b614212014-12-04 22:37:322870 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2871 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2872 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322873}
2874
[email protected]989386c2013-07-18 21:37:232875TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:022876 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
jaydasikabf1875a2016-06-28 03:39:592877 LayerImpl* root = root_layer_for_testing();
enne6c281f6e2015-08-18 23:23:002878 LayerImpl* child1 = AddChild<LayerImpl>(root);
2879 LayerImpl* child2 = AddChild<LayerImpl>(root);
2880 LayerImpl* child3 = AddChild<LayerImpl>(root);
hush887bb542014-12-02 22:49:022881
danakje4fa7b72016-07-25 22:00:062882 root->SetBounds(gfx::Size(100, 100));
2883 child1->SetPosition(gfx::PointF(5.f, 5.f));
2884 child1->SetBounds(gfx::Size(50, 50));
2885 child1->SetDrawsContent(true);
2886 child2->SetPosition(gfx::PointF(75.f, 75.f));
2887 child2->SetBounds(gfx::Size(50, 50));
2888 child2->SetDrawsContent(true);
2889 child3->SetPosition(gfx::PointF(125.f, 125.f));
2890 child3->SetBounds(gfx::Size(50, 50));
2891 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:022892
ajumab784ef42017-04-28 23:01:522893 RenderSurfaceList render_surface_list_impl;
hush887bb542014-12-02 22:49:022894 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:002895 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:522896 root, gfx::Size(), &render_surface_list_impl);
hush887bb542014-12-02 22:49:022897
sunxdb365de02016-04-28 20:32:572898 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
chrishtr7e3aaf22017-05-04 15:04:012899 ASSERT_TRUE(GetRenderSurface(root));
hush887bb542014-12-02 22:49:022900 EXPECT_FALSE(root->is_clipped());
2901
2902 gfx::Rect empty;
chrishtr7e3aaf22017-05-04 15:04:012903 EXPECT_EQ(empty, GetRenderSurface(root)->clip_rect());
2904 EXPECT_TRUE(GetRenderSurface(root)->is_clipped());
hush887bb542014-12-02 22:49:022905
2906 // Visible content rect calculation will check if the target surface is
2907 // clipped or not. An empty clip rect does not indicate the render surface
2908 // is unclipped.
danakj64767d902015-06-19 00:10:432909 EXPECT_EQ(empty, child1->visible_layer_rect());
2910 EXPECT_EQ(empty, child2->visible_layer_rect());
2911 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:022912}
2913
2914TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:232915 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
jaydasikabf1875a2016-06-28 03:39:592916 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:172917 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:062918
2919 root->SetBounds(gfx::Size(100, 100));
2920 child->SetPosition(gfx::PointF(5.f, 5.f));
2921 child->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:172922 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:282923
[email protected]630ddad2013-08-16 03:01:322924 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472925 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322926 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472927
jaydasika10d43fc2016-08-18 04:06:042928 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:172929 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:472930
danakj64767d902015-06-19 00:10:432931 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472932 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322933
[email protected]08bdf1b2014-04-16 23:23:292934 // Case 2: a matrix with flattened z, uninvertible and not visible according
2935 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322936 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262937 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322938 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2939
jaydasika10d43fc2016-08-18 04:06:042940 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:172941 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:322942
danakj64767d902015-06-19 00:10:432943 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292944 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322945
[email protected]08bdf1b2014-04-16 23:23:292946 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322947 uninvertible_matrix.MakeIdentity();
2948 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262949 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322950 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2951
jaydasika10d43fc2016-08-18 04:06:042952 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:172953 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:322954
danakj64767d902015-06-19 00:10:432955 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292956 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472957}
2958
[email protected]989386c2013-07-18 21:37:232959TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:562960 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
jaydasikabf1875a2016-06-28 03:39:592961 LayerImpl* root = root_layer_for_testing();
ajumaae0dc2d2015-08-05 21:55:562962 LayerImpl* child = AddChildToRoot<LayerImpl>();
2963 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaae0dc2d2015-08-05 21:55:562964
ajumaae0dc2d2015-08-05 21:55:562965 gfx::Transform perspective;
2966 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2967
2968 gfx::Transform rotation;
2969 rotation.RotateAboutYAxis(45.0);
2970
danakje4fa7b72016-07-25 22:00:062971 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:042972 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:062973 child->SetPosition(gfx::PointF(10.f, 10.f));
2974 child->SetBounds(gfx::Size(100, 100));
2975 child->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:202976 child->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:062977 child->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:042978 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:062979 grand_child->SetBounds(gfx::Size(100, 100));
2980 grand_child->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:202981 child->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:062982 grand_child->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:202983 grand_child->test_properties()->sorting_context_id = 1;
ajumaae0dc2d2015-08-05 21:55:562984 ExecuteCalculateDrawProperties(root);
2985
2986 // Though all layers have invertible transforms, matrix multiplication using
2987 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:052988 EXPECT_FALSE(root->layer_tree_impl()
2989 ->property_trees()
2990 ->transform_tree.Node(grand_child->transform_tree_index())
trchendba8b1502016-07-08 09:47:012991 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:562992
sunxd71aea3e2016-04-01 23:48:052993 // CalcDrawProps skips a subtree when a layer's screen space transform is
2994 // uninvertible
2995 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:562996}
2997
jaydasika69c77aa2016-07-14 22:48:482998TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) {
2999 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika69c77aa2016-07-14 22:48:483000 TestTaskGraphRunner task_graph_runner;
danakjc7afae52017-06-20 21:12:413001 std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink =
3002 FakeLayerTreeFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223003 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483004
3005 std::unique_ptr<LayerImpl> root =
3006 LayerImpl::Create(host_impl.active_tree(), 1);
3007 std::unique_ptr<LayerImpl> child =
3008 LayerImpl::Create(host_impl.active_tree(), 2);
3009 std::unique_ptr<TextureLayerImpl> surface =
3010 TextureLayerImpl::Create(host_impl.active_tree(), 3);
3011 std::unique_ptr<TextureLayerImpl> surface_child =
3012 TextureLayerImpl::Create(host_impl.active_tree(), 4);
3013 std::unique_ptr<TextureLayerImpl> surface_sibling =
3014 TextureLayerImpl::Create(host_impl.active_tree(), 5);
3015 std::unique_ptr<TextureLayerImpl> surface_child_mask =
3016 TextureLayerImpl::Create(host_impl.active_tree(), 6);
3017
3018 surface->SetDrawsContent(true);
3019 surface_child->SetDrawsContent(true);
3020 surface_sibling->SetDrawsContent(true);
3021 surface_child_mask->SetDrawsContent(true);
3022 surface->SetContentsOpaque(true);
3023 surface_child->SetContentsOpaque(true);
3024 surface_sibling->SetContentsOpaque(true);
3025 surface_child_mask->SetContentsOpaque(true);
3026
jaydasika69c77aa2016-07-14 22:48:483027 gfx::Transform translate;
3028 translate.Translate(20.f, 20.f);
3029
danakje4fa7b72016-07-25 22:00:063030 root->SetBounds(gfx::Size(1000, 1000));
3031 child->SetBounds(gfx::Size(300, 300));
jaydasika10d43fc2016-08-18 04:06:043032 surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:063033 surface->SetBounds(gfx::Size(300, 300));
3034 surface->test_properties()->force_render_surface = true;
3035 surface_child->SetBounds(gfx::Size(300, 300));
3036 surface_child->test_properties()->force_render_surface = true;
3037 surface_sibling->SetBounds(gfx::Size(200, 200));
jaydasika69c77aa2016-07-14 22:48:483038
3039 LayerImpl* surface_ptr = surface.get();
3040 LayerImpl* surface_child_ptr = surface_child.get();
3041 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3042
3043 host_impl.SetViewportSize(root->bounds());
3044
3045 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3046 surface->test_properties()->AddChild(std::move(surface_child));
3047 child->test_properties()->AddChild(std::move(surface));
3048 child->test_properties()->AddChild(std::move(surface_sibling));
3049 root->test_properties()->AddChild(std::move(child));
3050 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3051 host_impl.SetVisible(true);
danakjc7afae52017-06-20 21:12:413052 host_impl.InitializeRenderer(layer_tree_frame_sink.get());
jaydasika69c77aa2016-07-14 22:48:483053 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
Vladimir Levin55c66402017-07-13 02:21:063054 host_impl.active_tree()->UpdateDrawProperties();
jaydasika69c77aa2016-07-14 22:48:483055
3056 EXPECT_TRANSFORMATION_MATRIX_EQ(
chrishtr7e3aaf22017-05-04 15:04:013057 GetRenderSurface(surface_ptr)->draw_transform(), translate);
jaydasika69c77aa2016-07-14 22:48:483058 // surface_sibling draws into the root render surface and occludes
3059 // surface_child's contents.
3060 Occlusion actual_occlusion =
chrishtr7e3aaf22017-05-04 15:04:013061 GetRenderSurface(surface_child_ptr)->occlusion_in_content_space();
jaydasika69c77aa2016-07-14 22:48:483062 Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()),
3063 SimpleEnclosedRegion(gfx::Rect(200, 200)));
3064 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3065
3066 // Mask layer should have the same occlusion.
3067 actual_occlusion =
3068 surface_child_mask_ptr->draw_properties().occlusion_in_content_space;
3069 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3070}
3071
jaydasika2a1718b2016-10-26 22:58:023072TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) {
3073 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika2a1718b2016-10-26 22:58:023074 TestTaskGraphRunner task_graph_runner;
danakjc7afae52017-06-20 21:12:413075 std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink =
3076 FakeLayerTreeFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223077 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika2a1718b2016-10-26 22:58:023078
3079 std::unique_ptr<LayerImpl> root =
3080 LayerImpl::Create(host_impl.active_tree(), 1);
3081 std::unique_ptr<TextureLayerImpl> child =
3082 TextureLayerImpl::Create(host_impl.active_tree(), 2);
3083
3084 LayerImpl* child_ptr = child.get();
3085
3086 root->SetBounds(gfx::Size(100, 100));
3087 child->SetBounds(gfx::Size(100, 100));
3088 child->SetDrawsContent(true);
3089 gfx::Transform fractional_translate;
3090 fractional_translate.Translate(10.5f, 20.3f);
3091 child->test_properties()->transform = fractional_translate;
3092
3093 host_impl.SetViewportSize(root->bounds());
3094
3095 root->test_properties()->AddChild(std::move(child));
3096 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3097 host_impl.SetVisible(true);
danakjc7afae52017-06-20 21:12:413098 host_impl.InitializeRenderer(layer_tree_frame_sink.get());
jaydasika2a1718b2016-10-26 22:58:023099 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
Vladimir Levin55c66402017-07-13 02:21:063100 host_impl.active_tree()->UpdateDrawProperties();
jaydasika2a1718b2016-10-26 22:58:023101
3102 EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate);
3103 fractional_translate.RoundTranslationComponents();
3104 EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(),
3105 fractional_translate);
3106 gfx::RectF layer_bounds_in_screen_space =
3107 MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(),
3108 gfx::RectF(gfx::SizeF(child_ptr->bounds())));
3109 EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f));
3110}
3111
ajumaae0dc2d2015-08-05 21:55:563112TEST_F(LayerTreeHostCommonTest,
3113 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163114 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563115 TestTaskGraphRunner task_graph_runner;
danakjc7afae52017-06-20 21:12:413116 std::unique_ptr<LayerTreeFrameSink> layer_tree_frame_sink =
3117 FakeLayerTreeFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223118 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483119
danakj60bc3bc2016-04-09 00:24:483120 std::unique_ptr<LayerImpl> root =
3121 LayerImpl::Create(host_impl.active_tree(), 1);
3122 std::unique_ptr<LayerImpl> child =
3123 LayerImpl::Create(host_impl.active_tree(), 2);
3124 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563125 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483126 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563127 LayerImpl::Create(host_impl.active_tree(), 4);
ajumaae0dc2d2015-08-05 21:55:563128
ajumaae0dc2d2015-08-05 21:55:563129 gfx::Transform perspective;
3130 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3131
3132 gfx::Transform rotation;
3133 rotation.RotateAboutYAxis(45.0);
3134
danakje4fa7b72016-07-25 22:00:063135 root->SetBounds(gfx::Size(1000, 1000));
jaydasika10d43fc2016-08-18 04:06:043136 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063137 child->SetPosition(gfx::PointF(10.f, 10.f));
3138 child->SetBounds(gfx::Size(300, 300));
3139 child->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203140 child->test_properties()->sorting_context_id = 1;
jaydasika10d43fc2016-08-18 04:06:043141 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063142 grand_child->SetBounds(gfx::Size(200, 200));
3143 grand_child->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203144 grand_child->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:063145 occluding_child->SetBounds(gfx::Size(200, 200));
3146 occluding_child->test_properties()->should_flatten_transform = false;
3147
3148 child->SetDrawsContent(true);
3149 grand_child->SetDrawsContent(true);
3150 occluding_child->SetDrawsContent(true);
3151 occluding_child->SetContentsOpaque(true);
ajumaae0dc2d2015-08-05 21:55:563152
3153 host_impl.SetViewportSize(root->bounds());
3154
jaydasika89f7b5a2016-06-22 02:08:393155 child->test_properties()->AddChild(std::move(grand_child));
3156 root->test_properties()->AddChild(std::move(child));
3157 root->test_properties()->AddChild(std::move(occluding_child));
jaydasikabf1875a2016-06-28 03:39:593158 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
sievers71c62dd52015-10-07 01:44:393159 host_impl.SetVisible(true);
danakjc7afae52017-06-20 21:12:413160 host_impl.InitializeRenderer(layer_tree_frame_sink.get());
jaydasika4340ea02016-06-06 19:44:263161 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
Vladimir Levin55c66402017-07-13 02:21:063162 host_impl.active_tree()->UpdateDrawProperties();
ajumaae0dc2d2015-08-05 21:55:563163
jaydasikafc66cfb2016-06-10 04:34:223164 LayerImpl* grand_child_ptr = host_impl.active_tree()
jaydasikabf1875a2016-06-28 03:39:593165 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:223166 ->test_properties()
3167 ->children[0]
3168 ->test_properties()
3169 ->children[0];
ajumaae0dc2d2015-08-05 21:55:563170
3171 // Though all layers have invertible transforms, matrix multiplication using
3172 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053173 EXPECT_FALSE(
3174 host_impl.active_tree()
3175 ->property_trees()
3176 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
trchendba8b1502016-07-08 09:47:013177 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563178
sunxd71aea3e2016-04-01 23:48:053179 // Since |grand_child| has an uninvertible screen space transform, it is
3180 // skipped so
3181 // that we are not computing its occlusion_in_content_space.
3182 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563183 EXPECT_EQ(
3184 layer_bounds,
3185 grand_child_ptr->draw_properties()
3186 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3187}
3188
3189TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233190 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593191 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173192 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3193 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173194 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173195 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283196
danakje4fa7b72016-07-25 22:00:063197 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323198 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063199 render_surface->SetBounds(gfx::Size(3, 4));
3200 render_surface->test_properties()->force_render_surface = true;
3201 child1->SetPosition(gfx::PointF(5.f, 5.f));
3202 child1->SetBounds(gfx::Size(50, 50));
3203 child1->SetDrawsContent(true);
3204 child2->SetPosition(gfx::PointF(75.f, 75.f));
3205 child2->SetBounds(gfx::Size(50, 50));
3206 child2->SetDrawsContent(true);
3207 child3->SetPosition(gfx::PointF(125.f, 125.f));
3208 child3->SetBounds(gfx::Size(50, 50));
3209 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173210 ExecuteCalculateDrawProperties(root);
3211
chrishtr7e3aaf22017-05-04 15:04:013212 ASSERT_TRUE(GetRenderSurface(render_surface));
[email protected]fb661802013-03-25 01:59:323213
danakj5e6ff6d2015-09-05 04:43:443214 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:013215 GetRenderSurface(root)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323216
3217 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433218 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173219 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323220
3221 // A clipped surface grows its DrawableContentRect to include all drawable
3222 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443223 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
chrishtr7e3aaf22017-05-04 15:04:013224 GetRenderSurface(render_surface)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323225
3226 // All layers that draw content into the surface have their visible content
3227 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433228 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3229 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3230 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323231
3232 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323233 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3234 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3235 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323236}
3237
[email protected]989386c2013-07-18 21:37:233238TEST_F(LayerTreeHostCommonTest,
3239 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323240 // Check that clipping does not propagate down surfaces.
jaydasikabf1875a2016-06-28 03:39:593241 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173242 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3243 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3244 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173245 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173246 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283247
danakje4fa7b72016-07-25 22:00:063248 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323249 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063250 render_surface1->SetBounds(gfx::Size(3, 4));
3251 render_surface1->test_properties()->force_render_surface = true;
3252 render_surface2->SetBounds(gfx::Size(7, 13));
3253 render_surface2->test_properties()->force_render_surface = true;
3254 child1->SetPosition(gfx::PointF(5.f, 5.f));
3255 child1->SetBounds(gfx::Size(50, 50));
3256 child1->SetDrawsContent(true);
3257 child2->SetPosition(gfx::PointF(75.f, 75.f));
3258 child2->SetBounds(gfx::Size(50, 50));
3259 child2->SetDrawsContent(true);
3260 child3->SetPosition(gfx::PointF(125.f, 125.f));
3261 child3->SetBounds(gfx::Size(50, 50));
3262 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173263 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323264
chrishtr7e3aaf22017-05-04 15:04:013265 ASSERT_TRUE(GetRenderSurface(render_surface1));
3266 ASSERT_TRUE(GetRenderSurface(render_surface2));
[email protected]fb661802013-03-25 01:59:323267
danakj5e6ff6d2015-09-05 04:43:443268 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:013269 GetRenderSurface(root)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323270
3271 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433272 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3273 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3274 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323275
3276 // A clipped surface grows its DrawableContentRect to include all drawable
3277 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443278 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
chrishtr7e3aaf22017-05-04 15:04:013279 GetRenderSurface(render_surface1)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323280
3281 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3282 // is only implicitly clipped by render_surface1's content rect. So,
3283 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443284 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
chrishtr7e3aaf22017-05-04 15:04:013285 GetRenderSurface(render_surface2)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323286
jaydasika94bebdd2016-09-16 22:11:183287 // All layers that draw content into render_surface2 think they are unclipped
3288 // by the surface. So, only the viewport clip applies.
danakj64767d902015-06-19 00:10:433289 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183290 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3291 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323292
3293 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323294 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3295 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3296 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323297}
3298
[email protected]989386c2013-07-18 21:37:233299TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463300 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593301 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463302 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3303 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3304 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3305 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
jaydasika27d0f2e2015-10-16 23:52:463306
danakje4fa7b72016-07-25 22:00:063307 root->SetBounds(gfx::Size(100, 100));
3308 render_surface1->SetBounds(gfx::Size(100, 100));
3309 render_surface1->test_properties()->force_render_surface = true;
3310 child1->SetBounds(gfx::Size(500, 500));
3311 child1->SetDrawsContent(true);
3312 child2->SetBounds(gfx::Size(700, 700));
3313 child2->SetDrawsContent(true);
3314 render_surface2->SetBounds(gfx::Size(1000, 1000));
3315 render_surface2->test_properties()->force_render_surface = true;
3316 render_surface2->SetDrawsContent(true);
jaydasika27d0f2e2015-10-16 23:52:463317
3318 child1->SetMasksToBounds(true);
3319 child2->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463320 ExecuteCalculateDrawProperties(root);
jaydasika526eae0a2016-09-02 01:47:593321 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463322 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3323}
3324
3325TEST_F(LayerTreeHostCommonTest,
3326 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593327 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463328 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3329 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3330 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3331 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3332
danakje4fa7b72016-07-25 22:00:063333 root->SetBounds(gfx::Size(100, 100));
3334
3335 clip_parent->SetBounds(gfx::Size(50, 50));
3336 clip_parent->SetMasksToBounds(true);
3337 clip_parent->test_properties()->clip_children =
3338 base::MakeUnique<std::set<LayerImpl*>>();
3339 clip_parent->test_properties()->clip_children->insert(clip_child);
3340
3341 render_surface1->SetBounds(gfx::Size(20, 20));
3342 render_surface1->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463343 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063344 render_surface1->test_properties()->force_render_surface = true;
3345
3346 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika27d0f2e2015-10-16 23:52:463347 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563348 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika27d0f2e2015-10-16 23:52:463349
danakje4fa7b72016-07-25 22:00:063350 render_surface2->SetBounds(gfx::Size(60, 60));
3351 render_surface2->SetDrawsContent(true);
3352 render_surface2->test_properties()->force_render_surface = true;
jaydasika27d0f2e2015-10-16 23:52:463353
3354 ExecuteCalculateDrawProperties(root);
3355 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3356 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3357 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3358}
3359
jaydasika1f5312d2015-10-21 21:34:323360TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
jaydasikabf1875a2016-06-28 03:39:593361 LayerImpl* root = root_layer_for_testing();
jaydasika1f5312d2015-10-21 21:34:323362 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
jaydasika1553a142017-04-05 00:37:093363 LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent);
3364 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer);
jaydasika1f5312d2015-10-21 21:34:323365 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3366 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3367
danakje4fa7b72016-07-25 22:00:063368 root->SetBounds(gfx::Size(100, 100));
3369
3370 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
3371 clip_parent->SetBounds(gfx::Size(50, 50));
3372 clip_parent->test_properties()->clip_children =
3373 base::MakeUnique<std::set<LayerImpl*>>();
3374 clip_parent->test_properties()->clip_children->insert(clip_child);
3375
jaydasika1553a142017-04-05 00:37:093376 clip_layer->SetBounds(gfx::Size(50, 50));
3377
danakje4fa7b72016-07-25 22:00:063378 render_surface1->SetBounds(gfx::Size(20, 20));
jaydasika1f5312d2015-10-21 21:34:323379 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063380 render_surface1->test_properties()->force_render_surface = true;
3381
3382 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika1f5312d2015-10-21 21:34:323383 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563384 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika1f5312d2015-10-21 21:34:323385
danakje4fa7b72016-07-25 22:00:063386 render_surface2->SetBounds(gfx::Size(60, 60));
3387 render_surface2->SetDrawsContent(true);
3388 render_surface2->test_properties()->force_render_surface = true;
3389
jaydasika1f5312d2015-10-21 21:34:323390 clip_parent->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:093391 clip_layer->SetMasksToBounds(true);
jaydasika1f5312d2015-10-21 21:34:323392 render_surface1->SetMasksToBounds(true);
3393
jaydasika44b074e2017-03-07 21:11:383394 float device_scale_factor = 1.f;
3395 ExecuteCalculateDrawProperties(root, device_scale_factor);
chrishtr7e3aaf22017-05-04 15:04:013396 EXPECT_EQ(gfx::Rect(50, 50), GetRenderSurface(render_surface2)->clip_rect());
jaydasika44b074e2017-03-07 21:11:383397 device_scale_factor = 2.f;
3398 ExecuteCalculateDrawProperties(root, device_scale_factor);
3399 EXPECT_EQ(gfx::Rect(100, 100),
chrishtr7e3aaf22017-05-04 15:04:013400 GetRenderSurface(render_surface2)->clip_rect());
jaydasika1f5312d2015-10-21 21:34:323401}
3402
jaydasika77a4a072015-10-20 21:47:273403TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3404 // Test that only drawn layers contribute to render surface content rect.
jaydasikabf1875a2016-06-28 03:39:593405 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:273406 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3407 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3408
danakje4fa7b72016-07-25 22:00:063409 root->SetBounds(gfx::Size(200, 200));
3410 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:273411 surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063412 surface->test_properties()->force_render_surface = true;
3413 test_layer->SetBounds(gfx::Size(150, 150));
jaydasika77a4a072015-10-20 21:47:273414
3415 ExecuteCalculateDrawProperties(root);
chrishtr7e3aaf22017-05-04 15:04:013416 EXPECT_EQ(gfx::Rect(100, 100), GetRenderSurface(surface)->content_rect());
jaydasika77a4a072015-10-20 21:47:273417
3418 test_layer->SetDrawsContent(true);
3419 ExecuteCalculateDrawProperties(root);
chrishtr7e3aaf22017-05-04 15:04:013420 EXPECT_EQ(gfx::Rect(150, 150), GetRenderSurface(surface)->content_rect());
jaydasika77a4a072015-10-20 21:47:273421}
3422
jaydasika27d0f2e2015-10-16 23:52:463423TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3424 // Tests visible rects computation when we have unclipped_surface->
3425 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3426 // of surface_with_unclipped_descendants doesn't propagate to the
3427 // clipped_surface below it.
jaydasikabf1875a2016-06-28 03:39:593428 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463429 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3430 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3431 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3432 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3433 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3434
danakje4fa7b72016-07-25 22:00:063435 root->SetBounds(gfx::Size(100, 100));
jaydasika27d0f2e2015-10-16 23:52:463436
danakje4fa7b72016-07-25 22:00:063437 unclipped_surface->SetBounds(gfx::Size(30, 30));
3438 unclipped_surface->SetDrawsContent(true);
3439 unclipped_surface->test_properties()->force_render_surface = true;
3440
3441 clip_parent->SetBounds(gfx::Size(50, 50));
3442 clip_parent->test_properties()->clip_children =
3443 base::MakeUnique<std::set<LayerImpl*>>();
3444 clip_parent->test_properties()->clip_children->insert(clip_child);
3445
3446 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
3447 unclipped_desc_surface->SetDrawsContent(true);
3448 unclipped_desc_surface->test_properties()->force_render_surface = true;
3449
3450 clip_child->SetBounds(gfx::Size(60, 60));
3451 clip_child->test_properties()->clip_parent = clip_parent;
3452
3453 clipped_surface->SetBounds(gfx::Size(60, 60));
3454 clipped_surface->SetDrawsContent(true);
3455 clipped_surface->test_properties()->force_render_surface = true;
3456
jaydasika27d0f2e2015-10-16 23:52:463457 clip_parent->SetMasksToBounds(true);
3458
3459 ExecuteCalculateDrawProperties(root);
3460 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3461 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3462 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3463}
3464
3465TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3466 // Tests visible rects computation when we have unclipped_surface->
3467 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3468 // of root propagate to the clipped_surface.
jaydasikabf1875a2016-06-28 03:39:593469 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463470 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3471 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3472 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3473 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3474 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3475
danakje4fa7b72016-07-25 22:00:063476 root->SetBounds(gfx::Size(10, 10));
jaydasika27d0f2e2015-10-16 23:52:463477
danakje4fa7b72016-07-25 22:00:063478 unclipped_surface->SetBounds(gfx::Size(50, 50));
3479 unclipped_surface->SetDrawsContent(true);
3480 unclipped_surface->test_properties()->force_render_surface = true;
3481
3482 clip_parent->SetBounds(gfx::Size(50, 50));
3483 clip_parent->test_properties()->clip_children =
3484 base::MakeUnique<std::set<LayerImpl*>>();
3485 clip_parent->test_properties()->clip_children->insert(clip_child);
3486
3487 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
3488 unclipped_desc_surface->SetDrawsContent(true);
3489 unclipped_desc_surface->test_properties()->force_render_surface = true;
3490
3491 clip_child->SetBounds(gfx::Size(100, 100));
3492 clip_child->test_properties()->clip_parent = clip_parent;
3493
3494 clipped_surface->SetBounds(gfx::Size(50, 50));
3495 clipped_surface->SetDrawsContent(true);
3496 clipped_surface->test_properties()->force_render_surface = true;
3497
jaydasika27d0f2e2015-10-16 23:52:463498 clip_parent->SetMasksToBounds(true);
3499 unclipped_desc_surface->SetMasksToBounds(true);
3500
3501 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:183502 EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593503 EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463504 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3505}
3506
3507TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233508 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323509 // Layers that have non-axis aligned bounds (due to transforms) have an
3510 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593511 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173512 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3513 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283514
[email protected]fb661802013-03-25 01:59:323515 gfx::Transform child_rotation;
3516 child_rotation.Rotate(45.0);
[email protected]fb661802013-03-25 01:59:323517
danakje4fa7b72016-07-25 22:00:063518 root->SetBounds(gfx::Size(100, 100));
3519 render_surface->SetBounds(gfx::Size(3, 4));
3520 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:043521 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:063522 child1->SetPosition(gfx::PointF(25.f, 25.f));
3523 child1->SetBounds(gfx::Size(50, 50));
3524 child1->SetDrawsContent(true);
3525 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173526 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323527
chrishtr7e3aaf22017-05-04 15:04:013528 ASSERT_TRUE(GetRenderSurface(render_surface));
[email protected]fb661802013-03-25 01:59:323529
danakj5e6ff6d2015-09-05 04:43:443530 EXPECT_EQ(gfx::RectF(100.f, 100.f),
chrishtr7e3aaf22017-05-04 15:04:013531 GetRenderSurface(root)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323532
3533 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433534 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173535 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323536
3537 // The unclipped surface grows its DrawableContentRect to include all drawable
3538 // regions of the subtree.
3539 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3540 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263541 gfx::Rect(50 - diagonal_radius,
3542 50 - diagonal_radius,
3543 diagonal_radius * 2,
3544 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443545 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
chrishtr7e3aaf22017-05-04 15:04:013546 GetRenderSurface(render_surface)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323547
3548 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433549 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:323550 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323551}
3552
[email protected]989386c2013-07-18 21:37:233553TEST_F(LayerTreeHostCommonTest,
3554 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323555 // Layers that have non-axis aligned bounds (due to transforms) have an
3556 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593557 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173558 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3559 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283560
[email protected]fb661802013-03-25 01:59:323561 gfx::Transform child_rotation;
3562 child_rotation.Rotate(45.0);
[email protected]a2566412014-06-05 03:14:203563
danakje4fa7b72016-07-25 22:00:063564 root->SetBounds(gfx::Size(50, 50));
[email protected]fb661802013-03-25 01:59:323565 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063566 render_surface->SetBounds(gfx::Size(3, 4));
3567 render_surface->test_properties()->force_render_surface = true;
3568 child1->SetPosition(gfx::PointF(25.f, 25.f));
3569 child1->SetBounds(gfx::Size(50, 50));
3570 child1->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:043571 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:063572 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173573 ExecuteCalculateDrawProperties(root);
3574
chrishtr7e3aaf22017-05-04 15:04:013575 ASSERT_TRUE(GetRenderSurface(render_surface));
[email protected]fb661802013-03-25 01:59:323576
3577 // The clipped surface clamps the DrawableContentRect that encloses the
3578 // rotated layer.
3579 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263580 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3581 50 - diagonal_radius,
3582 diagonal_radius * 2,
3583 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443584 gfx::RectF expected_surface_drawable_content(
3585 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:323586 EXPECT_EQ(expected_surface_drawable_content,
chrishtr7e3aaf22017-05-04 15:04:013587 GetRenderSurface(render_surface)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323588
3589 // On the clipped surface, only a quarter of the child1 is visible, but when
3590 // rotating it back to child1's content space, the actual enclosing rect ends
3591 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:333592 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323593
3594 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323595 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323596}
3597
[email protected]989386c2013-07-18 21:37:233598TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:593599 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173600 FakePictureLayerImpl* render_surface1 =
3601 AddChildToRoot<FakePictureLayerImpl>();
weiliangc0dece732015-07-27 19:06:173602 FakePictureLayerImpl* render_surface2 =
3603 AddChild<FakePictureLayerImpl>(render_surface1);
weiliangc0dece732015-07-27 19:06:173604 FakePictureLayerImpl* child1 =
3605 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173606 FakePictureLayerImpl* child2 =
3607 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173608 FakePictureLayerImpl* child3 =
3609 AddChild<FakePictureLayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283610
danakje4fa7b72016-07-25 22:00:063611 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323612 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063613 render_surface1->SetBounds(gfx::Size(3, 4));
3614 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
3615 render_surface1->SetDrawsContent(true);
3616 render_surface1->test_properties()->force_render_surface = true;
3617 render_surface2->SetBounds(gfx::Size(7, 13));
3618 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
3619 render_surface2->SetDrawsContent(true);
3620 render_surface2->test_properties()->force_render_surface = true;
3621 child1->SetBounds(gfx::Size(50, 50));
3622 child1->SetPosition(gfx::PointF(5.f, 5.f));
3623 child1->SetDrawsContent(true);
3624 child2->SetBounds(gfx::Size(50, 50));
3625 child2->SetPosition(gfx::PointF(75.f, 75.f));
3626 child2->SetDrawsContent(true);
3627 child3->SetBounds(gfx::Size(50, 50));
3628 child3->SetPosition(gfx::PointF(125.f, 125.f));
3629 child3->SetDrawsContent(true);
3630 float device_scale_factor = 2.f;
weiliangc0dece732015-07-27 19:06:173631 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:323632
chrishtr7e3aaf22017-05-04 15:04:013633 ASSERT_TRUE(GetRenderSurface(render_surface1));
3634 ASSERT_TRUE(GetRenderSurface(render_surface2));
[email protected]fb661802013-03-25 01:59:323635
3636 // drawable_content_rects for all layers and surfaces are scaled by
3637 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:443638 EXPECT_EQ(gfx::RectF(200.f, 200.f),
chrishtr7e3aaf22017-05-04 15:04:013639 GetRenderSurface(root)->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:443640 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
chrishtr7e3aaf22017-05-04 15:04:013641 GetRenderSurface(render_surface1)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323642
3643 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3644 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:443645 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
chrishtr7e3aaf22017-05-04 15:04:013646 GetRenderSurface(render_surface2)->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323647
hush6b614212014-12-04 22:37:323648 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3649 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3650 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323651
3652 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:433653 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323654
sohan.jyotie3bd6192014-10-13 07:13:593655 // All layer visible content rects are not expressed in content space of each
3656 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:433657 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
3658 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
3659 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183660 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect());
3661 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323662}
3663
[email protected]989386c2013-07-18 21:37:233664TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323665 // Verify the behavior of back-face culling when there are no preserve-3d
3666 // layers. Note that 3d transforms still apply in this case, but they are
3667 // "flattened" to each parent layer according to current W3C spec.
3668
danakje4fa7b72016-07-25 22:00:063669 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:323670 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
3671 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
3672 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
3673 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
3674 LayerImpl* front_facing_child_of_front_facing_surface =
3675 AddChild<LayerImpl>(front_facing_surface);
3676 LayerImpl* back_facing_child_of_front_facing_surface =
3677 AddChild<LayerImpl>(front_facing_surface);
3678 LayerImpl* front_facing_child_of_back_facing_surface =
3679 AddChild<LayerImpl>(back_facing_surface);
3680 LayerImpl* back_facing_child_of_back_facing_surface =
3681 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:283682
[email protected]fb661802013-03-25 01:59:323683 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:323684 front_facing_child->test_properties()->double_sided = false;
3685 back_facing_child->test_properties()->double_sided = false;
3686 front_facing_surface->test_properties()->double_sided = false;
3687 back_facing_surface->test_properties()->double_sided = false;
3688 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
3689 false;
3690 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
3691 false;
3692 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
3693 false;
3694 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
3695 false;
3696
3697 // Everything draws content.
3698 front_facing_child->SetDrawsContent(true);
3699 back_facing_child->SetDrawsContent(true);
3700 front_facing_surface->SetDrawsContent(true);
3701 back_facing_surface->SetDrawsContent(true);
3702 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
3703 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
3704 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
3705 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:323706
3707 gfx::Transform backface_matrix;
3708 backface_matrix.Translate(50.0, 50.0);
3709 backface_matrix.RotateAboutYAxis(180.0);
3710 backface_matrix.Translate(-50.0, -50.0);
3711
danakje4fa7b72016-07-25 22:00:063712 root->SetBounds(gfx::Size(100, 100));
3713 front_facing_child->SetBounds(gfx::Size(100, 100));
3714 back_facing_child->SetBounds(gfx::Size(100, 100));
3715 front_facing_surface->SetBounds(gfx::Size(100, 100));
3716 back_facing_surface->SetBounds(gfx::Size(100, 100));
3717 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
3718 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
3719 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
3720 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323721
danakje4fa7b72016-07-25 22:00:063722 front_facing_surface->test_properties()->force_render_surface = true;
3723 back_facing_surface->test_properties()->force_render_surface = true;
[email protected]fb661802013-03-25 01:59:323724
jaydasika10d43fc2016-08-18 04:06:043725 back_facing_child->test_properties()->transform = backface_matrix;
3726 back_facing_surface->test_properties()->transform = backface_matrix;
3727 back_facing_child_of_front_facing_surface->test_properties()->transform =
3728 backface_matrix;
3729 back_facing_child_of_back_facing_surface->test_properties()->transform =
3730 backface_matrix;
danakje4fa7b72016-07-25 22:00:063731
3732 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
3733 // spec, these layers should blindly use their own local transforms to
3734 // determine back-face culling.
jaydasika6ed869662016-09-21 14:29:593735 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:323736
3737 // Verify which render surfaces were created.
chrishtr5f60ca02017-05-11 23:09:493738 EXPECT_EQ(GetRenderSurface(front_facing_child), GetRenderSurface(root));
3739 EXPECT_EQ(GetRenderSurface(back_facing_child), GetRenderSurface(root));
3740 EXPECT_NE(GetRenderSurface(front_facing_surface), GetRenderSurface(root));
3741 EXPECT_NE(GetRenderSurface(back_facing_surface), GetRenderSurface(root));
3742 EXPECT_NE(GetRenderSurface(back_facing_surface),
3743 GetRenderSurface(front_facing_surface));
3744 EXPECT_EQ(GetRenderSurface(front_facing_child_of_front_facing_surface),
3745 GetRenderSurface(front_facing_surface));
3746 EXPECT_EQ(GetRenderSurface(back_facing_child_of_front_facing_surface),
3747 GetRenderSurface(front_facing_surface));
3748 EXPECT_EQ(GetRenderSurface(front_facing_child_of_back_facing_surface),
3749 GetRenderSurface(back_facing_surface));
3750 EXPECT_EQ(GetRenderSurface(back_facing_child_of_back_facing_surface),
3751 GetRenderSurface(back_facing_surface));
[email protected]fb661802013-03-25 01:59:323752
trchen75204782016-11-03 01:05:423753 EXPECT_EQ(3u, update_layer_list_impl()->size());
ajuma4711f4b12016-05-16 18:48:323754 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
3755 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
3756 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:533757 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:323758}
3759
[email protected]989386c2013-07-18 21:37:233760TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323761 // Verify the behavior of back-face culling when preserves-3d transform style
3762 // is used.
3763
danakje4fa7b72016-07-25 22:00:063764 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:263765 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
3766 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
3767 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
3768 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
3769 LayerImpl* front_facing_child_of_front_facing_surface =
3770 AddChild<LayerImpl>(front_facing_surface);
3771 LayerImpl* back_facing_child_of_front_facing_surface =
3772 AddChild<LayerImpl>(front_facing_surface);
3773 LayerImpl* front_facing_child_of_back_facing_surface =
3774 AddChild<LayerImpl>(back_facing_surface);
3775 LayerImpl* back_facing_child_of_back_facing_surface =
3776 AddChild<LayerImpl>(back_facing_surface);
3777 // Opacity will not force creation of render surfaces in this case because of
3778 // the preserve-3d transform style. Instead, an example of when a surface
wangxianzhu932d7f12016-09-30 05:47:003779 // would be created with preserve-3d is when there is a mask layer.
3780 LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface);
3781 LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:283782
[email protected]fb661802013-03-25 01:59:323783 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:363784 front_facing_child->test_properties()->double_sided = false;
3785 back_facing_child->test_properties()->double_sided = false;
3786 front_facing_surface->test_properties()->double_sided = false;
3787 back_facing_surface->test_properties()->double_sided = false;
3788 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
3789 false;
3790 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
3791 false;
3792 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
3793 false;
3794 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
3795 false;
[email protected]fb661802013-03-25 01:59:323796
weiliangcc154ce22015-12-09 03:39:263797 // Everything draws content.
3798 front_facing_child->SetDrawsContent(true);
3799 back_facing_child->SetDrawsContent(true);
3800 front_facing_surface->SetDrawsContent(true);
3801 back_facing_surface->SetDrawsContent(true);
3802 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
3803 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
3804 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
3805 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
wangxianzhu932d7f12016-09-30 05:47:003806 dummy_mask_layer1->SetDrawsContent(true);
3807 dummy_mask_layer2->SetDrawsContent(true);
weiliangcc154ce22015-12-09 03:39:263808
[email protected]fb661802013-03-25 01:59:323809 gfx::Transform backface_matrix;
3810 backface_matrix.Translate(50.0, 50.0);
3811 backface_matrix.RotateAboutYAxis(180.0);
3812 backface_matrix.Translate(-50.0, -50.0);
3813
danakje4fa7b72016-07-25 22:00:063814 root->SetBounds(gfx::Size(100, 100));
3815 front_facing_child->SetBounds(gfx::Size(100, 100));
3816 back_facing_child->SetBounds(gfx::Size(100, 100));
3817 front_facing_surface->SetBounds(gfx::Size(100, 100));
3818 back_facing_surface->SetBounds(gfx::Size(100, 100));
3819 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
3820 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
3821 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
3822 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
3823
jaydasika10d43fc2016-08-18 04:06:043824 back_facing_child->test_properties()->transform = backface_matrix;
3825 back_facing_surface->test_properties()->transform = backface_matrix;
3826 back_facing_child_of_front_facing_surface->test_properties()->transform =
3827 backface_matrix;
3828 back_facing_child_of_back_facing_surface->test_properties()->transform =
3829 backface_matrix;
danakje4fa7b72016-07-25 22:00:063830
[email protected]fb661802013-03-25 01:59:323831 // Each surface creates its own new 3d rendering context (as defined by W3C
3832 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3833 // rendering context should use the transform with respect to that context.
3834 // This 3d rendering context occurs when (a) parent's transform style is flat
3835 // and (b) the layer's transform style is preserve-3d.
danakje4fa7b72016-07-25 22:00:063836 front_facing_surface->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203837 front_facing_surface->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:063838 back_facing_surface->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203839 back_facing_surface->test_properties()->sorting_context_id = 1;
3840 front_facing_child_of_front_facing_surface->test_properties()
3841 ->sorting_context_id = 1;
3842 back_facing_child_of_front_facing_surface->test_properties()
3843 ->sorting_context_id = 1;
3844 front_facing_child_of_back_facing_surface->test_properties()
3845 ->sorting_context_id = 1;
3846 back_facing_child_of_back_facing_surface->test_properties()
3847 ->sorting_context_id = 1;
[email protected]fb661802013-03-25 01:59:323848
jaydasika6ed869662016-09-21 14:29:593849 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:323850
awoloszyne83f28c2014-12-22 15:40:003851 // Verify which render surfaces were created and used.
chrishtr5f60ca02017-05-11 23:09:493852 EXPECT_EQ(GetRenderSurface(front_facing_child), GetRenderSurface(root));
3853 EXPECT_EQ(GetRenderSurface(back_facing_child), GetRenderSurface(root));
3854 EXPECT_NE(GetRenderSurface(front_facing_surface), GetRenderSurface(root));
ennec1332992015-08-24 19:45:093855 // We expect that a has_render_surface was created but not used.
chrishtr5f60ca02017-05-11 23:09:493856 EXPECT_NE(GetRenderSurface(back_facing_surface), GetRenderSurface(root));
3857 EXPECT_NE(GetRenderSurface(back_facing_surface),
3858 GetRenderSurface(front_facing_surface));
3859 EXPECT_EQ(GetRenderSurface(front_facing_child_of_front_facing_surface),
3860 GetRenderSurface(front_facing_surface));
3861 EXPECT_EQ(GetRenderSurface(back_facing_child_of_front_facing_surface),
3862 GetRenderSurface(front_facing_surface));
3863 EXPECT_EQ(GetRenderSurface(front_facing_child_of_back_facing_surface),
3864 GetRenderSurface(back_facing_surface));
3865 EXPECT_EQ(GetRenderSurface(back_facing_child_of_back_facing_surface),
3866 GetRenderSurface(back_facing_surface));
[email protected]fb661802013-03-25 01:59:323867
weiliangcc154ce22015-12-09 03:39:263868 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:323869
weiliangcc154ce22015-12-09 03:39:263870 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
3871 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
3872 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:533873 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:323874}
3875
[email protected]989386c2013-07-18 21:37:233876TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323877 // Verify that layers are appropriately culled when their back face is showing
3878 // and they are not double sided, while animations are going on.
3879 //
ajuma4711f4b12016-05-16 18:48:323880 // Even layers that are animating get culled if their back face is showing and
3881 // they are not double sided.
danakje4fa7b72016-07-25 22:00:063882 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:323883 LayerImpl* child = AddChildToRoot<LayerImpl>();
3884 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
3885 LayerImpl* child_of_animating_surface =
3886 AddChild<LayerImpl>(animating_surface);
3887 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
3888 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:283889
[email protected]fb661802013-03-25 01:59:323890 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:323891 child->test_properties()->double_sided = false;
3892 child2->test_properties()->double_sided = false;
3893 animating_surface->test_properties()->double_sided = false;
3894 child_of_animating_surface->test_properties()->double_sided = false;
3895 animating_child->test_properties()->double_sided = false;
3896
3897 // Everything draws content.
3898 child->SetDrawsContent(true);
3899 child2->SetDrawsContent(true);
3900 animating_surface->SetDrawsContent(true);
3901 child_of_animating_surface->SetDrawsContent(true);
3902 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:323903
3904 gfx::Transform backface_matrix;
3905 backface_matrix.Translate(50.0, 50.0);
3906 backface_matrix.RotateAboutYAxis(180.0);
3907 backface_matrix.Translate(-50.0, -50.0);
3908
vollickef2ae922016-06-29 17:54:273909 SetElementIdsForTesting();
3910
loyso9556c732016-03-11 07:54:583911 // Animate the transform on the render surface.
vollickef2ae922016-06-29 17:54:273912 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
3913 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:583914 // This is just an animating layer, not a surface.
vollickef2ae922016-06-29 17:54:273915 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
3916 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:323917
danakje4fa7b72016-07-25 22:00:063918 root->SetBounds(gfx::Size(100, 100));
3919 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043920 child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:063921 animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043922 animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:063923 animating_surface->test_properties()->force_render_surface = true;
3924 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043925 child_of_animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:063926 animating_child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043927 animating_child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:063928 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323929
jaydasika6ed869662016-09-21 14:29:593930 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:323931
chrishtr5f60ca02017-05-11 23:09:493932 EXPECT_EQ(GetRenderSurface(child), GetRenderSurface(root));
chrishtr7e3aaf22017-05-04 15:04:013933 EXPECT_TRUE(GetRenderSurface(animating_surface));
chrishtr5f60ca02017-05-11 23:09:493934 EXPECT_EQ(GetRenderSurface(child_of_animating_surface),
3935 GetRenderSurface(animating_surface));
3936 EXPECT_EQ(GetRenderSurface(animating_child), GetRenderSurface(root));
3937 EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(root));
[email protected]fb661802013-03-25 01:59:323938
ajuma4711f4b12016-05-16 18:48:323939 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:533940
ajuma4711f4b12016-05-16 18:48:323941 // The back facing layers are culled from the layer list, and have an empty
3942 // visible rect.
3943 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
3944 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
3945 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
3946 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
3947 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323948
ajuma4711f4b12016-05-16 18:48:323949 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323950}
3951
[email protected]989386c2013-07-18 21:37:233952TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:323953 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3954 // Verify the behavior of back-face culling for a render surface that is
3955 // created when it flattens its subtree, and its parent has preserves-3d.
3956
danakje4fa7b72016-07-25 22:00:063957 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:323958 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
3959 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
3960 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
3961 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:283962
[email protected]fb661802013-03-25 01:59:323963 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:323964 front_facing_surface->test_properties()->double_sided = false;
3965 back_facing_surface->test_properties()->double_sided = false;
3966
3967 // Everything draws content.
3968 front_facing_surface->SetDrawsContent(true);
3969 back_facing_surface->SetDrawsContent(true);
3970 child1->SetDrawsContent(true);
3971 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:323972
3973 gfx::Transform backface_matrix;
3974 backface_matrix.Translate(50.0, 50.0);
3975 backface_matrix.RotateAboutYAxis(180.0);
3976 backface_matrix.Translate(-50.0, -50.0);
3977
danakje4fa7b72016-07-25 22:00:063978 root->SetBounds(gfx::Size(100, 100));
3979 front_facing_surface->SetBounds(gfx::Size(100, 100));
3980 front_facing_surface->test_properties()->force_render_surface = true;
3981 back_facing_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043982 back_facing_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:063983 back_facing_surface->test_properties()->force_render_surface = true;
3984 child1->SetBounds(gfx::Size(100, 100));
3985 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323986
wkormanf09921d2017-01-07 01:01:203987 front_facing_surface->test_properties()->sorting_context_id = 1;
3988 back_facing_surface->test_properties()->sorting_context_id = 1;
[email protected]56fffdd2014-02-11 19:50:573989
jaydasika6ed869662016-09-21 14:29:593990 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:323991
awoloszyne83f28c2014-12-22 15:40:003992 // Verify which render surfaces were created and used.
chrishtr7e3aaf22017-05-04 15:04:013993 EXPECT_TRUE(GetRenderSurface(front_facing_surface));
awoloszyne83f28c2014-12-22 15:40:003994
3995 // We expect the render surface to have been created, but remain unused.
chrishtr5f60ca02017-05-11 23:09:493996 EXPECT_NE(GetRenderSurface(back_facing_surface), GetRenderSurface(root));
3997 EXPECT_EQ(GetRenderSurface(child1), GetRenderSurface(front_facing_surface));
3998 EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(back_facing_surface));
[email protected]fb661802013-03-25 01:59:323999
ajuma4711f4b12016-05-16 18:48:324000 EXPECT_EQ(2u, update_layer_list_impl()->size());
4001 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4002 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324003}
4004
enne637715732015-07-07 02:05:264005TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324006 // Verify draw and screen space transforms of layers not in a surface.
danakje4fa7b72016-07-25 22:00:064007 LayerImpl* root = root_layer_for_testing();
4008 root->SetBounds(gfx::Size(100, 100));
4009 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144010
enne637715732015-07-07 02:05:264011 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064012 child->SetPosition(gfx::PointF(2.f, 2.f));
4013 child->SetBounds(gfx::Size(10, 10));
jaydasika8640f9f2015-11-10 01:34:364014 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144015
jaydasika8640f9f2015-11-10 01:34:364016 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064017 child2->SetPosition(gfx::PointF(2.f, 2.f));
4018 child2->SetBounds(gfx::Size(5, 5));
jaydasika8640f9f2015-11-10 01:34:364019 child2->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284020
[email protected]fb661802013-03-25 01:59:324021 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264022 gfx::Size viewport_size(100, 100);
danakje4fa7b72016-07-25 22:00:064023 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144024
danakj59931942016-07-26 22:11:294025 EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale());
4026 EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale());
4027 EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale());
[email protected]518ee582012-10-24 18:29:444028
ajumab784ef42017-04-28 23:01:524029 EXPECT_EQ(1u, render_surface_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144030
danakje4fa7b72016-07-25 22:00:064031 // Verify root transforms
4032 gfx::Transform expected_root_transform;
4033 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4034 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4035 root->ScreenSpaceTransform());
4036 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4037 root->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144038
danakje4fa7b72016-07-25 22:00:064039 // Verify results of transformed root rects
4040 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
[email protected]94f206c12012-08-25 00:09:144041
danakje4fa7b72016-07-25 22:00:064042 gfx::RectF root_draw_rect =
4043 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4044 gfx::RectF root_screen_space_rect =
4045 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
[email protected]94f206c12012-08-25 00:09:144046
danakje4fa7b72016-07-25 22:00:064047 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4048 expected_root_draw_rect.Scale(device_scale_factor);
4049 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4050 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144051
jaydasika8640f9f2015-11-10 01:34:364052 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324053 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594054 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4055 expected_child_transform.Translate(child->position().x(),
4056 child->position().y());
[email protected]fb661802013-03-25 01:59:324057 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444058 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324059 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104060 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324061 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444062 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324063 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104064 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144065
jaydasika8640f9f2015-11-10 01:34:364066 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324067 // match.
danakjddaec912015-09-25 19:38:404068 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144069
[email protected]fb661802013-03-25 01:59:324070 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444071 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144072 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104073 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144074
jaydasika8640f9f2015-11-10 01:34:364075 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444076 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364077 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104078 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454079
danakjddaec912015-09-25 19:38:404080 gfx::RectF expected_child_draw_rect(child->position(),
4081 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324082 expected_child_draw_rect.Scale(device_scale_factor);
4083 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4084 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364085 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4086 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144087}
4088
enne637715732015-07-07 02:05:264089TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324090 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324091 gfx::Transform perspective_matrix;
4092 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094093
[email protected]fb661802013-03-25 01:59:324094 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054095 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094096
jaydasikabf1875a2016-06-28 03:39:594097 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064098 root->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094099
4100 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064101 page_scale->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094102
4103 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
danakje4fa7b72016-07-25 22:00:064104 parent->SetBounds(gfx::Size(100, 100));
jaydasika8640f9f2015-11-10 01:34:364105 parent->SetDrawsContent(true);
[email protected]9781afa2013-07-17 23:15:324106
enne637715732015-07-07 02:05:264107 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064108 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4109 perspective_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044110 perspective_surface->test_properties()->transform =
4111 perspective_matrix * scale_small_matrix;
enne637715732015-07-07 02:05:264112 perspective_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064113 perspective_surface->test_properties()->force_render_surface = true;
[email protected]1b30e8e2012-12-21 02:59:094114
enne637715732015-07-07 02:05:264115 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064116 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4117 scale_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044118 scale_surface->test_properties()->transform = scale_small_matrix;
enne637715732015-07-07 02:05:264119 scale_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064120 scale_surface->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:284121
[email protected]fb661802013-03-25 01:59:324122 float device_scale_factor = 2.5f;
4123 float page_scale_factor = 3.f;
pdr53abb452017-05-19 01:59:424124 LayerTreeImpl::ViewportLayerIds viewport_ids;
4125 viewport_ids.page_scale = page_scale->id();
4126 root->layer_tree_impl()->SetViewportLayersFromIds(viewport_ids);
jaydasika4340ea02016-06-06 19:44:264127 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094128 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264129 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackra283bed2016-10-31 14:49:424130 root, nullptr, nullptr);
[email protected]1b30e8e2012-12-21 02:59:094131
danakj59931942016-07-26 22:11:294132 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4133 parent->GetIdealContentsScale());
4134 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4135 perspective_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594136 // Ideal scale is the max 2d scale component of the combined transform up to
4137 // the nearest render target. Here this includes the layer transform as well
4138 // as the device and page scale factors.
4139 gfx::Transform transform = scale_small_matrix;
4140 transform.Scale(device_scale_factor * page_scale_factor,
4141 device_scale_factor * page_scale_factor);
4142 gfx::Vector2dF scales =
4143 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4144 float max_2d_scale = std::max(scales.x(), scales.y());
danakj59931942016-07-26 22:11:294145 EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594146
4147 // The ideal scale will draw 1:1 with its render target space along
4148 // the larger-scale axis.
4149 gfx::Vector2dF target_space_transform_scales =
4150 MathUtil::ComputeTransform2dScaleComponents(
4151 scale_surface->draw_properties().target_space_transform, 0.f);
4152 EXPECT_FLOAT_EQ(max_2d_scale,
4153 std::max(target_space_transform_scales.x(),
4154 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094155
ajumab784ef42017-04-28 23:01:524156 EXPECT_EQ(3u, render_surface_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094157
[email protected]fb661802013-03-25 01:59:324158 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594159 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4160 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324161 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444162 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094163
[email protected]fb661802013-03-25 01:59:324164 // The scale for the perspective surface is not known, so it is rendered 1:1
4165 // with the screen, and then scaled during drawing.
4166 gfx::Transform expected_perspective_surface_draw_transform;
4167 expected_perspective_surface_draw_transform.Translate(
4168 device_scale_factor * page_scale_factor *
4169 perspective_surface->position().x(),
4170 device_scale_factor * page_scale_factor *
4171 perspective_surface->position().y());
4172 expected_perspective_surface_draw_transform.PreconcatTransform(
4173 perspective_matrix);
4174 expected_perspective_surface_draw_transform.PreconcatTransform(
4175 scale_small_matrix);
4176 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594177 expected_perspective_surface_layer_draw_transform.Scale(
4178 device_scale_factor * page_scale_factor,
4179 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324180 EXPECT_TRANSFORMATION_MATRIX_EQ(
4181 expected_perspective_surface_draw_transform,
chrishtr7e3aaf22017-05-04 15:04:014182 GetRenderSurface(perspective_surface)->draw_transform());
[email protected]fb661802013-03-25 01:59:324183 EXPECT_TRANSFORMATION_MATRIX_EQ(
4184 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444185 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094186}
4187
enne637715732015-07-07 02:05:264188TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294189 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264190 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294191 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4192
4193 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264194 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294195 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4196
jaydasikabf1875a2016-06-28 03:39:594197 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294198 root->SetBounds(gfx::Size(100, 100));
4199
enne637715732015-07-07 02:05:264200 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064201 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044202 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364203 parent->SetDrawsContent(true);
[email protected]35a99a12013-05-09 23:52:294204
enne637715732015-07-07 02:05:264205 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064206 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4207 child_scale->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044208 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364209 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284210
[email protected]fb661802013-03-25 01:59:324211 float device_scale_factor = 2.5f;
4212 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214213
[email protected]989386c2013-07-18 21:37:234214 {
enne637715732015-07-07 02:05:264215 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackra283bed2016-10-31 14:49:424216 root, nullptr, nullptr);
[email protected]11ec92972012-11-10 03:06:214217
sohan.jyotie3bd6192014-10-13 07:13:594218 // The ideal scale is able to go below 1.
4219 float expected_ideal_scale =
4220 device_scale_factor * page_scale_factor * initial_parent_scale;
4221 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294222 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale());
[email protected]11ec92972012-11-10 03:06:214223
sohan.jyotie3bd6192014-10-13 07:13:594224 expected_ideal_scale = device_scale_factor * page_scale_factor *
4225 initial_parent_scale * initial_child_scale;
4226 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294227 EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale());
[email protected]989386c2013-07-18 21:37:234228 }
[email protected]11ec92972012-11-10 03:06:214229}
4230
enne637715732015-07-07 02:05:264231TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324232 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264233 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324234 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264235
[email protected]fb661802013-03-25 01:59:324236 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264237 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324238 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264239
jaydasikabf1875a2016-06-28 03:39:594240 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294241 root->SetBounds(gfx::Size(100, 100));
4242
enne637715732015-07-07 02:05:264243 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064244 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044245 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364246 parent->SetDrawsContent(true);
[email protected]6a9cff92012-11-08 11:53:264247
enne637715732015-07-07 02:05:264248 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064249 child_scale->SetBounds(gfx::Size(10, 10));
4250 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
jaydasika10d43fc2016-08-18 04:06:044251 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364252 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284253
danakje4fa7b72016-07-25 22:00:064254 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264255
danakj59931942016-07-26 22:11:294256 EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale());
danakje4fa7b72016-07-25 22:00:064257 // Animating layers compute ideal scale in the same way as when
4258 // they are static.
danakj59931942016-07-26 22:11:294259 EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale,
4260 child_scale->GetIdealContentsScale());
[email protected]6a9cff92012-11-08 11:53:264261}
4262
[email protected]989386c2013-07-18 21:37:234263TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594264 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064265 parent->SetBounds(gfx::Size(30, 30));
enneea850232015-07-27 16:43:124266 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064267 parent->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:204268 parent->test_properties()->sorting_context_id = 1;
[email protected]94f206c12012-08-25 00:09:144269
enneea850232015-07-27 16:43:124270 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064271 child->SetBounds(gfx::Size(10, 10));
4272 child->SetPosition(gfx::PointF(2.f, 2.f));
enneea850232015-07-27 16:43:124273 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064274 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:144275
[email protected]fb661802013-03-25 01:59:324276 // This layer should end up in the same surface as child, with the same draw
4277 // and screen space transforms.
enneea850232015-07-27 16:43:124278 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:064279 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
enneea850232015-07-27 16:43:124280 duplicate_child_non_owner->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144281
[email protected]fb661802013-03-25 01:59:324282 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124283 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144284
[email protected]fb661802013-03-25 01:59:324285 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004286 // render surface (it needs one because of force_render_surface).
ajumab784ef42017-04-28 23:01:524287 EXPECT_EQ(2u, render_surface_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144288
[email protected]fb661802013-03-25 01:59:324289 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594290 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324291 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104292 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444294 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144295
[email protected]fb661802013-03-25 01:59:324296 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594297 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324298 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444299 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144300
[email protected]fb661802013-03-25 01:59:324301 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594302 expected_screen_space_transform.Scale(device_scale_factor,
4303 device_scale_factor);
4304 expected_screen_space_transform.Translate(child->position().x(),
4305 child->position().y());
[email protected]fb661802013-03-25 01:59:324306 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104307 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144308
[email protected]fb661802013-03-25 01:59:324309 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444310 child->DrawTransform();
trchendba8b1502016-07-08 09:47:014311 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform,
ajumad9432e32015-11-30 19:43:444312 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324313 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104314 child->ScreenSpaceTransform(),
4315 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324316 EXPECT_EQ(child->drawable_content_rect(),
4317 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144318 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144319
[email protected]fb661802013-03-25 01:59:324320 gfx::Transform expected_render_surface_draw_transform;
4321 expected_render_surface_draw_transform.Translate(
4322 device_scale_factor * child->position().x(),
4323 device_scale_factor * child->position().y());
4324 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
chrishtr7e3aaf22017-05-04 15:04:014325 GetRenderSurface(child)->draw_transform());
[email protected]94f206c12012-08-25 00:09:144326
[email protected]fb661802013-03-25 01:59:324327 gfx::Transform expected_surface_draw_transform;
4328 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4329 device_scale_factor * 2.f);
4330 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
chrishtr7e3aaf22017-05-04 15:04:014331 GetRenderSurface(child)->draw_transform());
[email protected]94f206c12012-08-25 00:09:144332
[email protected]fb661802013-03-25 01:59:324333 gfx::Transform expected_surface_screen_space_transform;
4334 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4335 device_scale_factor * 2.f);
4336 EXPECT_TRANSFORMATION_MATRIX_EQ(
4337 expected_surface_screen_space_transform,
chrishtr7e3aaf22017-05-04 15:04:014338 GetRenderSurface(child)->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474339}
4340
[email protected]989386c2013-07-18 21:37:234341TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324342 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
jaydasikabf1875a2016-06-28 03:39:594343 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064344 parent->SetBounds(gfx::Size(33, 31));
enneea850232015-07-27 16:43:124345 parent->SetDrawsContent(true);
[email protected]904e9132012-11-01 00:12:474346
enneea850232015-07-27 16:43:124347 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064348 child->SetBounds(gfx::Size(13, 11));
enneea850232015-07-27 16:43:124349 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064350 child->test_properties()->force_render_surface = true;
[email protected]904e9132012-11-01 00:12:474351
[email protected]873639e2013-07-24 19:56:314352 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124353 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474354
[email protected]fb661802013-03-25 01:59:324355 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004356 // render surface (it needs one because of force_render_surface).
ajumab784ef42017-04-28 23:01:524357 EXPECT_EQ(2u, render_surface_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474358
danakjf78fb272016-07-26 19:06:154359 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:014360 GetRenderSurface(child)->draw_transform());
danakjf78fb272016-07-26 19:06:154361 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
chrishtr7e3aaf22017-05-04 15:04:014362 GetRenderSurface(child)->draw_transform());
[email protected]fb661802013-03-25 01:59:324363 EXPECT_TRANSFORMATION_MATRIX_EQ(
chrishtr7e3aaf22017-05-04 15:04:014364 gfx::Transform(), GetRenderSurface(child)->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144365}
4366
jaydasikadb41a582016-03-28 20:48:214367TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314368 scoped_refptr<Layer> root = Layer::Create();
4369 scoped_refptr<Layer> child = Layer::Create();
4370 scoped_refptr<Layer> grand_child = Layer::Create();
4371 scoped_refptr<Layer> mask_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:144372
[email protected]fb661802013-03-25 01:59:324373 child->AddChild(grand_child.get());
4374 child->SetMaskLayer(mask_layer.get());
4375 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144376
ennea7b43c32015-06-18 20:01:334377 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284378
[email protected]fb661802013-03-25 01:59:324379 int nonexistent_id = -1;
khushalsagarb69ba9452017-01-27 22:20:074380 EXPECT_EQ(root.get(), host()->LayerById(root->id()));
4381 EXPECT_EQ(child.get(), host()->LayerById(child->id()));
4382 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
4383 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
4384 EXPECT_FALSE(host()->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144385}
4386
[email protected]989386c2013-07-18 21:37:234387TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
jaydasikabf1875a2016-06-28 03:39:594388 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324389 LayerImpl* child = AddChild<LayerImpl>(root);
4390 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]498ec6e0e2012-11-30 18:24:574391
danakje4fa7b72016-07-25 22:00:064392 root->SetBounds(gfx::Size(100, 100));
4393 child->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:184394 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:064395 grand_child->SetBounds(gfx::Size(10, 10));
4396 grand_child->SetDrawsContent(true);
ajuma4711f4b12016-05-16 18:48:324397 ExecuteCalculateDrawProperties(root);
chrishtr5f60ca02017-05-11 23:09:494398 EXPECT_EQ(GetRenderSurface(child), GetRenderSurface(root));
[email protected]498ec6e0e2012-11-30 18:24:574399}
4400
[email protected]989386c2013-07-18 21:37:234401TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164402 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564403 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:014404 FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider,
pimanc44437a22016-10-29 00:09:224405 &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:164406 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:484407 std::unique_ptr<LayerImpl> root =
4408 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064409 root->SetBounds(gfx::Size(100, 100));
[email protected]f90fc412013-03-30 20:13:164410 root->SetDrawsContent(true);
4411
danakj60bc3bc2016-04-09 00:24:484412 std::unique_ptr<LayerImpl> child =
4413 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064414 child->SetBounds(gfx::Size(50, 50));
[email protected]f90fc412013-03-30 20:13:164415 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:184416 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:164417
jaydasika9cb21c772016-05-10 22:37:084418 const int child_id = child->id();
jaydasika89f7b5a2016-06-22 02:08:394419 root->test_properties()->AddChild(std::move(child));
jaydasika9cb21c772016-05-10 22:37:084420 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594421 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
jaydasika4340ea02016-06-06 19:44:264422 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:274423
[email protected]f90fc412013-03-30 20:13:164424 // Add opacity animation.
loyso9556c732016-03-11 07:54:584425 scoped_refptr<AnimationTimeline> timeline =
4426 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4427 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:484428
vollickef2ae922016-06-29 17:54:274429 ElementId child_element_id =
4430 host_impl.pending_tree()->LayerById(child_id)->element_id();
4431
4432 AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0,
4433 0.0f, 1.0f, false);
[email protected]f90fc412013-03-30 20:13:164434
ajumab784ef42017-04-28 23:01:524435 RenderSurfaceList render_surface_list;
[email protected]7aad55f2013-07-26 11:25:534436 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524437 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534438 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574439 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:164440
jaydasika50612fa02017-05-19 20:56:024441 // We should have one render surface and two layers. The child
4442 // layer should be included even though it is transparent.
ajumab784ef42017-04-28 23:01:524443 ASSERT_EQ(1u, render_surface_list.size());
jaydasika50612fa02017-05-19 20:56:024444 ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
jaydasika86654512016-01-27 17:05:074445
jaydasika50612fa02017-05-19 20:56:024446 // If the root itself is hidden, the child should not be drawn even if it has
4447 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:184448 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054449 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
ajumab784ef42017-04-28 23:01:524450 RenderSurfaceList render_surface_list2;
jaydasika86654512016-01-27 17:05:074451 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajumab784ef42017-04-28 23:01:524452 root_layer, root_layer->bounds(), &render_surface_list2);
jaydasika86654512016-01-27 17:05:074453 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574454 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:074455
jaydasika0c2fd472016-03-24 01:26:054456 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika50612fa02017-05-19 20:56:024457 EffectTree& tree =
4458 root_layer->layer_tree_impl()->property_trees()->effect_tree;
4459 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
4460 EXPECT_FALSE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404461
jaydasika50612fa02017-05-19 20:56:024462 // A layer should be drawn and it should contribute to drawn surface when
4463 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:184464 root_layer->test_properties()->opacity = 1.0f;
4465 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054466 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
ajumab784ef42017-04-28 23:01:524467 RenderSurfaceList render_surface_list3;
jaydasikae99e83e2016-01-29 19:35:404468 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajumab784ef42017-04-28 23:01:524469 root_layer, root_layer->bounds(), &render_surface_list3);
jaydasikae99e83e2016-01-29 19:35:404470 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574471 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:404472
jaydasika0c2fd472016-03-24 01:26:054473 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika50612fa02017-05-19 20:56:024474 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
4475 node = tree.Node(child_ptr->effect_tree_index());
4476 EXPECT_TRUE(node->is_drawn);
4477 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:064478
jaydasika50612fa02017-05-19 20:56:024479 // But if the opacity of the layer remains 0 after activation, it should not
4480 // be drawn.
jaydasika8185d302016-04-14 15:20:064481 host_impl.ActivateSyncTree();
danakj0da42ca62016-07-01 19:42:334482 LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id());
jaydasika8185d302016-04-14 15:20:064483 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
4484
jaydasika50612fa02017-05-19 20:56:024485 EffectTree& active_effect_tree =
4486 host_impl.active_tree()->property_trees()->effect_tree;
4487 EXPECT_TRUE(active_effect_tree.needs_update());
4488
jaydasika8185d302016-04-14 15:20:064489 ExecuteCalculateDrawProperties(active_root);
4490
jaydasika50612fa02017-05-19 20:56:024491 node = active_effect_tree.Node(active_child->effect_tree_index());
4492 EXPECT_FALSE(node->is_drawn);
4493 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
4494 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:164495}
4496
danakj3f76ace2014-11-18 16:56:004497using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:264498class LCDTextTest : public LayerTreeHostCommonTestBase,
4499 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:364500 public:
4501 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:224502 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
4503 host_impl_(LCDTextTestLayerTreeSettings(),
4504 &task_runner_provider_,
danakj59931942016-07-26 22:11:294505 &task_graph_runner_) {}
enneaf5bda32015-02-19 01:27:364506
loyso968163c92016-01-04 23:18:484507 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
4508
[email protected]fb661802013-03-25 01:59:324509 protected:
sunxd5a7a4032016-06-01 18:49:224510 LayerTreeSettings LCDTextTestLayerTreeSettings() {
danakj59931942016-07-26 22:11:294511 LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings();
sunxd5a7a4032016-06-01 18:49:224512
4513 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4514 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4515 settings.can_use_lcd_text = can_use_lcd_text_;
4516 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
4517 return settings;
4518 }
4519
dcheng93a52eb2014-12-23 02:14:234520 void SetUp() override {
loyso9556c732016-03-11 07:54:584521 timeline_ =
4522 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4523 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:484524
danakj60bc3bc2016-04-09 00:24:484525 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:364526 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:484527 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:364528 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:484529 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:364530 LayerImpl::Create(host_impl_.active_tree(), 3);
4531
4532 // Stash raw pointers to look at later.
4533 root_ = root_ptr.get();
4534 child_ = child_ptr.get();
4535 grand_child_ = grand_child_ptr.get();
4536
jaydasika89f7b5a2016-06-22 02:08:394537 child_->test_properties()->AddChild(std::move(grand_child_ptr));
4538 root_->test_properties()->AddChild(std::move(child_ptr));
jaydasikabf1875a2016-06-28 03:39:594539 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:594540
vollickef2ae922016-06-29 17:54:274541 host_impl_.active_tree()->SetElementIdsForTesting();
4542
fmalita51b5e202014-11-18 20:11:504543 root_->SetContentsOpaque(true);
4544 child_->SetContentsOpaque(true);
4545 grand_child_->SetContentsOpaque(true);
4546
jaydasika3f930c12015-06-30 15:18:254547 root_->SetDrawsContent(true);
4548 child_->SetDrawsContent(true);
4549 grand_child_->SetDrawsContent(true);
4550
danakje4fa7b72016-07-25 22:00:064551 root_->SetBounds(gfx::Size(1, 1));
4552 child_->SetBounds(gfx::Size(1, 1));
4553 grand_child_->SetBounds(gfx::Size(1, 1));
4554
4555 child_->test_properties()->force_render_surface =
4556 std::tr1::get<2>(GetParam());
[email protected]fb661802013-03-25 01:59:324557 }
[email protected]10aabcc32012-12-13 09:18:594558
[email protected]fb661802013-03-25 01:59:324559 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:004560 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:364561
khushalsagarb64b360d2015-10-21 19:25:164562 FakeImplTaskRunnerProvider task_runner_provider_;
reveman34b7a1522015-03-23 20:27:474563 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:364564 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:484565 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:364566
danakj59931942016-07-26 22:11:294567 LayerImpl* root_ = nullptr;
4568 LayerImpl* child_ = nullptr;
4569 LayerImpl* grand_child_ = nullptr;
[email protected]10aabcc32012-12-13 09:18:594570};
4571
[email protected]fb661802013-03-25 01:59:324572TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:004573 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4574 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4575
[email protected]fb661802013-03-25 01:59:324576 // Case 1: Identity transform.
flackra283bed2016-10-31 14:49:424577 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224578 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4579 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4580 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594581
[email protected]fb661802013-03-25 01:59:324582 // Case 2: Integral translation.
4583 gfx::Transform integral_translation;
4584 integral_translation.Translate(1.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:044585 child_->test_properties()->transform = integral_translation;
jaydasika3f930c12015-06-30 15:18:254586 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:424587 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224588 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4589 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4590 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594591
[email protected]fb661802013-03-25 01:59:324592 // Case 3: Non-integral translation.
4593 gfx::Transform non_integral_translation;
4594 non_integral_translation.Translate(1.5, 2.5);
jaydasika10d43fc2016-08-18 04:06:044595 child_->test_properties()->transform = non_integral_translation;
jaydasika3f930c12015-06-30 15:18:254596 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:424597 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224598 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4599 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4600 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594601
[email protected]fb661802013-03-25 01:59:324602 // Case 4: Rotation.
4603 gfx::Transform rotation;
4604 rotation.Rotate(10.0);
jaydasika10d43fc2016-08-18 04:06:044605 child_->test_properties()->transform = rotation;
jaydasika3f930c12015-06-30 15:18:254606 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:424607 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224608 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4609 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4610 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594611
[email protected]fb661802013-03-25 01:59:324612 // Case 5: Scale.
4613 gfx::Transform scale;
4614 scale.Scale(2.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:044615 child_->test_properties()->transform = scale;
jaydasika3f930c12015-06-30 15:18:254616 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:424617 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224618 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4619 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4620 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594621
[email protected]fb661802013-03-25 01:59:324622 // Case 6: Skew.
4623 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:104624 skew.Skew(10.0, 0.0);
jaydasika10d43fc2016-08-18 04:06:044625 child_->test_properties()->transform = skew;
jaydasika3f930c12015-06-30 15:18:254626 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:424627 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224628 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4629 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4630 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594631
[email protected]fb661802013-03-25 01:59:324632 // Case 7: Translucent.
jaydasika10d43fc2016-08-18 04:06:044633 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:254634 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:184635 child_->test_properties()->opacity = 0.5f;
flackra283bed2016-10-31 14:49:424636 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224637 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4638 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4639 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594640
[email protected]fb661802013-03-25 01:59:324641 // Case 8: Sanity check: restore transform and opacity.
jaydasika10d43fc2016-08-18 04:06:044642 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:254643 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:184644 child_->test_properties()->opacity = 1.f;
flackra283bed2016-10-31 14:49:424645 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224646 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4647 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4648 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:504649
4650 // Case 9: Non-opaque content.
4651 child_->SetContentsOpaque(false);
flackra283bed2016-10-31 14:49:424652 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224653 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4654 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4655 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:504656
4657 // Case 10: Sanity check: restore content opaqueness.
4658 child_->SetContentsOpaque(true);
flackra283bed2016-10-31 14:49:424659 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224660 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4661 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4662 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594663}
4664
[email protected]fd9a3b6d2013-08-03 00:46:174665TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:004666 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:334667 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:004668
[email protected]fb661802013-03-25 01:59:324669 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackra283bed2016-10-31 14:49:424670 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224671 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4672 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4673 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594674
[email protected]fb661802013-03-25 01:59:324675 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:184676 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:254677 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
vollickef2ae922016-06-29 17:54:274678
4679 SetElementIdsForTesting();
4680
4681 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
4682 10.0, 0.9f, 0.1f, false);
flackra283bed2016-10-31 14:49:424683 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:334684 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:224685 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4686 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4687 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:334688}
4689
4690TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
4691 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4692 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4693
4694 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackra283bed2016-10-31 14:49:424695 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:224696 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4697 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4698 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
vollickef2ae922016-06-29 17:54:274699 SetElementIdsForTesting();
fmalitafcd926a2015-05-13 20:19:334700
4701 // Mark contents non-opaque within the first animation frame.
4702 child_->SetContentsOpaque(false);
vollickef2ae922016-06-29 17:54:274703 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
4704 10.0, 0.9f, 0.1f, false);
flackra283bed2016-10-31 14:49:424705 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:334706 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:224707 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4708 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4709 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594710}
4711
4712INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4713 LCDTextTest,
danakj3f76ace2014-11-18 16:56:004714 testing::Combine(testing::Bool(),
4715 testing::Bool(),
4716 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:594717
[email protected]989386c2013-07-18 21:37:234718TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:164719 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564720 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:224721 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:194722 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:194723
danakj60bc3bc2016-04-09 00:24:484724 std::unique_ptr<LayerImpl> root =
4725 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064726 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:194727 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064728 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:194729
danakj60bc3bc2016-04-09 00:24:484730 std::unique_ptr<LayerImpl> child =
4731 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064732 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:194733 child->SetDrawsContent(true);
ajumab784ef42017-04-28 23:01:524734 LayerImpl* child_layer = child.get();
[email protected]c0ae06c12013-06-24 18:32:194735
danakj60bc3bc2016-04-09 00:24:484736 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:194737 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:064738 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:194739 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:354740 grand_child->test_properties()->hide_layer_and_subtree = true;
ajumab784ef42017-04-28 23:01:524741 LayerImpl* grand_child_layer = grand_child.get();
[email protected]c0ae06c12013-06-24 18:32:194742
jaydasika89f7b5a2016-06-22 02:08:394743 child->test_properties()->AddChild(std::move(grand_child));
4744 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:594745 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:194746
ajumab784ef42017-04-28 23:01:524747 RenderSurfaceList render_surface_list;
[email protected]7aad55f2013-07-26 11:25:534748 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524749 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534750 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574751 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:194752
4753 // We should have one render surface and two layers. The grand child has
4754 // hidden itself.
ajumab784ef42017-04-28 23:01:524755 ASSERT_EQ(1u, render_surface_list.size());
chrishtr7e3aaf22017-05-04 15:04:014756 ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454757 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
4758 EXPECT_TRUE(child_layer->contributes_to_drawn_render_surface());
4759 EXPECT_FALSE(grand_child_layer->contributes_to_drawn_render_surface());
[email protected]c0ae06c12013-06-24 18:32:194760}
4761
[email protected]989386c2013-07-18 21:37:234762TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:164763 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564764 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:224765 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:194766 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:194767
danakj60bc3bc2016-04-09 00:24:484768 std::unique_ptr<LayerImpl> root =
4769 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064770 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:194771 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:094772 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:194773
danakj60bc3bc2016-04-09 00:24:484774 std::unique_ptr<LayerImpl> child =
4775 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064776 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:194777 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:354778 child->test_properties()->hide_layer_and_subtree = true;
ajumab784ef42017-04-28 23:01:524779 LayerImpl* child_layer = child.get();
[email protected]c0ae06c12013-06-24 18:32:194780
danakj60bc3bc2016-04-09 00:24:484781 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:194782 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:064783 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:194784 grand_child->SetDrawsContent(true);
ajumab784ef42017-04-28 23:01:524785 LayerImpl* grand_child_layer = grand_child.get();
[email protected]c0ae06c12013-06-24 18:32:194786
jaydasika89f7b5a2016-06-22 02:08:394787 child->test_properties()->AddChild(std::move(grand_child));
4788 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:594789 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:194790
ajumab784ef42017-04-28 23:01:524791 RenderSurfaceList render_surface_list;
[email protected]7aad55f2013-07-26 11:25:534792 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524793 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534794 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574795 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:194796
ajumab784ef42017-04-28 23:01:524797 // We should have one render surface and one layer. The child has
[email protected]c0ae06c12013-06-24 18:32:194798 // hidden itself and the grand child.
ajumab784ef42017-04-28 23:01:524799 ASSERT_EQ(1u, render_surface_list.size());
chrishtr7e3aaf22017-05-04 15:04:014800 ASSERT_EQ(1, GetRenderSurface(root_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454801 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
4802 EXPECT_FALSE(child_layer->contributes_to_drawn_render_surface());
4803 EXPECT_FALSE(grand_child_layer->contributes_to_drawn_render_surface());
[email protected]c0ae06c12013-06-24 18:32:194804}
4805
danakj60bc3bc2016-04-09 00:24:484806void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:454807
[email protected]989386c2013-07-18 21:37:234808TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:164809 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564810 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:224811 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:454812 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:454813
danakj60bc3bc2016-04-09 00:24:484814 std::unique_ptr<LayerImpl> root =
4815 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064816 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:304817 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:094818 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:454819
danakj60bc3bc2016-04-09 00:24:484820 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:304821 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064822 copy_grand_parent->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:304823 copy_grand_parent->SetDrawsContent(true);
4824 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:454825
danakj60bc3bc2016-04-09 00:24:484826 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:304827 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:064828 copy_parent->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:304829 copy_parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064830 copy_parent->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:304831 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:454832
danakj60bc3bc2016-04-09 00:24:484833 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:304834 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:064835 copy_request->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:304836 copy_request->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064837 copy_request->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:304838 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:454839
danakj60bc3bc2016-04-09 00:24:484840 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:304841 LayerImpl::Create(host_impl.pending_tree(), 5);
danakje4fa7b72016-07-25 22:00:064842 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:304843 copy_child->SetDrawsContent(true);
4844 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:454845
danakj60bc3bc2016-04-09 00:24:484846 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:404847 LayerImpl::Create(host_impl.pending_tree(), 6);
danakje4fa7b72016-07-25 22:00:064848 copy_grand_child->SetBounds(gfx::Size(20, 20));
4849 copy_grand_child->SetDrawsContent(true);
jaydasika86654512016-01-27 17:05:074850 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
4851
danakj60bc3bc2016-04-09 00:24:484852 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:074853 LayerImpl::Create(host_impl.pending_tree(), 7);
danakje4fa7b72016-07-25 22:00:064854 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:304855 copy_grand_parent_sibling_before->SetDrawsContent(true);
4856 LayerImpl* copy_grand_parent_sibling_before_layer =
4857 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:534858
danakj60bc3bc2016-04-09 00:24:484859 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:074860 LayerImpl::Create(host_impl.pending_tree(), 8);
danakje4fa7b72016-07-25 22:00:064861 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:304862 copy_grand_parent_sibling_after->SetDrawsContent(true);
4863 LayerImpl* copy_grand_parent_sibling_after_layer =
4864 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:534865
jaydasika89f7b5a2016-06-22 02:08:394866 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
4867 copy_request->test_properties()->AddChild(std::move(copy_child));
4868 copy_parent->test_properties()->AddChild(std::move(copy_request));
4869 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
4870 root->test_properties()->AddChild(
4871 std::move(copy_grand_parent_sibling_before));
4872 root->test_properties()->AddChild(std::move(copy_grand_parent));
4873 root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasikabf1875a2016-06-28 03:39:594874 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]d600df7d2013-08-03 02:34:284875
[email protected]30fe19ff2013-07-04 00:54:454876 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:074877 // hidden subtree on copy_layer. Also hide the copy grand child and its
4878 // subtree.
jaydasika5121caa82016-05-05 15:43:354879 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
4880 copy_grand_parent_sibling_before_layer->test_properties()
4881 ->hide_layer_and_subtree = true;
4882 copy_grand_parent_sibling_after_layer->test_properties()
4883 ->hide_layer_and_subtree = true;
4884 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:304885
ajumae6f541b2016-05-31 16:50:504886 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:304887 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:454888
ajumab784ef42017-04-28 23:01:524889 RenderSurfaceList render_surface_list;
weiliangc51fb255d2015-07-24 15:32:304890 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524891 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534892 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574893 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:454894
jaydasikaebc94282017-04-24 20:34:014895 EXPECT_TRUE(root_layer->has_copy_requests_in_target_subtree());
4896 EXPECT_TRUE(copy_grand_parent_layer->has_copy_requests_in_target_subtree());
4897 EXPECT_TRUE(copy_parent_layer->has_copy_requests_in_target_subtree());
4898 EXPECT_TRUE(copy_layer->has_copy_requests_in_target_subtree());
[email protected]ac020122013-07-12 23:45:534899
jaydasika86654512016-01-27 17:05:074900 // We should have four render surfaces, one for the root, one for the grand
4901 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:454902 // since it owns a surface, and one for the copy_layer.
ajumab784ef42017-04-28 23:01:524903 ASSERT_EQ(4u, render_surface_list.size());
Chris Harrelson9bdbcce2017-06-02 03:12:144904 EXPECT_EQ(static_cast<uint64_t>(root_layer->id()),
4905 render_surface_list.at(0)->id());
4906 EXPECT_EQ(static_cast<uint64_t>(copy_grand_parent_layer->id()),
4907 render_surface_list.at(1)->id());
4908 EXPECT_EQ(static_cast<uint64_t>(copy_parent_layer->id()),
4909 render_surface_list.at(2)->id());
4910 EXPECT_EQ(static_cast<uint64_t>(copy_layer->id()),
4911 render_surface_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:454912
jaydasika86654512016-01-27 17:05:074913 // The root render surface should have 2 contributing layers.
chrishtr7e3aaf22017-05-04 15:04:014914 EXPECT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454915 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
4916 EXPECT_FALSE(copy_grand_parent_layer->contributes_to_drawn_render_surface());
ajumab784ef42017-04-28 23:01:524917 EXPECT_FALSE(copy_grand_parent_sibling_before_layer
ajuma651848a2017-05-01 21:23:454918 ->contributes_to_drawn_render_surface());
ajumab784ef42017-04-28 23:01:524919 EXPECT_FALSE(copy_grand_parent_sibling_after_layer
ajuma651848a2017-05-01 21:23:454920 ->contributes_to_drawn_render_surface());
[email protected]30fe19ff2013-07-04 00:54:454921
[email protected]7392c7b2014-02-07 08:28:284922 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:454923 // appear in its list, since it needs to be drawn for the copy request.
chrishtr7e3aaf22017-05-04 15:04:014924 ASSERT_EQ(1, GetRenderSurface(copy_parent_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454925 EXPECT_FALSE(copy_parent_layer->contributes_to_drawn_render_surface());
[email protected]30fe19ff2013-07-04 00:54:454926
ajumab784ef42017-04-28 23:01:524927 // The copy layer's render surface should have 2 contributing layers.
chrishtr7e3aaf22017-05-04 15:04:014928 ASSERT_EQ(2, GetRenderSurface(copy_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454929 EXPECT_TRUE(copy_layer->contributes_to_drawn_render_surface());
4930 EXPECT_TRUE(copy_child_layer->contributes_to_drawn_render_surface());
4931 EXPECT_FALSE(copy_grand_child_layer->contributes_to_drawn_render_surface());
jaydasika86654512016-01-27 17:05:074932
4933 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
4934 // but the copy_layer and copy_child should be drawn for the copy request.
4935 // copy grand child should not be drawn as its hidden even in the copy
4936 // request.
ajumae4af47062016-05-24 23:59:044937 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:094938 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:074939 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014940 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074941 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014942 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074943 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014944 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074945 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014946 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074947 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014948 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074949
4950 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
4951 // actually hidden.
chrishtr7e3aaf22017-05-04 15:04:014952 EXPECT_FALSE(GetRenderSurface(copy_layer)->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:454953}
4954
[email protected]989386c2013-07-18 21:37:234955TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:164956 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564957 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:224958 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:454959 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:454960
danakj60bc3bc2016-04-09 00:24:484961 std::unique_ptr<LayerImpl> root =
4962 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064963 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:304964 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:454965
danakj60bc3bc2016-04-09 00:24:484966 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:304967 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:304968 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:454969 copy_parent->SetMasksToBounds(true);
4970
danakj60bc3bc2016-04-09 00:24:484971 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:304972 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:064973 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:304974 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064975 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:454976
danakj60bc3bc2016-04-09 00:24:484977 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:304978 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:064979 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:304980 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:454981
ajumae6f541b2016-05-31 16:50:504982 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:304983 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:454984
jaydasika89f7b5a2016-06-22 02:08:394985 copy_layer->test_properties()->AddChild(std::move(copy_child));
4986 copy_parent->test_properties()->AddChild(std::move(copy_layer));
4987 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:304988
ajumab784ef42017-04-28 23:01:524989 RenderSurfaceList render_surface_list;
sunxd71aea3e2016-04-01 23:48:054990 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594991 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:304992 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524993 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534994 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574995 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:454996
xjze19f76402015-11-06 21:48:444997 // We should have two render surface, as the others are clipped out.
ajumab784ef42017-04-28 23:01:524998 ASSERT_EQ(2u, render_surface_list.size());
Chris Harrelson9bdbcce2017-06-02 03:12:144999 EXPECT_EQ(static_cast<uint64_t>(root_layer->id()),
5000 render_surface_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455001
ajumab784ef42017-04-28 23:01:525002 // The root render surface should have only 2 contributing layer, since the
5003 // other layers are clipped away.
chrishtr7e3aaf22017-05-04 15:04:015004 ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:455005 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
[email protected]30fe19ff2013-07-04 00:54:455006}
5007
jaydasika96e69462017-05-03 23:06:455008TEST_F(LayerTreeHostCommonTest, SingularTransformAndCopyRequests) {
5009 LayerImpl* root = root_layer_for_testing();
5010 root->SetBounds(gfx::Size(50, 50));
5011 root->SetDrawsContent(true);
5012
5013 LayerImpl* singular_transform_layer = AddChild<LayerImpl>(root);
5014 singular_transform_layer->SetBounds(gfx::Size(100, 100));
5015 singular_transform_layer->SetDrawsContent(true);
5016 gfx::Transform singular;
5017 singular.Scale3d(6.f, 6.f, 0.f);
5018 singular_transform_layer->test_properties()->transform = singular;
5019
5020 LayerImpl* copy_layer = AddChild<LayerImpl>(singular_transform_layer);
5021 copy_layer->SetBounds(gfx::Size(100, 100));
5022 copy_layer->SetDrawsContent(true);
5023 copy_layer->test_properties()->copy_requests.push_back(
5024 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5025
5026 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
5027 copy_child->SetBounds(gfx::Size(100, 100));
5028 copy_child->SetDrawsContent(true);
5029
5030 LayerImpl* copy_grand_child = AddChild<LayerImpl>(copy_child);
5031 copy_grand_child->SetBounds(gfx::Size(100, 100));
5032 copy_grand_child->SetDrawsContent(true);
5033 copy_grand_child->test_properties()->transform = singular;
5034
5035 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5036 ExecuteCalculateDrawProperties(root);
5037 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5038
5039 // A layer with singular transform should not contribute to drawn render
5040 // surface.
5041 EXPECT_FALSE(singular_transform_layer->contributes_to_drawn_render_surface());
5042 // Even though copy_layer and copy_child have singular screen space transform,
5043 // they still contribute to drawn render surface as their transform to the
5044 // closest ancestor with copy request is not singular.
5045 EXPECT_TRUE(copy_layer->contributes_to_drawn_render_surface());
5046 EXPECT_TRUE(copy_child->contributes_to_drawn_render_surface());
5047 // copy_grand_child's transform to its closest ancestor with copy request is
5048 // also singular. So, it doesn't contribute to drawn render surface.
5049 EXPECT_FALSE(copy_grand_child->contributes_to_drawn_render_surface());
5050}
5051
weiliangcde7e0c32016-06-15 15:02:415052TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595053 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065054 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415055 root->SetDrawsContent(true);
5056 root->SetMasksToBounds(true);
5057
5058 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065059 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415060 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065061 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415062
5063 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065064 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5065 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415066 copy_child->SetDrawsContent(true);
5067
5068 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065069 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415070 copy_clip->SetMasksToBounds(true);
5071
5072 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065073 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5074 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415075 copy_clipped_child->SetDrawsContent(true);
5076
5077 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065078 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5079 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415080 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065081 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415082
5083 copy_layer->test_properties()->copy_requests.push_back(
5084 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5085
weiliangce22ce842016-07-04 23:31:535086 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415087 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535088 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415089
5090 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5091 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5092 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5093 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5094
5095 // Case 2: When the non root copy request layer is clipped.
5096 copy_layer->SetBounds(gfx::Size(50, 50));
5097 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535098 copy_layer->test_properties()->copy_requests.push_back(
5099 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415100 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5101
weiliangce22ce842016-07-04 23:31:535102 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415103 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535104 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415105
5106 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5107 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5108 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5109 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515110
5111 // Case 3: When there is device scale factor.
5112 float device_scale_factor = 2.f;
5113 copy_layer->test_properties()->copy_requests.push_back(
5114 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5115
5116 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5117 ExecuteCalculateDrawProperties(root, device_scale_factor);
5118 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5119
5120 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5121 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5122 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5123 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415124}
5125
[email protected]420fdf6e2013-08-26 20:36:385126TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5127 // Ensure that a transform between the layer and its render surface is not a
5128 // problem. Constructs the following layer tree.
5129 //
5130 // root (a render surface)
5131 // + render_surface
5132 // + clip_parent (scaled)
5133 // + intervening_clipping_layer
5134 // + clip_child
5135 //
5136 // The render surface should be resized correctly and the clip child should
5137 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595138 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315139 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5140 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285141 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315142 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285143 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315144 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5145 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565146 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485147 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315148 clip_children->insert(clip_child);
gogag217889152017-03-13 14:34:425149 clip_parent->test_properties()->clip_children = std::move(clip_children);
[email protected]420fdf6e2013-08-26 20:36:385150
5151 intervening->SetMasksToBounds(true);
5152 clip_parent->SetMasksToBounds(true);
5153
[email protected]420fdf6e2013-08-26 20:36:385154 gfx::Transform scale_transform;
5155 scale_transform.Scale(2, 2);
5156
danakjf78fb272016-07-26 19:06:155157 root->SetBounds(gfx::Size(50, 50));
5158 render_surface->SetBounds(gfx::Size(10, 10));
5159 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:045160 clip_parent->test_properties()->transform = scale_transform;
danakjf78fb272016-07-26 19:06:155161 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5162 clip_parent->SetBounds(gfx::Size(10, 10));
5163 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5164 intervening->SetBounds(gfx::Size(5, 5));
5165 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5166 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315167 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385168
chrishtr7e3aaf22017-05-04 15:04:015169 ASSERT_TRUE(GetRenderSurface(root));
5170 ASSERT_TRUE(GetRenderSurface(render_surface));
[email protected]420fdf6e2013-08-26 20:36:385171
5172 // Ensure that we've inherited our clip parent's clip and weren't affected
5173 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145174 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5175 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5176 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385177
5178 // Ensure that the render surface reports a content rect that has been grown
5179 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145180 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
chrishtr7e3aaf22017-05-04 15:04:015181 GetRenderSurface(render_surface)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385182
5183 // The above check implies the two below, but they nicely demonstrate that
5184 // we've grown, despite the intervening layer's clip.
5185 ASSERT_TRUE(clip_parent->clip_rect().Contains(
chrishtr7e3aaf22017-05-04 15:04:015186 GetRenderSurface(render_surface)->content_rect()));
[email protected]420fdf6e2013-08-26 20:36:385187 ASSERT_FALSE(intervening->clip_rect().Contains(
chrishtr7e3aaf22017-05-04 15:04:015188 GetRenderSurface(render_surface)->content_rect()));
[email protected]420fdf6e2013-08-26 20:36:385189}
5190
5191TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5192 // Ensure that intervening render surfaces are not a problem in the basic
5193 // case. In the following tree, both render surfaces should be resized to
5194 // accomodate for the clip child, despite an intervening clip.
5195 //
5196 // root (a render surface)
5197 // + clip_parent (masks to bounds)
5198 // + render_surface1 (sets opacity)
5199 // + intervening (masks to bounds)
5200 // + render_surface2 (also sets opacity)
5201 // + clip_child
5202 //
jaydasikabf1875a2016-06-28 03:39:595203 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235204 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5205 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5206 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5207 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5208 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365209 render_surface1->SetDrawsContent(true);
5210 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235211 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385212
jaydasika1c0a27d42016-04-28 01:54:565213 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385214
5215 intervening->SetMasksToBounds(true);
5216 clip_parent->SetMasksToBounds(true);
5217
[email protected]420fdf6e2013-08-26 20:36:385218 gfx::Transform translation_transform;
5219 translation_transform.Translate(2, 2);
5220
danakjf78fb272016-07-26 19:06:155221 root->SetBounds(gfx::Size(50, 50));
5222 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5223 clip_parent->SetBounds(gfx::Size(40, 40));
5224 render_surface1->SetBounds(gfx::Size(10, 10));
5225 render_surface1->test_properties()->force_render_surface = true;
5226 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5227 intervening->SetBounds(gfx::Size(5, 5));
5228 render_surface2->SetBounds(gfx::Size(10, 10));
5229 render_surface2->test_properties()->force_render_surface = true;
5230 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5231 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235232 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385233
chrishtr7e3aaf22017-05-04 15:04:015234 EXPECT_TRUE(GetRenderSurface(root));
5235 EXPECT_TRUE(GetRenderSurface(render_surface1));
5236 EXPECT_TRUE(GetRenderSurface(render_surface2));
[email protected]420fdf6e2013-08-26 20:36:385237
jaydasika1553a142017-04-05 00:37:095238 // render_surface1 should apply the clip from clip_parent. Though there is a
5239 // clip child, render_surface1 can apply the clip as there are no clips
5240 // between the clip parent and render_surface1
5241 EXPECT_EQ(gfx::Rect(1, 1, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015242 GetRenderSurface(render_surface1)->clip_rect());
5243 EXPECT_TRUE(GetRenderSurface(render_surface1)->is_clipped());
jaydasika1553a142017-04-05 00:37:095244 EXPECT_EQ(gfx::Rect(), render_surface1->clip_rect());
5245 EXPECT_FALSE(render_surface1->is_clipped());
5246
5247 // render_surface2 could have expanded, as there is a clip between
5248 // clip_child's clip (clip_parent) and render_surface2's clip (intervening).
5249 // So, it should not be clipped (their bounds would no longer be reliable).
5250 // We should resort to layer clipping in this case.
jaydasika6f972de2016-04-07 16:16:145251 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
chrishtr7e3aaf22017-05-04 15:04:015252 GetRenderSurface(render_surface2)->clip_rect());
5253 EXPECT_FALSE(GetRenderSurface(render_surface2)->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385254
[email protected]420fdf6e2013-08-26 20:36:385255 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145256 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385257 EXPECT_TRUE(render_surface2->is_clipped());
5258
jaydasika1553a142017-04-05 00:37:095259 // The content rects of render_surface2 should have expanded to contain the
5260 // clip child.
jaydasika6f972de2016-04-07 16:16:145261 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015262 GetRenderSurface(render_surface1)->content_rect());
jaydasika1553a142017-04-05 00:37:095263 EXPECT_EQ(gfx::Rect(-10, -10, 60, 60),
chrishtr7e3aaf22017-05-04 15:04:015264 GetRenderSurface(render_surface2)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385265
5266 // The clip child should have inherited the clip parent's clip (projected to
jaydasika1553a142017-04-05 00:37:095267 // the right space, of course), but as render_surface1 already applies that
5268 // clip, clip_child need not apply it again.
5269 EXPECT_EQ(gfx::Rect(), clip_child->clip_rect());
jaydasika6f972de2016-04-07 16:16:145270 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
jaydasika1553a142017-04-05 00:37:095271 EXPECT_FALSE(clip_child->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385272}
5273
5274TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5275 // Ensure that intervening render surfaces are not a problem, even if there
5276 // is a scroll involved. Note, we do _not_ have to consider any other sort
5277 // of transform.
5278 //
5279 // root (a render surface)
5280 // + clip_parent (masks to bounds)
5281 // + render_surface1 (sets opacity)
5282 // + intervening (masks to bounds AND scrolls)
5283 // + render_surface2 (also sets opacity)
5284 // + clip_child
5285 //
jaydasikabf1875a2016-06-28 03:39:595286 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235287 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5288 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5289 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5290 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5291 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365292 render_surface1->SetDrawsContent(true);
5293 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235294 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385295
jaydasika1c0a27d42016-04-28 01:54:565296 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385297
5298 intervening->SetMasksToBounds(true);
5299 clip_parent->SetMasksToBounds(true);
pdrbbfd8822017-06-27 22:44:525300 intervening->SetScrollable(gfx::Size(1, 1));
pdr54d038192017-06-08 22:44:135301 intervening->SetElementId(LayerIdToElementIdForTesting(intervening->id()));
[email protected]420fdf6e2013-08-26 20:36:385302
5303 gfx::Transform translation_transform;
5304 translation_transform.Translate(2, 2);
5305
danakjf78fb272016-07-26 19:06:155306 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:045307 clip_parent->test_properties()->transform = translation_transform;
danakjf78fb272016-07-26 19:06:155308 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5309 clip_parent->SetBounds(gfx::Size(40, 40));
5310 render_surface1->SetBounds(gfx::Size(10, 10));
5311 render_surface1->test_properties()->force_render_surface = true;
5312 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5313 intervening->SetBounds(gfx::Size(5, 5));
5314 render_surface2->SetBounds(gfx::Size(10, 10));
5315 render_surface2->test_properties()->force_render_surface = true;
5316 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5317 clip_child->SetBounds(gfx::Size(60, 60));
pdr80d5a3e2017-07-17 19:04:075318 BuildPropertyTreesForTesting();
5319 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
weiliangcd6a836d2015-07-28 21:20:235320 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385321
chrishtr7e3aaf22017-05-04 15:04:015322 EXPECT_TRUE(GetRenderSurface(root));
5323 EXPECT_TRUE(GetRenderSurface(render_surface1));
5324 EXPECT_TRUE(GetRenderSurface(render_surface2));
[email protected]420fdf6e2013-08-26 20:36:385325
jaydasika1553a142017-04-05 00:37:095326 // render_surface1 should apply the clip from clip_parent. Though there is a
5327 // clip child, render_surface1 can apply the clip as there are no clips
5328 // between the clip parent and render_surface1
5329 EXPECT_EQ(gfx::Rect(3, 3, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015330 GetRenderSurface(render_surface1)->clip_rect());
5331 EXPECT_TRUE(GetRenderSurface(render_surface1)->is_clipped());
jaydasika1553a142017-04-05 00:37:095332 EXPECT_EQ(gfx::Rect(), render_surface1->clip_rect());
5333 EXPECT_FALSE(render_surface1->is_clipped());
5334
5335 // render_surface2 could have expanded, as there is a clip between
5336 // clip_child's clip (clip_parent) and render_surface2's clip (intervening).
5337 // So, it should not be clipped (their bounds would no longer be reliable).
5338 // We should resort to layer clipping in this case.
jaydasika6f972de2016-04-07 16:16:145339 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
chrishtr7e3aaf22017-05-04 15:04:015340 GetRenderSurface(render_surface2)->clip_rect());
5341 EXPECT_FALSE(GetRenderSurface(render_surface2)->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385342 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika1553a142017-04-05 00:37:095343 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385344 EXPECT_TRUE(render_surface2->is_clipped());
5345
jaydasika1553a142017-04-05 00:37:095346 // The content rects of render_surface2 should have expanded to contain the
5347 // clip child.
jaydasika6f972de2016-04-07 16:16:145348 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015349 GetRenderSurface(render_surface1)->content_rect());
jaydasika1553a142017-04-05 00:37:095350 EXPECT_EQ(gfx::Rect(-10, -10, 60, 60),
chrishtr7e3aaf22017-05-04 15:04:015351 GetRenderSurface(render_surface2)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385352
5353 // The clip child should have inherited the clip parent's clip (projected to
jaydasika1553a142017-04-05 00:37:095354 // the right space, of course), but as render_surface1 already applies that
5355 // clip, clip_child need not apply it again.
5356 EXPECT_EQ(gfx::Rect(), clip_child->clip_rect());
jaydasika6f972de2016-04-07 16:16:145357 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
jaydasika1553a142017-04-05 00:37:095358 EXPECT_FALSE(clip_child->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385359}
5360
5361TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5362 // Ensures that descendants of the clip child inherit the correct clip.
5363 //
5364 // root (a render surface)
5365 // + clip_parent (masks to bounds)
5366 // + intervening (masks to bounds)
5367 // + clip_child
5368 // + child
5369 //
jaydasikabf1875a2016-06-28 03:39:595370 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175371 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5372 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5373 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5374 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365375 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175376 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385377
jaydasika1c0a27d42016-04-28 01:54:565378 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155379 clip_parent->test_properties()->clip_children =
5380 base::MakeUnique<std::set<LayerImpl*>>();
5381 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385382
danakjf78fb272016-07-26 19:06:155383 root->SetBounds(gfx::Size(50, 50));
5384 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385385 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155386 intervening->SetBounds(gfx::Size(5, 5));
5387 intervening->SetMasksToBounds(true);
5388 clip_child->SetBounds(gfx::Size(60, 60));
5389 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385390
enne2d0d8e62015-08-18 18:29:175391 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385392
chrishtr7e3aaf22017-05-04 15:04:015393 EXPECT_TRUE(GetRenderSurface(root));
[email protected]420fdf6e2013-08-26 20:36:385394
5395 // Neither the clip child nor its descendant should have inherited the clip
5396 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145397 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385398 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145399 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385400 EXPECT_TRUE(child->is_clipped());
5401}
5402
5403TEST_F(LayerTreeHostCommonTest,
5404 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5405 // Ensures that non-descendant clip children in the tree do not affect
5406 // render surfaces.
5407 //
5408 // root (a render surface)
5409 // + clip_parent (masks to bounds)
jaydasika1553a142017-04-05 00:37:095410 // + clip_layer (masks to bounds)
5411 // + render_surface1
5412 // + clip_child
5413 // + render_surface2
5414 // + non_clip_child
[email protected]420fdf6e2013-08-26 20:36:385415 //
5416 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595417 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505418 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
jaydasika1553a142017-04-05 00:37:095419 LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent);
5420 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer);
enneb441cdd2015-07-28 22:47:505421 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
jaydasika1553a142017-04-05 00:37:095422 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_layer);
enneb441cdd2015-07-28 22:47:505423 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385424
jaydasika1c0a27d42016-04-28 01:54:565425 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155426 clip_parent->test_properties()->clip_children =
5427 base::MakeUnique<std::set<LayerImpl*>>();
5428 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385429
5430 clip_parent->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:095431 clip_layer->SetMasksToBounds(true);
[email protected]420fdf6e2013-08-26 20:36:385432
danakjf78fb272016-07-26 19:06:155433 render_surface1->SetDrawsContent(true);
5434 clip_child->SetDrawsContent(true);
5435 render_surface2->SetDrawsContent(true);
5436 non_clip_child->SetDrawsContent(true);
5437
5438 root->SetBounds(gfx::Size(15, 15));
5439 clip_parent->SetBounds(gfx::Size(10, 10));
jaydasika1553a142017-04-05 00:37:095440 clip_layer->SetBounds(gfx::Size(10, 10));
danakjf78fb272016-07-26 19:06:155441 render_surface1->SetPosition(gfx::PointF(5, 5));
5442 render_surface1->SetBounds(gfx::Size(5, 5));
5443 render_surface1->test_properties()->force_render_surface = true;
5444 render_surface2->SetBounds(gfx::Size(5, 5));
5445 render_surface2->test_properties()->force_render_surface = true;
5446 clip_child->SetPosition(gfx::PointF(-1, 1));
5447 clip_child->SetBounds(gfx::Size(10, 10));
5448 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:385449
enneb441cdd2015-07-28 22:47:505450 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385451
chrishtr7e3aaf22017-05-04 15:04:015452 EXPECT_TRUE(GetRenderSurface(root));
5453 EXPECT_TRUE(GetRenderSurface(render_surface1));
5454 EXPECT_TRUE(GetRenderSurface(render_surface2));
[email protected]420fdf6e2013-08-26 20:36:385455
jaydasika1553a142017-04-05 00:37:095456 EXPECT_EQ(gfx::Rect(-5, -5, 10, 10), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385457 EXPECT_TRUE(render_surface1->is_clipped());
5458
5459 // The render surface should not clip (it has unclipped descendants), instead
5460 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:145461 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
chrishtr7e3aaf22017-05-04 15:04:015462 GetRenderSurface(render_surface1)->clip_rect());
5463 EXPECT_FALSE(GetRenderSurface(render_surface1)->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385464
jaydasika0d98ba92015-11-17 05:17:285465 // That said, it should have grown to accomodate the unclipped descendant and
5466 // its own size.
jaydasika6f972de2016-04-07 16:16:145467 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
chrishtr7e3aaf22017-05-04 15:04:015468 GetRenderSurface(render_surface1)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385469
5470 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:145471 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
chrishtr7e3aaf22017-05-04 15:04:015472 GetRenderSurface(render_surface2)->clip_rect());
5473 EXPECT_TRUE(GetRenderSurface(render_surface2)->is_clipped());
weiliangcbb2e8642016-03-04 00:24:425474 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385475
5476 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:145477 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
chrishtr7e3aaf22017-05-04 15:04:015478 GetRenderSurface(render_surface2)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385479}
5480
weiliangc9ced1592015-11-17 19:04:375481TEST_F(LayerTreeHostCommonTest,
5482 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5483 // Verifies that Render Surfaces are created at the edge of rendering context.
5484
jaydasikabf1875a2016-06-28 03:39:595485 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:265486 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
5487 LayerImpl* child2 = AddChild<LayerImpl>(child1);
5488 LayerImpl* child3 = AddChild<LayerImpl>(child2);
5489 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375490
weiliangc9ced1592015-11-17 19:04:375491 gfx::Size bounds(100, 100);
5492
danakjf78fb272016-07-26 19:06:155493 root->SetBounds(bounds);
5494 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265495 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155496 child1->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:205497 child1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155498 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265499 child2->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:205500 child2->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155501 child3->SetBounds(bounds);
5502 child3->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:205503 child3->test_properties()->sorting_context_id = 1;
jaydasika6ed869662016-09-21 14:29:595504 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
weiliangc9ced1592015-11-17 19:04:375505
5506 // Verify which render surfaces were created.
chrishtr7e3aaf22017-05-04 15:04:015507 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:495508 EXPECT_EQ(GetRenderSurface(child1), GetRenderSurface(root));
5509 EXPECT_NE(GetRenderSurface(child2), GetRenderSurface(root));
5510 EXPECT_EQ(GetRenderSurface(child3), GetRenderSurface(child2));
weiliangc9ced1592015-11-17 19:04:375511}
5512
[email protected]a9aa60a82013-08-29 04:28:265513TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:595514 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:335515 LayerImpl* back_facing = AddChild<LayerImpl>(root);
trchen75204782016-11-03 01:05:425516
jaydasikae00c8a42016-01-28 20:18:335517 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
jaydasikae00c8a42016-01-28 20:18:335518 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
trchen75204782016-11-03 01:05:425519
5520 LayerImpl* flattener = AddChild<LayerImpl>(back_facing);
5521 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener);
jaydasikae00c8a42016-01-28 20:18:335522 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:155523
jaydasikae00c8a42016-01-28 20:18:335524 child1->SetDrawsContent(true);
5525 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:265526
danakjf78fb272016-07-26 19:06:155527 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:155528 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:525529 back_facing->test_properties()->should_flatten_transform = false;
trchen75204782016-11-03 01:05:425530
danakjf78fb272016-07-26 19:06:155531 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155532 render_surface1->test_properties()->should_flatten_transform = false;
5533 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:365534 render_surface1->test_properties()->double_sided = false;
trchen75204782016-11-03 01:05:425535 child1->SetBounds(gfx::Size(20, 20));
5536
5537 flattener->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155538 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155539 render_surface2->test_properties()->should_flatten_transform = false;
5540 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:365541 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155542 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:265543
enne03b0e9a2015-06-19 00:08:025544 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:265545
ajumab784ef42017-04-28 23:01:525546 EXPECT_EQ(3u, render_surface_list_impl()->size());
5547 EXPECT_EQ(2, render_surface_list_impl()->at(0)->num_contributors());
5548 EXPECT_EQ(1, render_surface_list_impl()->at(1)->num_contributors());
[email protected]a9aa60a82013-08-29 04:28:265549
danakjf78fb272016-07-26 19:06:155550 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:265551 rotation_transform.RotateAboutXAxis(180.0);
5552
jaydasika10d43fc2016-08-18 04:06:045553 back_facing->test_properties()->transform = rotation_transform;
jaydasika5aa88b82015-11-10 01:48:035554 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:265555
enne03b0e9a2015-06-19 00:08:025556 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:265557
jaydasikae00c8a42016-01-28 20:18:335558 // render_surface1 is in the same 3d rendering context as back_facing and is
5559 // not double sided, so it should not be in RSLL. render_surface2 is also not
5560 // double-sided, but will still be in RSLL as it's in a different 3d rendering
5561 // context.
ajumab784ef42017-04-28 23:01:525562 EXPECT_EQ(2u, render_surface_list_impl()->size());
5563 EXPECT_EQ(1, render_surface_list_impl()->at(0)->num_contributors());
[email protected]a9aa60a82013-08-29 04:28:265564}
5565
ajumaaa0d3862015-11-09 22:24:465566TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:595567 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:465568 LayerImpl* child = AddChild<LayerImpl>(root);
5569 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:465570
danakjf78fb272016-07-26 19:06:155571 root->SetBounds(gfx::Size(50, 50));
5572 root->test_properties()->should_flatten_transform = false;
5573 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:365574 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155575 child->test_properties()->should_flatten_transform = false;
5576 grand_child->SetBounds(gfx::Size(20, 20));
5577 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:465578 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:155579 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:465580 ExecuteCalculateDrawProperties(root);
5581
ajumab784ef42017-04-28 23:01:525582 EXPECT_EQ(1u, render_surface_list_impl()->size());
ajuma651848a2017-05-01 21:23:455583 EXPECT_TRUE(grand_child->contributes_to_drawn_render_surface());
jaydasika62bd3dd2016-02-04 18:52:555584
Chris Harrelsondaececa42017-06-16 20:42:025585 // A ll layers with invisible backfgaces should be checked.
jaydasika62bd3dd2016-02-04 18:52:555586 EXPECT_FALSE(root->should_check_backface_visibility());
Chris Harrelsondaececa42017-06-16 20:42:025587 EXPECT_TRUE(child->should_check_backface_visibility());
5588 EXPECT_TRUE(grand_child->should_check_backface_visibility());
jaydasika62bd3dd2016-02-04 18:52:555589
danakjf78fb272016-07-26 19:06:155590 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:465591 rotation_transform.RotateAboutXAxis(180.0);
5592
jaydasika10d43fc2016-08-18 04:06:045593 child->test_properties()->transform = rotation_transform;
wkormanf09921d2017-01-07 01:01:205594 child->test_properties()->sorting_context_id = 1;
5595 grand_child->test_properties()->sorting_context_id = 1;
ajumaaa0d3862015-11-09 22:24:465596 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
5597
5598 ExecuteCalculateDrawProperties(root);
ajumab784ef42017-04-28 23:01:525599 EXPECT_EQ(1u, render_surface_list_impl()->size());
5600 EXPECT_EQ(0, render_surface_list_impl()->at(0)->num_contributors());
jaydasika62bd3dd2016-02-04 18:52:555601
5602 // We should check for backface visibilty of child as it has a rotation
5603 // transform. We should also check for grand_child as it uses the backface
5604 // visibility of its parent.
5605 EXPECT_FALSE(root->should_check_backface_visibility());
5606 EXPECT_TRUE(child->should_check_backface_visibility());
5607 EXPECT_TRUE(grand_child->should_check_backface_visibility());
jaydasika62bd3dd2016-02-04 18:52:555608
5609 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:365610 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:555611 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
5612
5613 ExecuteCalculateDrawProperties(root);
ajumab784ef42017-04-28 23:01:525614 EXPECT_EQ(1u, render_surface_list_impl()->size());
5615 EXPECT_EQ(0, render_surface_list_impl()->at(0)->num_contributors());
jaydasika62bd3dd2016-02-04 18:52:555616
5617 // We should check the backface visibility of child as it has a rotation
5618 // transform and for grand_child as it is in a 3d rendering context and not
5619 // the root of it.
5620 EXPECT_FALSE(root->should_check_backface_visibility());
5621 EXPECT_TRUE(child->should_check_backface_visibility());
5622 EXPECT_TRUE(grand_child->should_check_backface_visibility());
ajumaaa0d3862015-11-09 22:24:465623}
5624
sunxd59dd7da2016-05-19 20:07:475625TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:595626 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:475627 LayerImpl* back_facing = AddChild<LayerImpl>(root);
5628 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
5629 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
5630
sunxd59dd7da2016-05-19 20:07:475631 gfx::Transform rotate_about_y;
5632 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:475633
danakjf78fb272016-07-26 19:06:155634 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:155635 root->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:205636 root->test_properties()->sorting_context_id = 1;
jaydasika10d43fc2016-08-18 04:06:045637 back_facing->test_properties()->transform = rotate_about_y;
danakjf78fb272016-07-26 19:06:155638 back_facing->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:155639 back_facing->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:205640 back_facing->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155641 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155642 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:475643 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155644 render_surface1->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205645 render_surface1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155646 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155647 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:475648 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155649 render_surface2->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205650 render_surface2->test_properties()->sorting_context_id = 1;
weiliangcea09f3372017-03-29 16:43:245651 SetElementIdsForTesting();
sunxd59dd7da2016-05-19 20:07:475652 ExecuteCalculateDrawProperties(root);
5653
5654 const EffectTree& tree =
5655 root->layer_tree_impl()->property_trees()->effect_tree;
5656 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:015657 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475658 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:015659 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475660
weiliangcea09f3372017-03-29 16:43:245661 root->layer_tree_impl()->SetTransformMutated(back_facing->element_id(),
5662 gfx::Transform());
5663 root->layer_tree_impl()->SetTransformMutated(render_surface2->element_id(),
5664 rotate_about_y);
sunxd59dd7da2016-05-19 20:07:475665 ExecuteCalculateDrawProperties(root);
5666 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:015667 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475668 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:015669 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475670
weiliangcea09f3372017-03-29 16:43:245671 root->layer_tree_impl()->SetTransformMutated(render_surface1->element_id(),
5672 rotate_about_y);
sunxd59dd7da2016-05-19 20:07:475673 ExecuteCalculateDrawProperties(root);
5674 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:015675 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475676 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:015677 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475678}
5679
[email protected]995708c52013-10-17 20:52:595680TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
5681 // Checks that the simple case (being clipped by a scroll parent that would
5682 // have been processed before you anyhow) results in the right clips.
5683 //
5684 // + root
5685 // + scroll_parent_border
5686 // | + scroll_parent_clip
5687 // | + scroll_parent
5688 // + scroll_child
5689 //
jaydasikabf1875a2016-06-28 03:39:595690 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:485691 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
5692 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5693 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5694 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:595695
enne085b48a2015-08-18 17:54:485696 scroll_parent->SetDrawsContent(true);
5697 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595698 scroll_parent_clip->SetMasksToBounds(true);
5699
jaydasika1c0a27d42016-04-28 01:54:565700 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155701 scroll_parent->test_properties()->scroll_children =
5702 base::MakeUnique<std::set<LayerImpl*>>();
5703 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:595704
danakjf78fb272016-07-26 19:06:155705 root->SetBounds(gfx::Size(50, 50));
5706 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5707 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
5708 scroll_parent->SetBounds(gfx::Size(50, 50));
5709 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:485710 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595711
chrishtr7e3aaf22017-05-04 15:04:015712 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595713
jaydasika6f972de2016-04-07 16:16:145714 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595715 EXPECT_TRUE(scroll_child->is_clipped());
5716}
5717
jaydasika8ccff3d2016-01-20 19:51:305718TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
5719 // Tests the computation of draw transform for the scroll child when its
5720 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:595721 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:305722 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
5723 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
5724 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
5725 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
5726
5727 scroll_parent->SetDrawsContent(true);
5728 scroll_child->SetDrawsContent(true);
5729
jaydasika1c0a27d42016-04-28 01:54:565730 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155731 scroll_parent->test_properties()->scroll_children =
5732 base::MakeUnique<std::set<LayerImpl*>>();
5733 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:305734
danakjf78fb272016-07-26 19:06:155735 root->SetBounds(gfx::Size(50, 50));
5736 scroll_child_target->SetBounds(gfx::Size(50, 50));
5737 scroll_child_target->test_properties()->force_render_surface = true;
5738 scroll_child->SetBounds(gfx::Size(50, 50));
5739 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
5740 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:005741 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155742 scroll_parent_target->test_properties()->force_render_surface = true;
5743 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:305744
jaydasika2489a442016-01-29 02:26:005745 float device_scale_factor = 1.5f;
ajumab784ef42017-04-28 23:01:525746 RenderSurfaceList render_surface_list_impl;
jaydasikab4df4032016-09-13 18:38:495747 gfx::Size device_viewport_size =
5748 gfx::Size(root->bounds().width() * device_scale_factor,
5749 root->bounds().height() * device_scale_factor);
jaydasika2489a442016-01-29 02:26:005750 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:525751 root, device_viewport_size, gfx::Transform(), &render_surface_list_impl);
jaydasika2489a442016-01-29 02:26:005752 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:575753 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:005754
weiliangc1da3fb892016-03-14 20:23:525755 EXPECT_EQ(scroll_child->effect_tree_index(),
5756 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:005757 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
5758 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
5759 gfx::Transform scale;
5760 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:025761 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:305762}
5763
[email protected]08bdf1b2014-04-16 23:23:295764TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:595765 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:195766 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:195767 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:155768
5769 root->SetBounds(gfx::Size(50, 50));
5770 root->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:205771 root->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155772 parent->SetBounds(gfx::Size(30, 30));
5773 parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155774 parent->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205775 parent->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155776 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:195777 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155778 child->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205779 child->test_properties()->sorting_context_id = 1;
enneca33fed2015-07-27 18:22:195780 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:295781
ajumab784ef42017-04-28 23:01:525782 EXPECT_EQ(3u, render_surface_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:295783
5784 gfx::Transform singular_transform;
5785 singular_transform.Scale3d(
5786 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5787
jaydasika10d43fc2016-08-18 04:06:045788 child->test_properties()->transform = singular_transform;
[email protected]08bdf1b2014-04-16 23:23:295789
sunxd71aea3e2016-04-01 23:48:055790 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:195791 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:295792
ajumab784ef42017-04-28 23:01:525793 EXPECT_EQ(2u, render_surface_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:295794
5795 // Ensure that the entire subtree under a layer with singular transform does
5796 // not get rendered.
jaydasika10d43fc2016-08-18 04:06:045797 parent->test_properties()->transform = singular_transform;
5798 child->test_properties()->transform = gfx::Transform();
[email protected]08bdf1b2014-04-16 23:23:295799
sunxd71aea3e2016-04-01 23:48:055800 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:195801 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:295802
ajumab784ef42017-04-28 23:01:525803 EXPECT_EQ(1u, render_surface_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:295804}
5805
[email protected]995708c52013-10-17 20:52:595806TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
5807 // Checks that clipping by a scroll parent that follows you in paint order
5808 // still results in correct clipping.
5809 //
5810 // + root
[email protected]995708c52013-10-17 20:52:595811 // + scroll_parent_border
5812 // + scroll_parent_clip
5813 // + scroll_parent
enne03b0e9a2015-06-19 00:08:025814 // + scroll_child
[email protected]995708c52013-10-17 20:52:595815 //
jaydasikabf1875a2016-06-28 03:39:595816 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:025817 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5818 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5819 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5820 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:595821
enne03b0e9a2015-06-19 00:08:025822 scroll_parent->SetDrawsContent(true);
5823 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595824
danakjf78fb272016-07-26 19:06:155825 root->SetBounds(gfx::Size(50, 50));
5826 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5827 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:595828 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155829 scroll_parent->SetBounds(gfx::Size(50, 50));
5830 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:595831
jaydasika1c0a27d42016-04-28 01:54:565832 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155833 scroll_parent->test_properties()->scroll_children =
5834 base::MakeUnique<std::set<LayerImpl*>>();
5835 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:595836
enne03b0e9a2015-06-19 00:08:025837 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595838
chrishtr7e3aaf22017-05-04 15:04:015839 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595840
jaydasika6f972de2016-04-07 16:16:145841 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595842 EXPECT_TRUE(scroll_child->is_clipped());
5843}
5844
5845TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
5846 // Checks that clipping by a scroll parent and scroll grandparent that follow
5847 // you in paint order still results in correct clipping.
5848 //
5849 // + root
5850 // + scroll_child
5851 // + scroll_parent_border
5852 // | + scroll_parent_clip
5853 // | + scroll_parent
5854 // + scroll_grandparent_border
5855 // + scroll_grandparent_clip
5856 // + scroll_grandparent
5857 //
jaydasikabf1875a2016-06-28 03:39:595858 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:025859 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5860 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5861 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5862 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5863 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5864 LayerImpl* scroll_grandparent_clip =
5865 AddChild<LayerImpl>(scroll_grandparent_border);
5866 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:595867
enne03b0e9a2015-06-19 00:08:025868 scroll_parent->SetDrawsContent(true);
5869 scroll_grandparent->SetDrawsContent(true);
5870 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595871
5872 scroll_parent_clip->SetMasksToBounds(true);
5873 scroll_grandparent_clip->SetMasksToBounds(true);
5874
jaydasika1c0a27d42016-04-28 01:54:565875 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155876 scroll_parent->test_properties()->scroll_children =
5877 base::MakeUnique<std::set<LayerImpl*>>();
5878 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:385879
jaydasika1c0a27d42016-04-28 01:54:565880 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:155881 scroll_grandparent->test_properties()->scroll_children =
5882 base::MakeUnique<std::set<LayerImpl*>>();
5883 scroll_grandparent->test_properties()->scroll_children->insert(
5884 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:595885
danakjf78fb272016-07-26 19:06:155886 root->SetBounds(gfx::Size(50, 50));
5887 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
5888 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
5889 scroll_grandparent->SetBounds(gfx::Size(50, 50));
5890 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5891 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
5892 scroll_parent->SetBounds(gfx::Size(50, 50));
5893 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:595894
enne03b0e9a2015-06-19 00:08:025895 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595896
chrishtr7e3aaf22017-05-04 15:04:015897 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595898
jaydasika6f972de2016-04-07 16:16:145899 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595900 EXPECT_TRUE(scroll_child->is_clipped());
5901
5902 // Despite the fact that we visited the above layers out of order to get the
5903 // correct clip, the layer lists should be unaffected.
chrishtr7e3aaf22017-05-04 15:04:015904 EXPECT_EQ(3, GetRenderSurface(root)->num_contributors());
ajuma651848a2017-05-01 21:23:455905 EXPECT_TRUE(scroll_child->contributes_to_drawn_render_surface());
5906 EXPECT_TRUE(scroll_parent->contributes_to_drawn_render_surface());
5907 EXPECT_TRUE(scroll_grandparent->contributes_to_drawn_render_surface());
[email protected]995708c52013-10-17 20:52:595908}
5909
5910TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
5911 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:225912 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:595913 // + root
5914 // + scroll_child
5915 // + scroll_parent_border
5916 // + scroll_parent_clip
5917 // + scroll_parent
enne03b0e9a2015-06-19 00:08:025918 // + render_surface2
[email protected]995708c52013-10-17 20:52:595919 // + scroll_grandparent_border
5920 // + scroll_grandparent_clip
5921 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:025922 // + render_surface1
[email protected]995708c52013-10-17 20:52:595923 //
jaydasikabf1875a2016-06-28 03:39:595924 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:025925 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595926
enne03b0e9a2015-06-19 00:08:025927 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5928 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595929
enne03b0e9a2015-06-19 00:08:025930 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5931 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5932 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5933 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
5934 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5935 LayerImpl* scroll_grandparent_clip =
5936 AddChild<LayerImpl>(scroll_grandparent_border);
5937 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
5938 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:595939
enne03b0e9a2015-06-19 00:08:025940 scroll_parent->SetDrawsContent(true);
5941 render_surface1->SetDrawsContent(true);
5942 scroll_grandparent->SetDrawsContent(true);
5943 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595944
5945 scroll_parent_clip->SetMasksToBounds(true);
5946 scroll_grandparent_clip->SetMasksToBounds(true);
5947
jaydasika1c0a27d42016-04-28 01:54:565948 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155949 scroll_parent->test_properties()->scroll_children =
5950 base::MakeUnique<std::set<LayerImpl*>>();
5951 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:385952
jaydasika1c0a27d42016-04-28 01:54:565953 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:155954 scroll_grandparent->test_properties()->scroll_children =
5955 base::MakeUnique<std::set<LayerImpl*>>();
5956 scroll_grandparent->test_properties()->scroll_children->insert(
5957 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:595958
danakjf78fb272016-07-26 19:06:155959 root->SetBounds(gfx::Size(50, 50));
5960 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
5961 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
5962 scroll_grandparent->SetBounds(gfx::Size(50, 50));
5963 render_surface1->SetBounds(gfx::Size(50, 50));
5964 render_surface1->test_properties()->force_render_surface = true;
5965 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5966 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
5967 scroll_parent->SetBounds(gfx::Size(50, 50));
5968 render_surface2->SetBounds(gfx::Size(50, 50));
5969 render_surface2->test_properties()->force_render_surface = true;
5970 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:595971
enne03b0e9a2015-06-19 00:08:025972 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595973
chrishtr7e3aaf22017-05-04 15:04:015974 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595975
jaydasika6f972de2016-04-07 16:16:145976 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595977 EXPECT_TRUE(scroll_child->is_clipped());
5978
5979 // Despite the fact that we had to process the layers out of order to get the
ajumab784ef42017-04-28 23:01:525980 // right clip, our render_surface_list's order should be unaffected.
5981 EXPECT_EQ(3u, render_surface_list_impl()->size());
chrishtr7e3aaf22017-05-04 15:04:015982 EXPECT_EQ(GetRenderSurface(root), render_surface_list_impl()->at(0));
5983 EXPECT_EQ(GetRenderSurface(render_surface2),
ajumab784ef42017-04-28 23:01:525984 render_surface_list_impl()->at(1));
chrishtr7e3aaf22017-05-04 15:04:015985 EXPECT_EQ(GetRenderSurface(render_surface1),
ajumab784ef42017-04-28 23:01:525986 render_surface_list_impl()->at(2));
[email protected]995708c52013-10-17 20:52:595987}
5988
ajuma0b10f942015-03-21 07:45:535989TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
5990 // Ensures that when we have a render surface between a fixed position layer
5991 // and its container, we compute the fixed position layer's draw transform
5992 // with respect to that intervening render surface, not with respect to its
5993 // container's render target.
5994 //
5995 // + root
5996 // + render_surface
5997 // + fixed
ajuma737b2702015-05-06 01:18:375998 // + child
ajuma0b10f942015-03-21 07:45:535999 //
jaydasikabf1875a2016-06-28 03:39:596000 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516001 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6002 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6003 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536004
jaydasika6b5a32bf2016-04-22 21:56:366005 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526006 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536007
6008 LayerPositionConstraint constraint;
6009 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526010 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536011
danakjf78fb272016-07-26 19:06:156012 root->SetBounds(gfx::Size(50, 50));
6013 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6014 render_surface->SetBounds(gfx::Size(50, 50));
6015 render_surface->SetDrawsContent(true);
6016 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6017 fixed->SetBounds(gfx::Size(50, 50));
6018 fixed->SetDrawsContent(true);
6019 child->SetPosition(gfx::PointF(1.f, 2.f));
6020 child->SetBounds(gfx::Size(50, 50));
6021 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516022 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536023
jaydasikabaede2d92016-07-20 00:34:326024 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516025 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326026 EffectTree& effect_tree =
6027 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156028
ajuma737b2702015-05-06 01:18:376029 gfx::Transform expected_fixed_draw_transform;
6030 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026031 EXPECT_TRANSFORMATION_MATRIX_EQ(
6032 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326033 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536034
ajuma737b2702015-05-06 01:18:376035 gfx::Transform expected_fixed_screen_space_transform;
6036 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026037 EXPECT_TRANSFORMATION_MATRIX_EQ(
6038 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326039 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376040
6041 gfx::Transform expected_child_draw_transform;
6042 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026043 EXPECT_TRANSFORMATION_MATRIX_EQ(
6044 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326045 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376046
6047 gfx::Transform expected_child_screen_space_transform;
6048 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026049 EXPECT_TRANSFORMATION_MATRIX_EQ(
6050 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326051 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536052}
6053
[email protected]d81752b2013-10-25 08:32:236054TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6055 // This test verifies that a scrolling layer that gets snapped to
6056 // integer coordinates doesn't move a fixed position child.
6057 //
6058 // + root
6059 // + container
6060 // + scroller
6061 // + fixed
6062 //
khushalsagarb64b360d2015-10-21 19:25:166063 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:566064 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:226065 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236066 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486067 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426068 LayerImpl::Create(host_impl.active_tree(), 1);
6069 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486070 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236071 LayerImpl::Create(host_impl.active_tree(), 2);
6072 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486073 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236074 LayerImpl::Create(host_impl.active_tree(), 3);
6075 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486076 std::unique_ptr<LayerImpl> fixed =
6077 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236078 LayerImpl* fixed_layer = fixed.get();
6079
jaydasikaca2605e2016-04-23 02:52:526080 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236081
6082 LayerPositionConstraint constraint;
6083 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526084 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236085
pdr54d038192017-06-08 22:44:136086 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
[email protected]d81752b2013-10-25 08:32:236087
[email protected]d81752b2013-10-25 08:32:236088 gfx::Transform container_transform;
6089 container_transform.Translate3d(10.0, 20.0, 0.0);
6090 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6091
danakjf78fb272016-07-26 19:06:156092 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046093 container->test_properties()->transform = container_transform;
danakjf78fb272016-07-26 19:06:156094 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286095 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156096 scroller->SetBounds(gfx::Size(30, 30));
pdrbbfd8822017-06-27 22:44:526097 scroller->SetScrollable(container->bounds());
jaydasika0d98ba92015-11-17 05:17:286098 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156099 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286100 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156101
jaydasika89f7b5a2016-06-22 02:08:396102 scroller->test_properties()->AddChild(std::move(fixed));
6103 container->test_properties()->AddChild(std::move(scroller));
6104 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486105 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6106 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236107
6108 // Rounded to integers already.
6109 {
6110 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426111 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236112
ajumab784ef42017-04-28 23:01:526113 RenderSurfaceList render_surface_list;
[email protected]d81752b2013-10-25 08:32:236114 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:526115 root, root->bounds(), &render_surface_list);
sunxdb7e79432016-03-09 21:13:426116 root->layer_tree_impl()
6117 ->property_trees()
6118 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576119 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236120
6121 EXPECT_TRANSFORMATION_MATRIX_EQ(
6122 container_layer->draw_properties().screen_space_transform,
6123 fixed_layer->draw_properties().screen_space_transform);
6124 EXPECT_VECTOR_EQ(
6125 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6126 container_offset);
6127 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6128 .screen_space_transform.To2dTranslation(),
6129 container_offset - scroll_delta);
6130 }
6131
6132 // Scroll delta requiring rounding.
6133 {
6134 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426135 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236136
6137 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6138
ajumab784ef42017-04-28 23:01:526139 RenderSurfaceList render_surface_list;
[email protected]d81752b2013-10-25 08:32:236140 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:526141 root, root->bounds(), &render_surface_list);
sunxdb365de02016-04-28 20:32:576142 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236143
6144 EXPECT_TRANSFORMATION_MATRIX_EQ(
6145 container_layer->draw_properties().screen_space_transform,
6146 fixed_layer->draw_properties().screen_space_transform);
6147 EXPECT_VECTOR_EQ(
6148 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6149 container_offset);
6150 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6151 .screen_space_transform.To2dTranslation(),
6152 container_offset - rounded_scroll_delta);
6153 }
[email protected]cf15ad7b2014-04-02 03:59:266154
6155 // Scale is applied earlier in the tree.
6156 {
sunxdb7e79432016-03-09 21:13:426157 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266158 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286159 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:046160 container_layer->test_properties()->transform = scaled_container_transform;
danakj74af409e2016-07-01 00:41:486161
jaydasika0d98ba92015-11-17 05:17:286162 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266163
6164 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426165 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266166
ajumab784ef42017-04-28 23:01:526167 RenderSurfaceList render_surface_list;
[email protected]cf15ad7b2014-04-02 03:59:266168 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:526169 root, root->bounds(), &render_surface_list);
sunxdb365de02016-04-28 20:32:576170 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266171
6172 EXPECT_TRANSFORMATION_MATRIX_EQ(
6173 container_layer->draw_properties().screen_space_transform,
6174 fixed_layer->draw_properties().screen_space_transform);
6175 EXPECT_VECTOR_EQ(
6176 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6177 container_offset);
6178
jaydasika10d43fc2016-08-18 04:06:046179 container_layer->test_properties()->transform = container_transform;
[email protected]cf15ad7b2014-04-02 03:59:266180 }
[email protected]d81752b2013-10-25 08:32:236181}
6182
miletus2c78036b2015-01-29 20:52:376183TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506184 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6185 // This test verifies that a scrolling layer whose screen space transform is
6186 // animating doesn't get snapped to integer coordinates.
6187 //
6188 // + root
6189 // + animated layer
6190 // + surface
6191 // + container
6192 // + scroller
6193 //
jaydasikabf1875a2016-06-28 03:39:596194 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506195 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6196 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6197 LayerImpl* container = AddChild<LayerImpl>(surface);
6198 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506199
ajuma5e8e40d2015-07-31 01:50:506200 gfx::Transform start_scale;
6201 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156202
6203 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046204 animated_layer->test_properties()->transform = start_scale;
danakjf78fb272016-07-26 19:06:156205 animated_layer->SetBounds(gfx::Size(50, 50));
6206 surface->SetBounds(gfx::Size(50, 50));
6207 surface->test_properties()->force_render_surface = true;
6208 container->SetBounds(gfx::Size(50, 50));
6209 scroller->SetBounds(gfx::Size(100, 100));
pdr54d038192017-06-08 22:44:136210 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdrbbfd8822017-06-27 22:44:526211 scroller->SetScrollable(container->bounds());
danakjf78fb272016-07-26 19:06:156212 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506213
6214 gfx::Transform end_scale;
6215 end_scale.Scale(2.f, 2.f);
6216 TransformOperations start_operations;
6217 start_operations.AppendMatrix(start_scale);
6218 TransformOperations end_operations;
6219 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276220 SetElementIdsForTesting();
6221
6222 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6223 timeline_impl(), 1.0,
6224 start_operations, end_operations);
pdr80d5a3e2017-07-17 19:04:076225 BuildPropertyTreesForTesting();
ajuma5e8e40d2015-07-31 01:50:506226 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426227 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506228
6229 ExecuteCalculateDrawProperties(root);
6230
6231 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6232 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446233 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506234}
6235
sunxd8a9a60982016-07-29 18:46:566236TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6237 // This test verifies that a scrolling child of a scrolling layer doesn't get
6238 // snapped to integer coordinates.
6239 //
6240 // + root
6241 // + container
6242 // + scroller
6243 // + scroll_child
6244 //
6245 scoped_refptr<Layer> root = Layer::Create();
6246 scoped_refptr<Layer> container = Layer::Create();
6247 scoped_refptr<Layer> scroller = Layer::Create();
6248 scoped_refptr<Layer> scroll_child = Layer::Create();
6249 root->AddChild(container);
6250 root->AddChild(scroll_child);
6251 container->AddChild(scroller);
6252 host()->SetRootLayer(root);
6253
pdr54d038192017-06-08 22:44:136254 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
sunxd8a9a60982016-07-29 18:46:566255 scroll_child->SetScrollParent(scroller.get());
6256
6257 gfx::Transform rotate;
6258 rotate.RotateAboutYAxis(30);
6259 root->SetBounds(gfx::Size(50, 50));
6260 container->SetBounds(gfx::Size(50, 50));
6261 scroller->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526262 scroller->SetScrollable(container->bounds());
sunxd8a9a60982016-07-29 18:46:566263 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6264 scroll_child->SetBounds(gfx::Size(10, 10));
6265 scroll_child->SetTransform(rotate);
6266
6267 ExecuteCalculateDrawProperties(root.get());
6268
6269 host()->host_impl()->CreatePendingTree();
6270 host()->CommitAndCreatePendingTree();
6271 host()->host_impl()->ActivateSyncTree();
6272 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6273
6274 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6275 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6276 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
6277 gfx::Vector2dF scroll_delta(5.f, 9.f);
6278 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6279
6280 ExecuteCalculateDrawProperties(root_impl);
6281
6282 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6283 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6284 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6285
6286 gfx::Transform expected_scroll_child_screen_space_transform;
6287 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6288 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6289 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6290 scroll_child_impl->ScreenSpaceTransform());
6291}
6292
flackr2215b4e2016-09-21 20:16:016293TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
6294 scoped_refptr<Layer> root = Layer::Create();
6295 scoped_refptr<Layer> container = Layer::Create();
6296 scoped_refptr<Layer> scroller = Layer::Create();
6297 scoped_refptr<Layer> sticky_pos = Layer::Create();
6298 root->AddChild(container);
6299 container->AddChild(scroller);
6300 scroller->AddChild(sticky_pos);
6301 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136302 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016303
6304 LayerStickyPositionConstraint sticky_position;
6305 sticky_position.is_sticky = true;
6306 sticky_position.is_anchored_top = true;
6307 sticky_position.top_offset = 10.0f;
6308 sticky_position.scroll_container_relative_sticky_box_rect =
6309 gfx::Rect(10, 20, 10, 10);
6310 sticky_position.scroll_container_relative_containing_block_rect =
6311 gfx::Rect(0, 0, 50, 50);
6312 sticky_pos->SetStickyPositionConstraint(sticky_position);
6313
6314 root->SetBounds(gfx::Size(100, 100));
6315 container->SetBounds(gfx::Size(100, 100));
6316 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526317 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016318 sticky_pos->SetBounds(gfx::Size(10, 10));
6319 sticky_pos->SetPosition(gfx::PointF(10, 20));
6320
6321 ExecuteCalculateDrawProperties(root.get());
6322 host()->host_impl()->CreatePendingTree();
6323 host()->CommitAndCreatePendingTree();
6324 host()->host_impl()->ActivateSyncTree();
6325 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6326
6327 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6328 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6329 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6330
6331 ExecuteCalculateDrawProperties(root_impl);
6332 EXPECT_VECTOR2DF_EQ(
6333 gfx::Vector2dF(10.f, 20.f),
6334 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6335
6336 // Scroll less than sticking point, sticky element should move with scroll as
6337 // we haven't gotten to the initial sticky item location yet.
6338 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6339 ExecuteCalculateDrawProperties(root_impl);
6340 EXPECT_VECTOR2DF_EQ(
6341 gfx::Vector2dF(5.f, 15.f),
6342 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6343
6344 // Scroll past the sticking point, the Y coordinate should now be clamped.
6345 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6346 ExecuteCalculateDrawProperties(root_impl);
6347 EXPECT_VECTOR2DF_EQ(
6348 gfx::Vector2dF(-5.f, 10.f),
6349 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6350 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6351 ExecuteCalculateDrawProperties(root_impl);
6352 EXPECT_VECTOR2DF_EQ(
6353 gfx::Vector2dF(-5.f, 10.f),
6354 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6355
6356 // Scroll past the end of the sticky container (note: this element does not
6357 // have its own layer as it does not need to be composited).
6358 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6359 ExecuteCalculateDrawProperties(root_impl);
6360 EXPECT_VECTOR2DF_EQ(
6361 gfx::Vector2dF(-5.f, -10.f),
6362 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6363}
6364
flackrd2ae03f2016-11-14 19:22:056365TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) {
6366 scoped_refptr<Layer> root = Layer::Create();
6367 scoped_refptr<Layer> container = Layer::Create();
6368 scoped_refptr<Layer> scroller = Layer::Create();
6369 scoped_refptr<Layer> sticky_pos = Layer::Create();
6370 root->AddChild(container);
6371 container->AddChild(scroller);
6372 root->AddChild(sticky_pos);
6373 sticky_pos->SetScrollParent(scroller.get());
6374 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136375 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackrd2ae03f2016-11-14 19:22:056376
smcgruer29014ff2017-03-24 14:34:436377 // The sticky layer has already been scrolled on the main thread side, and has
6378 // stuck. This test then checks that further changes from cc-only scrolling
6379 // are handled correctly.
flackrd2ae03f2016-11-14 19:22:056380 LayerStickyPositionConstraint sticky_position;
6381 sticky_position.is_sticky = true;
6382 sticky_position.is_anchored_top = true;
6383 sticky_position.top_offset = 10.0f;
flackrd2ae03f2016-11-14 19:22:056384 sticky_position.scroll_container_relative_sticky_box_rect =
6385 gfx::Rect(10, 20, 10, 10);
6386 sticky_position.scroll_container_relative_containing_block_rect =
6387 gfx::Rect(0, 0, 50, 50);
6388 sticky_pos->SetStickyPositionConstraint(sticky_position);
6389
6390 root->SetBounds(gfx::Size(200, 200));
6391 container->SetBounds(gfx::Size(100, 100));
6392 container->SetPosition(gfx::PointF(50, 50));
6393 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526394 scroller->SetScrollable(container->bounds());
flackrd2ae03f2016-11-14 19:22:056395 sticky_pos->SetBounds(gfx::Size(10, 10));
6396 sticky_pos->SetPosition(gfx::PointF(60, 70));
6397
6398 ExecuteCalculateDrawProperties(root.get());
6399 host()->host_impl()->CreatePendingTree();
6400 host()->CommitAndCreatePendingTree();
6401 host()->host_impl()->ActivateSyncTree();
6402 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6403
6404 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6405 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6406 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6407
6408 ExecuteCalculateDrawProperties(root_impl);
6409 EXPECT_VECTOR2DF_EQ(
6410 gfx::Vector2dF(60.f, 70.f),
6411 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6412
6413 // Scroll less than sticking point, sticky element should move with scroll as
6414 // we haven't gotten to the initial sticky item location yet.
6415 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6416 ExecuteCalculateDrawProperties(root_impl);
6417 EXPECT_VECTOR2DF_EQ(
6418 gfx::Vector2dF(55.f, 65.f),
6419 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6420
6421 // Scroll past the sticking point, the Y coordinate should now be clamped.
6422 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6423 ExecuteCalculateDrawProperties(root_impl);
6424 EXPECT_VECTOR2DF_EQ(
6425 gfx::Vector2dF(45.f, 60.f),
6426 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6427 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6428 ExecuteCalculateDrawProperties(root_impl);
6429 EXPECT_VECTOR2DF_EQ(
6430 gfx::Vector2dF(45.f, 60.f),
6431 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6432
6433 // Scroll past the end of the sticky container (note: this element does not
6434 // have its own layer as it does not need to be composited).
6435 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6436 ExecuteCalculateDrawProperties(root_impl);
6437 EXPECT_VECTOR2DF_EQ(
6438 gfx::Vector2dF(45.f, 40.f),
6439 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6440}
6441
flackrdc5dfbe2016-10-24 21:43:386442TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) {
6443 scoped_refptr<Layer> root = Layer::Create();
6444 scoped_refptr<Layer> container = Layer::Create();
6445 scoped_refptr<Layer> scroller = Layer::Create();
6446 scoped_refptr<Layer> sticky_pos = Layer::Create();
6447 root->AddChild(container);
6448 container->AddChild(scroller);
6449 scroller->AddChild(sticky_pos);
6450 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136451 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackrdc5dfbe2016-10-24 21:43:386452
6453 LayerStickyPositionConstraint sticky_position;
6454 sticky_position.is_sticky = true;
6455 sticky_position.is_anchored_bottom = true;
6456 sticky_position.bottom_offset = 10.0f;
flackrdc5dfbe2016-10-24 21:43:386457 sticky_position.scroll_container_relative_sticky_box_rect =
6458 gfx::Rect(0, 200, 10, 10);
6459 sticky_position.scroll_container_relative_containing_block_rect =
6460 gfx::Rect(0, 0, 100, 500);
6461 sticky_pos->SetStickyPositionConstraint(sticky_position);
6462
6463 root->SetBounds(gfx::Size(100, 100));
6464 container->SetBounds(gfx::Size(100, 100));
6465 scroller->SetBounds(gfx::Size(100, 1000));
pdrbbfd8822017-06-27 22:44:526466 scroller->SetScrollable(container->bounds());
flackrdc5dfbe2016-10-24 21:43:386467 sticky_pos->SetBounds(gfx::Size(10, 10));
6468 sticky_pos->SetPosition(gfx::PointF(0, 200));
6469
6470 ExecuteCalculateDrawProperties(root.get());
6471 host()->host_impl()->CreatePendingTree();
6472 host()->CommitAndCreatePendingTree();
6473 host()->host_impl()->ActivateSyncTree();
6474 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6475
6476 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6477 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6478 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6479
6480 ExecuteCalculateDrawProperties(root_impl);
6481 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f));
6482 ExecuteCalculateDrawProperties(root_impl);
6483 EXPECT_VECTOR2DF_EQ(
6484 gfx::Vector2dF(0.f, 80.f),
6485 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6486}
6487
flackr2215b4e2016-09-21 20:16:016488TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
6489 scoped_refptr<Layer> root = Layer::Create();
6490 scoped_refptr<Layer> container = Layer::Create();
6491 scoped_refptr<Layer> scroller = Layer::Create();
6492 scoped_refptr<Layer> sticky_pos = Layer::Create();
6493 root->AddChild(container);
6494 container->AddChild(scroller);
6495 scroller->AddChild(sticky_pos);
6496 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136497 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016498
6499 LayerStickyPositionConstraint sticky_position;
6500 sticky_position.is_sticky = true;
6501 sticky_position.is_anchored_bottom = true;
6502 sticky_position.bottom_offset = 10.0f;
6503 sticky_position.scroll_container_relative_sticky_box_rect =
6504 gfx::Rect(0, 150, 10, 10);
6505 sticky_position.scroll_container_relative_containing_block_rect =
6506 gfx::Rect(0, 100, 50, 50);
6507 sticky_pos->SetStickyPositionConstraint(sticky_position);
6508
6509 root->SetBounds(gfx::Size(100, 100));
6510 container->SetBounds(gfx::Size(100, 100));
6511 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526512 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016513 sticky_pos->SetBounds(gfx::Size(10, 10));
6514 sticky_pos->SetPosition(gfx::PointF(0, 150));
6515
6516 ExecuteCalculateDrawProperties(root.get());
6517 host()->host_impl()->CreatePendingTree();
6518 host()->CommitAndCreatePendingTree();
6519 host()->host_impl()->ActivateSyncTree();
6520 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6521
6522 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6523 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6524 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6525
6526 // Initially the sticky element is moved up to the top of the container.
6527 ExecuteCalculateDrawProperties(root_impl);
6528 EXPECT_VECTOR2DF_EQ(
6529 gfx::Vector2dF(0.f, 100.f),
6530 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6531 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6532 ExecuteCalculateDrawProperties(root_impl);
6533 EXPECT_VECTOR2DF_EQ(
6534 gfx::Vector2dF(0.f, 95.f),
6535 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6536
6537 // Once we get past the top of the container it moves to be aligned 10px
6538 // up from the the bottom of the scroller.
6539 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
6540 ExecuteCalculateDrawProperties(root_impl);
6541 EXPECT_VECTOR2DF_EQ(
6542 gfx::Vector2dF(0.f, 80.f),
6543 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6544 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
6545 ExecuteCalculateDrawProperties(root_impl);
6546 EXPECT_VECTOR2DF_EQ(
6547 gfx::Vector2dF(0.f, 80.f),
6548 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6549
6550 // Once we scroll past its initial location, it sticks there.
6551 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
6552 ExecuteCalculateDrawProperties(root_impl);
6553 EXPECT_VECTOR2DF_EQ(
6554 gfx::Vector2dF(0.f, 0.f),
6555 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6556}
6557
flackra283bed2016-10-31 14:49:426558TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) {
flackre310f292016-10-12 21:09:286559 scoped_refptr<Layer> root = Layer::Create();
6560 scoped_refptr<Layer> scroller = Layer::Create();
6561 scoped_refptr<Layer> sticky_pos = Layer::Create();
6562 root->AddChild(scroller);
6563 scroller->AddChild(sticky_pos);
6564 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136565 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdr5200a052017-05-21 22:50:586566 LayerTreeHost::ViewportLayers viewport_layers;
6567 viewport_layers.page_scale = root;
6568 viewport_layers.inner_viewport_container = root;
6569 viewport_layers.inner_viewport_scroll = scroller;
6570 host()->RegisterViewportLayers(viewport_layers);
flackre310f292016-10-12 21:09:286571
6572 LayerStickyPositionConstraint sticky_position;
6573 sticky_position.is_sticky = true;
6574 sticky_position.is_anchored_bottom = true;
6575 sticky_position.bottom_offset = 10.0f;
flackre310f292016-10-12 21:09:286576 sticky_position.scroll_container_relative_sticky_box_rect =
flackra283bed2016-10-31 14:49:426577 gfx::Rect(0, 70, 10, 10);
flackre310f292016-10-12 21:09:286578 sticky_position.scroll_container_relative_containing_block_rect =
flackra283bed2016-10-31 14:49:426579 gfx::Rect(0, 60, 100, 100);
flackre310f292016-10-12 21:09:286580 sticky_pos->SetStickyPositionConstraint(sticky_position);
6581
6582 root->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526583 scroller->SetScrollable(gfx::Size(100, 100));
flackre310f292016-10-12 21:09:286584 scroller->SetBounds(gfx::Size(100, 1000));
6585 sticky_pos->SetBounds(gfx::Size(10, 10));
flackra283bed2016-10-31 14:49:426586 sticky_pos->SetPosition(gfx::PointF(0, 70));
flackre310f292016-10-12 21:09:286587
6588 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
flackra283bed2016-10-31 14:49:426589 scroller.get(), nullptr);
flackre310f292016-10-12 21:09:286590 host()->CommitAndCreateLayerImplTree();
6591 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6592 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6593 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id());
6594
6595 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
6596 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6597
6598 // Initially the sticky element is moved to the bottom of the container.
6599 EXPECT_VECTOR2DF_EQ(
flackra283bed2016-10-31 14:49:426600 gfx::Vector2dF(0.f, 70.f),
flackre310f292016-10-12 21:09:286601 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6602
flackra283bed2016-10-31 14:49:426603 // We start to hide the toolbar, but not far enough that the sticky element
6604 // should be moved up yet.
pdr23d381fd2017-04-25 21:06:316605 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f));
flackra283bed2016-10-31 14:49:426606 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6607 nullptr);
flackre310f292016-10-12 21:09:286608 EXPECT_VECTOR2DF_EQ(
6609 gfx::Vector2dF(0.f, 70.f),
6610 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackra283bed2016-10-31 14:49:426611
6612 // On hiding more of the toolbar the sticky element starts to stick.
pdr23d381fd2017-04-25 21:06:316613 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f));
flackra283bed2016-10-31 14:49:426614 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6615 nullptr);
6616 EXPECT_VECTOR2DF_EQ(
6617 gfx::Vector2dF(0.f, 60.f),
6618 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6619
6620 // On hiding more the sticky element stops moving as it has reached its
6621 // limit.
pdr23d381fd2017-04-25 21:06:316622 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f));
flackra283bed2016-10-31 14:49:426623 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6624 nullptr);
6625 EXPECT_VECTOR2DF_EQ(
6626 gfx::Vector2dF(0.f, 60.f),
6627 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6628}
6629
6630TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) {
6631 scoped_refptr<Layer> root = Layer::Create();
6632 scoped_refptr<Layer> scroller = Layer::Create();
6633 scoped_refptr<Layer> outer_clip = Layer::Create();
6634 scoped_refptr<Layer> outer_viewport = Layer::Create();
6635 scoped_refptr<Layer> sticky_pos = Layer::Create();
6636 root->AddChild(scroller);
6637 scroller->AddChild(outer_clip);
6638 outer_clip->AddChild(outer_viewport);
6639 outer_viewport->AddChild(sticky_pos);
6640 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136641 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdr5200a052017-05-21 22:50:586642 LayerTreeHost::ViewportLayers viewport_layers;
6643 viewport_layers.page_scale = root;
6644 viewport_layers.inner_viewport_container = root;
6645 viewport_layers.outer_viewport_container = outer_clip;
6646 viewport_layers.inner_viewport_scroll = scroller;
6647 viewport_layers.outer_viewport_scroll = outer_viewport;
6648 host()->RegisterViewportLayers(viewport_layers);
flackra283bed2016-10-31 14:49:426649
6650 LayerStickyPositionConstraint sticky_position;
6651 sticky_position.is_sticky = true;
6652 sticky_position.is_anchored_bottom = true;
6653 sticky_position.bottom_offset = 10.0f;
flackra283bed2016-10-31 14:49:426654 sticky_position.scroll_container_relative_sticky_box_rect =
6655 gfx::Rect(0, 70, 10, 10);
6656 sticky_position.scroll_container_relative_containing_block_rect =
6657 gfx::Rect(0, 60, 100, 100);
6658 sticky_pos->SetStickyPositionConstraint(sticky_position);
6659
6660 root->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526661 scroller->SetScrollable(gfx::Size(100, 100));
flackra283bed2016-10-31 14:49:426662 scroller->SetBounds(gfx::Size(100, 1000));
6663 outer_clip->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526664 outer_viewport->SetScrollable(gfx::Size(100, 100));
flackra283bed2016-10-31 14:49:426665 sticky_pos->SetBounds(gfx::Size(10, 10));
6666 sticky_pos->SetPosition(gfx::PointF(0, 70));
6667
6668 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
6669 scroller.get(), outer_viewport.get());
6670 host()->CommitAndCreateLayerImplTree();
6671 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6672 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6673 ASSERT_EQ(outer_viewport->id(),
6674 layer_tree_impl->OuterViewportScrollLayer()->id());
6675
6676 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
6677 LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer();
6678 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6679 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id());
6680
6681 // Initially the sticky element is moved to the bottom of the container.
6682 EXPECT_VECTOR2DF_EQ(
6683 gfx::Vector2dF(0.f, 70.f),
6684 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6685
6686 // We start to hide the toolbar, but not far enough that the sticky element
6687 // should be moved up yet.
pdr23d381fd2017-04-25 21:06:316688 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f));
flackra283bed2016-10-31 14:49:426689 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6690 outer_scroll);
6691 EXPECT_VECTOR2DF_EQ(
6692 gfx::Vector2dF(0.f, 70.f),
6693 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6694
6695 // On hiding more of the toolbar the sticky element starts to stick.
pdr23d381fd2017-04-25 21:06:316696 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f));
flackra283bed2016-10-31 14:49:426697 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6698 outer_scroll);
6699
6700 // On hiding more the sticky element stops moving as it has reached its
6701 // limit.
6702 EXPECT_VECTOR2DF_EQ(
6703 gfx::Vector2dF(0.f, 60.f),
6704 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6705
pdr23d381fd2017-04-25 21:06:316706 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f));
flackra283bed2016-10-31 14:49:426707 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6708 outer_scroll);
6709
6710 EXPECT_VECTOR2DF_EQ(
6711 gfx::Vector2dF(0.f, 60.f),
6712 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackre310f292016-10-12 21:09:286713}
6714
flackr2215b4e2016-09-21 20:16:016715TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
6716 scoped_refptr<Layer> root = Layer::Create();
6717 scoped_refptr<Layer> container = Layer::Create();
6718 scoped_refptr<Layer> scroller = Layer::Create();
6719 scoped_refptr<Layer> sticky_pos = Layer::Create();
6720 root->AddChild(container);
6721 container->AddChild(scroller);
6722 scroller->AddChild(sticky_pos);
6723 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136724 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016725
6726 LayerStickyPositionConstraint sticky_position;
6727 sticky_position.is_sticky = true;
6728 sticky_position.is_anchored_left = true;
6729 sticky_position.is_anchored_right = true;
6730 sticky_position.left_offset = 10.f;
6731 sticky_position.right_offset = 10.f;
6732 sticky_position.scroll_container_relative_sticky_box_rect =
6733 gfx::Rect(145, 0, 10, 10);
6734 sticky_position.scroll_container_relative_containing_block_rect =
6735 gfx::Rect(100, 0, 100, 100);
6736 sticky_pos->SetStickyPositionConstraint(sticky_position);
6737
6738 root->SetBounds(gfx::Size(100, 100));
6739 container->SetBounds(gfx::Size(100, 100));
6740 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526741 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016742 sticky_pos->SetBounds(gfx::Size(10, 10));
6743 sticky_pos->SetPosition(gfx::PointF(145, 0));
6744
6745 ExecuteCalculateDrawProperties(root.get());
6746 host()->host_impl()->CreatePendingTree();
6747 host()->CommitAndCreatePendingTree();
6748 host()->host_impl()->ActivateSyncTree();
6749 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6750
6751 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6752 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6753 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6754
6755 // Initially the sticky element is moved the leftmost side of the container.
6756 ExecuteCalculateDrawProperties(root_impl);
6757 EXPECT_VECTOR2DF_EQ(
6758 gfx::Vector2dF(100.f, 0.f),
6759 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6760 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
6761 ExecuteCalculateDrawProperties(root_impl);
6762 EXPECT_VECTOR2DF_EQ(
6763 gfx::Vector2dF(95.f, 0.f),
6764 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6765
6766 // Once we get past the left side of the container it moves to be aligned 10px
6767 // up from the the right of the scroller.
6768 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
6769 ExecuteCalculateDrawProperties(root_impl);
6770 EXPECT_VECTOR2DF_EQ(
6771 gfx::Vector2dF(80.f, 0.f),
6772 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6773 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
6774 ExecuteCalculateDrawProperties(root_impl);
6775 EXPECT_VECTOR2DF_EQ(
6776 gfx::Vector2dF(80.f, 0.f),
6777 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6778
6779 // When we get to the sticky element's original position we stop sticking
6780 // to the right.
6781 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
6782 ExecuteCalculateDrawProperties(root_impl);
6783 EXPECT_VECTOR2DF_EQ(
6784 gfx::Vector2dF(50.f, 0.f),
6785 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6786 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
6787 ExecuteCalculateDrawProperties(root_impl);
6788 EXPECT_VECTOR2DF_EQ(
6789 gfx::Vector2dF(40.f, 0.f),
6790 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6791
6792 // The element starts sticking to the left once we scroll far enough.
6793 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
6794 ExecuteCalculateDrawProperties(root_impl);
6795 EXPECT_VECTOR2DF_EQ(
6796 gfx::Vector2dF(10.f, 0.f),
6797 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6798 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
6799 ExecuteCalculateDrawProperties(root_impl);
6800 EXPECT_VECTOR2DF_EQ(
6801 gfx::Vector2dF(10.f, 0.f),
6802 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6803
6804 // Finally it stops sticking when it hits the right side of the container.
6805 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
6806 ExecuteCalculateDrawProperties(root_impl);
6807 EXPECT_VECTOR2DF_EQ(
6808 gfx::Vector2dF(0.f, 0.f),
6809 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6810 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
6811 ExecuteCalculateDrawProperties(root_impl);
6812 EXPECT_VECTOR2DF_EQ(
6813 gfx::Vector2dF(-5.f, 0.f),
6814 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6815}
6816
6817// This test ensures that the compositor sticky position code correctly accounts
6818// for the element having been given a position from the main thread sticky
6819// position code.
6820TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
6821 scoped_refptr<Layer> root = Layer::Create();
6822 scoped_refptr<Layer> container = Layer::Create();
6823 scoped_refptr<Layer> scroller = Layer::Create();
6824 scoped_refptr<Layer> sticky_pos = Layer::Create();
6825 root->AddChild(container);
6826 container->AddChild(scroller);
6827 scroller->AddChild(sticky_pos);
6828 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136829 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016830
6831 LayerStickyPositionConstraint sticky_position;
6832 sticky_position.is_sticky = true;
6833 sticky_position.is_anchored_top = true;
6834 sticky_position.top_offset = 10.0f;
6835 sticky_position.scroll_container_relative_sticky_box_rect =
6836 gfx::Rect(10, 20, 10, 10);
6837 sticky_position.scroll_container_relative_containing_block_rect =
6838 gfx::Rect(0, 0, 50, 50);
6839 sticky_pos->SetStickyPositionConstraint(sticky_position);
6840
6841 root->SetBounds(gfx::Size(100, 100));
6842 container->SetBounds(gfx::Size(100, 100));
6843 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526844 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016845 sticky_pos->SetBounds(gfx::Size(10, 10));
6846 sticky_pos->SetPosition(gfx::PointF(10, 20));
6847
6848 ExecuteCalculateDrawProperties(root.get());
6849 host()->host_impl()->CreatePendingTree();
6850 host()->CommitAndCreatePendingTree();
6851 host()->host_impl()->ActivateSyncTree();
6852 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6853
6854 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6855 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6856 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6857
6858 ExecuteCalculateDrawProperties(root_impl);
6859 EXPECT_VECTOR2DF_EQ(
6860 gfx::Vector2dF(10.f, 20.f),
6861 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6862
6863 // Scroll less than sticking point, sticky element should move with scroll as
6864 // we haven't gotten to the initial sticky item location yet.
6865 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6866 ExecuteCalculateDrawProperties(root_impl);
6867 EXPECT_VECTOR2DF_EQ(
6868 gfx::Vector2dF(5.f, 15.f),
6869 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6870
6871 // Scroll past the sticking point, the Y coordinate should now be clamped.
6872 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6873 ExecuteCalculateDrawProperties(root_impl);
6874 EXPECT_VECTOR2DF_EQ(
6875 gfx::Vector2dF(-5.f, 10.f),
6876 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6877
6878 // Now the main thread commits the new position of the sticky element.
6879 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
yigu23b68f62017-06-13 12:35:076880 // Shift the layer by -offset_for_position_sticky.
6881 sticky_pos->SetPosition(gfx::PointF(10, 25) - gfx::Vector2dF(0, 5));
flackr2215b4e2016-09-21 20:16:016882 ExecuteCalculateDrawProperties(root.get());
6883 host()->host_impl()->CreatePendingTree();
6884 host()->CommitAndCreatePendingTree();
6885 host()->host_impl()->ActivateSyncTree();
6886 layer_tree_impl = host()->host_impl()->active_tree();
6887 root_impl = layer_tree_impl->LayerById(root->id());
6888 scroller_impl = layer_tree_impl->LayerById(scroller->id());
6889 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6890
6891 // The element should still be where it was before. We reset the delta to
6892 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
6893 // thread.
6894 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
6895 ExecuteCalculateDrawProperties(root_impl);
6896 EXPECT_VECTOR2DF_EQ(
6897 gfx::Vector2dF(-5.f, 10.f),
6898 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6899
6900 // And if we scroll a little further it remains there.
6901 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
6902 ExecuteCalculateDrawProperties(root_impl);
6903 EXPECT_VECTOR2DF_EQ(
6904 gfx::Vector2dF(-5.f, 10.f),
6905 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6906}
6907
flackr68e1c292016-10-11 16:34:426908// This tests the main thread updates with a composited sticky container. In
6909// this case the position received from main is relative to the container but
6910// the constraint rects are relative to the ancestor scroller.
6911TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) {
6912 scoped_refptr<Layer> root = Layer::Create();
6913 scoped_refptr<Layer> container = Layer::Create();
6914 scoped_refptr<Layer> scroller = Layer::Create();
6915 scoped_refptr<Layer> sticky_container = Layer::Create();
6916 scoped_refptr<Layer> sticky_pos = Layer::Create();
6917 root->AddChild(container);
6918 container->AddChild(scroller);
6919 scroller->AddChild(sticky_container);
6920 sticky_container->AddChild(sticky_pos);
6921 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136922 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr68e1c292016-10-11 16:34:426923
6924 LayerStickyPositionConstraint sticky_position;
6925 sticky_position.is_sticky = true;
6926 sticky_position.is_anchored_top = true;
6927 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:426928 sticky_position.scroll_container_relative_sticky_box_rect =
6929 gfx::Rect(20, 30, 10, 10);
6930 sticky_position.scroll_container_relative_containing_block_rect =
6931 gfx::Rect(20, 20, 30, 30);
6932 sticky_pos->SetStickyPositionConstraint(sticky_position);
6933
6934 root->SetBounds(gfx::Size(100, 100));
6935 container->SetBounds(gfx::Size(100, 100));
6936 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526937 scroller->SetScrollable(container->bounds());
flackr68e1c292016-10-11 16:34:426938 sticky_container->SetPosition(gfx::PointF(20, 20));
6939 sticky_container->SetBounds(gfx::Size(30, 30));
6940 sticky_pos->SetBounds(gfx::Size(10, 10));
6941 sticky_pos->SetPosition(gfx::PointF(0, 10));
6942
6943 ExecuteCalculateDrawProperties(root.get());
6944 host()->host_impl()->CreatePendingTree();
6945 host()->CommitAndCreatePendingTree();
6946 host()->host_impl()->ActivateSyncTree();
6947 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6948
6949 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6950 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6951 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6952
6953 ExecuteCalculateDrawProperties(root_impl);
6954 EXPECT_VECTOR2DF_EQ(
6955 gfx::Vector2dF(20.f, 30.f),
6956 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6957
6958 // Scroll less than sticking point, sticky element should move with scroll as
6959 // we haven't gotten to the initial sticky item location yet.
6960 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6961 ExecuteCalculateDrawProperties(root_impl);
6962 EXPECT_VECTOR2DF_EQ(
6963 gfx::Vector2dF(20.f, 25.f),
6964 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6965
6966 // Scroll past the sticking point, the Y coordinate should now be clamped.
6967 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
6968 ExecuteCalculateDrawProperties(root_impl);
6969 EXPECT_VECTOR2DF_EQ(
6970 gfx::Vector2dF(20.f, 10.f),
6971 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6972
6973 // Now the main thread commits the new position of the sticky element.
6974 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25));
yigu23b68f62017-06-13 12:35:076975 // Shift the layer by -offset_for_position_sticky.
6976 sticky_pos->SetPosition(gfx::PointF(0, 15) - gfx::Vector2dF(0, 5));
flackr68e1c292016-10-11 16:34:426977 ExecuteCalculateDrawProperties(root.get());
6978 host()->host_impl()->CreatePendingTree();
6979 host()->CommitAndCreatePendingTree();
6980 host()->host_impl()->ActivateSyncTree();
6981 layer_tree_impl = host()->host_impl()->active_tree();
6982 root_impl = layer_tree_impl->LayerById(root->id());
6983 scroller_impl = layer_tree_impl->LayerById(scroller->id());
6984 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6985
6986 // The element should still be where it was before. We reset the delta to
6987 // (0, 0) because we have synced a scroll offset of (0, 25) from the main
6988 // thread.
6989 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
6990 ExecuteCalculateDrawProperties(root_impl);
6991 EXPECT_VECTOR2DF_EQ(
6992 gfx::Vector2dF(20.f, 10.f),
6993 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6994
6995 // And if we scroll a little further it remains there.
6996 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6997 ExecuteCalculateDrawProperties(root_impl);
6998 EXPECT_VECTOR2DF_EQ(
6999 gfx::Vector2dF(20.f, 10.f),
7000 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7001
7002 // And hits the bottom of the container.
7003 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7004 ExecuteCalculateDrawProperties(root_impl);
7005 EXPECT_VECTOR2DF_EQ(
7006 gfx::Vector2dF(20.f, 5.f),
7007 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7008}
7009
flackr2215b4e2016-09-21 20:16:017010// A transform on a sticky element should not affect its sticky position.
7011TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7012 scoped_refptr<Layer> root = Layer::Create();
7013 scoped_refptr<Layer> container = Layer::Create();
7014 scoped_refptr<Layer> scroller = Layer::Create();
7015 scoped_refptr<Layer> sticky_pos = Layer::Create();
7016 root->AddChild(container);
7017 container->AddChild(scroller);
7018 scroller->AddChild(sticky_pos);
7019 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:137020 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:017021 gfx::Transform t;
7022 t.Scale(2, 2);
7023 sticky_pos->SetTransform(t);
7024
7025 LayerStickyPositionConstraint sticky_position;
7026 sticky_position.is_sticky = true;
7027 sticky_position.is_anchored_top = true;
7028 sticky_position.top_offset = 0.0f;
7029 sticky_position.scroll_container_relative_sticky_box_rect =
7030 gfx::Rect(0, 20, 10, 10);
7031 sticky_position.scroll_container_relative_containing_block_rect =
7032 gfx::Rect(0, 0, 50, 50);
7033 sticky_pos->SetStickyPositionConstraint(sticky_position);
7034
7035 root->SetBounds(gfx::Size(100, 100));
7036 container->SetBounds(gfx::Size(100, 100));
7037 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:527038 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:017039 sticky_pos->SetBounds(gfx::Size(10, 10));
7040 sticky_pos->SetPosition(gfx::PointF(0, 20));
7041
7042 ExecuteCalculateDrawProperties(root.get());
7043 host()->host_impl()->CreatePendingTree();
7044 host()->CommitAndCreatePendingTree();
7045 host()->host_impl()->ActivateSyncTree();
7046 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7047
7048 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7049 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7050 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7051
7052 ExecuteCalculateDrawProperties(root_impl);
7053 EXPECT_VECTOR2DF_EQ(
7054 gfx::Vector2dF(0.f, 20.f),
7055 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7056
7057 // Scroll less than sticking point, sticky element should move with scroll as
7058 // we haven't gotten to the initial sticky item location yet.
7059 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7060 ExecuteCalculateDrawProperties(root_impl);
7061 EXPECT_VECTOR2DF_EQ(
7062 gfx::Vector2dF(0.f, 5.f),
7063 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7064
7065 // Scroll past the sticking point, the box is positioned at the scroller
7066 // edge.
7067 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7068 ExecuteCalculateDrawProperties(root_impl);
7069 EXPECT_VECTOR2DF_EQ(
7070 gfx::Vector2dF(0.f, 0.f),
7071 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7072 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7073 ExecuteCalculateDrawProperties(root_impl);
7074 EXPECT_VECTOR2DF_EQ(
7075 gfx::Vector2dF(0.f, 0.f),
7076 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7077
7078 // Scroll past the end of the sticky container.
7079 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7080 ExecuteCalculateDrawProperties(root_impl);
7081 EXPECT_VECTOR2DF_EQ(
7082 gfx::Vector2dF(0.f, -10.f),
7083 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7084}
7085
7086// Tests that a transform does not affect the sticking points. The sticky
7087// element will however move relative to the viewport due to its transform.
7088TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7089 scoped_refptr<Layer> root = Layer::Create();
7090 scoped_refptr<Layer> container = Layer::Create();
7091 scoped_refptr<Layer> scroller = Layer::Create();
7092 scoped_refptr<Layer> sticky_container = Layer::Create();
7093 scoped_refptr<Layer> sticky_pos = Layer::Create();
7094 root->AddChild(container);
7095 container->AddChild(scroller);
7096 scroller->AddChild(sticky_container);
7097 sticky_container->AddChild(sticky_pos);
7098 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:137099 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:017100 gfx::Transform t;
7101 t.Scale(2, 2);
7102 sticky_container->SetTransform(t);
7103
7104 LayerStickyPositionConstraint sticky_position;
7105 sticky_position.is_sticky = true;
7106 sticky_position.is_anchored_top = true;
7107 sticky_position.top_offset = 0.0f;
7108 sticky_position.scroll_container_relative_sticky_box_rect =
7109 gfx::Rect(0, 20, 10, 10);
7110 sticky_position.scroll_container_relative_containing_block_rect =
7111 gfx::Rect(0, 0, 50, 50);
7112 sticky_pos->SetStickyPositionConstraint(sticky_position);
7113
7114 root->SetBounds(gfx::Size(100, 100));
7115 container->SetBounds(gfx::Size(100, 100));
7116 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:527117 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:017118 sticky_container->SetBounds(gfx::Size(50, 50));
7119 sticky_pos->SetBounds(gfx::Size(10, 10));
7120 sticky_pos->SetPosition(gfx::PointF(0, 20));
7121
7122 ExecuteCalculateDrawProperties(root.get());
7123 host()->host_impl()->CreatePendingTree();
7124 host()->CommitAndCreatePendingTree();
7125 host()->host_impl()->ActivateSyncTree();
7126 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7127
7128 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7129 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7130 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7131
7132 ExecuteCalculateDrawProperties(root_impl);
7133 EXPECT_VECTOR2DF_EQ(
7134 gfx::Vector2dF(0.f, 40.f),
7135 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7136
7137 // Scroll less than sticking point, sticky element should move with scroll as
7138 // we haven't gotten to the initial sticky item location yet.
7139 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7140 ExecuteCalculateDrawProperties(root_impl);
7141 EXPECT_VECTOR2DF_EQ(
7142 gfx::Vector2dF(0.f, 25.f),
7143 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7144
7145 // Scroll past the sticking point, the box is positioned at the scroller
7146 // edge but is also scaled by its container so it begins to move down.
7147 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7148 ExecuteCalculateDrawProperties(root_impl);
7149 EXPECT_VECTOR2DF_EQ(
7150 gfx::Vector2dF(0.f, 25.f),
7151 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7152 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7153 ExecuteCalculateDrawProperties(root_impl);
7154 EXPECT_VECTOR2DF_EQ(
7155 gfx::Vector2dF(0.f, 30.f),
7156 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7157
7158 // Scroll past the end of the sticky container.
7159 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7160 ExecuteCalculateDrawProperties(root_impl);
7161 EXPECT_VECTOR2DF_EQ(
7162 gfx::Vector2dF(0.f, 30.f),
7163 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7164}
7165
smcgruer29014ff2017-03-24 14:34:437166TEST_F(LayerTreeHostCommonTest, StickyPositionNested) {
7167 scoped_refptr<Layer> root = Layer::Create();
7168 scoped_refptr<Layer> container = Layer::Create();
7169 scoped_refptr<Layer> scroller = Layer::Create();
7170 scoped_refptr<Layer> outer_sticky = Layer::Create();
7171 scoped_refptr<Layer> inner_sticky = Layer::Create();
7172
7173 root->AddChild(container);
7174 container->AddChild(scroller);
7175 scroller->AddChild(outer_sticky);
7176 outer_sticky->AddChild(inner_sticky);
7177 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:137178 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
smcgruer29014ff2017-03-24 14:34:437179
7180 root->SetBounds(gfx::Size(100, 100));
7181 container->SetBounds(gfx::Size(100, 100));
7182 scroller->SetBounds(gfx::Size(100, 1000));
pdrbbfd8822017-06-27 22:44:527183 scroller->SetScrollable(container->bounds());
smcgruer29014ff2017-03-24 14:34:437184 outer_sticky->SetBounds(gfx::Size(10, 50));
7185 outer_sticky->SetPosition(gfx::PointF(0, 50));
7186 inner_sticky->SetBounds(gfx::Size(10, 10));
7187 inner_sticky->SetPosition(gfx::PointF(0, 0));
7188
7189 LayerStickyPositionConstraint outer_sticky_pos;
7190 outer_sticky_pos.is_sticky = true;
7191 outer_sticky_pos.is_anchored_top = true;
7192 outer_sticky_pos.top_offset = 10.0f;
smcgruer29014ff2017-03-24 14:34:437193 outer_sticky_pos.scroll_container_relative_sticky_box_rect =
7194 gfx::Rect(0, 50, 10, 50);
7195 outer_sticky_pos.scroll_container_relative_containing_block_rect =
7196 gfx::Rect(0, 0, 50, 400);
7197 outer_sticky->SetStickyPositionConstraint(outer_sticky_pos);
7198
7199 LayerStickyPositionConstraint inner_sticky_pos;
7200 inner_sticky_pos.is_sticky = true;
7201 inner_sticky_pos.is_anchored_top = true;
7202 inner_sticky_pos.top_offset = 25.0f;
smcgruer29014ff2017-03-24 14:34:437203 inner_sticky_pos.scroll_container_relative_sticky_box_rect =
7204 gfx::Rect(0, 50, 10, 10);
7205 inner_sticky_pos.scroll_container_relative_containing_block_rect =
7206 gfx::Rect(0, 50, 10, 50);
7207 inner_sticky_pos.nearest_layer_shifting_containing_block = outer_sticky->id();
7208 inner_sticky->SetStickyPositionConstraint(inner_sticky_pos);
7209
7210 ExecuteCalculateDrawProperties(root.get());
7211 host()->host_impl()->CreatePendingTree();
7212 host()->CommitAndCreatePendingTree();
7213 host()->host_impl()->ActivateSyncTree();
7214 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7215
7216 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7217 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7218 LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id());
7219 LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id());
7220
7221 ExecuteCalculateDrawProperties(root_impl);
7222
7223 // Before any scrolling is done, the sticky elements should still be at their
7224 // original positions.
7225 EXPECT_VECTOR2DF_EQ(
7226 gfx::Vector2dF(0.f, 50.f),
7227 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7228 EXPECT_VECTOR2DF_EQ(
7229 gfx::Vector2dF(0.f, 50.f),
7230 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7231
7232 // Scroll less than the sticking point. Both sticky elements should move with
7233 // scroll as we haven't gotten to the sticky item locations yet.
7234 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7235 ExecuteCalculateDrawProperties(root_impl);
7236 EXPECT_VECTOR2DF_EQ(
7237 gfx::Vector2dF(0.f, 45.f),
7238 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7239 EXPECT_VECTOR2DF_EQ(
7240 gfx::Vector2dF(0.f, 45.f),
7241 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7242
7243 // Scroll such that the inner sticky should stick, but the outer one should
7244 // keep going as it hasn't reached its position yet.
7245 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7246 ExecuteCalculateDrawProperties(root_impl);
7247 EXPECT_VECTOR2DF_EQ(
7248 gfx::Vector2dF(0.f, 20.f),
7249 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7250 EXPECT_VECTOR2DF_EQ(
7251 gfx::Vector2dF(0.f, 25.f),
7252 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7253
7254 // Keep going, both should stick.
7255 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f));
7256 ExecuteCalculateDrawProperties(root_impl);
7257 EXPECT_VECTOR2DF_EQ(
7258 gfx::Vector2dF(0.f, 10.f),
7259 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7260 EXPECT_VECTOR2DF_EQ(
7261 gfx::Vector2dF(0.f, 25.f),
7262 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7263}
7264
jaydasikaaf1582f2016-08-10 18:39:387265TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7266 scoped_refptr<Layer> root = Layer::Create();
7267 scoped_refptr<Layer> container = Layer::Create();
7268 scoped_refptr<Layer> scroller = Layer::Create();
7269 scoped_refptr<Layer> fixed_pos = Layer::Create();
7270
7271 scroller->SetIsContainerForFixedPositionLayers(true);
7272 root->AddChild(container);
7273 container->AddChild(scroller);
7274 scroller->AddChild(fixed_pos);
7275 host()->SetRootLayer(root);
7276
7277 LayerPositionConstraint fixed_position;
7278 fixed_position.set_is_fixed_position(true);
pdr54d038192017-06-08 22:44:137279 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
jaydasikaaf1582f2016-08-10 18:39:387280 fixed_pos->SetPositionConstraint(fixed_position);
7281
7282 root->SetBounds(gfx::Size(50, 50));
7283 container->SetBounds(gfx::Size(50, 50));
7284 scroller->SetBounds(gfx::Size(50, 50));
pdrbbfd8822017-06-27 22:44:527285 scroller->SetScrollable(container->bounds());
jaydasikaaf1582f2016-08-10 18:39:387286 fixed_pos->SetBounds(gfx::Size(50, 50));
7287
7288 gfx::Transform rotate;
7289 rotate.RotateAboutXAxis(20);
7290 container->SetTransform(rotate);
7291
7292 ExecuteCalculateDrawProperties(root.get());
khushalsagarb69ba9452017-01-27 22:20:077293 TransformTree& tree =
7294 root->layer_tree_host()->property_trees()->transform_tree;
jaydasikaaf1582f2016-08-10 18:39:387295 gfx::Transform transform;
7296 tree.ComputeTranslation(fixed_pos->transform_tree_index(),
7297 container->transform_tree_index(), &transform);
7298 EXPECT_TRUE(transform.IsIdentity());
7299}
7300
sunxd8a9a60982016-07-29 18:46:567301TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
7302 // This test verifies that a fixed pos child of a scrolling layer doesn't get
7303 // snapped to integer coordinates.
7304 //
7305 // + root
7306 // + container
7307 // + scroller
7308 // + fixed_pos
7309 //
7310 scoped_refptr<Layer> root = Layer::Create();
7311 scoped_refptr<Layer> container = Layer::Create();
7312 scoped_refptr<Layer> scroller = Layer::Create();
7313 scoped_refptr<Layer> fixed_pos = Layer::Create();
7314
7315 scroller->SetIsContainerForFixedPositionLayers(true);
7316
7317 root->AddChild(container);
7318 container->AddChild(scroller);
7319 scroller->AddChild(fixed_pos);
7320 host()->SetRootLayer(root);
7321
7322 LayerPositionConstraint fixed_position;
7323 fixed_position.set_is_fixed_position(true);
pdr54d038192017-06-08 22:44:137324 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
sunxd8a9a60982016-07-29 18:46:567325 fixed_pos->SetPositionConstraint(fixed_position);
7326
7327 root->SetBounds(gfx::Size(50, 50));
7328 container->SetBounds(gfx::Size(50, 50));
7329 scroller->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:527330 scroller->SetScrollable(container->bounds());
sunxd8a9a60982016-07-29 18:46:567331 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7332 fixed_pos->SetBounds(gfx::Size(10, 10));
7333
7334 ExecuteCalculateDrawProperties(root.get());
7335
7336 host()->host_impl()->CreatePendingTree();
7337 host()->CommitAndCreatePendingTree();
7338 host()->host_impl()->ActivateSyncTree();
7339 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7340
7341 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7342 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7343 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
7344 gfx::Vector2dF scroll_delta(5.f, 9.f);
7345 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7346
7347 ExecuteCalculateDrawProperties(root_impl);
7348
7349 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7350 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7351 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7352
7353 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
7354 10.3f);
7355 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
7356 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
7357}
7358
[email protected]1c3626e2014-04-09 17:49:227359class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7360 public:
danakj60bc3bc2016-04-09 00:24:487361 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227362 LayerTreeImpl* tree_impl,
7363 int id) {
danakj60bc3bc2016-04-09 00:24:487364 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227365 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7366 }
7367
dcheng716bedf2014-10-21 09:51:087368 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227369
[email protected]1c3626e2014-04-09 17:49:227370 private:
7371 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7372 int id)
[email protected]a57cb8b12014-06-13 18:15:377373 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227374 SetDrawsContent(true);
7375 }
[email protected]1c3626e2014-04-09 17:49:227376};
7377
7378TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167379 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567380 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017381 LayerTreeSettings settings = host()->GetSettings();
ajumab4a846f22015-08-24 19:13:447382 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167383 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227384 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:487385 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227386 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487387 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227388 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487389 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227390 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487391 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227392 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7393
7394 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7395 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7396 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097397 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227398
danakjf78fb272016-07-26 19:06:157399 grand_parent->SetBounds(gfx::Size(1, 2));
7400 parent->SetBounds(gfx::Size(1, 2));
7401 child->SetBounds(gfx::Size(1, 2));
7402 grand_child->SetBounds(gfx::Size(1, 2));
7403
jaydasika89f7b5a2016-06-22 02:08:397404 child->test_properties()->AddChild(std::move(grand_child));
7405 parent->test_properties()->AddChild(std::move(child));
7406 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597407 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:057408
jaydasika2411692c2016-03-23 01:56:097409 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227410
7411 // No layers have animations.
sunxdf468675e2016-06-30 23:56:187412 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7413 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7414 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7415 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227416
sunxdf468675e2016-06-30 23:56:187417 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7418 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7419 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7420 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037421
[email protected]1c3626e2014-04-09 17:49:227422 TransformOperations translation;
7423 translation.AppendTranslate(1.f, 2.f, 3.f);
7424
loyso968163c92016-01-04 23:18:487425 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587426 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7427 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487428
vollickef2ae922016-06-29 17:54:277429 host_impl.active_tree()->SetElementIdsForTesting();
loysodb006882016-09-14 00:31:517430
7431 scoped_refptr<AnimationPlayer> grand_parent_player =
7432 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7433 timeline->AttachPlayer(grand_parent_player);
7434 grand_parent_player->AttachElement(grand_parent_raw->element_id());
7435
7436 scoped_refptr<AnimationPlayer> parent_player =
7437 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7438 timeline->AttachPlayer(parent_player);
7439 parent_player->AttachElement(parent_raw->element_id());
7440
7441 scoped_refptr<AnimationPlayer> child_player =
7442 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7443 timeline->AttachPlayer(child_player);
7444 child_player->AttachElement(child_raw->element_id());
7445
7446 scoped_refptr<AnimationPlayer> grand_child_player =
7447 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7448 timeline->AttachPlayer(grand_child_player);
7449 grand_child_player->AttachElement(grand_child_raw->element_id());
7450
7451 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7452 translation);
[email protected]1c3626e2014-04-09 17:49:227453
7454 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187455 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7456 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7457 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7458 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227459
sunxdf468675e2016-06-30 23:56:187460 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7461 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7462 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7463 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037464
[email protected]1c3626e2014-04-09 17:49:227465 TransformOperations scale;
7466 scale.AppendScale(5.f, 4.f, 3.f);
7467
loysodb006882016-09-14 00:31:517468 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7469 scale);
ajumacaaa9b32015-08-04 15:55:297470 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097471 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227472
7473 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:187474 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7475 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7476 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
7477 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227478
sunxdf468675e2016-06-30 23:56:187479 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7480 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7481 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
7482 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037483
loysodb006882016-09-14 00:31:517484 AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0,
7485 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097486 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7487 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227488
7489 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187490 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7491 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:227492 // We don't support combining animated scales from two nodes; 0.f means
7493 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:187494 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7495 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227496
sunxdf468675e2016-06-30 23:56:187497 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7498 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
7499 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7500 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037501
loysodb006882016-09-14 00:31:517502 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7503 scale);
ajumacaaa9b32015-08-04 15:55:297504 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097505 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227506
7507 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187508 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7509 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7510 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7511 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227512
sunxdf468675e2016-06-30 23:56:187513 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7514 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7515 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7516 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037517
loysodb006882016-09-14 00:31:517518 grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7519 parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7520 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
[email protected]1c3626e2014-04-09 17:49:227521
7522 TransformOperations perspective;
7523 perspective.AppendPerspective(10.f);
7524
loysodb006882016-09-14 00:31:517525 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7526 perspective);
ajumab4a846f22015-08-24 19:13:447527 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097528 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227529
7530 // |child| has a scale-affecting animation but computing the maximum of this
7531 // animation is not supported.
sunxdf468675e2016-06-30 23:56:187532 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7533 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7534 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7535 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227536
sunxdf468675e2016-06-30 23:56:187537 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7538 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7539 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7540 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037541
loysobb507792016-10-04 05:31:027542 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7543
[email protected]1c3626e2014-04-09 17:49:227544 gfx::Transform scale_matrix;
7545 scale_matrix.Scale(1.f, 2.f);
jaydasika10d43fc2016-08-18 04:06:047546 grand_parent_raw->test_properties()->transform = scale_matrix;
7547 parent_raw->test_properties()->transform = scale_matrix;
jaydasika2411692c2016-03-23 01:56:097548 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487549
loysodb006882016-09-14 00:31:517550 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7551 scale);
jaydasika2411692c2016-03-23 01:56:097552 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227553
7554 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7555 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:187556 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7557 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7558 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
7559 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227560
sunxdf468675e2016-06-30 23:56:187561 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7562 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7563 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
7564 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037565
[email protected]1c3626e2014-04-09 17:49:227566 gfx::Transform perspective_matrix;
7567 perspective_matrix.ApplyPerspectiveDepth(2.f);
jaydasika10d43fc2016-08-18 04:06:047568 child_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097569 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7570 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227571
7572 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187573 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7574 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7575 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7576 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227577
sunxdf468675e2016-06-30 23:56:187578 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7579 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7580 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7581 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037582
jaydasika10d43fc2016-08-18 04:06:047583 parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097584 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7585 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227586
7587 // |parent| and |child| have transforms that are neither translations nor
7588 // scales.
sunxdf468675e2016-06-30 23:56:187589 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7590 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7591 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7592 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227593
sunxdf468675e2016-06-30 23:56:187594 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7595 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7596 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7597 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037598
jaydasika10d43fc2016-08-18 04:06:047599 parent_raw->test_properties()->transform = gfx::Transform();
7600 child_raw->test_properties()->transform = gfx::Transform();
7601 grand_parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097602 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227603
jaydasika2411692c2016-03-23 01:56:097604 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227605
7606 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187607 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7608 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7609 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7610 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037611
sunxdf468675e2016-06-30 23:56:187612 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7613 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7614 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7615 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227616}
7617
ajuma956219582017-04-04 19:58:147618static void GatherDrawnLayers(LayerTreeImpl* tree_impl,
[email protected]390bb1ff2014-05-09 17:14:407619 std::set<LayerImpl*>* drawn_layers) {
ajuma956219582017-04-04 19:58:147620 for (EffectTreeLayerListIterator it(tree_impl);
7621 it.state() != EffectTreeLayerListIterator::State::END; ++it) {
7622 if (it.state() == EffectTreeLayerListIterator::State::LAYER)
7623 drawn_layers->insert(it.current_layer());
[email protected]390bb1ff2014-05-09 17:14:407624
ajuma956219582017-04-04 19:58:147625 if (it.state() != EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE)
[email protected]390bb1ff2014-05-09 17:14:407626 continue;
7627
ajuma956219582017-04-04 19:58:147628 if (it.current_render_surface()->MaskLayer())
7629 drawn_layers->insert(it.current_render_surface()->MaskLayer());
[email protected]390bb1ff2014-05-09 17:14:407630 }
7631}
7632
7633TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167634 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567635 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:227636 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407637
danakj60bc3bc2016-04-09 00:24:487638 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407639 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487640 std::unique_ptr<LayerImpl> parent =
7641 LayerImpl::Create(host_impl.active_tree(), 3);
7642 std::unique_ptr<LayerImpl> child =
7643 LayerImpl::Create(host_impl.active_tree(), 5);
7644 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407645 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487646 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407647 LayerImpl::Create(host_impl.active_tree(), 9);
7648
7649 LayerImpl* grand_parent_raw = grand_parent.get();
7650 LayerImpl* parent_raw = parent.get();
7651 LayerImpl* child_raw = child.get();
7652 LayerImpl* grand_child1_raw = grand_child1.get();
7653 LayerImpl* grand_child2_raw = grand_child2.get();
7654
danakjf78fb272016-07-26 19:06:157655 grand_parent->SetBounds(gfx::Size(1, 2));
7656 parent->SetBounds(gfx::Size(1, 2));
7657 child->SetBounds(gfx::Size(1, 2));
7658 grand_child1->SetBounds(gfx::Size(1, 2));
7659 grand_child2->SetBounds(gfx::Size(1, 2));
7660
jaydasika89f7b5a2016-06-22 02:08:397661 child->test_properties()->AddChild(std::move(grand_child1));
7662 child->test_properties()->AddChild(std::move(grand_child2));
7663 parent->test_properties()->AddChild(std::move(child));
7664 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597665 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407666
[email protected]390bb1ff2014-05-09 17:14:407667 // Start with nothing being drawn.
7668 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407669
ajuma651848a2017-05-01 21:23:457670 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7671 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7672 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7673 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7674 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407675
7676 std::set<LayerImpl*> expected;
7677 std::set<LayerImpl*> actual;
ajuma956219582017-04-04 19:58:147678 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407679 EXPECT_EQ(expected, actual);
7680
7681 // If we force render surface, but none of the layers are in the layer list,
7682 // then this layer should not appear in RSLL.
ajuma35b24f62017-01-27 21:23:097683 grand_child1_raw->test_properties()->force_render_surface = true;
jaydasikaebf9e4ea2015-08-14 21:29:127684 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407685
7686 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407687
ajuma651848a2017-05-01 21:23:457688 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7689 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7690 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7691 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7692 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407693
7694 expected.clear();
7695 actual.clear();
ajuma956219582017-04-04 19:58:147696 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407697 EXPECT_EQ(expected, actual);
7698
7699 // However, if we say that this layer also draws content, it will appear in
7700 // RSLL.
7701 grand_child1_raw->SetDrawsContent(true);
7702
7703 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407704
ajuma651848a2017-05-01 21:23:457705 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7706 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7707 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7708 EXPECT_TRUE(grand_child1_raw->contributes_to_drawn_render_surface());
7709 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407710
7711 expected.clear();
7712 expected.insert(grand_child1_raw);
7713
7714 actual.clear();
ajuma956219582017-04-04 19:58:147715 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407716 EXPECT_EQ(expected, actual);
7717
7718 // Now child is forced to have a render surface, and one if its children draws
7719 // content.
7720 grand_child1_raw->SetDrawsContent(false);
ajuma35b24f62017-01-27 21:23:097721 grand_child1_raw->test_properties()->force_render_surface = false;
jaydasikaebf9e4ea2015-08-14 21:29:127722 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
ajuma35b24f62017-01-27 21:23:097723 child_raw->test_properties()->force_render_surface = true;
[email protected]390bb1ff2014-05-09 17:14:407724 grand_child2_raw->SetDrawsContent(true);
7725
7726 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407727
ajuma651848a2017-05-01 21:23:457728 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7729 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7730 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7731 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7732 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407733
7734 expected.clear();
7735 expected.insert(grand_child2_raw);
7736
7737 actual.clear();
ajuma956219582017-04-04 19:58:147738 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407739 EXPECT_EQ(expected, actual);
7740
7741 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:507742 child_raw->test_properties()->SetMaskLayer(
7743 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047744 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407745
7746 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407747
ajuma651848a2017-05-01 21:23:457748 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7749 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7750 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507751 EXPECT_TRUE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457752 ->mask_layer->contributes_to_drawn_render_surface());
7753 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7754 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407755
7756 expected.clear();
7757 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507758 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407759
7760 expected.clear();
7761 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507762 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407763
7764 actual.clear();
ajuma956219582017-04-04 19:58:147765 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407766 EXPECT_EQ(expected, actual);
7767
[email protected]390bb1ff2014-05-09 17:14:407768 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407769
ajuma651848a2017-05-01 21:23:457770 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7771 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7772 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507773 EXPECT_TRUE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457774 ->mask_layer->contributes_to_drawn_render_surface());
7775 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7776 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407777
7778 expected.clear();
7779 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507780 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407781
7782 actual.clear();
ajuma956219582017-04-04 19:58:147783 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407784 EXPECT_EQ(expected, actual);
7785
ajuma1d4026a32016-06-14 13:18:507786 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407787
7788 // With nothing drawing, we should have no layers.
7789 grand_child2_raw->SetDrawsContent(false);
7790
7791 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407792
ajuma651848a2017-05-01 21:23:457793 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7794 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7795 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507796 EXPECT_FALSE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457797 ->mask_layer->contributes_to_drawn_render_surface());
7798 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7799 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407800
7801 expected.clear();
7802 actual.clear();
ajuma956219582017-04-04 19:58:147803 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407804 EXPECT_EQ(expected, actual);
7805
7806 // Child itself draws means that we should have the child and the mask in the
7807 // list.
7808 child_raw->SetDrawsContent(true);
7809
7810 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407811
ajuma651848a2017-05-01 21:23:457812 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7813 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7814 EXPECT_TRUE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507815 EXPECT_TRUE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457816 ->mask_layer->contributes_to_drawn_render_surface());
7817 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7818 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407819
7820 expected.clear();
7821 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:507822 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407823 actual.clear();
ajuma956219582017-04-04 19:58:147824 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407825 EXPECT_EQ(expected, actual);
7826
ajuma1d4026a32016-06-14 13:18:507827 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:047828 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407829
7830 // Now everyone's a member!
7831 grand_parent_raw->SetDrawsContent(true);
7832 parent_raw->SetDrawsContent(true);
7833 child_raw->SetDrawsContent(true);
7834 grand_child1_raw->SetDrawsContent(true);
7835 grand_child2_raw->SetDrawsContent(true);
7836
7837 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407838
ajuma651848a2017-05-01 21:23:457839 EXPECT_TRUE(grand_parent_raw->contributes_to_drawn_render_surface());
7840 EXPECT_TRUE(parent_raw->contributes_to_drawn_render_surface());
7841 EXPECT_TRUE(child_raw->contributes_to_drawn_render_surface());
7842 EXPECT_TRUE(grand_child1_raw->contributes_to_drawn_render_surface());
7843 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407844
7845 expected.clear();
7846 expected.insert(grand_parent_raw);
7847 expected.insert(parent_raw);
7848 expected.insert(child_raw);
7849 expected.insert(grand_child1_raw);
7850 expected.insert(grand_child2_raw);
7851
7852 actual.clear();
ajuma956219582017-04-04 19:58:147853 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407854 EXPECT_EQ(expected, actual);
7855}
[email protected]18e69652014-06-13 12:50:587856
7857TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167858 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567859 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017860 LayerTreeSettings settings = host()->GetSettings();
enne637715732015-07-07 02:05:267861 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167862 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227863 &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587864
danakj60bc3bc2016-04-09 00:24:487865 std::unique_ptr<LayerImpl> root =
7866 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:587867 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:487868 std::unique_ptr<LayerImpl> child1 =
7869 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:587870 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:487871 std::unique_ptr<LayerImpl> child2 =
7872 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:587873 LayerImpl* child2_layer = child2.get();
7874
danakjf78fb272016-07-26 19:06:157875 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:587876 scale_transform_child1.Scale(2, 3);
7877 scale_transform_child2.Scale(4, 5);
7878
danakjf78fb272016-07-26 19:06:157879 root->SetBounds(gfx::Size(1, 1));
7880 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:047881 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:157882 child1_layer->SetBounds(gfx::Size(1, 1));
7883 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587884
ajuma1d4026a32016-06-14 13:18:507885 child1_layer->test_properties()->SetMaskLayer(
7886 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:587887
danakjf78fb272016-07-26 19:06:157888 root->test_properties()->AddChild(std::move(child1));
7889 root->test_properties()->AddChild(std::move(child2));
7890 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7891 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:587892
7893 ExecuteCalculateDrawProperties(root_layer);
7894
7895 TransformOperations scale;
7896 scale.AppendScale(5.f, 8.f, 3.f);
7897
loyso9556c732016-03-11 07:54:587898 scoped_refptr<AnimationTimeline> timeline =
7899 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7900 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487901
jaydasika10d43fc2016-08-18 04:06:047902 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:157903 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:287904 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:277905 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
7906 1.0, TransformOperations(), scale);
7907
jaydasika2411692c2016-03-23 01:56:097908 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587909 ExecuteCalculateDrawProperties(root_layer);
7910
enne637715732015-07-07 02:05:267911 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7912 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:507913 EXPECT_FLOAT_EQ(
7914 3.f,
7915 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267916 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587917
sunxdf468675e2016-06-30 23:56:187918 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7919 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7920 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587921
[email protected]18e69652014-06-13 12:50:587922 // Changing page-scale would affect ideal_contents_scale and
7923 // maximum_animation_contents_scale.
7924
7925 float page_scale_factor = 3.f;
7926 float device_scale_factor = 1.0f;
ajumab784ef42017-04-28 23:01:527927 RenderSurfaceList render_surface_list;
[email protected]18e69652014-06-13 12:50:587928 gfx::Size device_viewport_size =
7929 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7930 root_layer->bounds().height() * device_scale_factor);
7931 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:527932 root_layer, device_viewport_size, &render_surface_list);
[email protected]18e69652014-06-13 12:50:587933
7934 inputs.page_scale_factor = page_scale_factor;
7935 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117936 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:577937 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587938
enne637715732015-07-07 02:05:267939 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7940 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587941 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267942 9.f,
ajuma1d4026a32016-06-14 13:18:507943 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267944 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587945
sunxdf468675e2016-06-30 23:56:187946 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7947 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7948 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587949
[email protected]18e69652014-06-13 12:50:587950 // Changing device-scale would affect ideal_contents_scale and
7951 // maximum_animation_contents_scale.
7952
7953 device_scale_factor = 4.0f;
7954 inputs.device_scale_factor = device_scale_factor;
7955 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097956 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:577957 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587958
enne637715732015-07-07 02:05:267959 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7960 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587961 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267962 36.f,
ajuma1d4026a32016-06-14 13:18:507963 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267964 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587965
sunxdf468675e2016-06-30 23:56:187966 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7967 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7968 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
7969}
7970
7971TEST_F(LayerTreeHostCommonTest, AnimationScales) {
7972 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:187973 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017974 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:187975 settings.layer_transforms_should_scale_layer_contents = true;
7976 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227977 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:187978
7979 std::unique_ptr<LayerImpl> root =
7980 LayerImpl::Create(host_impl.active_tree(), 1);
7981 LayerImpl* root_layer = root.get();
7982 std::unique_ptr<LayerImpl> child1 =
7983 LayerImpl::Create(host_impl.active_tree(), 2);
7984 LayerImpl* child1_layer = child1.get();
7985 std::unique_ptr<LayerImpl> child2 =
7986 LayerImpl::Create(host_impl.active_tree(), 3);
7987 LayerImpl* child2_layer = child2.get();
7988
7989 root->test_properties()->AddChild(std::move(child1));
7990 child1_layer->test_properties()->AddChild(std::move(child2));
7991 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7992
7993 host_impl.active_tree()->SetElementIdsForTesting();
7994
danakjf78fb272016-07-26 19:06:157995 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:187996 scale_transform_child1.Scale(2, 3);
7997 scale_transform_child2.Scale(4, 5);
7998
danakjf78fb272016-07-26 19:06:157999 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048000 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158001 child1_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048002 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158003 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:188004
8005 TransformOperations scale;
8006 scale.AppendScale(5.f, 8.f, 3.f);
8007
8008 scoped_refptr<AnimationTimeline> timeline =
8009 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8010 host_impl.animation_host()->AddAnimationTimeline(timeline);
8011
8012 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8013 1.0, TransformOperations(), scale);
8014
sunxdf468675e2016-06-30 23:56:188015 // Correctly computes animation scale when rebuilding property trees.
8016 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8017 ExecuteCalculateDrawProperties(root_layer);
8018
8019 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8020 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8021 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
8022
8023 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8024 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
8025 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
8026
8027 // Correctly updates animation scale when layer property changes.
jaydasika10d43fc2016-08-18 04:06:048028 child1_layer->test_properties()->transform = gfx::Transform();
weiliangcea09f3372017-03-29 16:43:248029 root_layer->layer_tree_impl()->SetTransformMutated(child1_layer->element_id(),
8030 gfx::Transform());
sunxdf468675e2016-06-30 23:56:188031 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
8032 ExecuteCalculateDrawProperties(root_layer);
8033 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
8034 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
8035
8036 // Do not update animation scale if already updated.
8037 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
8038 child2_layer->transform_tree_index(), 100.f, 100.f);
8039 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
8040 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
8041}
8042
8043TEST_F(LayerTreeHostCommonTest,
8044 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
8045 // Returns empty scale if layer_transforms_should_scale_layer_contents is
8046 // false.
8047 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188048 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018049 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188050 settings.layer_transforms_should_scale_layer_contents = false;
8051 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228052 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188053
8054 std::unique_ptr<LayerImpl> root =
8055 LayerImpl::Create(host_impl.active_tree(), 1);
8056 LayerImpl* root_layer = root.get();
8057 std::unique_ptr<LayerImpl> child =
8058 LayerImpl::Create(host_impl.active_tree(), 2);
8059 LayerImpl* child_layer = child.get();
8060
8061 root->test_properties()->AddChild(std::move(child));
8062 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8063
8064 host_impl.active_tree()->SetElementIdsForTesting();
8065
danakjf78fb272016-07-26 19:06:158066 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:188067 scale_transform_child.Scale(4, 5);
8068
danakjf78fb272016-07-26 19:06:158069 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048070 child_layer->test_properties()->transform = scale_transform_child;
danakjf78fb272016-07-26 19:06:158071 child_layer->SetBounds(gfx::Size(1, 1));
8072
sunxdf468675e2016-06-30 23:56:188073 TransformOperations scale;
8074 scale.AppendScale(5.f, 8.f, 3.f);
8075
8076 scoped_refptr<AnimationTimeline> timeline =
8077 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8078 host_impl.animation_host()->AddAnimationTimeline(timeline);
8079
8080 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
8081 1.0, TransformOperations(), scale);
8082
sunxdf468675e2016-06-30 23:56:188083 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8084 ExecuteCalculateDrawProperties(root_layer);
8085
8086 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8087 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
8088
8089 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8090 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:588091}
8092
danakjf6069db2014-09-13 00:46:478093TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598094 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148095 LayerImpl* clip = AddChild<LayerImpl>(root);
8096 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:478097
danakjf78fb272016-07-26 19:06:158098 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:148099 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158100 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:478101 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158102 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:148103 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158104 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:478105
8106 gfx::Size device_viewport_size(768, 582);
ajumab784ef42017-04-28 23:01:528107 RenderSurfaceList render_surface_list_impl;
jaydasika6f972de2016-04-07 16:16:148108 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:528109 root, device_viewport_size, gfx::Transform(), &render_surface_list_impl);
danakjf6069db2014-09-13 00:46:478110 inputs.device_scale_factor = 2.f;
8111 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:298112 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:578113 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478114
8115 // Layers in the root render surface have their visible content rect clipped
8116 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148117 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478118
8119 // Layers drawing to a child render surface should still have their visible
8120 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148121 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478122}
8123
pdr23d381fd2017-04-25 21:06:318124TEST_F(LayerTreeHostCommonTest, ViewportBoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168125 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568126 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228127 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
timav599f4359d2014-12-05 00:12:228128
8129 // Set two layers: the root layer clips it's child,
8130 // the child draws its content.
8131
8132 gfx::Size root_size = gfx::Size(300, 500);
8133
8134 // Sublayer should be bigger than the root enlarged by bounds_delta.
8135 gfx::Size sublayer_size = gfx::Size(300, 1000);
8136
mdjones2ee41afd2016-10-27 16:50:208137 // Device viewport accomidated the root and the browser controls.
timav599f4359d2014-12-05 00:12:228138 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:228139
miletus8bd08a622015-06-16 18:44:528140 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:598141 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:228142 LayerImpl::Create(host_impl.active_tree(), 1));
8143
jaydasikabf1875a2016-06-28 03:39:598144 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:158145 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:228146 root->SetMasksToBounds(true);
8147
pdr23d381fd2017-04-25 21:06:318148 // Make root the inner viewport scroll layer. This ensures the later call to
8149 // |SetViewportBoundsDelta| will be on a viewport layer.
pdr53abb452017-05-19 01:59:428150 LayerTreeImpl::ViewportLayerIds viewport_ids;
8151 viewport_ids.inner_viewport_scroll = root->id();
8152 host_impl.active_tree()->SetViewportLayersFromIds(viewport_ids);
pdr23d381fd2017-04-25 21:06:318153
jaydasika89f7b5a2016-06-22 02:08:398154 root->test_properties()->AddChild(
8155 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:228156
jaydasikafc66cfb2016-06-10 04:34:228157 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:158158 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:228159 sublayer->SetDrawsContent(true);
8160
danakj74af409e2016-07-01 00:41:488161 host_impl.active_tree()->BuildPropertyTreesForTesting();
8162
ajumab784ef42017-04-28 23:01:528163 RenderSurfaceList render_surface_list;
timav599f4359d2014-12-05 00:12:228164 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:528165 root, device_viewport_size, &render_surface_list);
timav599f4359d2014-12-05 00:12:228166
sunxdb365de02016-04-28 20:32:578167 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438168 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228169
pdr23d381fd2017-04-25 21:06:318170 root->SetViewportBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578171 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228172
8173 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8174 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438175 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228176}
8177
pdr23d381fd2017-04-25 21:06:318178TEST_F(LayerTreeHostCommonTest, NodesAffectedByViewportBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318179 scoped_refptr<Layer> root = Layer::Create();
Philip Rogersd9e5ffd2017-06-16 00:10:538180 scoped_refptr<Layer> page_scale_layer = Layer::Create();
loyso0940d412016-03-14 01:30:318181 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8182 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8183 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8184 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298185
8186 root->AddChild(inner_viewport_container_layer);
Philip Rogersd9e5ffd2017-06-16 00:10:538187 inner_viewport_container_layer->AddChild(page_scale_layer);
8188 page_scale_layer->AddChild(inner_viewport_scroll_layer);
ajumadd2802e72015-06-30 20:28:298189 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8190 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8191
ajumadd2802e72015-06-30 20:28:298192 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8193 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8194
8195 host()->SetRootLayer(root);
pdr5200a052017-05-21 22:50:588196 LayerTreeHost::ViewportLayers viewport_layers;
Philip Rogersd9e5ffd2017-06-16 00:10:538197 viewport_layers.page_scale = page_scale_layer;
pdr5200a052017-05-21 22:50:588198 viewport_layers.inner_viewport_container = inner_viewport_container_layer;
8199 viewport_layers.outer_viewport_container = outer_viewport_container_layer;
8200 viewport_layers.inner_viewport_scroll = inner_viewport_scroll_layer;
8201 viewport_layers.outer_viewport_scroll = outer_viewport_scroll_layer;
8202 host()->RegisterViewportLayers(viewport_layers);
ajumadd2802e72015-06-30 20:28:298203
loyso0940d412016-03-14 01:30:318204 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8205 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298206
8207 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8208 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8209
8210 LayerPositionConstraint fixed_to_right;
8211 fixed_to_right.set_is_fixed_position(true);
8212 fixed_to_right.set_is_fixed_to_right_edge(true);
8213
8214 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8215 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8216
jaydasika6ed869662016-09-21 14:29:598217 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298218
8219 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8220 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8221 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8222
8223 LayerPositionConstraint fixed_to_left;
8224 fixed_to_left.set_is_fixed_position(true);
8225 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8226
jaydasika6ed869662016-09-21 14:29:598227 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298228 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8229 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8230
8231 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8232
jaydasika6ed869662016-09-21 14:29:598233 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298234 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8235 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8236}
8237
vollick7d83b452015-02-24 20:18:068238TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
sunxd713aedbd2016-08-10 22:22:148239 host_impl()->CreatePendingTree();
8240 std::unique_ptr<LayerImpl> pending_root =
8241 LayerImpl::Create(host_impl()->pending_tree(), 1);
8242 LayerImpl* root = pending_root.get();
8243 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root));
8244 std::unique_ptr<LayerImpl> animated_ptr =
8245 LayerImpl::Create(host_impl()->pending_tree(), 2);
8246 LayerImpl* animated = animated_ptr.get();
8247 root->test_properties()->AddChild(std::move(animated_ptr));
vollick7d83b452015-02-24 20:18:068248
sunxd713aedbd2016-08-10 22:22:148249 animated->SetDrawsContent(true);
8250 host_impl()->pending_tree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278251
danakjf78fb272016-07-26 19:06:158252 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:068253 root->SetMasksToBounds(true);
sunxd713aedbd2016-08-10 22:22:148254 root->test_properties()->force_render_surface = true;
8255 animated->test_properties()->opacity = 0.f;
danakjf78fb272016-07-26 19:06:158256 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:068257
sunxd713aedbd2016-08-10 22:22:148258 AddOpacityTransitionToElementWithPlayer(
8259 animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false);
8260 animated->test_properties()->opacity_can_animate = true;
8261 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598262 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
vollick7d83b452015-02-24 20:18:068263
sunxd713aedbd2016-08-10 22:22:148264 EXPECT_FALSE(animated->visible_layer_rect().IsEmpty());
vollick7d83b452015-02-24 20:18:068265}
8266
ajumaa92fdc12015-03-31 22:47:418267TEST_F(LayerTreeHostCommonTest,
8268 VisibleContentRectForAnimatedLayerWithSingularTransform) {
jaydasikaaf0dcd172017-05-01 17:37:178269 host_impl()->CreatePendingTree();
8270 std::unique_ptr<LayerImpl> root_ptr =
8271 LayerImpl::Create(host_impl()->pending_tree(), 1);
8272 LayerImpl* root = root_ptr.get();
8273 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(root_ptr));
8274 std::unique_ptr<LayerImpl> clip_ptr =
8275 LayerImpl::Create(host_impl()->pending_tree(), 2);
8276 LayerImpl* clip = clip_ptr.get();
8277 root->test_properties()->AddChild(std::move(clip_ptr));
8278 std::unique_ptr<LayerImpl> animated_ptr =
8279 LayerImpl::Create(host_impl()->pending_tree(), 3);
8280 LayerImpl* animated = animated_ptr.get();
8281 clip->test_properties()->AddChild(std::move(animated_ptr));
8282 std::unique_ptr<LayerImpl> surface_ptr =
8283 LayerImpl::Create(host_impl()->pending_tree(), 4);
8284 LayerImpl* surface = surface_ptr.get();
8285 animated->test_properties()->AddChild(std::move(surface_ptr));
8286 std::unique_ptr<LayerImpl> descendant_of_animation_ptr =
8287 LayerImpl::Create(host_impl()->pending_tree(), 5);
8288 LayerImpl* descendant_of_animation = descendant_of_animation_ptr.get();
8289 surface->test_properties()->AddChild(std::move(descendant_of_animation_ptr));
ajumaa92fdc12015-03-31 22:47:418290
jaydasikaaf0dcd172017-05-01 17:37:178291 host_impl()->pending_tree()->SetElementIdsForTesting();
ajumaa92fdc12015-03-31 22:47:418292
jaydasikaaf0dcd172017-05-01 17:37:178293 root->SetDrawsContent(true);
sunxd713aedbd2016-08-10 22:22:148294 animated->SetDrawsContent(true);
8295 surface->SetDrawsContent(true);
8296 descendant_of_animation->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278297
ajumaa92fdc12015-03-31 22:47:418298 gfx::Transform uninvertible_matrix;
8299 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8300
danakjf78fb272016-07-26 19:06:158301 root->SetBounds(gfx::Size(100, 100));
8302 clip->SetBounds(gfx::Size(10, 10));
8303 clip->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:048304 animated->test_properties()->transform = uninvertible_matrix;
danakjf78fb272016-07-26 19:06:158305 animated->SetBounds(gfx::Size(120, 120));
8306 surface->SetBounds(gfx::Size(100, 100));
sunxd713aedbd2016-08-10 22:22:148307 surface->test_properties()->force_render_surface = true;
danakjf78fb272016-07-26 19:06:158308 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:418309
8310 TransformOperations start_transform_operations;
8311 start_transform_operations.AppendMatrix(uninvertible_matrix);
8312 TransformOperations end_transform_operations;
8313
sunxd713aedbd2016-08-10 22:22:148314 AddAnimatedTransformToElementWithPlayer(
8315 animated->element_id(), timeline_impl(), 10.0, start_transform_operations,
8316 end_transform_operations);
jaydasikaaf0dcd172017-05-01 17:37:178317 ExecuteCalculateDrawProperties(root);
8318 // Since animated has singular transform, it is not be part of render
8319 // surface layer list but should be rastered.
ajuma651848a2017-05-01 21:23:458320 EXPECT_FALSE(animated->contributes_to_drawn_render_surface());
khushalsagar2fc1dbd2017-05-26 21:48:168321 EXPECT_TRUE(animated->raster_even_if_not_drawn());
ajumaa92fdc12015-03-31 22:47:418322
8323 // The animated layer has a singular transform and maps to a non-empty rect in
8324 // clipped target space, so is treated as fully visible.
sunxd713aedbd2016-08-10 22:22:148325 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418326
8327 // The singular transform on |animated| is flattened when inherited by
8328 // |surface|, and this happens to make it invertible.
sunxd713aedbd2016-08-10 22:22:148329 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect());
8330 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418331
8332 gfx::Transform zero_matrix;
8333 zero_matrix.Scale3d(0.f, 0.f, 0.f);
weiliangcea09f3372017-03-29 16:43:248334 root->layer_tree_impl()->SetTransformMutated(animated->element_id(),
8335 zero_matrix);
jaydasikaaf0dcd172017-05-01 17:37:178336 ExecuteCalculateDrawProperties(root);
ajumaa92fdc12015-03-31 22:47:418337
jaydasika6ed869662016-09-21 14:29:598338 // The animated layer will be treated as fully visible when we combine clips
8339 // in screen space.
jaydasika3a6b14432017-03-21 23:11:198340 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
jaydasika6ed869662016-09-21 14:29:598341
ajumaa92fdc12015-03-31 22:47:418342 // This time, flattening does not make |animated|'s transform invertible. This
8343 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348344 // |surface| and layers that draw into it as having empty visible rect.
jaydasika3a6b14432017-03-21 23:11:198345 EXPECT_EQ(gfx::Rect(100, 100), surface->visible_layer_rect());
8346 EXPECT_EQ(gfx::Rect(200, 200), descendant_of_animation->visible_layer_rect());
jaydasikaaf0dcd172017-05-01 17:37:178347
8348 host_impl()->ActivateSyncTree();
8349 LayerImpl* active_root = host_impl()->active_tree()->LayerById(root->id());
8350 ExecuteCalculateDrawProperties(active_root);
8351
8352 // Since the animated has singular transform, it is not be part of render
8353 // surface layer list.
8354 LayerImpl* active_animated =
8355 host_impl()->active_tree()->LayerById(animated->id());
ajuma651848a2017-05-01 21:23:458356 EXPECT_TRUE(active_root->contributes_to_drawn_render_surface());
8357 EXPECT_FALSE(active_animated->contributes_to_drawn_render_surface());
jaydasikaaf0dcd172017-05-01 17:37:178358
8359 // Since animated has singular transform, it is not be part of render
8360 // surface layer list but should be rastered.
khushalsagar2fc1dbd2017-05-26 21:48:168361 EXPECT_TRUE(animated->raster_even_if_not_drawn());
jaydasikaaf0dcd172017-05-01 17:37:178362 EXPECT_EQ(gfx::Rect(120, 120), active_animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418363}
8364
ajuma20384bf2016-07-22 13:26:158365// Verify that having animated opacity but current opacity 1 still creates
8366// a render surface.
8367TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
8368 LayerImpl* root = root_layer_for_testing();
8369 LayerImpl* child = AddChild<LayerImpl>(root);
8370 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:158371
danakjf78fb272016-07-26 19:06:158372 root->SetBounds(gfx::Size(50, 50));
8373 child->SetBounds(gfx::Size(50, 50));
8374 child->SetDrawsContent(true);
8375 grandchild->SetBounds(gfx::Size(50, 50));
8376 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:158377
8378 SetElementIdsForTesting();
8379 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
8380 10.0, 1.f, 0.2f, false);
8381 ExecuteCalculateDrawProperties(root);
8382
8383 EXPECT_EQ(1.f, child->Opacity());
chrishtr7e3aaf22017-05-04 15:04:018384 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:498385 EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root));
8386 EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child));
ajuma20384bf2016-07-22 13:26:158387}
8388
wkorman53a44322017-05-12 15:39:238389static bool FilterIsAnimating(LayerImpl* layer) {
8390 return layer->GetMutatorHost()->IsAnimatingFilterProperty(
8391 layer->element_id(), layer->GetElementTypeForAnimation());
8392}
8393
enne92f2f6d92015-02-25 23:13:318394// Verify that having an animated filter (but no current filter, as these
8395// are mutually exclusive) correctly creates a render surface.
8396TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598397 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328398 LayerImpl* child = AddChild<LayerImpl>(root);
8399 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318400
danakjf78fb272016-07-26 19:06:158401 root->SetBounds(gfx::Size(50, 50));
8402 child->SetBounds(gfx::Size(50, 50));
8403 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:318404
vollickef2ae922016-06-29 17:54:278405 SetElementIdsForTesting();
8406 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
8407 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:328408 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318409
chrishtr7e3aaf22017-05-04 15:04:018410 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:498411 EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root));
8412 EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child));
enne92f2f6d92015-02-25 23:13:318413
chrishtr7e3aaf22017-05-04 15:04:018414 EXPECT_TRUE(GetRenderSurface(root)->Filters().IsEmpty());
8415 EXPECT_TRUE(GetRenderSurface(child)->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:318416
wkorman53a44322017-05-12 15:39:238417 EXPECT_FALSE(FilterIsAnimating(root));
8418 EXPECT_TRUE(FilterIsAnimating(child));
8419 EXPECT_FALSE(FilterIsAnimating(grandchild));
enne92f2f6d92015-02-25 23:13:318420}
8421
ajuma315a4782015-07-24 21:16:348422// Verify that having a filter animation with a delayed start time creates a
8423// render surface.
8424TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598425 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328426 LayerImpl* child = AddChild<LayerImpl>(root);
8427 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348428
danakjf78fb272016-07-26 19:06:158429 root->SetBounds(gfx::Size(50, 50));
8430 child->SetBounds(gfx::Size(50, 50));
8431 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:348432
vollickef2ae922016-06-29 17:54:278433 SetElementIdsForTesting();
8434
danakj60bc3bc2016-04-09 00:24:488435 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348436 KeyframedFilterAnimationCurve::Create());
8437 FilterOperations start_filters;
8438 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8439 FilterOperations end_filters;
8440 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8441 curve->AddKeyframe(
8442 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8443 curve->AddKeyframe(FilterKeyframe::Create(
8444 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488445 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308446 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558447 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348448 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348449
vollickef2ae922016-06-29 17:54:278450 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
8451 std::move(animation));
ajuma4711f4b12016-05-16 18:48:328452 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348453
chrishtr7e3aaf22017-05-04 15:04:018454 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:498455 EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root));
8456 EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child));
ajuma315a4782015-07-24 21:16:348457
chrishtr7e3aaf22017-05-04 15:04:018458 EXPECT_TRUE(GetRenderSurface(root)->Filters().IsEmpty());
8459 EXPECT_TRUE(GetRenderSurface(child)->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:348460
wkorman53a44322017-05-12 15:39:238461 EXPECT_FALSE(FilterIsAnimating(root));
ajuma315a4782015-07-24 21:16:348462 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
wkorman53a44322017-05-12 15:39:238463 EXPECT_FALSE(FilterIsAnimating(child));
ajuma315a4782015-07-24 21:16:348464 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
wkorman53a44322017-05-12 15:39:238465 EXPECT_FALSE(FilterIsAnimating(grandchild));
ajuma315a4782015-07-24 21:16:348466 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8467}
8468
vollick0120eb22015-03-02 03:07:348469// Ensures that the property tree code accounts for offsets between fixed
8470// position layers and their respective containers.
8471TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:598472 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148473 LayerImpl* child = AddChild<LayerImpl>(root);
8474 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348475
danakjf78fb272016-07-26 19:06:158476 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:348477 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528478 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158479 child->SetPosition(gfx::PointF(1000, 1000));
8480 child->SetBounds(gfx::Size(50, 50));
8481 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8482 grandchild->SetBounds(gfx::Size(50, 50));
8483 grandchild->SetDrawsContent(true);
8484
vollick0120eb22015-03-02 03:07:348485 LayerPositionConstraint constraint;
8486 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528487 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:348488
jaydasika6f972de2016-04-07 16:16:148489 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348490
jaydasika6f972de2016-04-07 16:16:148491 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348492}
8493
ajuma0178b522015-07-02 21:08:418494// Ensures that the property tree code accounts for offsets between fixed
8495// position containers and their transform tree parents, when a fixed position
8496// layer's container is its layer tree parent, but this parent doesn't have its
8497// own transform tree node.
8498TEST_F(LayerTreeHostCommonTest,
8499 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:598500 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148501 LayerImpl* child = AddChild<LayerImpl>(root);
8502 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418503
danakjf78fb272016-07-26 19:06:158504 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:418505 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158506 root->test_properties()->is_container_for_fixed_position_layers = true;
8507 child->SetPosition(gfx::PointF(1000, 1000));
8508 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:528509 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158510 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8511 grandchild->SetBounds(gfx::Size(50, 50));
8512 grandchild->SetDrawsContent(true);
8513
ajuma0178b522015-07-02 21:08:418514 LayerPositionConstraint constraint;
8515 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528516 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:418517
jaydasika6f972de2016-04-07 16:16:148518 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418519
jaydasika6f972de2016-04-07 16:16:148520 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418521}
8522
vollick8c824742015-03-20 22:21:088523TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:598524 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148525 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8526 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088527 gfx::Transform translate_z;
8528 translate_z.Translate3d(0, 0, 10);
8529
danakjf78fb272016-07-26 19:06:158530 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:528531 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088532
danakjf78fb272016-07-26 19:06:158533 frame_clip->SetPosition(gfx::PointF(500, 100));
8534 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:088535 frame_clip->SetMasksToBounds(true);
8536
danakjf78fb272016-07-26 19:06:158537 fixed->SetBounds(gfx::Size(1000, 1000));
8538 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088539
8540 LayerPositionConstraint constraint;
8541 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528542 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:088543
jaydasika6f972de2016-04-07 16:16:148544 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088545
8546 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148547 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088548}
8549
vollick06ca3e832015-03-31 19:37:128550TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:598551 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148552 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8553 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8554 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8555
danakjf78fb272016-07-26 19:06:158556 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:148557 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158558 root->test_properties()->is_container_for_fixed_position_layers = true;
8559 frame_clip->SetPosition(gfx::PointF(500, 100));
8560 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148561 frame_clip->SetMasksToBounds(true);
8562 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158563 scroller->SetBounds(gfx::Size(1000, 1000));
pdr54d038192017-06-08 22:44:138564 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdr54d038192017-06-08 22:44:138565 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdrbbfd8822017-06-27 22:44:528566 scroller->SetScrollable(frame_clip->bounds());
jaydasika6f972de2016-04-07 16:16:148567 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158568 fixed->SetPosition(gfx::PointF(100, 100));
8569 fixed->SetBounds(gfx::Size(50, 50));
8570 fixed->SetMasksToBounds(true);
8571 fixed->SetDrawsContent(true);
8572 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:128573
pdr80d5a3e2017-07-17 19:04:078574 BuildPropertyTreesForTesting();
8575 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8576
vollick06ca3e832015-03-31 19:37:128577 LayerPositionConstraint constraint;
8578 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528579 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128580
jaydasika6f972de2016-04-07 16:16:148581 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128582
8583 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148584 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128585}
8586
vollick5057e1e2015-04-17 19:12:328587TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:328588 gfx::Transform translate;
8589 gfx::Transform rotate;
8590
8591 translate.Translate(10, 10);
8592 rotate.Rotate(45);
8593
loyso0940d412016-03-14 01:30:318594 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:158595 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:328596 root->SetIsContainerForFixedPositionLayers(true);
8597
ennea7b43c32015-06-18 20:01:338598 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328599
jaydasika6ed869662016-09-21 14:29:598600 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ennea7b43c32015-06-18 20:01:338601 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328602
8603 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338604 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328605
8606 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338607 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328608}
8609
ajumab0e0c1c2015-04-23 00:29:238610TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:598611 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148612 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238613
ajumab0e0c1c2015-04-23 00:29:238614 gfx::Transform scale_matrix;
8615 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:238616
danakjf78fb272016-07-26 19:06:158617 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148618 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048619 child->test_properties()->transform = scale_matrix;
danakjf78fb272016-07-26 19:06:158620 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148621 child->SetDrawsContent(true);
8622
8623 ExecuteCalculateDrawProperties(root);
8624 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238625
jaydasika38be7a822016-04-21 16:07:068626 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238627
jaydasika6f972de2016-04-07 16:16:148628 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8629 ExecuteCalculateDrawProperties(root);
8630 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238631}
8632
ajumaf09db8962015-04-24 21:55:348633TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:598634 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148635 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8636 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348637
ajumaf09db8962015-04-24 21:55:348638 gfx::Transform scale;
8639 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:158640
8641 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:048642 scroll_child->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:158643 scroll_child->SetBounds(gfx::Size(40, 40));
8644 scroll_child->SetDrawsContent(true);
8645 scroll_parent->SetBounds(gfx::Size(30, 30));
pdr80d5a3e2017-07-17 19:04:078646 scroll_parent->SetScrollable(gfx::Size(50, 50));
8647 scroll_parent->SetElementId(
8648 LayerIdToElementIdForTesting(scroll_parent->id()));
danakjf78fb272016-07-26 19:06:158649 scroll_parent->SetDrawsContent(true);
8650
8651 scroll_child->test_properties()->scroll_parent = scroll_parent;
8652 scroll_parent->test_properties()->scroll_children =
8653 base::MakeUnique<std::set<LayerImpl*>>();
8654 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:348655
jaydasika6f972de2016-04-07 16:16:148656 ExecuteCalculateDrawProperties(root);
8657 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348658
8659 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148660 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
Philip Rogers5657b402017-07-10 19:04:358661 ExecuteCalculateDrawProperties(root);
Philip Rogersc2cd1a12017-07-13 23:29:588662 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
pdr80d5a3e2017-07-17 19:04:078663
8664 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8665 ExecuteCalculateDrawProperties(root);
8666 EXPECT_EQ(gfx::Rect(0, 10, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348667}
8668
danakj60bc3bc2016-04-09 00:24:488669static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128670
jaydasikaebc94282017-04-24 20:34:018671TEST_F(LayerTreeHostCommonTest, HasCopyRequestsInTargetSubtree) {
loyso0940d412016-03-14 01:30:318672 scoped_refptr<Layer> root = Layer::Create();
8673 scoped_refptr<Layer> child1 = Layer::Create();
8674 scoped_refptr<Layer> child2 = Layer::Create();
8675 scoped_refptr<Layer> grandchild = Layer::Create();
8676 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028677
8678 root->AddChild(child1);
8679 root->AddChild(child2);
8680 child1->AddChild(grandchild);
8681 grandchild->AddChild(greatgrandchild);
8682 host()->SetRootLayer(root);
8683
8684 child1->RequestCopyOfOutput(
8685 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8686 greatgrandchild->RequestCopyOfOutput(
8687 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8688 child2->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598689 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:028690
jaydasikaebc94282017-04-24 20:34:018691 EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
8692 EXPECT_TRUE(child1->has_copy_requests_in_target_subtree());
8693 EXPECT_FALSE(child2->has_copy_requests_in_target_subtree());
8694 EXPECT_TRUE(grandchild->has_copy_requests_in_target_subtree());
8695 EXPECT_TRUE(greatgrandchild->has_copy_requests_in_target_subtree());
sunxded58688e2016-01-11 21:01:028696}
8697
vollick2175fae82015-04-27 21:18:128698TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:318699 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328700 FakeContentLayerClient client;
8701 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128702 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318703 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128704 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318705 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258706 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318707 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:158708
8709 root->SetBounds(gfx::Size(100, 100));
8710 child->SetBounds(gfx::Size(10, 10));
8711 grandchild->SetBounds(gfx::Size(10, 10));
8712 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128713
8714 root->AddChild(child);
8715 child->AddChild(grandchild);
8716 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:338717 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:078718 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278719
vollick2175fae82015-04-27 21:18:128720 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598721 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148722 const LayerList* update_list = GetUpdateLayerList();
8723 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128724
8725 // Now we will reset the visible rect from property trees for the grandchild,
8726 // and we will configure |child| in several ways that should force the subtree
8727 // to be skipped. The visible content rect for |grandchild| should, therefore,
8728 // remain empty.
vollick2175fae82015-04-27 21:18:128729 gfx::Transform singular;
8730 singular.matrix().set(0, 0, 0);
8731
8732 child->SetTransform(singular);
jaydasika6ed869662016-09-21 14:29:598733 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148734 update_list = GetUpdateLayerList();
8735 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
danakjf78fb272016-07-26 19:06:158736 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128737
8738 child->SetHideLayerAndSubtree(true);
jaydasika6ed869662016-09-21 14:29:598739 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148740 update_list = GetUpdateLayerList();
8741 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128742 child->SetHideLayerAndSubtree(false);
8743
ajuma315a4782015-07-24 21:16:348744 gfx::Transform zero_z_scale;
8745 zero_z_scale.Scale3d(1, 1, 0);
8746 child->SetTransform(zero_z_scale);
8747
8748 // Add a transform animation with a start delay. Now, even though |child| has
8749 // a singular transform, the subtree should still get processed.
8750 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488751 std::unique_ptr<Animation> animation = Animation::Create(
8752 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308753 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558754 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348755 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278756 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
8757 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598758 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148759 update_list = GetUpdateLayerList();
8760 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348761
vollickef2ae922016-06-29 17:54:278762 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
8763 animation_id);
danakjf78fb272016-07-26 19:06:158764 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128765 child->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598766 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148767 update_list = GetUpdateLayerList();
8768 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128769
8770 // Now, even though child has zero opacity, we will configure |grandchild| and
8771 // |greatgrandchild| in several ways that should force the subtree to be
8772 // processed anyhow.
jaydasika86654512016-01-27 17:05:078773 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128774 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
jaydasika6ed869662016-09-21 14:29:598775 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148776 update_list = GetUpdateLayerList();
8777 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348778
8779 // Add an opacity animation with a start delay.
8780 animation_id = 1;
8781 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488782 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308783 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558784 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348785 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278786 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
8787 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598788 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148789 update_list = GetUpdateLayerList();
8790 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128791}
8792
sunxd71aea3e2016-04-01 23:48:058793TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168794 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568795 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228796 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
vollick2175fae82015-04-27 21:18:128797
danakj60bc3bc2016-04-09 00:24:488798 std::unique_ptr<LayerImpl> root =
8799 LayerImpl::Create(host_impl.active_tree(), 1);
8800 std::unique_ptr<LayerImpl> child =
8801 LayerImpl::Create(host_impl.active_tree(), 2);
8802 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:128803 LayerImpl::Create(host_impl.active_tree(), 3);
8804
danakj60bc3bc2016-04-09 00:24:488805 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:258806 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128807
danakjf78fb272016-07-26 19:06:158808 root->SetBounds(gfx::Size(100, 100));
8809 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128810 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158811 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128812 grandchild->SetDrawsContent(true);
8813 greatgrandchild->SetDrawsContent(true);
8814
jaydasika2411692c2016-03-23 01:56:098815 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128816 LayerImpl* child_ptr = child.get();
8817 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128818
jaydasika89f7b5a2016-06-22 02:08:398819 child->test_properties()->AddChild(std::move(grandchild));
8820 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:598821 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:128822
vollickef2ae922016-06-29 17:54:278823 host_impl.active_tree()->SetElementIdsForTesting();
8824
vollick2175fae82015-04-27 21:18:128825 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598826 // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058827 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128828
8829 // Now we will reset the visible rect from property trees for the grandchild,
8830 // and we will configure |child| in several ways that should force the subtree
8831 // to be skipped. The visible content rect for |grandchild| should, therefore,
8832 // remain empty.
weiliangcc97575c2016-03-03 18:34:278833 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058834
vollick2175fae82015-04-27 21:18:128835 gfx::Transform singular;
8836 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058837 // This line is used to make the results of skipping and not skipping layers
8838 // different.
8839 singular.matrix().set(0, 1, 1);
8840
8841 gfx::Transform rotate;
8842 rotate.Rotate(90);
8843
8844 gfx::Transform rotate_back_and_translate;
8845 rotate_back_and_translate.RotateAboutYAxis(180);
8846 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128847
jaydasika10d43fc2016-08-18 04:06:048848 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058849 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598850 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278851 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048852 child_ptr->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:128853
jaydasika5121caa82016-05-05 15:43:358854 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika6ed869662016-09-21 14:29:598855 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278856 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358857 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128858
weiliangcea09f3372017-03-29 16:43:248859 child_ptr->test_properties()->opacity = 0.f;
8860 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598861 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278862 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188863 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:128864
jaydasika10d43fc2016-08-18 04:06:048865 root_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058866 // Force transform tree to have a node for child, so that ancestor's
8867 // invertible transform can be tested.
jaydasika10d43fc2016-08-18 04:06:048868 child_ptr->test_properties()->transform = rotate;
sunxd71aea3e2016-04-01 23:48:058869 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598870 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058871 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048872 root_ptr->test_properties()->transform = gfx::Transform();
8873 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:058874
jaydasikaab317e02016-06-01 00:53:188875 root_ptr->test_properties()->opacity = 0.f;
8876 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:058877 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598878 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058879 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188880 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058881
jaydasikaab317e02016-06-01 00:53:188882 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:128883 // Now, even though child has zero opacity, we will configure |grandchild| and
8884 // |greatgrandchild| in several ways that should force the subtree to be
8885 // processed anyhow.
ajumae6f541b2016-05-31 16:50:508886 grandchild_ptr->test_properties()->copy_requests.push_back(
8887 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:098888 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598889 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278890 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:508891
8892 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:188893 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058894
8895 // A double sided render surface with backface visible should not be skipped
8896 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
ajuma35b24f62017-01-27 21:23:098897 child_ptr->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:368898 child_ptr->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:048899 child_ptr->test_properties()->transform = rotate_back_and_translate;
sunxd71aea3e2016-04-01 23:48:058900 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598901 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058902 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048903 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:058904
danakj60bc3bc2016-04-09 00:24:488905 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058906 KeyframedTransformAnimationCurve::Create());
8907 TransformOperations start;
8908 start.AppendTranslate(1.f, 2.f, 3.f);
8909 gfx::Transform transform;
8910 transform.Scale3d(1.0, 2.0, 3.0);
8911 TransformOperations operation;
8912 operation.AppendMatrix(transform);
8913 curve->AddKeyframe(
8914 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8915 curve->AddKeyframe(TransformKeyframe::Create(
8916 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:488917 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:058918 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8919 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:088920 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
8921 player.get());
loysobb507792016-10-04 05:31:028922 player->AddAnimation(std::move(transform_animation));
sunxd71aea3e2016-04-01 23:48:058923 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
jaydasika10d43fc2016-08-18 04:06:048924 root_ptr->test_properties()->transform = singular;
8925 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058926 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598927 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:278928 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058929
loyso6d6356e2016-11-02 23:41:088930 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
8931 player.get());
sunxd71aea3e2016-04-01 23:48:058932}
8933
jaydasikaf187b06b2016-04-11 23:30:278934TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:598935 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:278936 LayerImpl* child = AddChild<LayerImpl>(root);
8937 LayerImpl* grand_child = AddChild<LayerImpl>(child);
8938
vollickef2ae922016-06-29 17:54:278939 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:278940
8941 gfx::Transform singular;
8942 singular.matrix().set(0, 0, 0);
8943 singular.matrix().set(0, 1, 1);
8944
danakjf78fb272016-07-26 19:06:158945 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:048946 child->test_properties()->transform = singular;
danakjf78fb272016-07-26 19:06:158947 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278948 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158949 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278950 grand_child->SetDrawsContent(true);
8951
danakj25c52c32016-04-12 21:51:088952 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:278953 KeyframedTransformAnimationCurve::Create());
8954 TransformOperations start;
8955 start.AppendTranslate(1.f, 2.f, 3.f);
8956 gfx::Transform transform;
8957 transform.Scale3d(1.0, 2.0, 3.0);
8958 TransformOperations operation;
8959 operation.AppendMatrix(transform);
8960 curve->AddKeyframe(
8961 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8962 curve->AddKeyframe(TransformKeyframe::Create(
8963 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:088964 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:278965 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8966 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:088967 host_impl()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278968 grand_child->element_id(), player.get());
loysobb507792016-10-04 05:31:028969 player->AddAnimation(std::move(transform_animation));
jaydasikaf187b06b2016-04-11 23:30:278970
8971 ExecuteCalculateDrawProperties(root);
8972 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
8973 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
8974
loyso6d6356e2016-11-02 23:41:088975 host_impl()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278976 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:278977}
8978
sunxd71aea3e2016-04-01 23:48:058979TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8980 FakeImplTaskRunnerProvider task_runner_provider;
sunxd71aea3e2016-04-01 23:48:058981 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228982 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
sunxd71aea3e2016-04-01 23:48:058983
sunxd71aea3e2016-04-01 23:48:058984 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:488985 std::unique_ptr<LayerImpl> root =
8986 LayerImpl::Create(host_impl.pending_tree(), 1);
8987 std::unique_ptr<LayerImpl> child =
8988 LayerImpl::Create(host_impl.pending_tree(), 2);
8989 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:058990 LayerImpl::Create(host_impl.pending_tree(), 3);
8991
danakj60bc3bc2016-04-09 00:24:488992 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:058993 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8994
danakjf78fb272016-07-26 19:06:158995 root->SetBounds(gfx::Size(100, 100));
8996 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058997 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158998 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058999 grandchild->SetDrawsContent(true);
9000 greatgrandchild->SetDrawsContent(true);
9001
sunxd71aea3e2016-04-01 23:48:059002 LayerImpl* root_ptr = root.get();
9003 LayerImpl* grandchild_ptr = grandchild.get();
9004
jaydasika89f7b5a2016-06-22 02:08:399005 child->test_properties()->AddChild(std::move(grandchild));
9006 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:059007
jaydasikabf1875a2016-06-28 03:39:599008 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:279009 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:059010
9011 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599012 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059013 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9014
danakj60bc3bc2016-04-09 00:24:489015 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059016 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:499017 std::unique_ptr<TimingFunction> func =
9018 CubicBezierTimingFunction::CreatePreset(
9019 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:059020 curve->AddKeyframe(
9021 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9022 curve->AddKeyframe(
9023 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489024 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059025 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9026 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089027 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
9028 player.get());
loysobb507792016-10-04 05:31:029029 player->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189030 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059031 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9032 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599033 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059034 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9035
loyso6d6356e2016-11-02 23:41:089036 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
9037 player.get());
vollick2175fae82015-04-27 21:18:129038}
9039
9040TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:599041 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149042 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129043
danakjf78fb272016-07-26 19:06:159044 root->SetBounds(gfx::Size(100, 100));
9045 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149046 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129047
jaydasika6f972de2016-04-07 16:16:149048 ExecuteCalculateDrawProperties(root);
9049 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279050 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129051
jaydasika5121caa82016-05-05 15:43:359052 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149053 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9054 ExecuteCalculateDrawProperties(root);
9055 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359056 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129057
9058 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149059 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9060 ExecuteCalculateDrawProperties(root);
9061 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129062 child->SetBounds(gfx::Size(10, 10));
9063
9064 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369065 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129066 rotate.RotateAboutXAxis(180.f);
jaydasika10d43fc2016-08-18 04:06:049067 child->test_properties()->transform = rotate;
jaydasika6f972de2016-04-07 16:16:149068 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9069 ExecuteCalculateDrawProperties(root);
9070 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369071 child->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049072 child->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129073
jaydasikaab317e02016-06-01 00:53:189074 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149075 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9076 ExecuteCalculateDrawProperties(root);
9077 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129078}
9079
jaydasika3d10aa62015-05-06 17:50:449080TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9081 // Ensure that the treewalk in LayerTreeHostCommom::
9082 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319083 scoped_refptr<Layer> root = Layer::Create();
9084 scoped_refptr<Layer> parent = Layer::Create();
9085 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449086
danakjf78fb272016-07-26 19:06:159087 root->SetBounds(gfx::Size(100, 100));
9088 parent->SetBounds(gfx::Size(100, 100));
9089 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:449090 child->SetClipParent(root.get());
9091
danakjf78fb272016-07-26 19:06:159092 root->AddChild(parent);
9093 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:339094 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449095
jaydasika3d10aa62015-05-06 17:50:449096 child->RequestCopyOfOutput(
9097 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029098
jaydasika6ed869662016-09-21 14:29:599099 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasikaebc94282017-04-24 20:34:019100 EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
jaydasika1553a142017-04-05 00:37:099101
jaydasika6ed869662016-09-21 14:29:599102 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasikaebc94282017-04-24 20:34:019103 EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
jaydasika3d10aa62015-05-06 17:50:449104}
9105
vollick692444f2015-05-20 15:39:149106TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:159107 scoped_refptr<Layer> root = Layer::Create();
9108 root->SetBounds(gfx::Size(800, 800));
9109
vollick692444f2015-05-20 15:39:149110 gfx::Transform translate_z;
9111 translate_z.Translate3d(0, 0, 10);
9112
loyso0940d412016-03-14 01:30:319113 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:159114 child->SetTransform(translate_z);
9115 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:149116
9117 root->AddChild(child);
9118
ennea7b43c32015-06-18 20:01:339119 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149120
jaydasika6ed869662016-09-21 14:29:599121 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149122 EXPECT_NE(-1, child->transform_tree_index());
9123
9124 child->RemoveFromParent();
9125
jaydasika6ed869662016-09-21 14:29:599126 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149127 EXPECT_EQ(-1, child->transform_tree_index());
9128}
9129
jaydasika67d7989e2015-08-06 21:55:349130TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9131 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:599132 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349133 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9134 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9135 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9136 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9137
jaydasika67d7989e2015-08-06 21:55:349138 // This transform should be a significant one so that a transform node is
9139 // formed for it.
9140 gfx::Transform transform1;
9141 transform1.RotateAboutYAxis(45);
9142 transform1.RotateAboutXAxis(30);
9143 // This transform should be a 3d transform as we want the render surface
9144 // to flatten the transform
9145 gfx::Transform transform2;
9146 transform2.Translate3d(10, 10, 10);
9147
danakjf78fb272016-07-26 19:06:159148 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049149 significant_transform->test_properties()->transform = transform1;
danakjf78fb272016-07-26 19:06:159150 significant_transform->SetBounds(gfx::Size(30, 30));
9151 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349152 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159153 layer_clips_subtree->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049154 render_surface->test_properties()->transform = transform2;
danakjf78fb272016-07-26 19:06:159155 render_surface->SetBounds(gfx::Size(30, 30));
9156 render_surface->test_properties()->force_render_surface = true;
9157 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349158 test_layer->SetDrawsContent(true);
9159
jaydasika5237db02016-09-20 01:34:309160 float device_scale_factor = 1.f;
9161 float page_scale_factor = 1.f;
9162 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:289163 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:429164 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika5237db02016-09-20 01:34:309165 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:289166 page_scale_layer, inner_viewport_scroll_layer,
jaydasika3a6b14432017-03-21 23:11:199167 outer_viewport_scroll_layer);
jaydasika67d7989e2015-08-06 21:55:349168
chrishtr7e3aaf22017-05-04 15:04:019169 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:499170 EXPECT_EQ(GetRenderSurface(significant_transform), GetRenderSurface(root));
chrishtr7e3aaf22017-05-04 15:04:019171 EXPECT_TRUE(GetRenderSurface(layer_clips_subtree));
chrishtr5f60ca02017-05-11 23:09:499172 EXPECT_NE(GetRenderSurface(render_surface), GetRenderSurface(root));
9173 EXPECT_EQ(GetRenderSurface(test_layer), GetRenderSurface(render_surface));
weiliangcc154ce22015-12-09 03:39:269174
jaydasika3a6b14432017-03-21 23:11:199175 EXPECT_EQ(gfx::Rect(30, 20), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349176}
9177
9178TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9179 // Ensure that when parent clip node's transform is an ancestor of current
9180 // clip node's target, clip is 'projected' from parent space to current
9181 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:599182 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349183 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9184 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9185 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9186
jaydasika67d7989e2015-08-06 21:55:349187 gfx::Transform transform;
9188 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:159189
9190 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049191 clip_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159192 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349193 clip_layer->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049194 target_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159195 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349196 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159197 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349198 test_layer->SetDrawsContent(true);
9199
jaydasika67d7989e2015-08-06 21:55:349200 ExecuteCalculateDrawProperties(root);
9201
weiliangcc97575c2016-03-03 18:34:279202 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349203}
9204
jaydasika7d5c1ed2015-08-14 14:27:029205TEST_F(LayerTreeHostCommonTest,
9206 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9207 // Ensure clip rect is calculated correctly when render surface has unclipped
9208 // descendants.
jaydasikabf1875a2016-06-28 03:39:599209 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:029210 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9211 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9212 LayerImpl* render_surface =
9213 AddChild<LayerImpl>(between_clip_parent_and_child);
9214 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9215
weiliangcbb2e8642016-03-04 00:24:429216 gfx::Transform translate;
9217 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029218
danakjf78fb272016-07-26 19:06:159219 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049220 clip_parent->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159221 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:429222 clip_parent->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049223 between_clip_parent_and_child->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159224 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
jaydasika1553a142017-04-05 00:37:099225 between_clip_parent_and_child->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159226 render_surface->SetBounds(gfx::Size(30, 30));
9227 render_surface->test_properties()->force_render_surface = true;
9228 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:029229 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159230
jaydasika1c0a27d42016-04-28 01:54:569231 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159232 clip_parent->test_properties()->clip_children =
9233 base::MakeUnique<std::set<LayerImpl*>>();
9234 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:029235
9236 ExecuteCalculateDrawProperties(root);
9237
weiliangcbb2e8642016-03-04 00:24:429238 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259239 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569240 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9241 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029242}
9243
jaydasika571dd2cf2015-09-25 20:55:429244TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089245 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9246 // Ensure that the visible layer rect of a descendant of a surface with
9247 // unclipped descendants is computed correctly, when the surface doesn't apply
9248 // a clip.
jaydasikabf1875a2016-06-28 03:39:599249 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:089250 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9251 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9252 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9253 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9254
danakjf78fb272016-07-26 19:06:159255 root->SetBounds(gfx::Size(30, 10));
9256 clip_parent->SetBounds(gfx::Size(30, 30));
9257 render_surface->SetBounds(gfx::Size(10, 15));
9258 render_surface->test_properties()->force_render_surface = true;
9259 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:089260 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159261 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:089262 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159263
jaydasika1c0a27d42016-04-28 01:54:569264 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159265 clip_parent->test_properties()->clip_children =
9266 base::MakeUnique<std::set<LayerImpl*>>();
9267 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:089268
9269 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:189270 EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect());
ajuma01734dd02015-10-07 01:22:089271}
9272
9273TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429274 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:599275 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429276 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9277 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9278 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9279 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9280 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9281
danakjf78fb272016-07-26 19:06:159282 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429283 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159284 clip_parent->SetBounds(gfx::Size(30, 30));
9285 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429286 render_surface->SetMasksToBounds(true);
9287 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159288 render_surface->test_properties()->force_render_surface = true;
9289 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429290 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159291 clip_child->SetBounds(gfx::Size(50, 50));
9292 clip_child->SetDrawsContent(true);
9293 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429294 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429295
danakjf78fb272016-07-26 19:06:159296 clip_child->test_properties()->clip_parent = clip_parent;
9297 clip_parent->test_properties()->clip_children =
9298 base::MakeUnique<std::set<LayerImpl*>>();
9299 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:429300
9301 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569302 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9303 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429304 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9305 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9306}
9307
ajumae2b7a5c2015-09-30 21:41:429308TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:599309 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:429310 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9311 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9312 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9313
danakjf78fb272016-07-26 19:06:159314 root->SetBounds(gfx::Size(50, 50));
9315 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429316 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159317 render_surface->SetBounds(gfx::Size(30, 30));
9318 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:429319 render_surface->SetMasksToBounds(true);
9320 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159321 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429322 clip_child->SetDrawsContent(true);
9323
jaydasika1c0a27d42016-04-28 01:54:569324 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159325 clip_parent->test_properties()->clip_children =
9326 base::MakeUnique<std::set<LayerImpl*>>();
9327 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:429328
9329 ExecuteCalculateDrawProperties(root);
9330
9331 // The clip child should inherit its clip parent's clipping state, not its
9332 // tree parent's clipping state.
9333 EXPECT_FALSE(clip_parent->is_clipped());
9334 EXPECT_TRUE(render_surface->is_clipped());
9335 EXPECT_FALSE(clip_child->is_clipped());
9336}
9337
jaydasika77a4a072015-10-20 21:47:279338TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9339 // Tests the value of render surface content rect when we have multiple types
9340 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9341 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:599342 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279343 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9344 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
jaydasika1553a142017-04-05 00:37:099345 LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent);
9346 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_layer);
jaydasika77a4a072015-10-20 21:47:279347 LayerImpl* unclipped_desc_surface2 =
9348 AddChild<LayerImpl>(unclipped_desc_surface);
9349 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9350 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9351
danakjf78fb272016-07-26 19:06:159352 root->SetBounds(gfx::Size(80, 80));
9353 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:279354 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159355 unclipped_surface->SetDrawsContent(true);
9356 unclipped_surface->test_properties()->force_render_surface = true;
9357 clip_parent->SetBounds(gfx::Size(50, 50));
9358 clip_parent->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:099359 clip_layer->SetMasksToBounds(true);
9360 clip_layer->SetBounds(gfx::Size(100, 100));
danakjf78fb272016-07-26 19:06:159361 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
danakjf78fb272016-07-26 19:06:159362 unclipped_desc_surface->SetDrawsContent(true);
9363 unclipped_desc_surface->test_properties()->force_render_surface = true;
9364 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
9365 unclipped_desc_surface2->SetDrawsContent(true);
9366 unclipped_desc_surface2->test_properties()->force_render_surface = true;
9367 clip_child->SetBounds(gfx::Size(100, 100));
9368 clipped_surface->SetBounds(gfx::Size(70, 70));
9369 clipped_surface->SetDrawsContent(true);
9370 clipped_surface->test_properties()->force_render_surface = true;
9371
9372 clip_child->test_properties()->clip_parent = clip_parent;
9373 clip_parent->test_properties()->clip_children =
9374 base::MakeUnique<std::set<LayerImpl*>>();
9375 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279376
9377 ExecuteCalculateDrawProperties(root);
9378 EXPECT_EQ(gfx::Rect(50, 50),
chrishtr7e3aaf22017-05-04 15:04:019379 GetRenderSurface(unclipped_surface)->content_rect());
weiliangc0e13ba602016-03-12 04:53:569380 EXPECT_EQ(gfx::Rect(50, 50),
chrishtr7e3aaf22017-05-04 15:04:019381 GetRenderSurface(unclipped_desc_surface)->content_rect());
jaydasika1553a142017-04-05 00:37:099382 EXPECT_EQ(gfx::Rect(60, 60),
chrishtr7e3aaf22017-05-04 15:04:019383 GetRenderSurface(unclipped_desc_surface2)->content_rect());
jaydasika77a4a072015-10-20 21:47:279384 EXPECT_EQ(gfx::Rect(50, 50),
chrishtr7e3aaf22017-05-04 15:04:019385 GetRenderSurface(clipped_surface)->content_rect());
jaydasika77a4a072015-10-20 21:47:279386}
9387
9388TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9389 // Tests the value of render surface content rect when we have a layer that
9390 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:599391 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279392 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9393 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9394 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9395 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9396 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9397
jaydasika77a4a072015-10-20 21:47:279398 gfx::Transform translate;
9399 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:159400
jaydasika778cb272016-08-15 19:00:549401 gfx::Transform rotate;
9402 rotate.RotateAboutXAxis(10);
9403
danakjf78fb272016-07-26 19:06:159404 root->SetBounds(gfx::Size(100, 100));
9405 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279406 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159407 surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049408 surface->test_properties()->transform = rotate;
danakjf78fb272016-07-26 19:06:159409 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:279410 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159411 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:049412 unclipped_desc_surface->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159413 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9414 unclipped_desc_surface->SetDrawsContent(true);
9415 unclipped_desc_surface->test_properties()->force_render_surface = true;
9416 clip_child->SetBounds(gfx::Size(100, 100));
9417 clip_child->SetDrawsContent(true);
9418
9419 clip_child->test_properties()->clip_parent = clip_parent;
9420 clip_parent->test_properties()->clip_children =
9421 base::MakeUnique<std::set<LayerImpl*>>();
9422 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279423
9424 ExecuteCalculateDrawProperties(root);
9425
9426 EXPECT_EQ(gfx::Rect(10, 10),
chrishtr7e3aaf22017-05-04 15:04:019427 GetRenderSurface(unclipped_desc_surface)->content_rect());
jaydasika77a4a072015-10-20 21:47:279428}
9429
jaydasika2c8c2872015-10-21 23:28:219430TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:599431 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:219432 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9433 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9434 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9435 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9436 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9437
jaydasika2c8c2872015-10-21 23:28:219438
jaydasika2c8c2872015-10-21 23:28:219439 gfx::Transform scale;
9440 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:159441
9442 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:049443 surface->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159444 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:219445 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159446 surface->test_properties()->force_render_surface = true;
9447 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:219448 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159449 clip_parent->SetBounds(gfx::Size(50, 50));
9450 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9451 unclipped_desc_surface->SetDrawsContent(true);
9452 unclipped_desc_surface->test_properties()->force_render_surface = true;
9453 clip_child->SetBounds(gfx::Size(100, 100));
9454 clip_child->SetDrawsContent(true);
9455
9456 clip_child->test_properties()->clip_parent = clip_parent;
9457 clip_parent->test_properties()->clip_children =
9458 base::MakeUnique<std::set<LayerImpl*>>();
9459 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:219460
9461 ExecuteCalculateDrawProperties(root);
9462
9463 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9464}
9465
jaydasika60f85862015-10-01 20:36:149466TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:599467 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:149468 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9469 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9470
jaydasika86654512016-01-27 17:05:079471 gfx::Transform translation;
9472 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:149473
danakjf78fb272016-07-26 19:06:159474 root->SetBounds(gfx::Size(30, 30));
9475 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:149476 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159477 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049478 test_layer->test_properties()->transform = translation;
danakjf78fb272016-07-26 19:06:159479 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:149480 test_layer->SetDrawsContent(true);
Hayley Ferrd9ee3a72017-06-16 14:16:099481
9482 TouchActionRegion touch_action_region;
9483 touch_action_region.Union(kTouchActionNone, gfx::Rect(0, 0, 20, 20));
9484 test_layer->SetTouchActionRegion(std::move(touch_action_region));
danakjf78fb272016-07-26 19:06:159485 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:149486
9487 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:029488 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
9489 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149490}
9491
jaydasikab874eddc2016-11-02 22:34:289492TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) {
9493 LayerImpl* root = root_layer_for_testing();
9494 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9495 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
jaydasika1553a142017-04-05 00:37:099496 LayerImpl* clip_parent_child = AddChild<LayerImpl>(clip_parent);
9497 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent_child);
jaydasikab874eddc2016-11-02 22:34:289498 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9499
9500 root->SetBounds(gfx::Size(100, 100));
9501 clip_layer->SetBounds(gfx::Size(20, 20));
9502 clip_layer->SetMasksToBounds(true);
9503 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika1553a142017-04-05 00:37:099504 clip_parent_child->SetBounds(gfx::Size(20, 20));
9505 clip_parent_child->SetMasksToBounds(true);
jaydasikab874eddc2016-11-02 22:34:289506 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9507 unclipped_desc_surface->SetDrawsContent(true);
9508 unclipped_desc_surface->test_properties()->force_render_surface = true;
9509 clip_child->SetBounds(gfx::Size(100, 100));
9510 clip_child->SetDrawsContent(true);
jaydasika264a0dd2017-02-24 23:17:279511 gfx::Transform translate;
9512 translate.Translate(10, 10);
9513 unclipped_desc_surface->test_properties()->transform = translate;
jaydasikab874eddc2016-11-02 22:34:289514
9515 clip_child->test_properties()->clip_parent = clip_parent;
9516 clip_parent->test_properties()->clip_children =
9517 base::MakeUnique<std::set<LayerImpl*>>();
9518 clip_parent->test_properties()->clip_children->insert(clip_child);
9519
9520 float device_scale_factor = 1.f;
9521 ExecuteCalculateDrawProperties(root, device_scale_factor);
jaydasika264a0dd2017-02-24 23:17:279522 EXPECT_EQ(gfx::Rect(-10, -10, 20, 20), clip_child->clip_rect());
9523 EXPECT_EQ(gfx::Rect(10, 10), clip_child->visible_layer_rect());
jaydasikab874eddc2016-11-02 22:34:289524
9525 device_scale_factor = 2.f;
9526 ExecuteCalculateDrawProperties(root, device_scale_factor);
jaydasika264a0dd2017-02-24 23:17:279527 EXPECT_EQ(gfx::Rect(-20, -20, 40, 40), clip_child->clip_rect());
9528 EXPECT_EQ(gfx::Rect(10, 10), clip_child->visible_layer_rect());
jaydasikab874eddc2016-11-02 22:34:289529}
9530
jaydasikae4910fa22015-10-09 00:52:099531TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:599532 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:099533 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9534 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9535 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9536
danakjf78fb272016-07-26 19:06:159537 root->SetBounds(gfx::Size(30, 30));
9538 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:099539 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159540 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099541 render_surface->SetMasksToBounds(true);
9542 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159543 render_surface->test_properties()->force_render_surface = true;
9544 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099545 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:099546
danakjf78fb272016-07-26 19:06:159547 clip_child->test_properties()->clip_parent = clip_parent;
9548 clip_parent->test_properties()->clip_children =
9549 base::MakeUnique<std::set<LayerImpl*>>();
9550 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:099551
9552 ExecuteCalculateDrawProperties(root);
jaydasikab4df4032016-09-13 18:38:499553 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
jaydasikae4910fa22015-10-09 00:52:099554}
9555
jaydasika571dd2cf2015-09-25 20:55:429556TEST_F(LayerTreeHostCommonTest,
9557 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:599558 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429559 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9560 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:159561
9562 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429563 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369564 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159565 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429566 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369567 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159568 render_surface->test_properties()->force_render_surface = true;
9569 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429570 test_layer->SetMasksToBounds(true);
9571 test_layer->SetDrawsContent(true);
9572 ExecuteCalculateDrawProperties(root);
9573
9574 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9575 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9576 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9577}
9578
jaydasikab5504ca2015-12-18 23:41:559579TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9580 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:599581 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:559582 LayerImpl* hidden = AddChild<LayerImpl>(root);
9583 LayerImpl* test = AddChild<LayerImpl>(hidden);
9584
danakjf78fb272016-07-26 19:06:159585 root->SetBounds(gfx::Size(30, 30));
9586 hidden->SetBounds(gfx::Size(30, 30));
9587 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:359588 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:159589 test->SetBounds(gfx::Size(30, 30));
9590 test->test_properties()->force_render_surface = true;
9591
jaydasikab5504ca2015-12-18 23:41:559592 ExecuteCalculateDrawProperties(root);
ajuma956219582017-04-04 19:58:149593 EXPECT_EQ(0.f,
chrishtr7e3aaf22017-05-04 15:04:019594 GetRenderSurface(test)->OwningEffectNode()->screen_space_opacity);
jaydasikab5504ca2015-12-18 23:41:559595
jaydasika5121caa82016-05-05 15:43:359596 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559597 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9598 ExecuteCalculateDrawProperties(root);
ajuma956219582017-04-04 19:58:149599 EXPECT_EQ(1.f,
chrishtr7e3aaf22017-05-04 15:04:019600 GetRenderSurface(test)->OwningEffectNode()->screen_space_opacity);
jaydasikab5504ca2015-12-18 23:41:559601}
9602
jaydasikac0137282015-10-01 15:50:309603TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:599604 LayerImpl* root = root_layer_for_testing();
jaydasika1553a142017-04-05 00:37:099605 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9606 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer);
jaydasikac0137282015-10-01 15:50:309607 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9608 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9609
danakjf78fb272016-07-26 19:06:159610 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309611 root->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:099612 clip_layer->SetBounds(gfx::Size(30, 30));
9613 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159614 render_surface1->SetPosition(gfx::PointF(10, 10));
9615 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309616 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159617 render_surface1->test_properties()->force_render_surface = true;
9618 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309619 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159620 render_surface2->test_properties()->force_render_surface = true;
9621 clip_child->SetBounds(gfx::Size(30, 30));
jaydasika1553a142017-04-05 00:37:099622 clip_child->SetDrawsContent(true);
jaydasikac0137282015-10-01 15:50:309623
danakjf78fb272016-07-26 19:06:159624 clip_child->test_properties()->clip_parent = root;
9625 root->test_properties()->clip_children =
9626 base::MakeUnique<std::set<LayerImpl*>>();
9627 root->test_properties()->clip_children->insert(clip_child);
9628
jaydasikac0137282015-10-01 15:50:309629 ExecuteCalculateDrawProperties(root);
9630
9631 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
9632}
9633
ajumadb6216f2c2016-06-07 21:44:059634TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
9635 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599636 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:099637 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509638 child->test_properties()->SetMaskLayer(
9639 LayerImpl::Create(root->layer_tree_impl(), 100));
9640 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:099641
jaydasika224bca02015-12-18 02:37:099642 gfx::Transform transform;
9643 transform.Translate(10, 10);
9644
danakjf78fb272016-07-26 19:06:159645 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:099646 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:049647 child->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159648 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:099649 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:159650 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:099651 ExecuteCalculateDrawProperties(root);
9652
ajumadb6216f2c2016-06-07 21:44:059653 // The render surface created for the mask has no contributing content, so the
ajuma651848a2017-05-01 21:23:459654 // mask doesn't contribute to a drawn render surface. This means it has an
9655 // empty visible rect, but its screen space transform can still be computed
9656 // correctly on-demand.
9657 EXPECT_FALSE(mask->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:509658 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
9659 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059660
9661 // Make the child's render surface have contributing content.
9662 child->SetDrawsContent(true);
9663 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9664 ExecuteCalculateDrawProperties(root);
ajuma651848a2017-05-01 21:23:459665 EXPECT_TRUE(mask->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:509666 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
9667 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059668
jaydasika224bca02015-12-18 02:37:099669 transform.Translate(10, 10);
jaydasika10d43fc2016-08-18 04:06:049670 child->test_properties()->transform = transform;
jaydasika224bca02015-12-18 02:37:099671 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9672 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509673 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
9674 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:059675}
9676
jaydasikaf62311f2016-04-20 14:38:459677TEST_F(LayerTreeHostCommonTest,
9678 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:599679 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:459680 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9681 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9682 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9683 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:459684
9685 gfx::Transform scale;
9686 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:159687
9688 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049689 render_surface1->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159690 render_surface1->SetBounds(gfx::Size(30, 30));
9691 render_surface1->test_properties()->force_render_surface = true;
9692 between_targets->SetBounds(gfx::Size(30, 30));
9693 render_surface2->SetBounds(gfx::Size(30, 30));
9694 render_surface2->test_properties()->force_render_surface = true;
9695 test_layer->SetBounds(gfx::Size(30, 30));
9696 test_layer->SetDrawsContent(true);
9697
jaydasikab433552b2016-10-26 18:49:449698 // We want layer between the two targets to create a clip node and effect
jaydasikaf62311f2016-04-20 14:38:459699 // node but it shouldn't create a render surface.
9700 between_targets->SetMasksToBounds(true);
jaydasikab433552b2016-10-26 18:49:449701 between_targets->test_properties()->opacity = 0.5f;
jaydasikaf62311f2016-04-20 14:38:459702
9703 ExecuteCalculateDrawProperties(root);
9704
jaydasikab433552b2016-10-26 18:49:449705 EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree;
9706 EffectNode* node = tree.Node(render_surface1->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439707 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459708
jaydasikab433552b2016-10-26 18:49:449709 node = tree.Node(between_targets->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439710 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:459711
jaydasikab433552b2016-10-26 18:49:449712 node = tree.Node(render_surface2->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439713 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459714
9715 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9716}
9717
jaydasika3c5633d2016-08-25 00:39:229718TEST_F(LayerTreeHostCommonTest, NoisyTransform) {
9719 LayerImpl* root = root_layer_for_testing();
9720 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9721 LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface);
9722 LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface);
9723 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip);
9724
9725 scroll_child->test_properties()->scroll_parent = scroll_parent;
9726 scroll_parent->test_properties()->scroll_children =
9727 base::MakeUnique<std::set<LayerImpl*>>();
9728 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika3c5633d2016-08-25 00:39:229729
9730 scroll_parent->SetDrawsContent(true);
9731 scroll_child->SetDrawsContent(true);
9732 render_surface->test_properties()->force_render_surface = true;
9733
9734 // A noisy transform that's invertible.
9735 gfx::Transform transform;
9736 transform.matrix().setDouble(0, 0, 6.12323e-17);
9737 transform.matrix().setDouble(0, 2, 1);
9738 transform.matrix().setDouble(2, 2, 6.12323e-17);
9739 transform.matrix().setDouble(2, 0, -1);
9740
9741 scroll_child->test_properties()->transform = transform;
9742 render_surface->test_properties()->transform = transform;
9743
9744 root->SetBounds(gfx::Size(30, 30));
9745 scroll_child->SetBounds(gfx::Size(30, 30));
9746 scroll_parent->SetBounds(gfx::Size(30, 30));
9747 ExecuteCalculateDrawProperties(root);
9748
9749 gfx::Transform expected;
9750 expected.matrix().setDouble(0, 0, 3.749395e-33);
9751 expected.matrix().setDouble(0, 2, 6.12323e-17);
9752 expected.matrix().setDouble(2, 0, -1);
9753 expected.matrix().setDouble(2, 2, 6.12323e-17);
9754 EXPECT_TRANSFORMATION_MATRIX_EQ(expected,
9755 scroll_child->ScreenSpaceTransform());
9756}
9757
jaydasika5160e672015-10-15 15:25:149758TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:599759 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:149760 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059761 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149762
sunxd71aea3e2016-04-01 23:48:059763 child->SetDrawsContent(true);
9764 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149765
9766 gfx::Transform large_transform;
9767 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9768 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9769 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9770 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9771
danakjf78fb272016-07-26 19:06:159772 root->SetBounds(gfx::Size(30, 30));
9773 render_surface1->SetBounds(gfx::Size(30, 30));
9774 render_surface1->test_properties()->force_render_surface = true;
9775
sunxd71aea3e2016-04-01 23:48:059776 // TODO(sunxd): we make child have no render surface, because if the
9777 // child has one, the large transform applied to child will result in NaNs in
9778 // the draw_transform of the render_surface, thus make draw property updates
9779 // skip the child layer. We need further investigation into this to know
9780 // what exactly happens here.
jaydasika10d43fc2016-08-18 04:06:049781 child->test_properties()->transform = large_transform;
danakjf78fb272016-07-26 19:06:159782 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:149783
9784 ExecuteCalculateDrawProperties(root);
9785
jaydasika5160e672015-10-15 15:25:149786 EXPECT_EQ(gfx::RectF(),
chrishtr7e3aaf22017-05-04 15:04:019787 GetRenderSurface(render_surface1)->DrawableContentRect());
sunxd71aea3e2016-04-01 23:48:059788
9789 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9790 std::isnan(child->DrawTransform().matrix().get(0, 0));
9791 EXPECT_TRUE(is_inf_or_nan);
9792
9793 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9794 std::isnan(child->DrawTransform().matrix().get(1, 1));
9795 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149796
ajumab784ef42017-04-28 23:01:529797 // The root layer should be in the RenderSurfaceList.
9798 const auto* rsl = render_surface_list_impl();
chrishtr7e3aaf22017-05-04 15:04:019799 EXPECT_NE(std::find(rsl->begin(), rsl->end(), GetRenderSurface(root)),
ajumab784ef42017-04-28 23:01:529800 rsl->end());
jaydasika5160e672015-10-15 15:25:149801}
9802
jaydasika8d6efe2e2016-05-17 15:37:219803TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:219804 scoped_refptr<Layer> root = Layer::Create();
9805 scoped_refptr<LayerWithForcedDrawsContent> child =
9806 make_scoped_refptr(new LayerWithForcedDrawsContent());
9807 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:219808 host()->SetRootLayer(root);
9809
danakjf78fb272016-07-26 19:06:159810 root->SetBounds(gfx::Size(100, 100));
9811 child->SetBounds(gfx::Size(20, 20));
jaydasika6ed869662016-09-21 14:29:599812 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219813
9814 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9815 // property trees as a new effect node will be created.
9816 child->SetOpacity(0.5f);
9817 PropertyTrees* property_trees = host()->property_trees();
9818 EXPECT_TRUE(property_trees->needs_rebuild);
9819
jaydasika6ed869662016-09-21 14:29:599820 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
Chris Harrelson84670c92017-06-06 05:39:069821 EXPECT_NE(property_trees->effect_tree.Node(child->effect_tree_index()),
9822 property_trees->effect_tree.Node(root->effect_tree_index()));
jaydasika8d6efe2e2016-05-17 15:37:219823
9824 // child already has an effect node. Changing its opacity shouldn't trigger
9825 // a property trees rebuild.
9826 child->SetOpacity(0.8f);
9827 property_trees = host()->property_trees();
9828 EXPECT_FALSE(property_trees->needs_rebuild);
9829
jaydasika6ed869662016-09-21 14:29:599830 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
Chris Harrelson84670c92017-06-06 05:39:069831 EXPECT_NE(property_trees->effect_tree.Node(child->effect_tree_index()),
9832 property_trees->effect_tree.Node(root->effect_tree_index()));
jaydasika8d6efe2e2016-05-17 15:37:219833
9834 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
9835 // property trees as the effect node may no longer be needed.
9836 child->SetOpacity(1.f);
9837 property_trees = host()->property_trees();
9838 EXPECT_TRUE(property_trees->needs_rebuild);
9839
jaydasika6ed869662016-09-21 14:29:599840 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
Chris Harrelson84670c92017-06-06 05:39:069841 EXPECT_EQ(property_trees->effect_tree.Node(child->effect_tree_index()),
9842 property_trees->effect_tree.Node(root->effect_tree_index()));
jaydasika8d6efe2e2016-05-17 15:37:219843}
9844
jaydasika9cb21c772016-05-10 22:37:089845TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:089846 scoped_refptr<Layer> root = Layer::Create();
9847 scoped_refptr<LayerWithForcedDrawsContent> animated =
9848 make_scoped_refptr(new LayerWithForcedDrawsContent());
9849 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:089850 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:079851 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279852
danakjf78fb272016-07-26 19:06:159853 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:089854 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159855 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:089856 animated->SetOpacity(0.f);
9857
9858 scoped_refptr<AnimationPlayer> player =
9859 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9860 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279861
9862 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:089863
9864 int animation_id = 0;
9865 std::unique_ptr<Animation> animation = Animation::Create(
9866 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
9867 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559868 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:089869 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9870 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279871 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9872 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:089873
jaydasika6ed869662016-09-21 14:29:599874 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika9cb21c772016-05-10 22:37:089875
khushalsagarb69ba9452017-01-27 22:20:079876 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree;
jaydasika9cb21c772016-05-10 22:37:089877 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019878 EXPECT_FALSE(node->is_currently_animating_opacity);
9879 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089880
9881 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:589882 host()->AnimateLayers(
jaydasika9cb21c772016-05-10 22:37:089883 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9884 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019885 EXPECT_TRUE(node->is_currently_animating_opacity);
9886 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089887
9888 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
9889 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019890 EXPECT_FALSE(node->is_currently_animating_opacity);
9891 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089892}
9893
jaydasika6c3404e92016-05-19 02:40:369894TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:369895 scoped_refptr<Layer> root = Layer::Create();
9896 scoped_refptr<LayerWithForcedDrawsContent> animated =
9897 make_scoped_refptr(new LayerWithForcedDrawsContent());
9898 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:369899 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:079900 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279901
danakjf78fb272016-07-26 19:06:159902 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:369903 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159904 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:369905
9906 scoped_refptr<AnimationPlayer> player =
9907 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9908 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279909 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:369910
9911 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
9912 KeyframedTransformAnimationCurve::Create());
9913 TransformOperations start;
9914 start.AppendTranslate(1.f, 2.f, 3.f);
9915 gfx::Transform transform;
9916 transform.Scale3d(1.0, 2.0, 3.0);
9917 TransformOperations operation;
9918 operation.AppendMatrix(transform);
9919 curve->AddKeyframe(
9920 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9921 curve->AddKeyframe(TransformKeyframe::Create(
9922 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
9923 std::unique_ptr<Animation> animation(
9924 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9925 animation->set_fill_mode(Animation::FillMode::NONE);
9926 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9927 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279928 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9929 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:369930
jaydasika6ed869662016-09-21 14:29:599931 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika6c3404e92016-05-19 02:40:369932
khushalsagarb69ba9452017-01-27 22:20:079933 TransformTree& tree =
9934 root->layer_tree_host()->property_trees()->transform_tree;
jaydasika6c3404e92016-05-19 02:40:369935 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019936 EXPECT_FALSE(node->is_currently_animating);
9937 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369938
9939 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:589940 host()->AnimateLayers(
jaydasika6c3404e92016-05-19 02:40:369941 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9942 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019943 EXPECT_TRUE(node->is_currently_animating);
9944 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369945
9946 player->AbortAnimations(TargetProperty::TRANSFORM,
9947 false /*needs_completion*/);
9948 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019949 EXPECT_FALSE(node->is_currently_animating);
9950 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369951}
9952
sunxdea1df782016-01-28 00:12:339953TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9954 // Test the behavior of scroll tree builder
9955 // Topology:
sunxdcfccd1b32016-02-11 00:54:209956 // +root1(1)[inner_viewport_container_layer]
9957 // +-page_scale_layer
9958 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9959 // scrollable, inner_viewport_scroll_layer]
9960 // +------child6(6)[kScrollbarScrolling]
9961 // +--------grand_child10(10)[kScrollbarScrolling]
9962 // +----parent3(3)
9963 // +------child7(7)[scrollable]
9964 // +------child8(8)[scroll_parent=7]
9965 // +--------grand_child11(11)[scrollable]
9966 // +----parent4(4)
9967 // +------child9(9)
9968 // +--------grand_child12(12)
9969 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339970 //
9971 // Expected scroll tree topology:
9972 // +property_tree_root---owner:-1
9973 // +--root---owner:1, id:1
9974 // +----node---owner:2, id:2
9975 // +------node---owner:6, id:3
9976 // +----node---owner:7, id:4
9977 // +------node---owner:11, id:5
9978 // +----node---owner:5, id:6
9979 //
9980 // Extra check:
9981 // scroll_tree_index() of:
9982 // grand_child10:3
9983 // parent3:1
9984 // child8:4
9985 // parent4:1
9986 // child9:1
9987 // grand_child12:1
loyso0940d412016-03-14 01:30:319988 scoped_refptr<Layer> root1 = Layer::Create();
9989 scoped_refptr<Layer> page_scale_layer = Layer::Create();
9990 scoped_refptr<Layer> parent2 = Layer::Create();
9991 scoped_refptr<Layer> parent3 = Layer::Create();
9992 scoped_refptr<Layer> parent4 = Layer::Create();
9993 scoped_refptr<Layer> parent5 = Layer::Create();
9994 scoped_refptr<Layer> child6 = Layer::Create();
9995 scoped_refptr<Layer> child7 = Layer::Create();
9996 scoped_refptr<Layer> child8 = Layer::Create();
9997 scoped_refptr<Layer> child9 = Layer::Create();
9998 scoped_refptr<Layer> grand_child10 = Layer::Create();
9999 scoped_refptr<Layer> grand_child11 = Layer::Create();
10000 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:3310001
sunxdcfccd1b32016-02-11 00:54:2010002 root1->AddChild(page_scale_layer);
10003 page_scale_layer->AddChild(parent2);
10004 page_scale_layer->AddChild(parent3);
10005 page_scale_layer->AddChild(parent4);
10006 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310007 parent2->AddChild(child6);
10008 parent3->AddChild(child7);
10009 parent3->AddChild(child8);
10010 parent4->AddChild(child9);
10011 child6->AddChild(grand_child10);
10012 child8->AddChild(grand_child11);
10013 child9->AddChild(grand_child12);
10014 host()->SetRootLayer(root1);
10015
pdrbbfd8822017-06-27 22:44:5210016 root1->SetBounds(gfx::Size(1, 1));
sunxdea1df782016-01-28 00:12:3310017 parent2->AddMainThreadScrollingReasons(
10018 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:4810019 parent2->AddMainThreadScrollingReasons(
10020 MainThreadScrollingReason::kScrollbarScrolling);
pdr54d038192017-06-08 22:44:1310021 parent2->SetElementId(LayerIdToElementIdForTesting(parent2->id()));
pdrbbfd8822017-06-27 22:44:5210022 parent2->SetScrollable(root1->bounds());
sunxdea1df782016-01-28 00:12:3310023 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810024 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310025 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810026 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310027
pdrbbfd8822017-06-27 22:44:5210028 parent3->SetBounds(gfx::Size(2, 2));
10029 child7->SetScrollable(parent3->bounds());
pdr54d038192017-06-08 22:44:1310030 child7->SetElementId(LayerIdToElementIdForTesting(child7->id()));
sunxdcfccd1b32016-02-11 00:54:2010031
sunxdea1df782016-01-28 00:12:3310032 child8->SetScrollParent(child7.get());
pdrbbfd8822017-06-27 22:44:5210033 child8->SetBounds(gfx::Size(3, 3));
10034 grand_child11->SetScrollable(child8->bounds());
pdr54d038192017-06-08 22:44:1310035 grand_child11->SetElementId(
10036 LayerIdToElementIdForTesting(grand_child11->id()));
sunxdea1df782016-01-28 00:12:3310037
10038 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010039 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310040
pdr5200a052017-05-21 22:50:5810041 LayerTreeHost::ViewportLayers viewport_layers;
10042 viewport_layers.page_scale = page_scale_layer;
10043 viewport_layers.inner_viewport_container = root1;
10044 viewport_layers.inner_viewport_scroll = parent2;
10045 host()->RegisterViewportLayers(viewport_layers);
jaydasika6ed869662016-09-21 14:29:5910046 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get());
sunxdea1df782016-01-28 00:12:3310047
sunxdea1df782016-01-28 00:12:3310048 const int kRootPropertyTreeNodeId = 0;
10049
10050 // Property tree root
ajumae4af47062016-05-24 23:59:0410051 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010052 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010053 property_trees.is_main_thread = true;
10054 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410055 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310056 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10057 property_tree_root->id = kRootPropertyTreeNodeId;
ajumaf884cfb2017-01-16 22:27:5210058 property_tree_root->parent_id = ScrollTree::kInvalidNodeId;
trchendba8b1502016-07-08 09:47:0110059 property_tree_root->scrollable = false;
10060 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810061 MainThreadScrollingReason::kNotScrollingOnMain;
pdr0283fabf2017-02-28 23:53:2410062 property_tree_root->non_fast_scrollable_region = Region();
trchendba8b1502016-07-08 09:47:0110063 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310064
10065 // The node owned by root1
10066 ScrollNode scroll_root1;
10067 scroll_root1.id = 1;
pdrbbfd8822017-06-27 22:44:5210068 scroll_root1.bounds = root1->bounds();
trchendba8b1502016-07-08 09:47:0110069 scroll_root1.user_scrollable_horizontal = true;
10070 scroll_root1.user_scrollable_vertical = true;
10071 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310072 expected_scroll_tree.Insert(scroll_root1, 0);
sunxdea1df782016-01-28 00:12:3310073
10074 // The node owned by parent2
10075 ScrollNode scroll_parent2;
10076 scroll_parent2.id = 2;
pdr54d038192017-06-08 22:44:1310077 scroll_parent2.element_id = parent2->element_id();
trchendba8b1502016-07-08 09:47:0110078 scroll_parent2.scrollable = true;
10079 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810080 parent2->main_thread_scrolling_reasons();
Philip Rogers0dd36f42017-06-30 23:33:3710081 scroll_parent2.container_bounds = root1->bounds();
trchendba8b1502016-07-08 09:47:0110082 scroll_parent2.bounds = parent2->bounds();
10083 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
pdrabe15522017-02-24 19:15:5610084 scroll_parent2.scrolls_inner_viewport = true;
trchendba8b1502016-07-08 09:47:0110085 scroll_parent2.user_scrollable_horizontal = true;
10086 scroll_parent2.user_scrollable_vertical = true;
10087 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310088 expected_scroll_tree.Insert(scroll_parent2, 1);
sunxdea1df782016-01-28 00:12:3310089
10090 // The node owned by child6
10091 ScrollNode scroll_child6;
10092 scroll_child6.id = 3;
trchendba8b1502016-07-08 09:47:0110093 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810094 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110095 scroll_child6.should_flatten = true;
10096 scroll_child6.user_scrollable_horizontal = true;
10097 scroll_child6.user_scrollable_vertical = true;
10098 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310099 expected_scroll_tree.Insert(scroll_child6, 2);
sunxdea1df782016-01-28 00:12:3310100
10101 // The node owned by child7, child7 also owns a transform node
10102 ScrollNode scroll_child7;
10103 scroll_child7.id = 4;
pdr54d038192017-06-08 22:44:1310104 scroll_child7.element_id = child7->element_id();
trchendba8b1502016-07-08 09:47:0110105 scroll_child7.scrollable = true;
Philip Rogers0dd36f42017-06-30 23:33:3710106 scroll_child7.container_bounds = parent3->bounds();
trchendba8b1502016-07-08 09:47:0110107 scroll_child7.bounds = child7->bounds();
10108 scroll_child7.user_scrollable_horizontal = true;
10109 scroll_child7.user_scrollable_vertical = true;
10110 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310111 expected_scroll_tree.Insert(scroll_child7, 1);
sunxdea1df782016-01-28 00:12:3310112
10113 // The node owned by grand_child11, grand_child11 also owns a transform node
10114 ScrollNode scroll_grand_child11;
10115 scroll_grand_child11.id = 5;
pdr54d038192017-06-08 22:44:1310116 scroll_grand_child11.element_id = grand_child11->element_id();
trchendba8b1502016-07-08 09:47:0110117 scroll_grand_child11.scrollable = true;
Philip Rogers0dd36f42017-06-30 23:33:3710118 scroll_grand_child11.container_bounds = child8->bounds();
trchendba8b1502016-07-08 09:47:0110119 scroll_grand_child11.user_scrollable_horizontal = true;
10120 scroll_grand_child11.user_scrollable_vertical = true;
10121 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310122 expected_scroll_tree.Insert(scroll_grand_child11, 4);
sunxdea1df782016-01-28 00:12:3310123
10124 // The node owned by parent5
10125 ScrollNode scroll_parent5;
10126 scroll_parent5.id = 8;
pdr0283fabf2017-02-28 23:53:2410127 scroll_parent5.non_fast_scrollable_region = gfx::Rect(0, 0, 50, 50);
trchendba8b1502016-07-08 09:47:0110128 scroll_parent5.bounds = gfx::Size(10, 10);
10129 scroll_parent5.should_flatten = true;
10130 scroll_parent5.user_scrollable_horizontal = true;
10131 scroll_parent5.user_scrollable_vertical = true;
10132 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310133 expected_scroll_tree.Insert(scroll_parent5, 1);
sunxdea1df782016-01-28 00:12:3310134
pdr54d038192017-06-08 22:44:1310135 expected_scroll_tree.SetScrollOffset(parent2->element_id(),
10136 gfx::ScrollOffset(0, 0));
10137 expected_scroll_tree.SetScrollOffset(child7->element_id(),
10138 gfx::ScrollOffset(0, 0));
10139 expected_scroll_tree.SetScrollOffset(grand_child11->element_id(),
sunxdc044b11a2016-03-16 16:23:2010140 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310141 expected_scroll_tree.set_needs_update(false);
10142
10143 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10144
10145 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010146 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310147 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10148 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10149 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10150 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10151 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10152 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10153}
10154
revemanb2b99a3b2017-04-06 23:39:0810155TEST_F(LayerTreeHostCommonTest, CanAdjustRasterScaleTest) {
10156 LayerImpl* root = root_layer_for_testing();
10157 LayerImpl* render_surface = AddChild<LayerImpl>(root);
10158 LayerImpl* child = AddChild<LayerImpl>(render_surface);
10159
10160 root->SetBounds(gfx::Size(50, 50));
10161
10162 render_surface->SetBounds(gfx::Size(10, 10));
10163 render_surface->test_properties()->force_render_surface = true;
10164 gfx::Transform transform;
10165 transform.Scale(5.f, 5.f);
10166 render_surface->test_properties()->transform = transform;
10167
10168 child->SetDrawsContent(true);
10169 child->SetMasksToBounds(true);
10170 child->SetBounds(gfx::Size(10, 10));
10171
10172 ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root);
10173
10174 // Check surface draw properties.
10175 EXPECT_EQ(gfx::Rect(10, 10),
chrishtr7e3aaf22017-05-04 15:04:0110176 GetRenderSurface(render_surface)->content_rect());
10177 EXPECT_EQ(transform, GetRenderSurface(render_surface)->draw_transform());
revemanb2b99a3b2017-04-06 23:39:0810178 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
chrishtr7e3aaf22017-05-04 15:04:0110179 GetRenderSurface(render_surface)->DrawableContentRect());
revemanb2b99a3b2017-04-06 23:39:0810180
10181 // Check child layer draw properties.
10182 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
10183 EXPECT_EQ(gfx::Transform(), child->DrawTransform());
10184 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect());
10185 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect());
10186}
10187
wutao834bd202017-07-14 01:12:5310188TEST_F(LayerTreeHostCommonTest, SurfaceContentsScaleChangeWithCopyRequestTest) {
10189 LayerImpl* root = root_layer_for_testing();
10190 LayerImpl* scale_layer = AddChild<LayerImpl>(root);
10191 LayerImpl* copy_layer = AddChild<LayerImpl>(scale_layer);
10192 LayerImpl* clip_layer = AddChild<LayerImpl>(copy_layer);
10193 LayerImpl* test_layer = AddChild<LayerImpl>(clip_layer);
10194
10195 root->SetBounds(gfx::Size(150, 150));
10196
10197 scale_layer->SetBounds(gfx::Size(30, 30));
10198 gfx::Transform transform;
10199 transform.Scale(5.f, 5.f);
10200 scale_layer->test_properties()->transform = transform;
10201
10202 // Need to persist the render surface after copy request is cleared.
10203 copy_layer->test_properties()->force_render_surface = true;
10204 copy_layer->test_properties()->copy_requests.push_back(
10205 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
10206
10207 clip_layer->SetDrawsContent(true);
10208 clip_layer->SetMasksToBounds(true);
10209 clip_layer->SetBounds(gfx::Size(10, 10));
10210
10211 test_layer->SetDrawsContent(true);
10212 test_layer->SetMasksToBounds(true);
10213 test_layer->SetBounds(gfx::Size(20, 20));
10214
10215 ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root);
10216
10217 // Check surface with copy request draw properties.
10218 EXPECT_EQ(gfx::Rect(50, 50), GetRenderSurface(copy_layer)->content_rect());
10219 EXPECT_EQ(gfx::Transform(), GetRenderSurface(copy_layer)->draw_transform());
10220 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
10221 GetRenderSurface(copy_layer)->DrawableContentRect());
10222
10223 // Check test layer draw properties.
10224 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect());
10225 EXPECT_EQ(transform, test_layer->DrawTransform());
10226 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
10227 EXPECT_EQ(gfx::Rect(50, 50), test_layer->drawable_content_rect());
10228
10229 // Clear the copy request and call UpdateSurfaceContentsScale.
10230 host_impl()->active_tree()->property_trees()->effect_tree.ClearCopyRequests();
10231 ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root);
10232
10233 // Check surface draw properties without copy request.
10234 EXPECT_EQ(gfx::Rect(10, 10), GetRenderSurface(copy_layer)->content_rect());
10235 EXPECT_EQ(transform, GetRenderSurface(copy_layer)->draw_transform());
10236 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
10237 GetRenderSurface(copy_layer)->DrawableContentRect());
10238
10239 // Check test layer draw properties without copy request.
10240 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect());
10241 EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform());
10242 EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect());
10243 EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect());
10244}
10245
[email protected]ba565742012-11-10 09:29:4810246} // namespace
10247} // namespace cc