blob: 206739946f256323873280e6b45ba688688277ad [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"
sunxd29f17bf2016-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]101441ce2012-10-16 01:45:0329#include "cc/test/animation_test_common.h"
vollick2175fae82015-04-27 21:18:1230#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1631#include "cc/test/fake_impl_task_runner_provider.h"
danakjc7afae52017-06-20 21:12:4132#include "cc/test/fake_layer_tree_frame_sink.h"
[email protected]d600df7d2013-08-03 02:34:2833#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4534#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5935#include "cc/test/fake_picture_layer.h"
36#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0337#include "cc/test/geometry_test_utils.h"
danakj59931942016-07-26 22:11:2938#include "cc/test/layer_test_common.h"
reveman34b7a1522015-03-23 20:27:4739#include "cc/test/test_task_graph_runner.h"
trchendba8b1502016-07-08 09:47:0140#include "cc/trees/clip_node.h"
ennef6903532015-08-18 05:10:1541#include "cc/trees/draw_property_utils.h"
trchendba8b1502016-07-08 09:47:0142#include "cc/trees/effect_node.h"
danakj59931942016-07-26 22:11:2943#include "cc/trees/property_tree_builder.h"
trchendba8b1502016-07-08 09:47:0144#include "cc/trees/scroll_node.h"
[email protected]556fd292013-03-18 08:03:0445#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1646#include "cc/trees/task_runner_provider.h"
trchendba8b1502016-07-08 09:47:0147#include "cc/trees/transform_node.h"
Fady Samueldfecb7d2017-07-26 11:41:0448#include "components/viz/common/quads/copy_output_request.h"
49#include "components/viz/common/quads/copy_output_result.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()));
Philip Rogers4131a1c12017-07-21 19:36:50531 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
532 gfx::Transform impl_transform;
jaydasika89f7b5a2016-06-22 02:08:39533 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
Philip Rogers4131a1c12017-07-21 19:36:50534 scroll_layer_scoped_ptr->layer_tree_impl()
535 ->property_trees()
536 ->scroll_tree.UpdateScrollOffsetBaseForTesting(
537 scroll_layer_scoped_ptr->element_id(), kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20538
danakj60bc3bc2016-04-09 00:24:48539 std::unique_ptr<LayerImpl> root(
540 LayerImpl::Create(host_impl.active_tree(), 3));
danakje4fa7b72016-07-25 22:00:06541 root->SetBounds(gfx::Size(3, 4));
pdrbbfd8822017-06-27 22:44:52542 root->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
jaydasika2411692c2016-03-23 01:56:09543 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59544 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
[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
Fady Samueldfecb7d2017-07-26 11:41:044806void EmptyCopyOutputCallback(std::unique_ptr<viz::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(
Fady Samueldfecb7d2017-07-26 11:41:044887 viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:534888 base::BindOnce(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:454889
ajumab784ef42017-04-28 23:01:524890 RenderSurfaceList render_surface_list;
weiliangc51fb255d2015-07-24 15:32:304891 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524892 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534893 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574894 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:454895
jaydasikaebc94282017-04-24 20:34:014896 EXPECT_TRUE(root_layer->has_copy_requests_in_target_subtree());
4897 EXPECT_TRUE(copy_grand_parent_layer->has_copy_requests_in_target_subtree());
4898 EXPECT_TRUE(copy_parent_layer->has_copy_requests_in_target_subtree());
4899 EXPECT_TRUE(copy_layer->has_copy_requests_in_target_subtree());
[email protected]ac020122013-07-12 23:45:534900
jaydasika86654512016-01-27 17:05:074901 // We should have four render surfaces, one for the root, one for the grand
4902 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:454903 // since it owns a surface, and one for the copy_layer.
ajumab784ef42017-04-28 23:01:524904 ASSERT_EQ(4u, render_surface_list.size());
Chris Harrelson9bdbcce2017-06-02 03:12:144905 EXPECT_EQ(static_cast<uint64_t>(root_layer->id()),
4906 render_surface_list.at(0)->id());
4907 EXPECT_EQ(static_cast<uint64_t>(copy_grand_parent_layer->id()),
4908 render_surface_list.at(1)->id());
4909 EXPECT_EQ(static_cast<uint64_t>(copy_parent_layer->id()),
4910 render_surface_list.at(2)->id());
4911 EXPECT_EQ(static_cast<uint64_t>(copy_layer->id()),
4912 render_surface_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:454913
jaydasika86654512016-01-27 17:05:074914 // The root render surface should have 2 contributing layers.
chrishtr7e3aaf22017-05-04 15:04:014915 EXPECT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454916 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
4917 EXPECT_FALSE(copy_grand_parent_layer->contributes_to_drawn_render_surface());
ajumab784ef42017-04-28 23:01:524918 EXPECT_FALSE(copy_grand_parent_sibling_before_layer
ajuma651848a2017-05-01 21:23:454919 ->contributes_to_drawn_render_surface());
ajumab784ef42017-04-28 23:01:524920 EXPECT_FALSE(copy_grand_parent_sibling_after_layer
ajuma651848a2017-05-01 21:23:454921 ->contributes_to_drawn_render_surface());
[email protected]30fe19ff2013-07-04 00:54:454922
[email protected]7392c7b2014-02-07 08:28:284923 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:454924 // appear in its list, since it needs to be drawn for the copy request.
chrishtr7e3aaf22017-05-04 15:04:014925 ASSERT_EQ(1, GetRenderSurface(copy_parent_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454926 EXPECT_FALSE(copy_parent_layer->contributes_to_drawn_render_surface());
[email protected]30fe19ff2013-07-04 00:54:454927
ajumab784ef42017-04-28 23:01:524928 // The copy layer's render surface should have 2 contributing layers.
chrishtr7e3aaf22017-05-04 15:04:014929 ASSERT_EQ(2, GetRenderSurface(copy_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:454930 EXPECT_TRUE(copy_layer->contributes_to_drawn_render_surface());
4931 EXPECT_TRUE(copy_child_layer->contributes_to_drawn_render_surface());
4932 EXPECT_FALSE(copy_grand_child_layer->contributes_to_drawn_render_surface());
jaydasika86654512016-01-27 17:05:074933
4934 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
4935 // but the copy_layer and copy_child should be drawn for the copy request.
4936 // copy grand child should not be drawn as its hidden even in the copy
4937 // request.
ajumae4af47062016-05-24 23:59:044938 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:094939 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:074940 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014941 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074942 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014943 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074944 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014945 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074946 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014947 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074948 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:014949 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:074950
4951 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
4952 // actually hidden.
chrishtr7e3aaf22017-05-04 15:04:014953 EXPECT_FALSE(GetRenderSurface(copy_layer)->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:454954}
4955
[email protected]989386c2013-07-18 21:37:234956TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:164957 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564958 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:224959 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:454960 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:454961
danakj60bc3bc2016-04-09 00:24:484962 std::unique_ptr<LayerImpl> root =
4963 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064964 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:304965 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:454966
danakj60bc3bc2016-04-09 00:24:484967 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:304968 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:304969 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:454970 copy_parent->SetMasksToBounds(true);
4971
danakj60bc3bc2016-04-09 00:24:484972 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:304973 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:064974 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:304975 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064976 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:454977
danakj60bc3bc2016-04-09 00:24:484978 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:304979 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:064980 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:304981 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:454982
ajumae6f541b2016-05-31 16:50:504983 copy_layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:044984 viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:534985 base::BindOnce(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:454986
jaydasika89f7b5a2016-06-22 02:08:394987 copy_layer->test_properties()->AddChild(std::move(copy_child));
4988 copy_parent->test_properties()->AddChild(std::move(copy_layer));
4989 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:304990
ajumab784ef42017-04-28 23:01:524991 RenderSurfaceList render_surface_list;
sunxd71aea3e2016-04-01 23:48:054992 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594993 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:304994 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:524995 root_layer, root_layer->bounds(), &render_surface_list);
[email protected]7aad55f2013-07-26 11:25:534996 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574997 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:454998
xjze19f76402015-11-06 21:48:444999 // We should have two render surface, as the others are clipped out.
ajumab784ef42017-04-28 23:01:525000 ASSERT_EQ(2u, render_surface_list.size());
Chris Harrelson9bdbcce2017-06-02 03:12:145001 EXPECT_EQ(static_cast<uint64_t>(root_layer->id()),
5002 render_surface_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455003
ajumab784ef42017-04-28 23:01:525004 // The root render surface should have only 2 contributing layer, since the
5005 // other layers are clipped away.
chrishtr7e3aaf22017-05-04 15:04:015006 ASSERT_EQ(2, GetRenderSurface(root_layer)->num_contributors());
ajuma651848a2017-05-01 21:23:455007 EXPECT_TRUE(root_layer->contributes_to_drawn_render_surface());
[email protected]30fe19ff2013-07-04 00:54:455008}
5009
jaydasika96e69462017-05-03 23:06:455010TEST_F(LayerTreeHostCommonTest, SingularTransformAndCopyRequests) {
5011 LayerImpl* root = root_layer_for_testing();
5012 root->SetBounds(gfx::Size(50, 50));
5013 root->SetDrawsContent(true);
5014
5015 LayerImpl* singular_transform_layer = AddChild<LayerImpl>(root);
5016 singular_transform_layer->SetBounds(gfx::Size(100, 100));
5017 singular_transform_layer->SetDrawsContent(true);
5018 gfx::Transform singular;
5019 singular.Scale3d(6.f, 6.f, 0.f);
5020 singular_transform_layer->test_properties()->transform = singular;
5021
5022 LayerImpl* copy_layer = AddChild<LayerImpl>(singular_transform_layer);
5023 copy_layer->SetBounds(gfx::Size(100, 100));
5024 copy_layer->SetDrawsContent(true);
5025 copy_layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:045026 viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:535027 base::BindOnce(&EmptyCopyOutputCallback)));
jaydasika96e69462017-05-03 23:06:455028
5029 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
5030 copy_child->SetBounds(gfx::Size(100, 100));
5031 copy_child->SetDrawsContent(true);
5032
5033 LayerImpl* copy_grand_child = AddChild<LayerImpl>(copy_child);
5034 copy_grand_child->SetBounds(gfx::Size(100, 100));
5035 copy_grand_child->SetDrawsContent(true);
5036 copy_grand_child->test_properties()->transform = singular;
5037
5038 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5039 ExecuteCalculateDrawProperties(root);
5040 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5041
5042 // A layer with singular transform should not contribute to drawn render
5043 // surface.
5044 EXPECT_FALSE(singular_transform_layer->contributes_to_drawn_render_surface());
5045 // Even though copy_layer and copy_child have singular screen space transform,
5046 // they still contribute to drawn render surface as their transform to the
5047 // closest ancestor with copy request is not singular.
5048 EXPECT_TRUE(copy_layer->contributes_to_drawn_render_surface());
5049 EXPECT_TRUE(copy_child->contributes_to_drawn_render_surface());
5050 // copy_grand_child's transform to its closest ancestor with copy request is
5051 // also singular. So, it doesn't contribute to drawn render surface.
5052 EXPECT_FALSE(copy_grand_child->contributes_to_drawn_render_surface());
5053}
5054
weiliangcde7e0c32016-06-15 15:02:415055TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595056 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065057 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415058 root->SetDrawsContent(true);
5059 root->SetMasksToBounds(true);
5060
5061 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065062 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415063 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065064 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415065
5066 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065067 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5068 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415069 copy_child->SetDrawsContent(true);
5070
5071 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065072 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415073 copy_clip->SetMasksToBounds(true);
5074
5075 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065076 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5077 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415078 copy_clipped_child->SetDrawsContent(true);
5079
5080 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065081 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5082 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415083 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065084 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415085
5086 copy_layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:045087 viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:535088 base::BindOnce(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415089
weiliangce22ce842016-07-04 23:31:535090 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415091 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535092 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415093
5094 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5095 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5096 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5097 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5098
5099 // Case 2: When the non root copy request layer is clipped.
5100 copy_layer->SetBounds(gfx::Size(50, 50));
5101 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535102 copy_layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:045103 viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:535104 base::BindOnce(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415105 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5106
weiliangce22ce842016-07-04 23:31:535107 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415108 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535109 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415110
5111 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5112 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5113 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5114 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515115
5116 // Case 3: When there is device scale factor.
5117 float device_scale_factor = 2.f;
5118 copy_layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:045119 viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:535120 base::BindOnce(&EmptyCopyOutputCallback)));
weiliangc296dd9f2016-07-05 14:59:515121
5122 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5123 ExecuteCalculateDrawProperties(root, device_scale_factor);
5124 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5125
5126 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5127 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5128 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5129 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415130}
5131
[email protected]420fdf6e2013-08-26 20:36:385132TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5133 // Ensure that a transform between the layer and its render surface is not a
5134 // problem. Constructs the following layer tree.
5135 //
5136 // root (a render surface)
5137 // + render_surface
5138 // + clip_parent (scaled)
5139 // + intervening_clipping_layer
5140 // + clip_child
5141 //
5142 // The render surface should be resized correctly and the clip child should
5143 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595144 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315145 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5146 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285147 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315148 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285149 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315150 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5151 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565152 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485153 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315154 clip_children->insert(clip_child);
gogag217889152017-03-13 14:34:425155 clip_parent->test_properties()->clip_children = std::move(clip_children);
[email protected]420fdf6e2013-08-26 20:36:385156
5157 intervening->SetMasksToBounds(true);
5158 clip_parent->SetMasksToBounds(true);
5159
[email protected]420fdf6e2013-08-26 20:36:385160 gfx::Transform scale_transform;
5161 scale_transform.Scale(2, 2);
5162
danakjf78fb272016-07-26 19:06:155163 root->SetBounds(gfx::Size(50, 50));
5164 render_surface->SetBounds(gfx::Size(10, 10));
5165 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:045166 clip_parent->test_properties()->transform = scale_transform;
danakjf78fb272016-07-26 19:06:155167 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5168 clip_parent->SetBounds(gfx::Size(10, 10));
5169 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5170 intervening->SetBounds(gfx::Size(5, 5));
5171 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5172 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315173 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385174
chrishtr7e3aaf22017-05-04 15:04:015175 ASSERT_TRUE(GetRenderSurface(root));
5176 ASSERT_TRUE(GetRenderSurface(render_surface));
[email protected]420fdf6e2013-08-26 20:36:385177
5178 // Ensure that we've inherited our clip parent's clip and weren't affected
5179 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145180 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5181 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5182 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385183
5184 // Ensure that the render surface reports a content rect that has been grown
5185 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145186 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
chrishtr7e3aaf22017-05-04 15:04:015187 GetRenderSurface(render_surface)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385188
5189 // The above check implies the two below, but they nicely demonstrate that
5190 // we've grown, despite the intervening layer's clip.
5191 ASSERT_TRUE(clip_parent->clip_rect().Contains(
chrishtr7e3aaf22017-05-04 15:04:015192 GetRenderSurface(render_surface)->content_rect()));
[email protected]420fdf6e2013-08-26 20:36:385193 ASSERT_FALSE(intervening->clip_rect().Contains(
chrishtr7e3aaf22017-05-04 15:04:015194 GetRenderSurface(render_surface)->content_rect()));
[email protected]420fdf6e2013-08-26 20:36:385195}
5196
5197TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5198 // Ensure that intervening render surfaces are not a problem in the basic
5199 // case. In the following tree, both render surfaces should be resized to
5200 // accomodate for the clip child, despite an intervening clip.
5201 //
5202 // root (a render surface)
5203 // + clip_parent (masks to bounds)
5204 // + render_surface1 (sets opacity)
5205 // + intervening (masks to bounds)
5206 // + render_surface2 (also sets opacity)
5207 // + clip_child
5208 //
jaydasikabf1875a2016-06-28 03:39:595209 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235210 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5211 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5212 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5213 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5214 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365215 render_surface1->SetDrawsContent(true);
5216 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235217 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385218
jaydasika1c0a27d42016-04-28 01:54:565219 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385220
5221 intervening->SetMasksToBounds(true);
5222 clip_parent->SetMasksToBounds(true);
5223
[email protected]420fdf6e2013-08-26 20:36:385224 gfx::Transform translation_transform;
5225 translation_transform.Translate(2, 2);
5226
danakjf78fb272016-07-26 19:06:155227 root->SetBounds(gfx::Size(50, 50));
5228 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5229 clip_parent->SetBounds(gfx::Size(40, 40));
5230 render_surface1->SetBounds(gfx::Size(10, 10));
5231 render_surface1->test_properties()->force_render_surface = true;
5232 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5233 intervening->SetBounds(gfx::Size(5, 5));
5234 render_surface2->SetBounds(gfx::Size(10, 10));
5235 render_surface2->test_properties()->force_render_surface = true;
5236 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5237 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235238 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385239
chrishtr7e3aaf22017-05-04 15:04:015240 EXPECT_TRUE(GetRenderSurface(root));
5241 EXPECT_TRUE(GetRenderSurface(render_surface1));
5242 EXPECT_TRUE(GetRenderSurface(render_surface2));
[email protected]420fdf6e2013-08-26 20:36:385243
jaydasika1553a142017-04-05 00:37:095244 // render_surface1 should apply the clip from clip_parent. Though there is a
5245 // clip child, render_surface1 can apply the clip as there are no clips
5246 // between the clip parent and render_surface1
5247 EXPECT_EQ(gfx::Rect(1, 1, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015248 GetRenderSurface(render_surface1)->clip_rect());
5249 EXPECT_TRUE(GetRenderSurface(render_surface1)->is_clipped());
jaydasika1553a142017-04-05 00:37:095250 EXPECT_EQ(gfx::Rect(), render_surface1->clip_rect());
5251 EXPECT_FALSE(render_surface1->is_clipped());
5252
5253 // render_surface2 could have expanded, as there is a clip between
5254 // clip_child's clip (clip_parent) and render_surface2's clip (intervening).
5255 // So, it should not be clipped (their bounds would no longer be reliable).
5256 // We should resort to layer clipping in this case.
jaydasika6f972de2016-04-07 16:16:145257 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
chrishtr7e3aaf22017-05-04 15:04:015258 GetRenderSurface(render_surface2)->clip_rect());
5259 EXPECT_FALSE(GetRenderSurface(render_surface2)->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385260
[email protected]420fdf6e2013-08-26 20:36:385261 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145262 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385263 EXPECT_TRUE(render_surface2->is_clipped());
5264
jaydasika1553a142017-04-05 00:37:095265 // The content rects of render_surface2 should have expanded to contain the
5266 // clip child.
jaydasika6f972de2016-04-07 16:16:145267 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015268 GetRenderSurface(render_surface1)->content_rect());
jaydasika1553a142017-04-05 00:37:095269 EXPECT_EQ(gfx::Rect(-10, -10, 60, 60),
chrishtr7e3aaf22017-05-04 15:04:015270 GetRenderSurface(render_surface2)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385271
5272 // The clip child should have inherited the clip parent's clip (projected to
jaydasika1553a142017-04-05 00:37:095273 // the right space, of course), but as render_surface1 already applies that
5274 // clip, clip_child need not apply it again.
5275 EXPECT_EQ(gfx::Rect(), clip_child->clip_rect());
jaydasika6f972de2016-04-07 16:16:145276 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
jaydasika1553a142017-04-05 00:37:095277 EXPECT_FALSE(clip_child->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385278}
5279
5280TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5281 // Ensure that intervening render surfaces are not a problem, even if there
5282 // is a scroll involved. Note, we do _not_ have to consider any other sort
5283 // of transform.
5284 //
5285 // root (a render surface)
5286 // + clip_parent (masks to bounds)
5287 // + render_surface1 (sets opacity)
5288 // + intervening (masks to bounds AND scrolls)
5289 // + render_surface2 (also sets opacity)
5290 // + clip_child
5291 //
jaydasikabf1875a2016-06-28 03:39:595292 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235293 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5294 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5295 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5296 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5297 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365298 render_surface1->SetDrawsContent(true);
5299 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235300 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385301
jaydasika1c0a27d42016-04-28 01:54:565302 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385303
5304 intervening->SetMasksToBounds(true);
5305 clip_parent->SetMasksToBounds(true);
pdrbbfd8822017-06-27 22:44:525306 intervening->SetScrollable(gfx::Size(1, 1));
pdr54d038192017-06-08 22:44:135307 intervening->SetElementId(LayerIdToElementIdForTesting(intervening->id()));
Philip Rogers4131a1c12017-07-21 19:36:505308 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385309
5310 gfx::Transform translation_transform;
5311 translation_transform.Translate(2, 2);
5312
danakjf78fb272016-07-26 19:06:155313 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:045314 clip_parent->test_properties()->transform = translation_transform;
danakjf78fb272016-07-26 19:06:155315 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5316 clip_parent->SetBounds(gfx::Size(40, 40));
5317 render_surface1->SetBounds(gfx::Size(10, 10));
5318 render_surface1->test_properties()->force_render_surface = true;
5319 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5320 intervening->SetBounds(gfx::Size(5, 5));
5321 render_surface2->SetBounds(gfx::Size(10, 10));
5322 render_surface2->test_properties()->force_render_surface = true;
5323 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5324 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235325 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385326
chrishtr7e3aaf22017-05-04 15:04:015327 EXPECT_TRUE(GetRenderSurface(root));
5328 EXPECT_TRUE(GetRenderSurface(render_surface1));
5329 EXPECT_TRUE(GetRenderSurface(render_surface2));
[email protected]420fdf6e2013-08-26 20:36:385330
jaydasika1553a142017-04-05 00:37:095331 // render_surface1 should apply the clip from clip_parent. Though there is a
5332 // clip child, render_surface1 can apply the clip as there are no clips
5333 // between the clip parent and render_surface1
5334 EXPECT_EQ(gfx::Rect(3, 3, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015335 GetRenderSurface(render_surface1)->clip_rect());
5336 EXPECT_TRUE(GetRenderSurface(render_surface1)->is_clipped());
jaydasika1553a142017-04-05 00:37:095337 EXPECT_EQ(gfx::Rect(), render_surface1->clip_rect());
5338 EXPECT_FALSE(render_surface1->is_clipped());
5339
5340 // render_surface2 could have expanded, as there is a clip between
5341 // clip_child's clip (clip_parent) and render_surface2's clip (intervening).
5342 // So, it should not be clipped (their bounds would no longer be reliable).
5343 // We should resort to layer clipping in this case.
jaydasika6f972de2016-04-07 16:16:145344 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
chrishtr7e3aaf22017-05-04 15:04:015345 GetRenderSurface(render_surface2)->clip_rect());
5346 EXPECT_FALSE(GetRenderSurface(render_surface2)->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385347 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika1553a142017-04-05 00:37:095348 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385349 EXPECT_TRUE(render_surface2->is_clipped());
5350
jaydasika1553a142017-04-05 00:37:095351 // The content rects of render_surface2 should have expanded to contain the
5352 // clip child.
jaydasika6f972de2016-04-07 16:16:145353 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
chrishtr7e3aaf22017-05-04 15:04:015354 GetRenderSurface(render_surface1)->content_rect());
jaydasika1553a142017-04-05 00:37:095355 EXPECT_EQ(gfx::Rect(-10, -10, 60, 60),
chrishtr7e3aaf22017-05-04 15:04:015356 GetRenderSurface(render_surface2)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385357
5358 // The clip child should have inherited the clip parent's clip (projected to
jaydasika1553a142017-04-05 00:37:095359 // the right space, of course), but as render_surface1 already applies that
5360 // clip, clip_child need not apply it again.
5361 EXPECT_EQ(gfx::Rect(), clip_child->clip_rect());
jaydasika6f972de2016-04-07 16:16:145362 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
jaydasika1553a142017-04-05 00:37:095363 EXPECT_FALSE(clip_child->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385364}
5365
5366TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5367 // Ensures that descendants of the clip child inherit the correct clip.
5368 //
5369 // root (a render surface)
5370 // + clip_parent (masks to bounds)
5371 // + intervening (masks to bounds)
5372 // + clip_child
5373 // + child
5374 //
jaydasikabf1875a2016-06-28 03:39:595375 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175376 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5377 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5378 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5379 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365380 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175381 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385382
jaydasika1c0a27d42016-04-28 01:54:565383 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155384 clip_parent->test_properties()->clip_children =
5385 base::MakeUnique<std::set<LayerImpl*>>();
5386 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385387
danakjf78fb272016-07-26 19:06:155388 root->SetBounds(gfx::Size(50, 50));
5389 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385390 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155391 intervening->SetBounds(gfx::Size(5, 5));
5392 intervening->SetMasksToBounds(true);
5393 clip_child->SetBounds(gfx::Size(60, 60));
5394 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385395
enne2d0d8e62015-08-18 18:29:175396 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385397
chrishtr7e3aaf22017-05-04 15:04:015398 EXPECT_TRUE(GetRenderSurface(root));
[email protected]420fdf6e2013-08-26 20:36:385399
5400 // Neither the clip child nor its descendant should have inherited the clip
5401 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145402 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385403 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145404 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385405 EXPECT_TRUE(child->is_clipped());
5406}
5407
5408TEST_F(LayerTreeHostCommonTest,
5409 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5410 // Ensures that non-descendant clip children in the tree do not affect
5411 // render surfaces.
5412 //
5413 // root (a render surface)
5414 // + clip_parent (masks to bounds)
jaydasika1553a142017-04-05 00:37:095415 // + clip_layer (masks to bounds)
5416 // + render_surface1
5417 // + clip_child
5418 // + render_surface2
5419 // + non_clip_child
[email protected]420fdf6e2013-08-26 20:36:385420 //
5421 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595422 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505423 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
jaydasika1553a142017-04-05 00:37:095424 LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent);
5425 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer);
enneb441cdd2015-07-28 22:47:505426 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
jaydasika1553a142017-04-05 00:37:095427 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_layer);
enneb441cdd2015-07-28 22:47:505428 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385429
jaydasika1c0a27d42016-04-28 01:54:565430 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155431 clip_parent->test_properties()->clip_children =
5432 base::MakeUnique<std::set<LayerImpl*>>();
5433 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385434
5435 clip_parent->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:095436 clip_layer->SetMasksToBounds(true);
[email protected]420fdf6e2013-08-26 20:36:385437
danakjf78fb272016-07-26 19:06:155438 render_surface1->SetDrawsContent(true);
5439 clip_child->SetDrawsContent(true);
5440 render_surface2->SetDrawsContent(true);
5441 non_clip_child->SetDrawsContent(true);
5442
5443 root->SetBounds(gfx::Size(15, 15));
5444 clip_parent->SetBounds(gfx::Size(10, 10));
jaydasika1553a142017-04-05 00:37:095445 clip_layer->SetBounds(gfx::Size(10, 10));
danakjf78fb272016-07-26 19:06:155446 render_surface1->SetPosition(gfx::PointF(5, 5));
5447 render_surface1->SetBounds(gfx::Size(5, 5));
5448 render_surface1->test_properties()->force_render_surface = true;
5449 render_surface2->SetBounds(gfx::Size(5, 5));
5450 render_surface2->test_properties()->force_render_surface = true;
5451 clip_child->SetPosition(gfx::PointF(-1, 1));
5452 clip_child->SetBounds(gfx::Size(10, 10));
5453 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:385454
enneb441cdd2015-07-28 22:47:505455 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385456
chrishtr7e3aaf22017-05-04 15:04:015457 EXPECT_TRUE(GetRenderSurface(root));
5458 EXPECT_TRUE(GetRenderSurface(render_surface1));
5459 EXPECT_TRUE(GetRenderSurface(render_surface2));
[email protected]420fdf6e2013-08-26 20:36:385460
jaydasika1553a142017-04-05 00:37:095461 EXPECT_EQ(gfx::Rect(-5, -5, 10, 10), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385462 EXPECT_TRUE(render_surface1->is_clipped());
5463
5464 // The render surface should not clip (it has unclipped descendants), instead
5465 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:145466 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
chrishtr7e3aaf22017-05-04 15:04:015467 GetRenderSurface(render_surface1)->clip_rect());
5468 EXPECT_FALSE(GetRenderSurface(render_surface1)->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385469
jaydasika0d98ba92015-11-17 05:17:285470 // That said, it should have grown to accomodate the unclipped descendant and
5471 // its own size.
jaydasika6f972de2016-04-07 16:16:145472 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
chrishtr7e3aaf22017-05-04 15:04:015473 GetRenderSurface(render_surface1)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385474
5475 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:145476 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
chrishtr7e3aaf22017-05-04 15:04:015477 GetRenderSurface(render_surface2)->clip_rect());
5478 EXPECT_TRUE(GetRenderSurface(render_surface2)->is_clipped());
weiliangcbb2e8642016-03-04 00:24:425479 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385480
5481 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:145482 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
chrishtr7e3aaf22017-05-04 15:04:015483 GetRenderSurface(render_surface2)->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385484}
5485
weiliangc9ced1592015-11-17 19:04:375486TEST_F(LayerTreeHostCommonTest,
5487 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5488 // Verifies that Render Surfaces are created at the edge of rendering context.
5489
jaydasikabf1875a2016-06-28 03:39:595490 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:265491 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
5492 LayerImpl* child2 = AddChild<LayerImpl>(child1);
5493 LayerImpl* child3 = AddChild<LayerImpl>(child2);
5494 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375495
weiliangc9ced1592015-11-17 19:04:375496 gfx::Size bounds(100, 100);
5497
danakjf78fb272016-07-26 19:06:155498 root->SetBounds(bounds);
5499 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265500 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155501 child1->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:205502 child1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155503 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265504 child2->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:205505 child2->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155506 child3->SetBounds(bounds);
5507 child3->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:205508 child3->test_properties()->sorting_context_id = 1;
jaydasika6ed869662016-09-21 14:29:595509 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
weiliangc9ced1592015-11-17 19:04:375510
5511 // Verify which render surfaces were created.
chrishtr7e3aaf22017-05-04 15:04:015512 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:495513 EXPECT_EQ(GetRenderSurface(child1), GetRenderSurface(root));
5514 EXPECT_NE(GetRenderSurface(child2), GetRenderSurface(root));
5515 EXPECT_EQ(GetRenderSurface(child3), GetRenderSurface(child2));
weiliangc9ced1592015-11-17 19:04:375516}
5517
[email protected]a9aa60a82013-08-29 04:28:265518TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:595519 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:335520 LayerImpl* back_facing = AddChild<LayerImpl>(root);
trchen75204782016-11-03 01:05:425521
jaydasikae00c8a42016-01-28 20:18:335522 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
jaydasikae00c8a42016-01-28 20:18:335523 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
trchen75204782016-11-03 01:05:425524
5525 LayerImpl* flattener = AddChild<LayerImpl>(back_facing);
5526 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener);
jaydasikae00c8a42016-01-28 20:18:335527 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:155528
jaydasikae00c8a42016-01-28 20:18:335529 child1->SetDrawsContent(true);
5530 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:265531
danakjf78fb272016-07-26 19:06:155532 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:155533 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:525534 back_facing->test_properties()->should_flatten_transform = false;
trchen75204782016-11-03 01:05:425535
danakjf78fb272016-07-26 19:06:155536 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155537 render_surface1->test_properties()->should_flatten_transform = false;
5538 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:365539 render_surface1->test_properties()->double_sided = false;
trchen75204782016-11-03 01:05:425540 child1->SetBounds(gfx::Size(20, 20));
5541
5542 flattener->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155543 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155544 render_surface2->test_properties()->should_flatten_transform = false;
5545 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:365546 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155547 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:265548
enne03b0e9a2015-06-19 00:08:025549 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:265550
ajumab784ef42017-04-28 23:01:525551 EXPECT_EQ(3u, render_surface_list_impl()->size());
5552 EXPECT_EQ(2, render_surface_list_impl()->at(0)->num_contributors());
5553 EXPECT_EQ(1, render_surface_list_impl()->at(1)->num_contributors());
[email protected]a9aa60a82013-08-29 04:28:265554
danakjf78fb272016-07-26 19:06:155555 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:265556 rotation_transform.RotateAboutXAxis(180.0);
5557
jaydasika10d43fc2016-08-18 04:06:045558 back_facing->test_properties()->transform = rotation_transform;
jaydasika5aa88b82015-11-10 01:48:035559 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:265560
enne03b0e9a2015-06-19 00:08:025561 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:265562
jaydasikae00c8a42016-01-28 20:18:335563 // render_surface1 is in the same 3d rendering context as back_facing and is
5564 // not double sided, so it should not be in RSLL. render_surface2 is also not
5565 // double-sided, but will still be in RSLL as it's in a different 3d rendering
5566 // context.
ajumab784ef42017-04-28 23:01:525567 EXPECT_EQ(2u, render_surface_list_impl()->size());
5568 EXPECT_EQ(1, render_surface_list_impl()->at(0)->num_contributors());
[email protected]a9aa60a82013-08-29 04:28:265569}
5570
ajumaaa0d3862015-11-09 22:24:465571TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:595572 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:465573 LayerImpl* child = AddChild<LayerImpl>(root);
5574 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:465575
danakjf78fb272016-07-26 19:06:155576 root->SetBounds(gfx::Size(50, 50));
5577 root->test_properties()->should_flatten_transform = false;
5578 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:365579 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155580 child->test_properties()->should_flatten_transform = false;
5581 grand_child->SetBounds(gfx::Size(20, 20));
5582 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:465583 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:155584 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:465585 ExecuteCalculateDrawProperties(root);
5586
ajumab784ef42017-04-28 23:01:525587 EXPECT_EQ(1u, render_surface_list_impl()->size());
ajuma651848a2017-05-01 21:23:455588 EXPECT_TRUE(grand_child->contributes_to_drawn_render_surface());
jaydasika62bd3dd2016-02-04 18:52:555589
Chris Harrelsondaececa42017-06-16 20:42:025590 // A ll layers with invisible backfgaces should be checked.
jaydasika62bd3dd2016-02-04 18:52:555591 EXPECT_FALSE(root->should_check_backface_visibility());
Chris Harrelsondaececa42017-06-16 20:42:025592 EXPECT_TRUE(child->should_check_backface_visibility());
5593 EXPECT_TRUE(grand_child->should_check_backface_visibility());
jaydasika62bd3dd2016-02-04 18:52:555594
danakjf78fb272016-07-26 19:06:155595 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:465596 rotation_transform.RotateAboutXAxis(180.0);
5597
jaydasika10d43fc2016-08-18 04:06:045598 child->test_properties()->transform = rotation_transform;
wkormanf09921d2017-01-07 01:01:205599 child->test_properties()->sorting_context_id = 1;
5600 grand_child->test_properties()->sorting_context_id = 1;
ajumaaa0d3862015-11-09 22:24:465601 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
5602
5603 ExecuteCalculateDrawProperties(root);
ajumab784ef42017-04-28 23:01:525604 EXPECT_EQ(1u, render_surface_list_impl()->size());
5605 EXPECT_EQ(0, render_surface_list_impl()->at(0)->num_contributors());
jaydasika62bd3dd2016-02-04 18:52:555606
5607 // We should check for backface visibilty of child as it has a rotation
5608 // transform. We should also check for grand_child as it uses the backface
5609 // visibility of its parent.
5610 EXPECT_FALSE(root->should_check_backface_visibility());
5611 EXPECT_TRUE(child->should_check_backface_visibility());
5612 EXPECT_TRUE(grand_child->should_check_backface_visibility());
jaydasika62bd3dd2016-02-04 18:52:555613
5614 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:365615 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:555616 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
5617
5618 ExecuteCalculateDrawProperties(root);
ajumab784ef42017-04-28 23:01:525619 EXPECT_EQ(1u, render_surface_list_impl()->size());
5620 EXPECT_EQ(0, render_surface_list_impl()->at(0)->num_contributors());
jaydasika62bd3dd2016-02-04 18:52:555621
5622 // We should check the backface visibility of child as it has a rotation
5623 // transform and for grand_child as it is in a 3d rendering context and not
5624 // the root of it.
5625 EXPECT_FALSE(root->should_check_backface_visibility());
5626 EXPECT_TRUE(child->should_check_backface_visibility());
5627 EXPECT_TRUE(grand_child->should_check_backface_visibility());
ajumaaa0d3862015-11-09 22:24:465628}
5629
sunxd59dd7da2016-05-19 20:07:475630TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:595631 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:475632 LayerImpl* back_facing = AddChild<LayerImpl>(root);
5633 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
5634 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
5635
sunxd59dd7da2016-05-19 20:07:475636 gfx::Transform rotate_about_y;
5637 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:475638
danakjf78fb272016-07-26 19:06:155639 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:155640 root->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:205641 root->test_properties()->sorting_context_id = 1;
jaydasika10d43fc2016-08-18 04:06:045642 back_facing->test_properties()->transform = rotate_about_y;
danakjf78fb272016-07-26 19:06:155643 back_facing->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:155644 back_facing->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:205645 back_facing->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155646 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155647 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:475648 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155649 render_surface1->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205650 render_surface1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155651 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:155652 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:475653 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155654 render_surface2->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205655 render_surface2->test_properties()->sorting_context_id = 1;
weiliangcea09f3372017-03-29 16:43:245656 SetElementIdsForTesting();
sunxd59dd7da2016-05-19 20:07:475657 ExecuteCalculateDrawProperties(root);
5658
5659 const EffectTree& tree =
5660 root->layer_tree_impl()->property_trees()->effect_tree;
5661 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:015662 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475663 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:015664 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475665
weiliangcea09f3372017-03-29 16:43:245666 root->layer_tree_impl()->SetTransformMutated(back_facing->element_id(),
5667 gfx::Transform());
5668 root->layer_tree_impl()->SetTransformMutated(render_surface2->element_id(),
5669 rotate_about_y);
sunxd59dd7da2016-05-19 20:07:475670 ExecuteCalculateDrawProperties(root);
5671 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:015672 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475673 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:015674 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475675
weiliangcea09f3372017-03-29 16:43:245676 root->layer_tree_impl()->SetTransformMutated(render_surface1->element_id(),
5677 rotate_about_y);
sunxd59dd7da2016-05-19 20:07:475678 ExecuteCalculateDrawProperties(root);
5679 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:015680 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475681 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:015682 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:475683}
5684
[email protected]995708c52013-10-17 20:52:595685TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
5686 // Checks that the simple case (being clipped by a scroll parent that would
5687 // have been processed before you anyhow) results in the right clips.
5688 //
5689 // + root
5690 // + scroll_parent_border
5691 // | + scroll_parent_clip
5692 // | + scroll_parent
5693 // + scroll_child
5694 //
jaydasikabf1875a2016-06-28 03:39:595695 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:485696 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
5697 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5698 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5699 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:595700
enne085b48a2015-08-18 17:54:485701 scroll_parent->SetDrawsContent(true);
5702 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595703 scroll_parent_clip->SetMasksToBounds(true);
5704
jaydasika1c0a27d42016-04-28 01:54:565705 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155706 scroll_parent->test_properties()->scroll_children =
5707 base::MakeUnique<std::set<LayerImpl*>>();
5708 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:595709
danakjf78fb272016-07-26 19:06:155710 root->SetBounds(gfx::Size(50, 50));
5711 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5712 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
5713 scroll_parent->SetBounds(gfx::Size(50, 50));
5714 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:485715 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595716
chrishtr7e3aaf22017-05-04 15:04:015717 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595718
jaydasika6f972de2016-04-07 16:16:145719 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595720 EXPECT_TRUE(scroll_child->is_clipped());
5721}
5722
jaydasika8ccff3d2016-01-20 19:51:305723TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
5724 // Tests the computation of draw transform for the scroll child when its
5725 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:595726 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:305727 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
5728 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
5729 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
5730 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
5731
5732 scroll_parent->SetDrawsContent(true);
5733 scroll_child->SetDrawsContent(true);
5734
jaydasika1c0a27d42016-04-28 01:54:565735 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155736 scroll_parent->test_properties()->scroll_children =
5737 base::MakeUnique<std::set<LayerImpl*>>();
5738 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:305739
danakjf78fb272016-07-26 19:06:155740 root->SetBounds(gfx::Size(50, 50));
5741 scroll_child_target->SetBounds(gfx::Size(50, 50));
5742 scroll_child_target->test_properties()->force_render_surface = true;
5743 scroll_child->SetBounds(gfx::Size(50, 50));
5744 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
5745 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:005746 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155747 scroll_parent_target->test_properties()->force_render_surface = true;
5748 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:305749
jaydasika2489a442016-01-29 02:26:005750 float device_scale_factor = 1.5f;
ajumab784ef42017-04-28 23:01:525751 RenderSurfaceList render_surface_list_impl;
jaydasikab4df4032016-09-13 18:38:495752 gfx::Size device_viewport_size =
5753 gfx::Size(root->bounds().width() * device_scale_factor,
5754 root->bounds().height() * device_scale_factor);
jaydasika2489a442016-01-29 02:26:005755 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:525756 root, device_viewport_size, gfx::Transform(), &render_surface_list_impl);
jaydasika2489a442016-01-29 02:26:005757 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:575758 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:005759
weiliangc1da3fb892016-03-14 20:23:525760 EXPECT_EQ(scroll_child->effect_tree_index(),
5761 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:005762 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
5763 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
5764 gfx::Transform scale;
5765 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:025766 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:305767}
5768
[email protected]08bdf1b2014-04-16 23:23:295769TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:595770 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:195771 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:195772 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:155773
5774 root->SetBounds(gfx::Size(50, 50));
5775 root->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:205776 root->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155777 parent->SetBounds(gfx::Size(30, 30));
5778 parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155779 parent->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205780 parent->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:155781 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:195782 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155783 child->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:205784 child->test_properties()->sorting_context_id = 1;
enneca33fed2015-07-27 18:22:195785 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:295786
ajumab784ef42017-04-28 23:01:525787 EXPECT_EQ(3u, render_surface_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:295788
5789 gfx::Transform singular_transform;
5790 singular_transform.Scale3d(
5791 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5792
jaydasika10d43fc2016-08-18 04:06:045793 child->test_properties()->transform = singular_transform;
[email protected]08bdf1b2014-04-16 23:23:295794
sunxd71aea3e2016-04-01 23:48:055795 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:195796 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:295797
ajumab784ef42017-04-28 23:01:525798 EXPECT_EQ(2u, render_surface_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:295799
5800 // Ensure that the entire subtree under a layer with singular transform does
5801 // not get rendered.
jaydasika10d43fc2016-08-18 04:06:045802 parent->test_properties()->transform = singular_transform;
5803 child->test_properties()->transform = gfx::Transform();
[email protected]08bdf1b2014-04-16 23:23:295804
sunxd71aea3e2016-04-01 23:48:055805 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:195806 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:295807
ajumab784ef42017-04-28 23:01:525808 EXPECT_EQ(1u, render_surface_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:295809}
5810
[email protected]995708c52013-10-17 20:52:595811TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
5812 // Checks that clipping by a scroll parent that follows you in paint order
5813 // still results in correct clipping.
5814 //
5815 // + root
[email protected]995708c52013-10-17 20:52:595816 // + scroll_parent_border
5817 // + scroll_parent_clip
5818 // + scroll_parent
enne03b0e9a2015-06-19 00:08:025819 // + scroll_child
[email protected]995708c52013-10-17 20:52:595820 //
jaydasikabf1875a2016-06-28 03:39:595821 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:025822 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5823 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5824 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5825 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:595826
enne03b0e9a2015-06-19 00:08:025827 scroll_parent->SetDrawsContent(true);
5828 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595829
danakjf78fb272016-07-26 19:06:155830 root->SetBounds(gfx::Size(50, 50));
5831 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5832 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:595833 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155834 scroll_parent->SetBounds(gfx::Size(50, 50));
5835 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:595836
jaydasika1c0a27d42016-04-28 01:54:565837 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155838 scroll_parent->test_properties()->scroll_children =
5839 base::MakeUnique<std::set<LayerImpl*>>();
5840 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:595841
enne03b0e9a2015-06-19 00:08:025842 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595843
chrishtr7e3aaf22017-05-04 15:04:015844 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595845
jaydasika6f972de2016-04-07 16:16:145846 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595847 EXPECT_TRUE(scroll_child->is_clipped());
5848}
5849
5850TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
5851 // Checks that clipping by a scroll parent and scroll grandparent that follow
5852 // you in paint order still results in correct clipping.
5853 //
5854 // + root
5855 // + scroll_child
5856 // + scroll_parent_border
5857 // | + scroll_parent_clip
5858 // | + scroll_parent
5859 // + scroll_grandparent_border
5860 // + scroll_grandparent_clip
5861 // + scroll_grandparent
5862 //
jaydasikabf1875a2016-06-28 03:39:595863 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:025864 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5865 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5866 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5867 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5868 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5869 LayerImpl* scroll_grandparent_clip =
5870 AddChild<LayerImpl>(scroll_grandparent_border);
5871 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:595872
enne03b0e9a2015-06-19 00:08:025873 scroll_parent->SetDrawsContent(true);
5874 scroll_grandparent->SetDrawsContent(true);
5875 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595876
5877 scroll_parent_clip->SetMasksToBounds(true);
5878 scroll_grandparent_clip->SetMasksToBounds(true);
5879
jaydasika1c0a27d42016-04-28 01:54:565880 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155881 scroll_parent->test_properties()->scroll_children =
5882 base::MakeUnique<std::set<LayerImpl*>>();
5883 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:385884
jaydasika1c0a27d42016-04-28 01:54:565885 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:155886 scroll_grandparent->test_properties()->scroll_children =
5887 base::MakeUnique<std::set<LayerImpl*>>();
5888 scroll_grandparent->test_properties()->scroll_children->insert(
5889 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:595890
danakjf78fb272016-07-26 19:06:155891 root->SetBounds(gfx::Size(50, 50));
5892 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
5893 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
5894 scroll_grandparent->SetBounds(gfx::Size(50, 50));
5895 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5896 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
5897 scroll_parent->SetBounds(gfx::Size(50, 50));
5898 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:595899
enne03b0e9a2015-06-19 00:08:025900 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595901
chrishtr7e3aaf22017-05-04 15:04:015902 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595903
jaydasika6f972de2016-04-07 16:16:145904 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595905 EXPECT_TRUE(scroll_child->is_clipped());
5906
5907 // Despite the fact that we visited the above layers out of order to get the
5908 // correct clip, the layer lists should be unaffected.
chrishtr7e3aaf22017-05-04 15:04:015909 EXPECT_EQ(3, GetRenderSurface(root)->num_contributors());
ajuma651848a2017-05-01 21:23:455910 EXPECT_TRUE(scroll_child->contributes_to_drawn_render_surface());
5911 EXPECT_TRUE(scroll_parent->contributes_to_drawn_render_surface());
5912 EXPECT_TRUE(scroll_grandparent->contributes_to_drawn_render_surface());
[email protected]995708c52013-10-17 20:52:595913}
5914
5915TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
5916 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:225917 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:595918 // + root
5919 // + scroll_child
5920 // + scroll_parent_border
5921 // + scroll_parent_clip
5922 // + scroll_parent
enne03b0e9a2015-06-19 00:08:025923 // + render_surface2
[email protected]995708c52013-10-17 20:52:595924 // + scroll_grandparent_border
5925 // + scroll_grandparent_clip
5926 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:025927 // + render_surface1
[email protected]995708c52013-10-17 20:52:595928 //
jaydasikabf1875a2016-06-28 03:39:595929 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:025930 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595931
enne03b0e9a2015-06-19 00:08:025932 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5933 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595934
enne03b0e9a2015-06-19 00:08:025935 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5936 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5937 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5938 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
5939 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5940 LayerImpl* scroll_grandparent_clip =
5941 AddChild<LayerImpl>(scroll_grandparent_border);
5942 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
5943 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:595944
enne03b0e9a2015-06-19 00:08:025945 scroll_parent->SetDrawsContent(true);
5946 render_surface1->SetDrawsContent(true);
5947 scroll_grandparent->SetDrawsContent(true);
5948 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:595949
5950 scroll_parent_clip->SetMasksToBounds(true);
5951 scroll_grandparent_clip->SetMasksToBounds(true);
5952
jaydasika1c0a27d42016-04-28 01:54:565953 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:155954 scroll_parent->test_properties()->scroll_children =
5955 base::MakeUnique<std::set<LayerImpl*>>();
5956 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:385957
jaydasika1c0a27d42016-04-28 01:54:565958 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:155959 scroll_grandparent->test_properties()->scroll_children =
5960 base::MakeUnique<std::set<LayerImpl*>>();
5961 scroll_grandparent->test_properties()->scroll_children->insert(
5962 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:595963
danakjf78fb272016-07-26 19:06:155964 root->SetBounds(gfx::Size(50, 50));
5965 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
5966 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
5967 scroll_grandparent->SetBounds(gfx::Size(50, 50));
5968 render_surface1->SetBounds(gfx::Size(50, 50));
5969 render_surface1->test_properties()->force_render_surface = true;
5970 scroll_parent_border->SetBounds(gfx::Size(40, 40));
5971 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
5972 scroll_parent->SetBounds(gfx::Size(50, 50));
5973 render_surface2->SetBounds(gfx::Size(50, 50));
5974 render_surface2->test_properties()->force_render_surface = true;
5975 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:595976
enne03b0e9a2015-06-19 00:08:025977 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:595978
chrishtr7e3aaf22017-05-04 15:04:015979 EXPECT_TRUE(GetRenderSurface(root));
[email protected]995708c52013-10-17 20:52:595980
jaydasika6f972de2016-04-07 16:16:145981 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:595982 EXPECT_TRUE(scroll_child->is_clipped());
5983
5984 // Despite the fact that we had to process the layers out of order to get the
ajumab784ef42017-04-28 23:01:525985 // right clip, our render_surface_list's order should be unaffected.
5986 EXPECT_EQ(3u, render_surface_list_impl()->size());
chrishtr7e3aaf22017-05-04 15:04:015987 EXPECT_EQ(GetRenderSurface(root), render_surface_list_impl()->at(0));
5988 EXPECT_EQ(GetRenderSurface(render_surface2),
ajumab784ef42017-04-28 23:01:525989 render_surface_list_impl()->at(1));
chrishtr7e3aaf22017-05-04 15:04:015990 EXPECT_EQ(GetRenderSurface(render_surface1),
ajumab784ef42017-04-28 23:01:525991 render_surface_list_impl()->at(2));
[email protected]995708c52013-10-17 20:52:595992}
5993
ajuma0b10f942015-03-21 07:45:535994TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
5995 // Ensures that when we have a render surface between a fixed position layer
5996 // and its container, we compute the fixed position layer's draw transform
5997 // with respect to that intervening render surface, not with respect to its
5998 // container's render target.
5999 //
6000 // + root
6001 // + render_surface
6002 // + fixed
ajuma737b2702015-05-06 01:18:376003 // + child
ajuma0b10f942015-03-21 07:45:536004 //
jaydasikabf1875a2016-06-28 03:39:596005 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516006 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6007 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6008 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536009
jaydasika6b5a32bf2016-04-22 21:56:366010 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526011 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536012
6013 LayerPositionConstraint constraint;
6014 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526015 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536016
danakjf78fb272016-07-26 19:06:156017 root->SetBounds(gfx::Size(50, 50));
6018 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6019 render_surface->SetBounds(gfx::Size(50, 50));
6020 render_surface->SetDrawsContent(true);
6021 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6022 fixed->SetBounds(gfx::Size(50, 50));
6023 fixed->SetDrawsContent(true);
6024 child->SetPosition(gfx::PointF(1.f, 2.f));
6025 child->SetBounds(gfx::Size(50, 50));
6026 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516027 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536028
jaydasikabaede2d92016-07-20 00:34:326029 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516030 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326031 EffectTree& effect_tree =
6032 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156033
ajuma737b2702015-05-06 01:18:376034 gfx::Transform expected_fixed_draw_transform;
6035 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026036 EXPECT_TRANSFORMATION_MATRIX_EQ(
6037 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326038 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536039
ajuma737b2702015-05-06 01:18:376040 gfx::Transform expected_fixed_screen_space_transform;
6041 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026042 EXPECT_TRANSFORMATION_MATRIX_EQ(
6043 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326044 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376045
6046 gfx::Transform expected_child_draw_transform;
6047 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026048 EXPECT_TRANSFORMATION_MATRIX_EQ(
6049 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326050 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376051
6052 gfx::Transform expected_child_screen_space_transform;
6053 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026054 EXPECT_TRANSFORMATION_MATRIX_EQ(
6055 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326056 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536057}
6058
[email protected]d81752b2013-10-25 08:32:236059TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6060 // This test verifies that a scrolling layer that gets snapped to
6061 // integer coordinates doesn't move a fixed position child.
6062 //
6063 // + root
6064 // + container
6065 // + scroller
6066 // + fixed
6067 //
khushalsagarb64b360d2015-10-21 19:25:166068 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:566069 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:226070 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236071 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486072 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426073 LayerImpl::Create(host_impl.active_tree(), 1);
6074 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486075 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236076 LayerImpl::Create(host_impl.active_tree(), 2);
6077 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486078 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236079 LayerImpl::Create(host_impl.active_tree(), 3);
6080 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486081 std::unique_ptr<LayerImpl> fixed =
6082 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236083 LayerImpl* fixed_layer = fixed.get();
6084
jaydasikaca2605e2016-04-23 02:52:526085 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236086
6087 LayerPositionConstraint constraint;
6088 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526089 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236090
pdr54d038192017-06-08 22:44:136091 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
[email protected]d81752b2013-10-25 08:32:236092
[email protected]d81752b2013-10-25 08:32:236093 gfx::Transform container_transform;
6094 container_transform.Translate3d(10.0, 20.0, 0.0);
6095 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6096
danakjf78fb272016-07-26 19:06:156097 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046098 container->test_properties()->transform = container_transform;
danakjf78fb272016-07-26 19:06:156099 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286100 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156101 scroller->SetBounds(gfx::Size(30, 30));
pdrbbfd8822017-06-27 22:44:526102 scroller->SetScrollable(container->bounds());
jaydasika0d98ba92015-11-17 05:17:286103 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156104 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286105 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156106
jaydasika89f7b5a2016-06-22 02:08:396107 scroller->test_properties()->AddChild(std::move(fixed));
6108 container->test_properties()->AddChild(std::move(scroller));
6109 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486110 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6111 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236112
6113 // Rounded to integers already.
6114 {
6115 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426116 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236117
ajumab784ef42017-04-28 23:01:526118 RenderSurfaceList render_surface_list;
[email protected]d81752b2013-10-25 08:32:236119 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:526120 root, root->bounds(), &render_surface_list);
sunxdb7e79432016-03-09 21:13:426121 root->layer_tree_impl()
6122 ->property_trees()
6123 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576124 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236125
6126 EXPECT_TRANSFORMATION_MATRIX_EQ(
6127 container_layer->draw_properties().screen_space_transform,
6128 fixed_layer->draw_properties().screen_space_transform);
6129 EXPECT_VECTOR_EQ(
6130 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6131 container_offset);
6132 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6133 .screen_space_transform.To2dTranslation(),
6134 container_offset - scroll_delta);
6135 }
6136
6137 // Scroll delta requiring rounding.
6138 {
6139 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426140 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236141
6142 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6143
ajumab784ef42017-04-28 23:01:526144 RenderSurfaceList render_surface_list;
[email protected]d81752b2013-10-25 08:32:236145 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:526146 root, root->bounds(), &render_surface_list);
sunxdb365de02016-04-28 20:32:576147 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236148
6149 EXPECT_TRANSFORMATION_MATRIX_EQ(
6150 container_layer->draw_properties().screen_space_transform,
6151 fixed_layer->draw_properties().screen_space_transform);
6152 EXPECT_VECTOR_EQ(
6153 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6154 container_offset);
6155 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6156 .screen_space_transform.To2dTranslation(),
6157 container_offset - rounded_scroll_delta);
6158 }
[email protected]cf15ad7b2014-04-02 03:59:266159
6160 // Scale is applied earlier in the tree.
6161 {
sunxdb7e79432016-03-09 21:13:426162 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266163 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286164 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:046165 container_layer->test_properties()->transform = scaled_container_transform;
danakj74af409e2016-07-01 00:41:486166
jaydasika0d98ba92015-11-17 05:17:286167 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266168
6169 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426170 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266171
ajumab784ef42017-04-28 23:01:526172 RenderSurfaceList render_surface_list;
[email protected]cf15ad7b2014-04-02 03:59:266173 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:526174 root, root->bounds(), &render_surface_list);
sunxdb365de02016-04-28 20:32:576175 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266176
6177 EXPECT_TRANSFORMATION_MATRIX_EQ(
6178 container_layer->draw_properties().screen_space_transform,
6179 fixed_layer->draw_properties().screen_space_transform);
6180 EXPECT_VECTOR_EQ(
6181 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6182 container_offset);
6183
jaydasika10d43fc2016-08-18 04:06:046184 container_layer->test_properties()->transform = container_transform;
[email protected]cf15ad7b2014-04-02 03:59:266185 }
[email protected]d81752b2013-10-25 08:32:236186}
6187
miletus2c78036b2015-01-29 20:52:376188TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506189 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6190 // This test verifies that a scrolling layer whose screen space transform is
6191 // animating doesn't get snapped to integer coordinates.
6192 //
6193 // + root
6194 // + animated layer
6195 // + surface
6196 // + container
6197 // + scroller
6198 //
jaydasikabf1875a2016-06-28 03:39:596199 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506200 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6201 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6202 LayerImpl* container = AddChild<LayerImpl>(surface);
6203 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506204
ajuma5e8e40d2015-07-31 01:50:506205 gfx::Transform start_scale;
6206 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156207
6208 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046209 animated_layer->test_properties()->transform = start_scale;
danakjf78fb272016-07-26 19:06:156210 animated_layer->SetBounds(gfx::Size(50, 50));
6211 surface->SetBounds(gfx::Size(50, 50));
6212 surface->test_properties()->force_render_surface = true;
6213 container->SetBounds(gfx::Size(50, 50));
6214 scroller->SetBounds(gfx::Size(100, 100));
pdr54d038192017-06-08 22:44:136215 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdrbbfd8822017-06-27 22:44:526216 scroller->SetScrollable(container->bounds());
danakjf78fb272016-07-26 19:06:156217 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506218
6219 gfx::Transform end_scale;
6220 end_scale.Scale(2.f, 2.f);
6221 TransformOperations start_operations;
6222 start_operations.AppendMatrix(start_scale);
6223 TransformOperations end_operations;
6224 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276225 SetElementIdsForTesting();
6226
6227 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6228 timeline_impl(), 1.0,
6229 start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:506230 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426231 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506232
6233 ExecuteCalculateDrawProperties(root);
6234
6235 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6236 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446237 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506238}
6239
sunxd8a9a60982016-07-29 18:46:566240TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6241 // This test verifies that a scrolling child of a scrolling layer doesn't get
6242 // snapped to integer coordinates.
6243 //
6244 // + root
6245 // + container
6246 // + scroller
6247 // + scroll_child
6248 //
6249 scoped_refptr<Layer> root = Layer::Create();
6250 scoped_refptr<Layer> container = Layer::Create();
6251 scoped_refptr<Layer> scroller = Layer::Create();
6252 scoped_refptr<Layer> scroll_child = Layer::Create();
6253 root->AddChild(container);
6254 root->AddChild(scroll_child);
6255 container->AddChild(scroller);
6256 host()->SetRootLayer(root);
6257
pdr54d038192017-06-08 22:44:136258 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
sunxd8a9a60982016-07-29 18:46:566259 scroll_child->SetScrollParent(scroller.get());
6260
6261 gfx::Transform rotate;
6262 rotate.RotateAboutYAxis(30);
6263 root->SetBounds(gfx::Size(50, 50));
6264 container->SetBounds(gfx::Size(50, 50));
6265 scroller->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526266 scroller->SetScrollable(container->bounds());
sunxd8a9a60982016-07-29 18:46:566267 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6268 scroll_child->SetBounds(gfx::Size(10, 10));
6269 scroll_child->SetTransform(rotate);
6270
6271 ExecuteCalculateDrawProperties(root.get());
6272
6273 host()->host_impl()->CreatePendingTree();
6274 host()->CommitAndCreatePendingTree();
6275 host()->host_impl()->ActivateSyncTree();
6276 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6277
6278 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6279 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6280 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
6281 gfx::Vector2dF scroll_delta(5.f, 9.f);
6282 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6283
6284 ExecuteCalculateDrawProperties(root_impl);
6285
6286 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6287 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6288 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6289
6290 gfx::Transform expected_scroll_child_screen_space_transform;
6291 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6292 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6294 scroll_child_impl->ScreenSpaceTransform());
6295}
6296
flackr2215b4e2016-09-21 20:16:016297TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
6298 scoped_refptr<Layer> root = Layer::Create();
6299 scoped_refptr<Layer> container = Layer::Create();
6300 scoped_refptr<Layer> scroller = Layer::Create();
6301 scoped_refptr<Layer> sticky_pos = Layer::Create();
6302 root->AddChild(container);
6303 container->AddChild(scroller);
6304 scroller->AddChild(sticky_pos);
6305 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136306 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016307
6308 LayerStickyPositionConstraint sticky_position;
6309 sticky_position.is_sticky = true;
6310 sticky_position.is_anchored_top = true;
6311 sticky_position.top_offset = 10.0f;
6312 sticky_position.scroll_container_relative_sticky_box_rect =
6313 gfx::Rect(10, 20, 10, 10);
6314 sticky_position.scroll_container_relative_containing_block_rect =
6315 gfx::Rect(0, 0, 50, 50);
6316 sticky_pos->SetStickyPositionConstraint(sticky_position);
6317
6318 root->SetBounds(gfx::Size(100, 100));
6319 container->SetBounds(gfx::Size(100, 100));
6320 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526321 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016322 sticky_pos->SetBounds(gfx::Size(10, 10));
6323 sticky_pos->SetPosition(gfx::PointF(10, 20));
6324
6325 ExecuteCalculateDrawProperties(root.get());
6326 host()->host_impl()->CreatePendingTree();
6327 host()->CommitAndCreatePendingTree();
6328 host()->host_impl()->ActivateSyncTree();
6329 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6330
6331 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6332 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6333 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6334
6335 ExecuteCalculateDrawProperties(root_impl);
6336 EXPECT_VECTOR2DF_EQ(
6337 gfx::Vector2dF(10.f, 20.f),
6338 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6339
6340 // Scroll less than sticking point, sticky element should move with scroll as
6341 // we haven't gotten to the initial sticky item location yet.
6342 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6343 ExecuteCalculateDrawProperties(root_impl);
6344 EXPECT_VECTOR2DF_EQ(
6345 gfx::Vector2dF(5.f, 15.f),
6346 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6347
6348 // Scroll past the sticking point, the Y coordinate should now be clamped.
6349 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6350 ExecuteCalculateDrawProperties(root_impl);
6351 EXPECT_VECTOR2DF_EQ(
6352 gfx::Vector2dF(-5.f, 10.f),
6353 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6354 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6355 ExecuteCalculateDrawProperties(root_impl);
6356 EXPECT_VECTOR2DF_EQ(
6357 gfx::Vector2dF(-5.f, 10.f),
6358 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6359
6360 // Scroll past the end of the sticky container (note: this element does not
6361 // have its own layer as it does not need to be composited).
6362 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6363 ExecuteCalculateDrawProperties(root_impl);
6364 EXPECT_VECTOR2DF_EQ(
6365 gfx::Vector2dF(-5.f, -10.f),
6366 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6367}
6368
flackrd2ae03f2016-11-14 19:22:056369TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) {
6370 scoped_refptr<Layer> root = Layer::Create();
6371 scoped_refptr<Layer> container = Layer::Create();
6372 scoped_refptr<Layer> scroller = Layer::Create();
6373 scoped_refptr<Layer> sticky_pos = Layer::Create();
6374 root->AddChild(container);
6375 container->AddChild(scroller);
6376 root->AddChild(sticky_pos);
6377 sticky_pos->SetScrollParent(scroller.get());
6378 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136379 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackrd2ae03f2016-11-14 19:22:056380
smcgruer29014ff2017-03-24 14:34:436381 // The sticky layer has already been scrolled on the main thread side, and has
6382 // stuck. This test then checks that further changes from cc-only scrolling
6383 // are handled correctly.
flackrd2ae03f2016-11-14 19:22:056384 LayerStickyPositionConstraint sticky_position;
6385 sticky_position.is_sticky = true;
6386 sticky_position.is_anchored_top = true;
6387 sticky_position.top_offset = 10.0f;
flackrd2ae03f2016-11-14 19:22:056388 sticky_position.scroll_container_relative_sticky_box_rect =
6389 gfx::Rect(10, 20, 10, 10);
6390 sticky_position.scroll_container_relative_containing_block_rect =
6391 gfx::Rect(0, 0, 50, 50);
6392 sticky_pos->SetStickyPositionConstraint(sticky_position);
6393
6394 root->SetBounds(gfx::Size(200, 200));
6395 container->SetBounds(gfx::Size(100, 100));
6396 container->SetPosition(gfx::PointF(50, 50));
6397 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526398 scroller->SetScrollable(container->bounds());
flackrd2ae03f2016-11-14 19:22:056399 sticky_pos->SetBounds(gfx::Size(10, 10));
6400 sticky_pos->SetPosition(gfx::PointF(60, 70));
6401
6402 ExecuteCalculateDrawProperties(root.get());
6403 host()->host_impl()->CreatePendingTree();
6404 host()->CommitAndCreatePendingTree();
6405 host()->host_impl()->ActivateSyncTree();
6406 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6407
6408 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6409 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6410 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6411
6412 ExecuteCalculateDrawProperties(root_impl);
6413 EXPECT_VECTOR2DF_EQ(
6414 gfx::Vector2dF(60.f, 70.f),
6415 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6416
6417 // Scroll less than sticking point, sticky element should move with scroll as
6418 // we haven't gotten to the initial sticky item location yet.
6419 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6420 ExecuteCalculateDrawProperties(root_impl);
6421 EXPECT_VECTOR2DF_EQ(
6422 gfx::Vector2dF(55.f, 65.f),
6423 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6424
6425 // Scroll past the sticking point, the Y coordinate should now be clamped.
6426 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6427 ExecuteCalculateDrawProperties(root_impl);
6428 EXPECT_VECTOR2DF_EQ(
6429 gfx::Vector2dF(45.f, 60.f),
6430 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6431 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6432 ExecuteCalculateDrawProperties(root_impl);
6433 EXPECT_VECTOR2DF_EQ(
6434 gfx::Vector2dF(45.f, 60.f),
6435 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6436
6437 // Scroll past the end of the sticky container (note: this element does not
6438 // have its own layer as it does not need to be composited).
6439 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6440 ExecuteCalculateDrawProperties(root_impl);
6441 EXPECT_VECTOR2DF_EQ(
6442 gfx::Vector2dF(45.f, 40.f),
6443 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6444}
6445
flackrdc5dfbe2016-10-24 21:43:386446TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) {
6447 scoped_refptr<Layer> root = Layer::Create();
6448 scoped_refptr<Layer> container = Layer::Create();
6449 scoped_refptr<Layer> scroller = Layer::Create();
6450 scoped_refptr<Layer> sticky_pos = Layer::Create();
6451 root->AddChild(container);
6452 container->AddChild(scroller);
6453 scroller->AddChild(sticky_pos);
6454 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136455 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackrdc5dfbe2016-10-24 21:43:386456
6457 LayerStickyPositionConstraint sticky_position;
6458 sticky_position.is_sticky = true;
6459 sticky_position.is_anchored_bottom = true;
6460 sticky_position.bottom_offset = 10.0f;
flackrdc5dfbe2016-10-24 21:43:386461 sticky_position.scroll_container_relative_sticky_box_rect =
6462 gfx::Rect(0, 200, 10, 10);
6463 sticky_position.scroll_container_relative_containing_block_rect =
6464 gfx::Rect(0, 0, 100, 500);
6465 sticky_pos->SetStickyPositionConstraint(sticky_position);
6466
6467 root->SetBounds(gfx::Size(100, 100));
6468 container->SetBounds(gfx::Size(100, 100));
6469 scroller->SetBounds(gfx::Size(100, 1000));
pdrbbfd8822017-06-27 22:44:526470 scroller->SetScrollable(container->bounds());
flackrdc5dfbe2016-10-24 21:43:386471 sticky_pos->SetBounds(gfx::Size(10, 10));
6472 sticky_pos->SetPosition(gfx::PointF(0, 200));
6473
6474 ExecuteCalculateDrawProperties(root.get());
6475 host()->host_impl()->CreatePendingTree();
6476 host()->CommitAndCreatePendingTree();
6477 host()->host_impl()->ActivateSyncTree();
6478 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6479
6480 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6481 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6482 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6483
6484 ExecuteCalculateDrawProperties(root_impl);
6485 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f));
6486 ExecuteCalculateDrawProperties(root_impl);
6487 EXPECT_VECTOR2DF_EQ(
6488 gfx::Vector2dF(0.f, 80.f),
6489 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6490}
6491
flackr2215b4e2016-09-21 20:16:016492TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
6493 scoped_refptr<Layer> root = Layer::Create();
6494 scoped_refptr<Layer> container = Layer::Create();
6495 scoped_refptr<Layer> scroller = Layer::Create();
6496 scoped_refptr<Layer> sticky_pos = Layer::Create();
6497 root->AddChild(container);
6498 container->AddChild(scroller);
6499 scroller->AddChild(sticky_pos);
6500 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136501 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016502
6503 LayerStickyPositionConstraint sticky_position;
6504 sticky_position.is_sticky = true;
6505 sticky_position.is_anchored_bottom = true;
6506 sticky_position.bottom_offset = 10.0f;
6507 sticky_position.scroll_container_relative_sticky_box_rect =
6508 gfx::Rect(0, 150, 10, 10);
6509 sticky_position.scroll_container_relative_containing_block_rect =
6510 gfx::Rect(0, 100, 50, 50);
6511 sticky_pos->SetStickyPositionConstraint(sticky_position);
6512
6513 root->SetBounds(gfx::Size(100, 100));
6514 container->SetBounds(gfx::Size(100, 100));
6515 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526516 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016517 sticky_pos->SetBounds(gfx::Size(10, 10));
6518 sticky_pos->SetPosition(gfx::PointF(0, 150));
6519
6520 ExecuteCalculateDrawProperties(root.get());
6521 host()->host_impl()->CreatePendingTree();
6522 host()->CommitAndCreatePendingTree();
6523 host()->host_impl()->ActivateSyncTree();
6524 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6525
6526 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6527 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6528 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6529
6530 // Initially the sticky element is moved up to the top of the container.
6531 ExecuteCalculateDrawProperties(root_impl);
6532 EXPECT_VECTOR2DF_EQ(
6533 gfx::Vector2dF(0.f, 100.f),
6534 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6535 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6536 ExecuteCalculateDrawProperties(root_impl);
6537 EXPECT_VECTOR2DF_EQ(
6538 gfx::Vector2dF(0.f, 95.f),
6539 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6540
6541 // Once we get past the top of the container it moves to be aligned 10px
6542 // up from the the bottom of the scroller.
6543 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
6544 ExecuteCalculateDrawProperties(root_impl);
6545 EXPECT_VECTOR2DF_EQ(
6546 gfx::Vector2dF(0.f, 80.f),
6547 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6548 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
6549 ExecuteCalculateDrawProperties(root_impl);
6550 EXPECT_VECTOR2DF_EQ(
6551 gfx::Vector2dF(0.f, 80.f),
6552 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6553
6554 // Once we scroll past its initial location, it sticks there.
6555 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
6556 ExecuteCalculateDrawProperties(root_impl);
6557 EXPECT_VECTOR2DF_EQ(
6558 gfx::Vector2dF(0.f, 0.f),
6559 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6560}
6561
flackra283bed2016-10-31 14:49:426562TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) {
flackre310f292016-10-12 21:09:286563 scoped_refptr<Layer> root = Layer::Create();
6564 scoped_refptr<Layer> scroller = Layer::Create();
6565 scoped_refptr<Layer> sticky_pos = Layer::Create();
6566 root->AddChild(scroller);
6567 scroller->AddChild(sticky_pos);
6568 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136569 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdr5200a052017-05-21 22:50:586570 LayerTreeHost::ViewportLayers viewport_layers;
6571 viewport_layers.page_scale = root;
6572 viewport_layers.inner_viewport_container = root;
6573 viewport_layers.inner_viewport_scroll = scroller;
6574 host()->RegisterViewportLayers(viewport_layers);
flackre310f292016-10-12 21:09:286575
6576 LayerStickyPositionConstraint sticky_position;
6577 sticky_position.is_sticky = true;
6578 sticky_position.is_anchored_bottom = true;
6579 sticky_position.bottom_offset = 10.0f;
flackre310f292016-10-12 21:09:286580 sticky_position.scroll_container_relative_sticky_box_rect =
flackra283bed2016-10-31 14:49:426581 gfx::Rect(0, 70, 10, 10);
flackre310f292016-10-12 21:09:286582 sticky_position.scroll_container_relative_containing_block_rect =
flackra283bed2016-10-31 14:49:426583 gfx::Rect(0, 60, 100, 100);
flackre310f292016-10-12 21:09:286584 sticky_pos->SetStickyPositionConstraint(sticky_position);
6585
6586 root->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526587 scroller->SetScrollable(gfx::Size(100, 100));
flackre310f292016-10-12 21:09:286588 scroller->SetBounds(gfx::Size(100, 1000));
6589 sticky_pos->SetBounds(gfx::Size(10, 10));
flackra283bed2016-10-31 14:49:426590 sticky_pos->SetPosition(gfx::PointF(0, 70));
flackre310f292016-10-12 21:09:286591
6592 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
flackra283bed2016-10-31 14:49:426593 scroller.get(), nullptr);
flackre310f292016-10-12 21:09:286594 host()->CommitAndCreateLayerImplTree();
6595 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6596 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6597 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id());
6598
6599 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
6600 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6601
6602 // Initially the sticky element is moved to the bottom of the container.
6603 EXPECT_VECTOR2DF_EQ(
flackra283bed2016-10-31 14:49:426604 gfx::Vector2dF(0.f, 70.f),
flackre310f292016-10-12 21:09:286605 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6606
flackra283bed2016-10-31 14:49:426607 // We start to hide the toolbar, but not far enough that the sticky element
6608 // should be moved up yet.
pdr23d381fd2017-04-25 21:06:316609 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f));
flackra283bed2016-10-31 14:49:426610 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6611 nullptr);
flackre310f292016-10-12 21:09:286612 EXPECT_VECTOR2DF_EQ(
6613 gfx::Vector2dF(0.f, 70.f),
6614 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackra283bed2016-10-31 14:49:426615
6616 // On hiding more of the toolbar the sticky element starts to stick.
pdr23d381fd2017-04-25 21:06:316617 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f));
flackra283bed2016-10-31 14:49:426618 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6619 nullptr);
6620 EXPECT_VECTOR2DF_EQ(
6621 gfx::Vector2dF(0.f, 60.f),
6622 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6623
6624 // On hiding more the sticky element stops moving as it has reached its
6625 // limit.
pdr23d381fd2017-04-25 21:06:316626 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f));
flackra283bed2016-10-31 14:49:426627 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6628 nullptr);
6629 EXPECT_VECTOR2DF_EQ(
6630 gfx::Vector2dF(0.f, 60.f),
6631 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6632}
6633
6634TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) {
6635 scoped_refptr<Layer> root = Layer::Create();
6636 scoped_refptr<Layer> scroller = Layer::Create();
6637 scoped_refptr<Layer> outer_clip = Layer::Create();
6638 scoped_refptr<Layer> outer_viewport = Layer::Create();
6639 scoped_refptr<Layer> sticky_pos = Layer::Create();
6640 root->AddChild(scroller);
6641 scroller->AddChild(outer_clip);
6642 outer_clip->AddChild(outer_viewport);
6643 outer_viewport->AddChild(sticky_pos);
6644 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136645 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdr5200a052017-05-21 22:50:586646 LayerTreeHost::ViewportLayers viewport_layers;
6647 viewport_layers.page_scale = root;
6648 viewport_layers.inner_viewport_container = root;
6649 viewport_layers.outer_viewport_container = outer_clip;
6650 viewport_layers.inner_viewport_scroll = scroller;
6651 viewport_layers.outer_viewport_scroll = outer_viewport;
6652 host()->RegisterViewportLayers(viewport_layers);
flackra283bed2016-10-31 14:49:426653
6654 LayerStickyPositionConstraint sticky_position;
6655 sticky_position.is_sticky = true;
6656 sticky_position.is_anchored_bottom = true;
6657 sticky_position.bottom_offset = 10.0f;
flackra283bed2016-10-31 14:49:426658 sticky_position.scroll_container_relative_sticky_box_rect =
6659 gfx::Rect(0, 70, 10, 10);
6660 sticky_position.scroll_container_relative_containing_block_rect =
6661 gfx::Rect(0, 60, 100, 100);
6662 sticky_pos->SetStickyPositionConstraint(sticky_position);
6663
6664 root->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526665 scroller->SetScrollable(gfx::Size(100, 100));
flackra283bed2016-10-31 14:49:426666 scroller->SetBounds(gfx::Size(100, 1000));
6667 outer_clip->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:526668 outer_viewport->SetScrollable(gfx::Size(100, 100));
flackra283bed2016-10-31 14:49:426669 sticky_pos->SetBounds(gfx::Size(10, 10));
6670 sticky_pos->SetPosition(gfx::PointF(0, 70));
6671
6672 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
6673 scroller.get(), outer_viewport.get());
6674 host()->CommitAndCreateLayerImplTree();
6675 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6676 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6677 ASSERT_EQ(outer_viewport->id(),
6678 layer_tree_impl->OuterViewportScrollLayer()->id());
6679
6680 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
6681 LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer();
6682 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6683 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id());
6684
6685 // Initially the sticky element is moved to the bottom of the container.
6686 EXPECT_VECTOR2DF_EQ(
6687 gfx::Vector2dF(0.f, 70.f),
6688 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6689
6690 // We start to hide the toolbar, but not far enough that the sticky element
6691 // should be moved up yet.
pdr23d381fd2017-04-25 21:06:316692 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f));
flackra283bed2016-10-31 14:49:426693 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6694 outer_scroll);
6695 EXPECT_VECTOR2DF_EQ(
6696 gfx::Vector2dF(0.f, 70.f),
6697 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6698
6699 // On hiding more of the toolbar the sticky element starts to stick.
pdr23d381fd2017-04-25 21:06:316700 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f));
flackra283bed2016-10-31 14:49:426701 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6702 outer_scroll);
6703
6704 // On hiding more the sticky element stops moving as it has reached its
6705 // limit.
6706 EXPECT_VECTOR2DF_EQ(
6707 gfx::Vector2dF(0.f, 60.f),
6708 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6709
pdr23d381fd2017-04-25 21:06:316710 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f));
flackra283bed2016-10-31 14:49:426711 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
6712 outer_scroll);
6713
6714 EXPECT_VECTOR2DF_EQ(
6715 gfx::Vector2dF(0.f, 60.f),
6716 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackre310f292016-10-12 21:09:286717}
6718
flackr2215b4e2016-09-21 20:16:016719TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
6720 scoped_refptr<Layer> root = Layer::Create();
6721 scoped_refptr<Layer> container = Layer::Create();
6722 scoped_refptr<Layer> scroller = Layer::Create();
6723 scoped_refptr<Layer> sticky_pos = Layer::Create();
6724 root->AddChild(container);
6725 container->AddChild(scroller);
6726 scroller->AddChild(sticky_pos);
6727 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136728 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016729
6730 LayerStickyPositionConstraint sticky_position;
6731 sticky_position.is_sticky = true;
6732 sticky_position.is_anchored_left = true;
6733 sticky_position.is_anchored_right = true;
6734 sticky_position.left_offset = 10.f;
6735 sticky_position.right_offset = 10.f;
6736 sticky_position.scroll_container_relative_sticky_box_rect =
6737 gfx::Rect(145, 0, 10, 10);
6738 sticky_position.scroll_container_relative_containing_block_rect =
6739 gfx::Rect(100, 0, 100, 100);
6740 sticky_pos->SetStickyPositionConstraint(sticky_position);
6741
6742 root->SetBounds(gfx::Size(100, 100));
6743 container->SetBounds(gfx::Size(100, 100));
6744 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526745 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016746 sticky_pos->SetBounds(gfx::Size(10, 10));
6747 sticky_pos->SetPosition(gfx::PointF(145, 0));
6748
6749 ExecuteCalculateDrawProperties(root.get());
6750 host()->host_impl()->CreatePendingTree();
6751 host()->CommitAndCreatePendingTree();
6752 host()->host_impl()->ActivateSyncTree();
6753 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6754
6755 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6756 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6757 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6758
6759 // Initially the sticky element is moved the leftmost side of the container.
6760 ExecuteCalculateDrawProperties(root_impl);
6761 EXPECT_VECTOR2DF_EQ(
6762 gfx::Vector2dF(100.f, 0.f),
6763 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6764 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
6765 ExecuteCalculateDrawProperties(root_impl);
6766 EXPECT_VECTOR2DF_EQ(
6767 gfx::Vector2dF(95.f, 0.f),
6768 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6769
6770 // Once we get past the left side of the container it moves to be aligned 10px
6771 // up from the the right of the scroller.
6772 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
6773 ExecuteCalculateDrawProperties(root_impl);
6774 EXPECT_VECTOR2DF_EQ(
6775 gfx::Vector2dF(80.f, 0.f),
6776 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6777 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
6778 ExecuteCalculateDrawProperties(root_impl);
6779 EXPECT_VECTOR2DF_EQ(
6780 gfx::Vector2dF(80.f, 0.f),
6781 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6782
6783 // When we get to the sticky element's original position we stop sticking
6784 // to the right.
6785 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
6786 ExecuteCalculateDrawProperties(root_impl);
6787 EXPECT_VECTOR2DF_EQ(
6788 gfx::Vector2dF(50.f, 0.f),
6789 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6790 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
6791 ExecuteCalculateDrawProperties(root_impl);
6792 EXPECT_VECTOR2DF_EQ(
6793 gfx::Vector2dF(40.f, 0.f),
6794 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6795
6796 // The element starts sticking to the left once we scroll far enough.
6797 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
6798 ExecuteCalculateDrawProperties(root_impl);
6799 EXPECT_VECTOR2DF_EQ(
6800 gfx::Vector2dF(10.f, 0.f),
6801 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6802 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
6803 ExecuteCalculateDrawProperties(root_impl);
6804 EXPECT_VECTOR2DF_EQ(
6805 gfx::Vector2dF(10.f, 0.f),
6806 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6807
6808 // Finally it stops sticking when it hits the right side of the container.
6809 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
6810 ExecuteCalculateDrawProperties(root_impl);
6811 EXPECT_VECTOR2DF_EQ(
6812 gfx::Vector2dF(0.f, 0.f),
6813 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6814 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
6815 ExecuteCalculateDrawProperties(root_impl);
6816 EXPECT_VECTOR2DF_EQ(
6817 gfx::Vector2dF(-5.f, 0.f),
6818 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6819}
6820
6821// This test ensures that the compositor sticky position code correctly accounts
6822// for the element having been given a position from the main thread sticky
6823// position code.
6824TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
6825 scoped_refptr<Layer> root = Layer::Create();
6826 scoped_refptr<Layer> container = Layer::Create();
6827 scoped_refptr<Layer> scroller = Layer::Create();
6828 scoped_refptr<Layer> sticky_pos = Layer::Create();
6829 root->AddChild(container);
6830 container->AddChild(scroller);
6831 scroller->AddChild(sticky_pos);
6832 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136833 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:016834
6835 LayerStickyPositionConstraint sticky_position;
6836 sticky_position.is_sticky = true;
6837 sticky_position.is_anchored_top = true;
6838 sticky_position.top_offset = 10.0f;
6839 sticky_position.scroll_container_relative_sticky_box_rect =
6840 gfx::Rect(10, 20, 10, 10);
6841 sticky_position.scroll_container_relative_containing_block_rect =
6842 gfx::Rect(0, 0, 50, 50);
6843 sticky_pos->SetStickyPositionConstraint(sticky_position);
6844
6845 root->SetBounds(gfx::Size(100, 100));
6846 container->SetBounds(gfx::Size(100, 100));
6847 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526848 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:016849 sticky_pos->SetBounds(gfx::Size(10, 10));
6850 sticky_pos->SetPosition(gfx::PointF(10, 20));
6851
6852 ExecuteCalculateDrawProperties(root.get());
6853 host()->host_impl()->CreatePendingTree();
6854 host()->CommitAndCreatePendingTree();
6855 host()->host_impl()->ActivateSyncTree();
6856 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6857
6858 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6859 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6860 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6861
6862 ExecuteCalculateDrawProperties(root_impl);
6863 EXPECT_VECTOR2DF_EQ(
6864 gfx::Vector2dF(10.f, 20.f),
6865 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6866
6867 // Scroll less than sticking point, sticky element should move with scroll as
6868 // we haven't gotten to the initial sticky item location yet.
6869 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6870 ExecuteCalculateDrawProperties(root_impl);
6871 EXPECT_VECTOR2DF_EQ(
6872 gfx::Vector2dF(5.f, 15.f),
6873 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6874
6875 // Scroll past the sticking point, the Y coordinate should now be clamped.
6876 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6877 ExecuteCalculateDrawProperties(root_impl);
6878 EXPECT_VECTOR2DF_EQ(
6879 gfx::Vector2dF(-5.f, 10.f),
6880 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6881
6882 // Now the main thread commits the new position of the sticky element.
6883 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
yigu23b68f62017-06-13 12:35:076884 // Shift the layer by -offset_for_position_sticky.
6885 sticky_pos->SetPosition(gfx::PointF(10, 25) - gfx::Vector2dF(0, 5));
flackr2215b4e2016-09-21 20:16:016886 ExecuteCalculateDrawProperties(root.get());
6887 host()->host_impl()->CreatePendingTree();
6888 host()->CommitAndCreatePendingTree();
6889 host()->host_impl()->ActivateSyncTree();
6890 layer_tree_impl = host()->host_impl()->active_tree();
6891 root_impl = layer_tree_impl->LayerById(root->id());
6892 scroller_impl = layer_tree_impl->LayerById(scroller->id());
6893 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6894
6895 // The element should still be where it was before. We reset the delta to
6896 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
6897 // thread.
6898 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
6899 ExecuteCalculateDrawProperties(root_impl);
6900 EXPECT_VECTOR2DF_EQ(
6901 gfx::Vector2dF(-5.f, 10.f),
6902 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6903
6904 // And if we scroll a little further it remains there.
6905 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
6906 ExecuteCalculateDrawProperties(root_impl);
6907 EXPECT_VECTOR2DF_EQ(
6908 gfx::Vector2dF(-5.f, 10.f),
6909 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6910}
6911
flackr68e1c292016-10-11 16:34:426912// This tests the main thread updates with a composited sticky container. In
6913// this case the position received from main is relative to the container but
6914// the constraint rects are relative to the ancestor scroller.
6915TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) {
6916 scoped_refptr<Layer> root = Layer::Create();
6917 scoped_refptr<Layer> container = Layer::Create();
6918 scoped_refptr<Layer> scroller = Layer::Create();
6919 scoped_refptr<Layer> sticky_container = Layer::Create();
6920 scoped_refptr<Layer> sticky_pos = Layer::Create();
6921 root->AddChild(container);
6922 container->AddChild(scroller);
6923 scroller->AddChild(sticky_container);
6924 sticky_container->AddChild(sticky_pos);
6925 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:136926 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr68e1c292016-10-11 16:34:426927
6928 LayerStickyPositionConstraint sticky_position;
6929 sticky_position.is_sticky = true;
6930 sticky_position.is_anchored_top = true;
6931 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:426932 sticky_position.scroll_container_relative_sticky_box_rect =
6933 gfx::Rect(20, 30, 10, 10);
6934 sticky_position.scroll_container_relative_containing_block_rect =
6935 gfx::Rect(20, 20, 30, 30);
6936 sticky_pos->SetStickyPositionConstraint(sticky_position);
6937
6938 root->SetBounds(gfx::Size(100, 100));
6939 container->SetBounds(gfx::Size(100, 100));
6940 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:526941 scroller->SetScrollable(container->bounds());
flackr68e1c292016-10-11 16:34:426942 sticky_container->SetPosition(gfx::PointF(20, 20));
6943 sticky_container->SetBounds(gfx::Size(30, 30));
6944 sticky_pos->SetBounds(gfx::Size(10, 10));
6945 sticky_pos->SetPosition(gfx::PointF(0, 10));
6946
6947 ExecuteCalculateDrawProperties(root.get());
6948 host()->host_impl()->CreatePendingTree();
6949 host()->CommitAndCreatePendingTree();
6950 host()->host_impl()->ActivateSyncTree();
6951 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6952
6953 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6954 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6955 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6956
6957 ExecuteCalculateDrawProperties(root_impl);
6958 EXPECT_VECTOR2DF_EQ(
6959 gfx::Vector2dF(20.f, 30.f),
6960 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6961
6962 // Scroll less than sticking point, sticky element should move with scroll as
6963 // we haven't gotten to the initial sticky item location yet.
6964 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6965 ExecuteCalculateDrawProperties(root_impl);
6966 EXPECT_VECTOR2DF_EQ(
6967 gfx::Vector2dF(20.f, 25.f),
6968 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6969
6970 // Scroll past the sticking point, the Y coordinate should now be clamped.
6971 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
6972 ExecuteCalculateDrawProperties(root_impl);
6973 EXPECT_VECTOR2DF_EQ(
6974 gfx::Vector2dF(20.f, 10.f),
6975 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6976
6977 // Now the main thread commits the new position of the sticky element.
6978 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25));
yigu23b68f62017-06-13 12:35:076979 // Shift the layer by -offset_for_position_sticky.
6980 sticky_pos->SetPosition(gfx::PointF(0, 15) - gfx::Vector2dF(0, 5));
flackr68e1c292016-10-11 16:34:426981 ExecuteCalculateDrawProperties(root.get());
6982 host()->host_impl()->CreatePendingTree();
6983 host()->CommitAndCreatePendingTree();
6984 host()->host_impl()->ActivateSyncTree();
6985 layer_tree_impl = host()->host_impl()->active_tree();
6986 root_impl = layer_tree_impl->LayerById(root->id());
6987 scroller_impl = layer_tree_impl->LayerById(scroller->id());
6988 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6989
6990 // The element should still be where it was before. We reset the delta to
6991 // (0, 0) because we have synced a scroll offset of (0, 25) from the main
6992 // thread.
6993 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
6994 ExecuteCalculateDrawProperties(root_impl);
6995 EXPECT_VECTOR2DF_EQ(
6996 gfx::Vector2dF(20.f, 10.f),
6997 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6998
6999 // And if we scroll a little further it remains there.
7000 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7001 ExecuteCalculateDrawProperties(root_impl);
7002 EXPECT_VECTOR2DF_EQ(
7003 gfx::Vector2dF(20.f, 10.f),
7004 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7005
7006 // And hits the bottom of the container.
7007 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7008 ExecuteCalculateDrawProperties(root_impl);
7009 EXPECT_VECTOR2DF_EQ(
7010 gfx::Vector2dF(20.f, 5.f),
7011 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7012}
7013
flackr2215b4e2016-09-21 20:16:017014// A transform on a sticky element should not affect its sticky position.
7015TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7016 scoped_refptr<Layer> root = Layer::Create();
7017 scoped_refptr<Layer> container = Layer::Create();
7018 scoped_refptr<Layer> scroller = Layer::Create();
7019 scoped_refptr<Layer> sticky_pos = Layer::Create();
7020 root->AddChild(container);
7021 container->AddChild(scroller);
7022 scroller->AddChild(sticky_pos);
7023 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:137024 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:017025 gfx::Transform t;
7026 t.Scale(2, 2);
7027 sticky_pos->SetTransform(t);
7028
7029 LayerStickyPositionConstraint sticky_position;
7030 sticky_position.is_sticky = true;
7031 sticky_position.is_anchored_top = true;
7032 sticky_position.top_offset = 0.0f;
7033 sticky_position.scroll_container_relative_sticky_box_rect =
7034 gfx::Rect(0, 20, 10, 10);
7035 sticky_position.scroll_container_relative_containing_block_rect =
7036 gfx::Rect(0, 0, 50, 50);
7037 sticky_pos->SetStickyPositionConstraint(sticky_position);
7038
7039 root->SetBounds(gfx::Size(100, 100));
7040 container->SetBounds(gfx::Size(100, 100));
7041 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:527042 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:017043 sticky_pos->SetBounds(gfx::Size(10, 10));
7044 sticky_pos->SetPosition(gfx::PointF(0, 20));
7045
7046 ExecuteCalculateDrawProperties(root.get());
7047 host()->host_impl()->CreatePendingTree();
7048 host()->CommitAndCreatePendingTree();
7049 host()->host_impl()->ActivateSyncTree();
7050 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7051
7052 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7053 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7054 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7055
7056 ExecuteCalculateDrawProperties(root_impl);
7057 EXPECT_VECTOR2DF_EQ(
7058 gfx::Vector2dF(0.f, 20.f),
7059 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7060
7061 // Scroll less than sticking point, sticky element should move with scroll as
7062 // we haven't gotten to the initial sticky item location yet.
7063 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7064 ExecuteCalculateDrawProperties(root_impl);
7065 EXPECT_VECTOR2DF_EQ(
7066 gfx::Vector2dF(0.f, 5.f),
7067 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7068
7069 // Scroll past the sticking point, the box is positioned at the scroller
7070 // edge.
7071 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7072 ExecuteCalculateDrawProperties(root_impl);
7073 EXPECT_VECTOR2DF_EQ(
7074 gfx::Vector2dF(0.f, 0.f),
7075 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7076 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7077 ExecuteCalculateDrawProperties(root_impl);
7078 EXPECT_VECTOR2DF_EQ(
7079 gfx::Vector2dF(0.f, 0.f),
7080 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7081
7082 // Scroll past the end of the sticky container.
7083 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7084 ExecuteCalculateDrawProperties(root_impl);
7085 EXPECT_VECTOR2DF_EQ(
7086 gfx::Vector2dF(0.f, -10.f),
7087 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7088}
7089
7090// Tests that a transform does not affect the sticking points. The sticky
7091// element will however move relative to the viewport due to its transform.
7092TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7093 scoped_refptr<Layer> root = Layer::Create();
7094 scoped_refptr<Layer> container = Layer::Create();
7095 scoped_refptr<Layer> scroller = Layer::Create();
7096 scoped_refptr<Layer> sticky_container = Layer::Create();
7097 scoped_refptr<Layer> sticky_pos = Layer::Create();
7098 root->AddChild(container);
7099 container->AddChild(scroller);
7100 scroller->AddChild(sticky_container);
7101 sticky_container->AddChild(sticky_pos);
7102 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:137103 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
flackr2215b4e2016-09-21 20:16:017104 gfx::Transform t;
7105 t.Scale(2, 2);
7106 sticky_container->SetTransform(t);
7107
7108 LayerStickyPositionConstraint sticky_position;
7109 sticky_position.is_sticky = true;
7110 sticky_position.is_anchored_top = true;
7111 sticky_position.top_offset = 0.0f;
7112 sticky_position.scroll_container_relative_sticky_box_rect =
7113 gfx::Rect(0, 20, 10, 10);
7114 sticky_position.scroll_container_relative_containing_block_rect =
7115 gfx::Rect(0, 0, 50, 50);
7116 sticky_pos->SetStickyPositionConstraint(sticky_position);
7117
7118 root->SetBounds(gfx::Size(100, 100));
7119 container->SetBounds(gfx::Size(100, 100));
7120 scroller->SetBounds(gfx::Size(1000, 1000));
pdrbbfd8822017-06-27 22:44:527121 scroller->SetScrollable(container->bounds());
flackr2215b4e2016-09-21 20:16:017122 sticky_container->SetBounds(gfx::Size(50, 50));
7123 sticky_pos->SetBounds(gfx::Size(10, 10));
7124 sticky_pos->SetPosition(gfx::PointF(0, 20));
7125
7126 ExecuteCalculateDrawProperties(root.get());
7127 host()->host_impl()->CreatePendingTree();
7128 host()->CommitAndCreatePendingTree();
7129 host()->host_impl()->ActivateSyncTree();
7130 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7131
7132 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7133 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7134 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7135
7136 ExecuteCalculateDrawProperties(root_impl);
7137 EXPECT_VECTOR2DF_EQ(
7138 gfx::Vector2dF(0.f, 40.f),
7139 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7140
7141 // Scroll less than sticking point, sticky element should move with scroll as
7142 // we haven't gotten to the initial sticky item location yet.
7143 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7144 ExecuteCalculateDrawProperties(root_impl);
7145 EXPECT_VECTOR2DF_EQ(
7146 gfx::Vector2dF(0.f, 25.f),
7147 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7148
7149 // Scroll past the sticking point, the box is positioned at the scroller
7150 // edge but is also scaled by its container so it begins to move down.
7151 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7152 ExecuteCalculateDrawProperties(root_impl);
7153 EXPECT_VECTOR2DF_EQ(
7154 gfx::Vector2dF(0.f, 25.f),
7155 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7156 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7157 ExecuteCalculateDrawProperties(root_impl);
7158 EXPECT_VECTOR2DF_EQ(
7159 gfx::Vector2dF(0.f, 30.f),
7160 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7161
7162 // Scroll past the end of the sticky container.
7163 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7164 ExecuteCalculateDrawProperties(root_impl);
7165 EXPECT_VECTOR2DF_EQ(
7166 gfx::Vector2dF(0.f, 30.f),
7167 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7168}
7169
smcgruer29014ff2017-03-24 14:34:437170TEST_F(LayerTreeHostCommonTest, StickyPositionNested) {
7171 scoped_refptr<Layer> root = Layer::Create();
7172 scoped_refptr<Layer> container = Layer::Create();
7173 scoped_refptr<Layer> scroller = Layer::Create();
7174 scoped_refptr<Layer> outer_sticky = Layer::Create();
7175 scoped_refptr<Layer> inner_sticky = Layer::Create();
7176
7177 root->AddChild(container);
7178 container->AddChild(scroller);
7179 scroller->AddChild(outer_sticky);
7180 outer_sticky->AddChild(inner_sticky);
7181 host()->SetRootLayer(root);
pdr54d038192017-06-08 22:44:137182 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
smcgruer29014ff2017-03-24 14:34:437183
7184 root->SetBounds(gfx::Size(100, 100));
7185 container->SetBounds(gfx::Size(100, 100));
7186 scroller->SetBounds(gfx::Size(100, 1000));
pdrbbfd8822017-06-27 22:44:527187 scroller->SetScrollable(container->bounds());
smcgruer29014ff2017-03-24 14:34:437188 outer_sticky->SetBounds(gfx::Size(10, 50));
7189 outer_sticky->SetPosition(gfx::PointF(0, 50));
7190 inner_sticky->SetBounds(gfx::Size(10, 10));
7191 inner_sticky->SetPosition(gfx::PointF(0, 0));
7192
7193 LayerStickyPositionConstraint outer_sticky_pos;
7194 outer_sticky_pos.is_sticky = true;
7195 outer_sticky_pos.is_anchored_top = true;
7196 outer_sticky_pos.top_offset = 10.0f;
smcgruer29014ff2017-03-24 14:34:437197 outer_sticky_pos.scroll_container_relative_sticky_box_rect =
7198 gfx::Rect(0, 50, 10, 50);
7199 outer_sticky_pos.scroll_container_relative_containing_block_rect =
7200 gfx::Rect(0, 0, 50, 400);
7201 outer_sticky->SetStickyPositionConstraint(outer_sticky_pos);
7202
7203 LayerStickyPositionConstraint inner_sticky_pos;
7204 inner_sticky_pos.is_sticky = true;
7205 inner_sticky_pos.is_anchored_top = true;
7206 inner_sticky_pos.top_offset = 25.0f;
smcgruer29014ff2017-03-24 14:34:437207 inner_sticky_pos.scroll_container_relative_sticky_box_rect =
7208 gfx::Rect(0, 50, 10, 10);
7209 inner_sticky_pos.scroll_container_relative_containing_block_rect =
7210 gfx::Rect(0, 50, 10, 50);
7211 inner_sticky_pos.nearest_layer_shifting_containing_block = outer_sticky->id();
7212 inner_sticky->SetStickyPositionConstraint(inner_sticky_pos);
7213
7214 ExecuteCalculateDrawProperties(root.get());
7215 host()->host_impl()->CreatePendingTree();
7216 host()->CommitAndCreatePendingTree();
7217 host()->host_impl()->ActivateSyncTree();
7218 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7219
7220 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7221 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7222 LayerImpl* outer_sticky_impl = layer_tree_impl->LayerById(outer_sticky->id());
7223 LayerImpl* inner_sticky_impl = layer_tree_impl->LayerById(inner_sticky->id());
7224
7225 ExecuteCalculateDrawProperties(root_impl);
7226
7227 // Before any scrolling is done, the sticky elements should still be at their
7228 // original positions.
7229 EXPECT_VECTOR2DF_EQ(
7230 gfx::Vector2dF(0.f, 50.f),
7231 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7232 EXPECT_VECTOR2DF_EQ(
7233 gfx::Vector2dF(0.f, 50.f),
7234 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7235
7236 // Scroll less than the sticking point. Both sticky elements should move with
7237 // scroll as we haven't gotten to the sticky item locations yet.
7238 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7239 ExecuteCalculateDrawProperties(root_impl);
7240 EXPECT_VECTOR2DF_EQ(
7241 gfx::Vector2dF(0.f, 45.f),
7242 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7243 EXPECT_VECTOR2DF_EQ(
7244 gfx::Vector2dF(0.f, 45.f),
7245 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7246
7247 // Scroll such that the inner sticky should stick, but the outer one should
7248 // keep going as it hasn't reached its position yet.
7249 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7250 ExecuteCalculateDrawProperties(root_impl);
7251 EXPECT_VECTOR2DF_EQ(
7252 gfx::Vector2dF(0.f, 20.f),
7253 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7254 EXPECT_VECTOR2DF_EQ(
7255 gfx::Vector2dF(0.f, 25.f),
7256 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7257
7258 // Keep going, both should stick.
7259 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 100.f));
7260 ExecuteCalculateDrawProperties(root_impl);
7261 EXPECT_VECTOR2DF_EQ(
7262 gfx::Vector2dF(0.f, 10.f),
7263 outer_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7264 EXPECT_VECTOR2DF_EQ(
7265 gfx::Vector2dF(0.f, 25.f),
7266 inner_sticky_impl->ScreenSpaceTransform().To2dTranslation());
7267}
7268
jaydasikaaf1582f2016-08-10 18:39:387269TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7270 scoped_refptr<Layer> root = Layer::Create();
7271 scoped_refptr<Layer> container = Layer::Create();
7272 scoped_refptr<Layer> scroller = Layer::Create();
7273 scoped_refptr<Layer> fixed_pos = Layer::Create();
7274
7275 scroller->SetIsContainerForFixedPositionLayers(true);
7276 root->AddChild(container);
7277 container->AddChild(scroller);
7278 scroller->AddChild(fixed_pos);
7279 host()->SetRootLayer(root);
7280
7281 LayerPositionConstraint fixed_position;
7282 fixed_position.set_is_fixed_position(true);
pdr54d038192017-06-08 22:44:137283 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
jaydasikaaf1582f2016-08-10 18:39:387284 fixed_pos->SetPositionConstraint(fixed_position);
7285
7286 root->SetBounds(gfx::Size(50, 50));
7287 container->SetBounds(gfx::Size(50, 50));
7288 scroller->SetBounds(gfx::Size(50, 50));
pdrbbfd8822017-06-27 22:44:527289 scroller->SetScrollable(container->bounds());
jaydasikaaf1582f2016-08-10 18:39:387290 fixed_pos->SetBounds(gfx::Size(50, 50));
7291
7292 gfx::Transform rotate;
7293 rotate.RotateAboutXAxis(20);
7294 container->SetTransform(rotate);
7295
7296 ExecuteCalculateDrawProperties(root.get());
khushalsagarb69ba9452017-01-27 22:20:077297 TransformTree& tree =
7298 root->layer_tree_host()->property_trees()->transform_tree;
jaydasikaaf1582f2016-08-10 18:39:387299 gfx::Transform transform;
7300 tree.ComputeTranslation(fixed_pos->transform_tree_index(),
7301 container->transform_tree_index(), &transform);
7302 EXPECT_TRUE(transform.IsIdentity());
7303}
7304
sunxd8a9a60982016-07-29 18:46:567305TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
7306 // This test verifies that a fixed pos child of a scrolling layer doesn't get
7307 // snapped to integer coordinates.
7308 //
7309 // + root
7310 // + container
7311 // + scroller
7312 // + fixed_pos
7313 //
7314 scoped_refptr<Layer> root = Layer::Create();
7315 scoped_refptr<Layer> container = Layer::Create();
7316 scoped_refptr<Layer> scroller = Layer::Create();
7317 scoped_refptr<Layer> fixed_pos = Layer::Create();
7318
7319 scroller->SetIsContainerForFixedPositionLayers(true);
7320
7321 root->AddChild(container);
7322 container->AddChild(scroller);
7323 scroller->AddChild(fixed_pos);
7324 host()->SetRootLayer(root);
7325
7326 LayerPositionConstraint fixed_position;
7327 fixed_position.set_is_fixed_position(true);
pdr54d038192017-06-08 22:44:137328 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
sunxd8a9a60982016-07-29 18:46:567329 fixed_pos->SetPositionConstraint(fixed_position);
7330
7331 root->SetBounds(gfx::Size(50, 50));
7332 container->SetBounds(gfx::Size(50, 50));
7333 scroller->SetBounds(gfx::Size(100, 100));
pdrbbfd8822017-06-27 22:44:527334 scroller->SetScrollable(container->bounds());
sunxd8a9a60982016-07-29 18:46:567335 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7336 fixed_pos->SetBounds(gfx::Size(10, 10));
7337
7338 ExecuteCalculateDrawProperties(root.get());
7339
7340 host()->host_impl()->CreatePendingTree();
7341 host()->CommitAndCreatePendingTree();
7342 host()->host_impl()->ActivateSyncTree();
7343 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7344
7345 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7346 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7347 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
7348 gfx::Vector2dF scroll_delta(5.f, 9.f);
7349 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7350
7351 ExecuteCalculateDrawProperties(root_impl);
7352
7353 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7354 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7355 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7356
7357 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
7358 10.3f);
7359 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
7360 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
7361}
7362
[email protected]1c3626e2014-04-09 17:49:227363class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7364 public:
danakj60bc3bc2016-04-09 00:24:487365 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227366 LayerTreeImpl* tree_impl,
7367 int id) {
danakj60bc3bc2016-04-09 00:24:487368 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227369 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7370 }
7371
dcheng716bedf2014-10-21 09:51:087372 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227373
[email protected]1c3626e2014-04-09 17:49:227374 private:
7375 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7376 int id)
[email protected]a57cb8b12014-06-13 18:15:377377 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227378 SetDrawsContent(true);
7379 }
[email protected]1c3626e2014-04-09 17:49:227380};
7381
7382TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167383 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567384 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017385 LayerTreeSettings settings = host()->GetSettings();
ajumab4a846f22015-08-24 19:13:447386 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167387 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227388 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:487389 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227390 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487391 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227392 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487393 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227394 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487395 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227396 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7397
7398 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7399 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7400 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097401 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227402
danakjf78fb272016-07-26 19:06:157403 grand_parent->SetBounds(gfx::Size(1, 2));
7404 parent->SetBounds(gfx::Size(1, 2));
7405 child->SetBounds(gfx::Size(1, 2));
7406 grand_child->SetBounds(gfx::Size(1, 2));
7407
jaydasika89f7b5a2016-06-22 02:08:397408 child->test_properties()->AddChild(std::move(grand_child));
7409 parent->test_properties()->AddChild(std::move(child));
7410 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597411 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:057412
jaydasika2411692c2016-03-23 01:56:097413 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227414
7415 // No layers have animations.
sunxdf468675e2016-06-30 23:56:187416 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7417 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7418 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7419 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227420
sunxdf468675e2016-06-30 23:56:187421 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7422 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7423 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7424 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037425
[email protected]1c3626e2014-04-09 17:49:227426 TransformOperations translation;
7427 translation.AppendTranslate(1.f, 2.f, 3.f);
7428
loyso968163c92016-01-04 23:18:487429 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587430 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7431 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487432
vollickef2ae922016-06-29 17:54:277433 host_impl.active_tree()->SetElementIdsForTesting();
loysodb006882016-09-14 00:31:517434
7435 scoped_refptr<AnimationPlayer> grand_parent_player =
7436 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7437 timeline->AttachPlayer(grand_parent_player);
7438 grand_parent_player->AttachElement(grand_parent_raw->element_id());
7439
7440 scoped_refptr<AnimationPlayer> parent_player =
7441 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7442 timeline->AttachPlayer(parent_player);
7443 parent_player->AttachElement(parent_raw->element_id());
7444
7445 scoped_refptr<AnimationPlayer> child_player =
7446 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7447 timeline->AttachPlayer(child_player);
7448 child_player->AttachElement(child_raw->element_id());
7449
7450 scoped_refptr<AnimationPlayer> grand_child_player =
7451 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7452 timeline->AttachPlayer(grand_child_player);
7453 grand_child_player->AttachElement(grand_child_raw->element_id());
7454
7455 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7456 translation);
[email protected]1c3626e2014-04-09 17:49:227457
7458 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187459 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7460 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7461 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7462 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227463
sunxdf468675e2016-06-30 23:56:187464 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7465 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7466 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7467 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037468
[email protected]1c3626e2014-04-09 17:49:227469 TransformOperations scale;
7470 scale.AppendScale(5.f, 4.f, 3.f);
7471
loysodb006882016-09-14 00:31:517472 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7473 scale);
ajumacaaa9b32015-08-04 15:55:297474 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097475 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227476
7477 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:187478 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7479 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7480 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
7481 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227482
sunxdf468675e2016-06-30 23:56:187483 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7484 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7485 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
7486 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037487
loysodb006882016-09-14 00:31:517488 AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0,
7489 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097490 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7491 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227492
7493 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187494 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7495 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:227496 // We don't support combining animated scales from two nodes; 0.f means
7497 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:187498 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7499 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227500
sunxdf468675e2016-06-30 23:56:187501 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7502 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
7503 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7504 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037505
loysodb006882016-09-14 00:31:517506 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7507 scale);
ajumacaaa9b32015-08-04 15:55:297508 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097509 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227510
7511 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187512 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7513 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7514 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7515 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227516
sunxdf468675e2016-06-30 23:56:187517 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7518 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7519 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7520 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037521
loysodb006882016-09-14 00:31:517522 grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7523 parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7524 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
[email protected]1c3626e2014-04-09 17:49:227525
7526 TransformOperations perspective;
7527 perspective.AppendPerspective(10.f);
7528
loysodb006882016-09-14 00:31:517529 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7530 perspective);
ajumab4a846f22015-08-24 19:13:447531 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097532 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227533
7534 // |child| has a scale-affecting animation but computing the maximum of this
7535 // animation is not supported.
sunxdf468675e2016-06-30 23:56:187536 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7537 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7538 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7539 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227540
sunxdf468675e2016-06-30 23:56:187541 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7542 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7543 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7544 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037545
loysobb507792016-10-04 05:31:027546 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7547
[email protected]1c3626e2014-04-09 17:49:227548 gfx::Transform scale_matrix;
7549 scale_matrix.Scale(1.f, 2.f);
jaydasika10d43fc2016-08-18 04:06:047550 grand_parent_raw->test_properties()->transform = scale_matrix;
7551 parent_raw->test_properties()->transform = scale_matrix;
jaydasika2411692c2016-03-23 01:56:097552 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487553
loysodb006882016-09-14 00:31:517554 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7555 scale);
jaydasika2411692c2016-03-23 01:56:097556 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227557
7558 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7559 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:187560 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7561 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7562 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
7563 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227564
sunxdf468675e2016-06-30 23:56:187565 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7566 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7567 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
7568 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037569
[email protected]1c3626e2014-04-09 17:49:227570 gfx::Transform perspective_matrix;
7571 perspective_matrix.ApplyPerspectiveDepth(2.f);
jaydasika10d43fc2016-08-18 04:06:047572 child_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097573 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7574 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227575
7576 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187577 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7578 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7579 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7580 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227581
sunxdf468675e2016-06-30 23:56:187582 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7583 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7584 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7585 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037586
jaydasika10d43fc2016-08-18 04:06:047587 parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097588 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7589 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227590
7591 // |parent| and |child| have transforms that are neither translations nor
7592 // scales.
sunxdf468675e2016-06-30 23:56:187593 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7594 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7595 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7596 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227597
sunxdf468675e2016-06-30 23:56:187598 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7599 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7600 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7601 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037602
jaydasika10d43fc2016-08-18 04:06:047603 parent_raw->test_properties()->transform = gfx::Transform();
7604 child_raw->test_properties()->transform = gfx::Transform();
7605 grand_parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097606 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227607
jaydasika2411692c2016-03-23 01:56:097608 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227609
7610 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187611 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7612 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7613 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7614 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037615
sunxdf468675e2016-06-30 23:56:187616 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7617 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7618 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7619 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227620}
7621
ajuma956219582017-04-04 19:58:147622static void GatherDrawnLayers(LayerTreeImpl* tree_impl,
[email protected]390bb1ff2014-05-09 17:14:407623 std::set<LayerImpl*>* drawn_layers) {
ajuma956219582017-04-04 19:58:147624 for (EffectTreeLayerListIterator it(tree_impl);
7625 it.state() != EffectTreeLayerListIterator::State::END; ++it) {
7626 if (it.state() == EffectTreeLayerListIterator::State::LAYER)
7627 drawn_layers->insert(it.current_layer());
[email protected]390bb1ff2014-05-09 17:14:407628
ajuma956219582017-04-04 19:58:147629 if (it.state() != EffectTreeLayerListIterator::State::CONTRIBUTING_SURFACE)
[email protected]390bb1ff2014-05-09 17:14:407630 continue;
7631
ajuma956219582017-04-04 19:58:147632 if (it.current_render_surface()->MaskLayer())
7633 drawn_layers->insert(it.current_render_surface()->MaskLayer());
[email protected]390bb1ff2014-05-09 17:14:407634 }
7635}
7636
7637TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167638 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567639 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:227640 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407641
danakj60bc3bc2016-04-09 00:24:487642 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407643 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487644 std::unique_ptr<LayerImpl> parent =
7645 LayerImpl::Create(host_impl.active_tree(), 3);
7646 std::unique_ptr<LayerImpl> child =
7647 LayerImpl::Create(host_impl.active_tree(), 5);
7648 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407649 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487650 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407651 LayerImpl::Create(host_impl.active_tree(), 9);
7652
7653 LayerImpl* grand_parent_raw = grand_parent.get();
7654 LayerImpl* parent_raw = parent.get();
7655 LayerImpl* child_raw = child.get();
7656 LayerImpl* grand_child1_raw = grand_child1.get();
7657 LayerImpl* grand_child2_raw = grand_child2.get();
7658
danakjf78fb272016-07-26 19:06:157659 grand_parent->SetBounds(gfx::Size(1, 2));
7660 parent->SetBounds(gfx::Size(1, 2));
7661 child->SetBounds(gfx::Size(1, 2));
7662 grand_child1->SetBounds(gfx::Size(1, 2));
7663 grand_child2->SetBounds(gfx::Size(1, 2));
7664
jaydasika89f7b5a2016-06-22 02:08:397665 child->test_properties()->AddChild(std::move(grand_child1));
7666 child->test_properties()->AddChild(std::move(grand_child2));
7667 parent->test_properties()->AddChild(std::move(child));
7668 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597669 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407670
[email protected]390bb1ff2014-05-09 17:14:407671 // Start with nothing being drawn.
7672 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407673
ajuma651848a2017-05-01 21:23:457674 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7675 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7676 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7677 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7678 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407679
7680 std::set<LayerImpl*> expected;
7681 std::set<LayerImpl*> actual;
ajuma956219582017-04-04 19:58:147682 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407683 EXPECT_EQ(expected, actual);
7684
7685 // If we force render surface, but none of the layers are in the layer list,
7686 // then this layer should not appear in RSLL.
ajuma35b24f62017-01-27 21:23:097687 grand_child1_raw->test_properties()->force_render_surface = true;
jaydasikaebf9e4ea2015-08-14 21:29:127688 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407689
7690 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407691
ajuma651848a2017-05-01 21:23:457692 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7693 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7694 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7695 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7696 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407697
7698 expected.clear();
7699 actual.clear();
ajuma956219582017-04-04 19:58:147700 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407701 EXPECT_EQ(expected, actual);
7702
7703 // However, if we say that this layer also draws content, it will appear in
7704 // RSLL.
7705 grand_child1_raw->SetDrawsContent(true);
7706
7707 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407708
ajuma651848a2017-05-01 21:23:457709 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7710 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7711 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7712 EXPECT_TRUE(grand_child1_raw->contributes_to_drawn_render_surface());
7713 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407714
7715 expected.clear();
7716 expected.insert(grand_child1_raw);
7717
7718 actual.clear();
ajuma956219582017-04-04 19:58:147719 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407720 EXPECT_EQ(expected, actual);
7721
7722 // Now child is forced to have a render surface, and one if its children draws
7723 // content.
7724 grand_child1_raw->SetDrawsContent(false);
ajuma35b24f62017-01-27 21:23:097725 grand_child1_raw->test_properties()->force_render_surface = false;
jaydasikaebf9e4ea2015-08-14 21:29:127726 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
ajuma35b24f62017-01-27 21:23:097727 child_raw->test_properties()->force_render_surface = true;
[email protected]390bb1ff2014-05-09 17:14:407728 grand_child2_raw->SetDrawsContent(true);
7729
7730 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407731
ajuma651848a2017-05-01 21:23:457732 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7733 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7734 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
7735 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7736 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407737
7738 expected.clear();
7739 expected.insert(grand_child2_raw);
7740
7741 actual.clear();
ajuma956219582017-04-04 19:58:147742 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407743 EXPECT_EQ(expected, actual);
7744
7745 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:507746 child_raw->test_properties()->SetMaskLayer(
7747 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047748 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407749
7750 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407751
ajuma651848a2017-05-01 21:23:457752 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7753 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7754 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507755 EXPECT_TRUE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457756 ->mask_layer->contributes_to_drawn_render_surface());
7757 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7758 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[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 expected.clear();
7765 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507766 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407767
7768 actual.clear();
ajuma956219582017-04-04 19:58:147769 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407770 EXPECT_EQ(expected, actual);
7771
[email protected]390bb1ff2014-05-09 17:14:407772 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407773
ajuma651848a2017-05-01 21:23:457774 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7775 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7776 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507777 EXPECT_TRUE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457778 ->mask_layer->contributes_to_drawn_render_surface());
7779 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7780 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407781
7782 expected.clear();
7783 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507784 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407785
7786 actual.clear();
ajuma956219582017-04-04 19:58:147787 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407788 EXPECT_EQ(expected, actual);
7789
ajuma1d4026a32016-06-14 13:18:507790 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407791
7792 // With nothing drawing, we should have no layers.
7793 grand_child2_raw->SetDrawsContent(false);
7794
7795 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407796
ajuma651848a2017-05-01 21:23:457797 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7798 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7799 EXPECT_FALSE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507800 EXPECT_FALSE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457801 ->mask_layer->contributes_to_drawn_render_surface());
7802 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7803 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407804
7805 expected.clear();
7806 actual.clear();
ajuma956219582017-04-04 19:58:147807 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407808 EXPECT_EQ(expected, actual);
7809
7810 // Child itself draws means that we should have the child and the mask in the
7811 // list.
7812 child_raw->SetDrawsContent(true);
7813
7814 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407815
ajuma651848a2017-05-01 21:23:457816 EXPECT_FALSE(grand_parent_raw->contributes_to_drawn_render_surface());
7817 EXPECT_FALSE(parent_raw->contributes_to_drawn_render_surface());
7818 EXPECT_TRUE(child_raw->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:507819 EXPECT_TRUE(child_raw->test_properties()
ajuma651848a2017-05-01 21:23:457820 ->mask_layer->contributes_to_drawn_render_surface());
7821 EXPECT_FALSE(grand_child1_raw->contributes_to_drawn_render_surface());
7822 EXPECT_FALSE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407823
7824 expected.clear();
7825 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:507826 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407827 actual.clear();
ajuma956219582017-04-04 19:58:147828 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407829 EXPECT_EQ(expected, actual);
7830
ajuma1d4026a32016-06-14 13:18:507831 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:047832 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407833
7834 // Now everyone's a member!
7835 grand_parent_raw->SetDrawsContent(true);
7836 parent_raw->SetDrawsContent(true);
7837 child_raw->SetDrawsContent(true);
7838 grand_child1_raw->SetDrawsContent(true);
7839 grand_child2_raw->SetDrawsContent(true);
7840
7841 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407842
ajuma651848a2017-05-01 21:23:457843 EXPECT_TRUE(grand_parent_raw->contributes_to_drawn_render_surface());
7844 EXPECT_TRUE(parent_raw->contributes_to_drawn_render_surface());
7845 EXPECT_TRUE(child_raw->contributes_to_drawn_render_surface());
7846 EXPECT_TRUE(grand_child1_raw->contributes_to_drawn_render_surface());
7847 EXPECT_TRUE(grand_child2_raw->contributes_to_drawn_render_surface());
[email protected]390bb1ff2014-05-09 17:14:407848
7849 expected.clear();
7850 expected.insert(grand_parent_raw);
7851 expected.insert(parent_raw);
7852 expected.insert(child_raw);
7853 expected.insert(grand_child1_raw);
7854 expected.insert(grand_child2_raw);
7855
7856 actual.clear();
ajuma956219582017-04-04 19:58:147857 GatherDrawnLayers(host_impl.active_tree(), &actual);
[email protected]390bb1ff2014-05-09 17:14:407858 EXPECT_EQ(expected, actual);
7859}
[email protected]18e69652014-06-13 12:50:587860
7861TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167862 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567863 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017864 LayerTreeSettings settings = host()->GetSettings();
enne637715732015-07-07 02:05:267865 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167866 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227867 &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587868
danakj60bc3bc2016-04-09 00:24:487869 std::unique_ptr<LayerImpl> root =
7870 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:587871 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:487872 std::unique_ptr<LayerImpl> child1 =
7873 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:587874 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:487875 std::unique_ptr<LayerImpl> child2 =
7876 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:587877 LayerImpl* child2_layer = child2.get();
7878
danakjf78fb272016-07-26 19:06:157879 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:587880 scale_transform_child1.Scale(2, 3);
7881 scale_transform_child2.Scale(4, 5);
7882
danakjf78fb272016-07-26 19:06:157883 root->SetBounds(gfx::Size(1, 1));
7884 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:047885 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:157886 child1_layer->SetBounds(gfx::Size(1, 1));
7887 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587888
ajuma1d4026a32016-06-14 13:18:507889 child1_layer->test_properties()->SetMaskLayer(
7890 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:587891
danakjf78fb272016-07-26 19:06:157892 root->test_properties()->AddChild(std::move(child1));
7893 root->test_properties()->AddChild(std::move(child2));
7894 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7895 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:587896
7897 ExecuteCalculateDrawProperties(root_layer);
7898
7899 TransformOperations scale;
7900 scale.AppendScale(5.f, 8.f, 3.f);
7901
loyso9556c732016-03-11 07:54:587902 scoped_refptr<AnimationTimeline> timeline =
7903 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7904 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487905
jaydasika10d43fc2016-08-18 04:06:047906 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:157907 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:287908 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:277909 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
7910 1.0, TransformOperations(), scale);
7911
jaydasika2411692c2016-03-23 01:56:097912 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587913 ExecuteCalculateDrawProperties(root_layer);
7914
enne637715732015-07-07 02:05:267915 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7916 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:507917 EXPECT_FLOAT_EQ(
7918 3.f,
7919 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267920 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587921
sunxdf468675e2016-06-30 23:56:187922 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7923 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7924 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587925
[email protected]18e69652014-06-13 12:50:587926 // Changing page-scale would affect ideal_contents_scale and
7927 // maximum_animation_contents_scale.
7928
7929 float page_scale_factor = 3.f;
7930 float device_scale_factor = 1.0f;
ajumab784ef42017-04-28 23:01:527931 RenderSurfaceList render_surface_list;
[email protected]18e69652014-06-13 12:50:587932 gfx::Size device_viewport_size =
7933 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7934 root_layer->bounds().height() * device_scale_factor);
7935 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:527936 root_layer, device_viewport_size, &render_surface_list);
[email protected]18e69652014-06-13 12:50:587937
7938 inputs.page_scale_factor = page_scale_factor;
7939 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117940 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:577941 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587942
enne637715732015-07-07 02:05:267943 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7944 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587945 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267946 9.f,
ajuma1d4026a32016-06-14 13:18:507947 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267948 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587949
sunxdf468675e2016-06-30 23:56:187950 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7951 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7952 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587953
[email protected]18e69652014-06-13 12:50:587954 // Changing device-scale would affect ideal_contents_scale and
7955 // maximum_animation_contents_scale.
7956
7957 device_scale_factor = 4.0f;
7958 inputs.device_scale_factor = device_scale_factor;
7959 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097960 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:577961 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587962
enne637715732015-07-07 02:05:267963 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7964 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587965 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267966 36.f,
ajuma1d4026a32016-06-14 13:18:507967 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267968 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587969
sunxdf468675e2016-06-30 23:56:187970 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7971 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7972 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
7973}
7974
7975TEST_F(LayerTreeHostCommonTest, AnimationScales) {
7976 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:187977 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017978 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:187979 settings.layer_transforms_should_scale_layer_contents = true;
7980 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227981 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:187982
7983 std::unique_ptr<LayerImpl> root =
7984 LayerImpl::Create(host_impl.active_tree(), 1);
7985 LayerImpl* root_layer = root.get();
7986 std::unique_ptr<LayerImpl> child1 =
7987 LayerImpl::Create(host_impl.active_tree(), 2);
7988 LayerImpl* child1_layer = child1.get();
7989 std::unique_ptr<LayerImpl> child2 =
7990 LayerImpl::Create(host_impl.active_tree(), 3);
7991 LayerImpl* child2_layer = child2.get();
7992
7993 root->test_properties()->AddChild(std::move(child1));
7994 child1_layer->test_properties()->AddChild(std::move(child2));
7995 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7996
7997 host_impl.active_tree()->SetElementIdsForTesting();
7998
danakjf78fb272016-07-26 19:06:157999 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:188000 scale_transform_child1.Scale(2, 3);
8001 scale_transform_child2.Scale(4, 5);
8002
danakjf78fb272016-07-26 19:06:158003 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048004 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158005 child1_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048006 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158007 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:188008
8009 TransformOperations scale;
8010 scale.AppendScale(5.f, 8.f, 3.f);
8011
8012 scoped_refptr<AnimationTimeline> timeline =
8013 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8014 host_impl.animation_host()->AddAnimationTimeline(timeline);
8015
8016 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8017 1.0, TransformOperations(), scale);
8018
sunxdf468675e2016-06-30 23:56:188019 // Correctly computes animation scale when rebuilding property trees.
8020 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8021 ExecuteCalculateDrawProperties(root_layer);
8022
8023 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8024 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8025 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
8026
8027 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8028 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
8029 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
8030
8031 // Correctly updates animation scale when layer property changes.
jaydasika10d43fc2016-08-18 04:06:048032 child1_layer->test_properties()->transform = gfx::Transform();
weiliangcea09f3372017-03-29 16:43:248033 root_layer->layer_tree_impl()->SetTransformMutated(child1_layer->element_id(),
8034 gfx::Transform());
sunxdf468675e2016-06-30 23:56:188035 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
8036 ExecuteCalculateDrawProperties(root_layer);
8037 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
8038 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
8039
8040 // Do not update animation scale if already updated.
8041 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
8042 child2_layer->transform_tree_index(), 100.f, 100.f);
8043 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
8044 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
8045}
8046
8047TEST_F(LayerTreeHostCommonTest,
8048 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
8049 // Returns empty scale if layer_transforms_should_scale_layer_contents is
8050 // false.
8051 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188052 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018053 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188054 settings.layer_transforms_should_scale_layer_contents = false;
8055 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228056 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188057
8058 std::unique_ptr<LayerImpl> root =
8059 LayerImpl::Create(host_impl.active_tree(), 1);
8060 LayerImpl* root_layer = root.get();
8061 std::unique_ptr<LayerImpl> child =
8062 LayerImpl::Create(host_impl.active_tree(), 2);
8063 LayerImpl* child_layer = child.get();
8064
8065 root->test_properties()->AddChild(std::move(child));
8066 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8067
8068 host_impl.active_tree()->SetElementIdsForTesting();
8069
danakjf78fb272016-07-26 19:06:158070 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:188071 scale_transform_child.Scale(4, 5);
8072
danakjf78fb272016-07-26 19:06:158073 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048074 child_layer->test_properties()->transform = scale_transform_child;
danakjf78fb272016-07-26 19:06:158075 child_layer->SetBounds(gfx::Size(1, 1));
8076
sunxdf468675e2016-06-30 23:56:188077 TransformOperations scale;
8078 scale.AppendScale(5.f, 8.f, 3.f);
8079
8080 scoped_refptr<AnimationTimeline> timeline =
8081 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8082 host_impl.animation_host()->AddAnimationTimeline(timeline);
8083
8084 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
8085 1.0, TransformOperations(), scale);
8086
sunxdf468675e2016-06-30 23:56:188087 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8088 ExecuteCalculateDrawProperties(root_layer);
8089
8090 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8091 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
8092
8093 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8094 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:588095}
8096
danakjf6069db2014-09-13 00:46:478097TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598098 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148099 LayerImpl* clip = AddChild<LayerImpl>(root);
8100 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:478101
danakjf78fb272016-07-26 19:06:158102 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:148103 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158104 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:478105 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158106 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:148107 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158108 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:478109
8110 gfx::Size device_viewport_size(768, 582);
ajumab784ef42017-04-28 23:01:528111 RenderSurfaceList render_surface_list_impl;
jaydasika6f972de2016-04-07 16:16:148112 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:528113 root, device_viewport_size, gfx::Transform(), &render_surface_list_impl);
danakjf6069db2014-09-13 00:46:478114 inputs.device_scale_factor = 2.f;
8115 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:298116 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:578117 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478118
8119 // Layers in the root render surface have their visible content rect clipped
8120 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148121 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478122
8123 // Layers drawing to a child render surface should still have their visible
8124 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148125 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478126}
8127
pdr23d381fd2017-04-25 21:06:318128TEST_F(LayerTreeHostCommonTest, ViewportBoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168129 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568130 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228131 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
timav599f4359d2014-12-05 00:12:228132
8133 // Set two layers: the root layer clips it's child,
8134 // the child draws its content.
8135
8136 gfx::Size root_size = gfx::Size(300, 500);
8137
8138 // Sublayer should be bigger than the root enlarged by bounds_delta.
8139 gfx::Size sublayer_size = gfx::Size(300, 1000);
8140
mdjones2ee41afd2016-10-27 16:50:208141 // Device viewport accomidated the root and the browser controls.
timav599f4359d2014-12-05 00:12:228142 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:228143
miletus8bd08a622015-06-16 18:44:528144 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:598145 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:228146 LayerImpl::Create(host_impl.active_tree(), 1));
8147
jaydasikabf1875a2016-06-28 03:39:598148 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:158149 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:228150 root->SetMasksToBounds(true);
8151
pdr23d381fd2017-04-25 21:06:318152 // Make root the inner viewport scroll layer. This ensures the later call to
8153 // |SetViewportBoundsDelta| will be on a viewport layer.
pdr53abb452017-05-19 01:59:428154 LayerTreeImpl::ViewportLayerIds viewport_ids;
8155 viewport_ids.inner_viewport_scroll = root->id();
8156 host_impl.active_tree()->SetViewportLayersFromIds(viewport_ids);
pdr23d381fd2017-04-25 21:06:318157
jaydasika89f7b5a2016-06-22 02:08:398158 root->test_properties()->AddChild(
8159 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:228160
jaydasikafc66cfb2016-06-10 04:34:228161 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:158162 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:228163 sublayer->SetDrawsContent(true);
8164
danakj74af409e2016-07-01 00:41:488165 host_impl.active_tree()->BuildPropertyTreesForTesting();
8166
ajumab784ef42017-04-28 23:01:528167 RenderSurfaceList render_surface_list;
timav599f4359d2014-12-05 00:12:228168 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumab784ef42017-04-28 23:01:528169 root, device_viewport_size, &render_surface_list);
timav599f4359d2014-12-05 00:12:228170
sunxdb365de02016-04-28 20:32:578171 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438172 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228173
pdr23d381fd2017-04-25 21:06:318174 root->SetViewportBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578175 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228176
8177 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8178 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438179 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228180}
8181
pdr23d381fd2017-04-25 21:06:318182TEST_F(LayerTreeHostCommonTest, NodesAffectedByViewportBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318183 scoped_refptr<Layer> root = Layer::Create();
Philip Rogersd9e5ffd2017-06-16 00:10:538184 scoped_refptr<Layer> page_scale_layer = Layer::Create();
loyso0940d412016-03-14 01:30:318185 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8186 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8187 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8188 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298189
8190 root->AddChild(inner_viewport_container_layer);
Philip Rogersd9e5ffd2017-06-16 00:10:538191 inner_viewport_container_layer->AddChild(page_scale_layer);
8192 page_scale_layer->AddChild(inner_viewport_scroll_layer);
ajumadd2802e72015-06-30 20:28:298193 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8194 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8195
ajumadd2802e72015-06-30 20:28:298196 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8197 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8198
8199 host()->SetRootLayer(root);
pdr5200a052017-05-21 22:50:588200 LayerTreeHost::ViewportLayers viewport_layers;
Philip Rogersd9e5ffd2017-06-16 00:10:538201 viewport_layers.page_scale = page_scale_layer;
pdr5200a052017-05-21 22:50:588202 viewport_layers.inner_viewport_container = inner_viewport_container_layer;
8203 viewport_layers.outer_viewport_container = outer_viewport_container_layer;
8204 viewport_layers.inner_viewport_scroll = inner_viewport_scroll_layer;
8205 viewport_layers.outer_viewport_scroll = outer_viewport_scroll_layer;
8206 host()->RegisterViewportLayers(viewport_layers);
ajumadd2802e72015-06-30 20:28:298207
loyso0940d412016-03-14 01:30:318208 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8209 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298210
8211 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8212 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8213
8214 LayerPositionConstraint fixed_to_right;
8215 fixed_to_right.set_is_fixed_position(true);
8216 fixed_to_right.set_is_fixed_to_right_edge(true);
8217
8218 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8219 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8220
jaydasika6ed869662016-09-21 14:29:598221 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298222
8223 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8224 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8225 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8226
8227 LayerPositionConstraint fixed_to_left;
8228 fixed_to_left.set_is_fixed_position(true);
8229 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8230
jaydasika6ed869662016-09-21 14:29:598231 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298232 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8233 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8234
8235 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8236
jaydasika6ed869662016-09-21 14:29:598237 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298238 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8239 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8240}
8241
vollick7d83b452015-02-24 20:18:068242TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
sunxd713aedbd2016-08-10 22:22:148243 host_impl()->CreatePendingTree();
8244 std::unique_ptr<LayerImpl> pending_root =
8245 LayerImpl::Create(host_impl()->pending_tree(), 1);
8246 LayerImpl* root = pending_root.get();
8247 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root));
8248 std::unique_ptr<LayerImpl> animated_ptr =
8249 LayerImpl::Create(host_impl()->pending_tree(), 2);
8250 LayerImpl* animated = animated_ptr.get();
8251 root->test_properties()->AddChild(std::move(animated_ptr));
vollick7d83b452015-02-24 20:18:068252
sunxd713aedbd2016-08-10 22:22:148253 animated->SetDrawsContent(true);
8254 host_impl()->pending_tree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278255
danakjf78fb272016-07-26 19:06:158256 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:068257 root->SetMasksToBounds(true);
sunxd713aedbd2016-08-10 22:22:148258 root->test_properties()->force_render_surface = true;
8259 animated->test_properties()->opacity = 0.f;
danakjf78fb272016-07-26 19:06:158260 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:068261
sunxd713aedbd2016-08-10 22:22:148262 AddOpacityTransitionToElementWithPlayer(
8263 animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false);
8264 animated->test_properties()->opacity_can_animate = true;
8265 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598266 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
vollick7d83b452015-02-24 20:18:068267
sunxd713aedbd2016-08-10 22:22:148268 EXPECT_FALSE(animated->visible_layer_rect().IsEmpty());
vollick7d83b452015-02-24 20:18:068269}
8270
ajumaa92fdc12015-03-31 22:47:418271TEST_F(LayerTreeHostCommonTest,
8272 VisibleContentRectForAnimatedLayerWithSingularTransform) {
jaydasikaaf0dcd172017-05-01 17:37:178273 host_impl()->CreatePendingTree();
8274 std::unique_ptr<LayerImpl> root_ptr =
8275 LayerImpl::Create(host_impl()->pending_tree(), 1);
8276 LayerImpl* root = root_ptr.get();
8277 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(root_ptr));
8278 std::unique_ptr<LayerImpl> clip_ptr =
8279 LayerImpl::Create(host_impl()->pending_tree(), 2);
8280 LayerImpl* clip = clip_ptr.get();
8281 root->test_properties()->AddChild(std::move(clip_ptr));
8282 std::unique_ptr<LayerImpl> animated_ptr =
8283 LayerImpl::Create(host_impl()->pending_tree(), 3);
8284 LayerImpl* animated = animated_ptr.get();
8285 clip->test_properties()->AddChild(std::move(animated_ptr));
8286 std::unique_ptr<LayerImpl> surface_ptr =
8287 LayerImpl::Create(host_impl()->pending_tree(), 4);
8288 LayerImpl* surface = surface_ptr.get();
8289 animated->test_properties()->AddChild(std::move(surface_ptr));
8290 std::unique_ptr<LayerImpl> descendant_of_animation_ptr =
8291 LayerImpl::Create(host_impl()->pending_tree(), 5);
8292 LayerImpl* descendant_of_animation = descendant_of_animation_ptr.get();
8293 surface->test_properties()->AddChild(std::move(descendant_of_animation_ptr));
ajumaa92fdc12015-03-31 22:47:418294
jaydasikaaf0dcd172017-05-01 17:37:178295 host_impl()->pending_tree()->SetElementIdsForTesting();
ajumaa92fdc12015-03-31 22:47:418296
jaydasikaaf0dcd172017-05-01 17:37:178297 root->SetDrawsContent(true);
sunxd713aedbd2016-08-10 22:22:148298 animated->SetDrawsContent(true);
8299 surface->SetDrawsContent(true);
8300 descendant_of_animation->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278301
ajumaa92fdc12015-03-31 22:47:418302 gfx::Transform uninvertible_matrix;
8303 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8304
danakjf78fb272016-07-26 19:06:158305 root->SetBounds(gfx::Size(100, 100));
8306 clip->SetBounds(gfx::Size(10, 10));
8307 clip->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:048308 animated->test_properties()->transform = uninvertible_matrix;
danakjf78fb272016-07-26 19:06:158309 animated->SetBounds(gfx::Size(120, 120));
8310 surface->SetBounds(gfx::Size(100, 100));
sunxd713aedbd2016-08-10 22:22:148311 surface->test_properties()->force_render_surface = true;
danakjf78fb272016-07-26 19:06:158312 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:418313
8314 TransformOperations start_transform_operations;
8315 start_transform_operations.AppendMatrix(uninvertible_matrix);
8316 TransformOperations end_transform_operations;
8317
sunxd713aedbd2016-08-10 22:22:148318 AddAnimatedTransformToElementWithPlayer(
8319 animated->element_id(), timeline_impl(), 10.0, start_transform_operations,
8320 end_transform_operations);
jaydasikaaf0dcd172017-05-01 17:37:178321 ExecuteCalculateDrawProperties(root);
8322 // Since animated has singular transform, it is not be part of render
8323 // surface layer list but should be rastered.
ajuma651848a2017-05-01 21:23:458324 EXPECT_FALSE(animated->contributes_to_drawn_render_surface());
khushalsagar2fc1dbd2017-05-26 21:48:168325 EXPECT_TRUE(animated->raster_even_if_not_drawn());
ajumaa92fdc12015-03-31 22:47:418326
8327 // The animated layer has a singular transform and maps to a non-empty rect in
8328 // clipped target space, so is treated as fully visible.
sunxd713aedbd2016-08-10 22:22:148329 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418330
8331 // The singular transform on |animated| is flattened when inherited by
8332 // |surface|, and this happens to make it invertible.
sunxd713aedbd2016-08-10 22:22:148333 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect());
8334 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418335
8336 gfx::Transform zero_matrix;
8337 zero_matrix.Scale3d(0.f, 0.f, 0.f);
weiliangcea09f3372017-03-29 16:43:248338 root->layer_tree_impl()->SetTransformMutated(animated->element_id(),
8339 zero_matrix);
jaydasikaaf0dcd172017-05-01 17:37:178340 ExecuteCalculateDrawProperties(root);
ajumaa92fdc12015-03-31 22:47:418341
jaydasika6ed869662016-09-21 14:29:598342 // The animated layer will be treated as fully visible when we combine clips
8343 // in screen space.
jaydasika3a6b14432017-03-21 23:11:198344 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
jaydasika6ed869662016-09-21 14:29:598345
ajumaa92fdc12015-03-31 22:47:418346 // This time, flattening does not make |animated|'s transform invertible. This
8347 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348348 // |surface| and layers that draw into it as having empty visible rect.
jaydasika3a6b14432017-03-21 23:11:198349 EXPECT_EQ(gfx::Rect(100, 100), surface->visible_layer_rect());
8350 EXPECT_EQ(gfx::Rect(200, 200), descendant_of_animation->visible_layer_rect());
jaydasikaaf0dcd172017-05-01 17:37:178351
8352 host_impl()->ActivateSyncTree();
8353 LayerImpl* active_root = host_impl()->active_tree()->LayerById(root->id());
8354 ExecuteCalculateDrawProperties(active_root);
8355
8356 // Since the animated has singular transform, it is not be part of render
8357 // surface layer list.
8358 LayerImpl* active_animated =
8359 host_impl()->active_tree()->LayerById(animated->id());
ajuma651848a2017-05-01 21:23:458360 EXPECT_TRUE(active_root->contributes_to_drawn_render_surface());
8361 EXPECT_FALSE(active_animated->contributes_to_drawn_render_surface());
jaydasikaaf0dcd172017-05-01 17:37:178362
8363 // Since animated has singular transform, it is not be part of render
8364 // surface layer list but should be rastered.
khushalsagar2fc1dbd2017-05-26 21:48:168365 EXPECT_TRUE(animated->raster_even_if_not_drawn());
jaydasikaaf0dcd172017-05-01 17:37:178366 EXPECT_EQ(gfx::Rect(120, 120), active_animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418367}
8368
ajuma20384bf2016-07-22 13:26:158369// Verify that having animated opacity but current opacity 1 still creates
8370// a render surface.
8371TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
8372 LayerImpl* root = root_layer_for_testing();
8373 LayerImpl* child = AddChild<LayerImpl>(root);
8374 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:158375
danakjf78fb272016-07-26 19:06:158376 root->SetBounds(gfx::Size(50, 50));
8377 child->SetBounds(gfx::Size(50, 50));
8378 child->SetDrawsContent(true);
8379 grandchild->SetBounds(gfx::Size(50, 50));
8380 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:158381
8382 SetElementIdsForTesting();
8383 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
8384 10.0, 1.f, 0.2f, false);
8385 ExecuteCalculateDrawProperties(root);
8386
8387 EXPECT_EQ(1.f, child->Opacity());
chrishtr7e3aaf22017-05-04 15:04:018388 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:498389 EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root));
8390 EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child));
ajuma20384bf2016-07-22 13:26:158391}
8392
wkorman53a44322017-05-12 15:39:238393static bool FilterIsAnimating(LayerImpl* layer) {
8394 return layer->GetMutatorHost()->IsAnimatingFilterProperty(
8395 layer->element_id(), layer->GetElementTypeForAnimation());
8396}
8397
enne92f2f6d92015-02-25 23:13:318398// Verify that having an animated filter (but no current filter, as these
8399// are mutually exclusive) correctly creates a render surface.
8400TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598401 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328402 LayerImpl* child = AddChild<LayerImpl>(root);
8403 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318404
danakjf78fb272016-07-26 19:06:158405 root->SetBounds(gfx::Size(50, 50));
8406 child->SetBounds(gfx::Size(50, 50));
8407 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:318408
vollickef2ae922016-06-29 17:54:278409 SetElementIdsForTesting();
8410 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
8411 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:328412 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318413
chrishtr7e3aaf22017-05-04 15:04:018414 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:498415 EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root));
8416 EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child));
enne92f2f6d92015-02-25 23:13:318417
chrishtr7e3aaf22017-05-04 15:04:018418 EXPECT_TRUE(GetRenderSurface(root)->Filters().IsEmpty());
8419 EXPECT_TRUE(GetRenderSurface(child)->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:318420
wkorman53a44322017-05-12 15:39:238421 EXPECT_FALSE(FilterIsAnimating(root));
8422 EXPECT_TRUE(FilterIsAnimating(child));
8423 EXPECT_FALSE(FilterIsAnimating(grandchild));
enne92f2f6d92015-02-25 23:13:318424}
8425
ajuma315a4782015-07-24 21:16:348426// Verify that having a filter animation with a delayed start time creates a
8427// render surface.
8428TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598429 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328430 LayerImpl* child = AddChild<LayerImpl>(root);
8431 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348432
danakjf78fb272016-07-26 19:06:158433 root->SetBounds(gfx::Size(50, 50));
8434 child->SetBounds(gfx::Size(50, 50));
8435 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:348436
vollickef2ae922016-06-29 17:54:278437 SetElementIdsForTesting();
8438
danakj60bc3bc2016-04-09 00:24:488439 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348440 KeyframedFilterAnimationCurve::Create());
8441 FilterOperations start_filters;
8442 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8443 FilterOperations end_filters;
8444 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8445 curve->AddKeyframe(
8446 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8447 curve->AddKeyframe(FilterKeyframe::Create(
8448 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488449 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308450 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558451 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348452 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348453
vollickef2ae922016-06-29 17:54:278454 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
8455 std::move(animation));
ajuma4711f4b12016-05-16 18:48:328456 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348457
chrishtr7e3aaf22017-05-04 15:04:018458 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:498459 EXPECT_NE(GetRenderSurface(child), GetRenderSurface(root));
8460 EXPECT_EQ(GetRenderSurface(grandchild), GetRenderSurface(child));
ajuma315a4782015-07-24 21:16:348461
chrishtr7e3aaf22017-05-04 15:04:018462 EXPECT_TRUE(GetRenderSurface(root)->Filters().IsEmpty());
8463 EXPECT_TRUE(GetRenderSurface(child)->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:348464
wkorman53a44322017-05-12 15:39:238465 EXPECT_FALSE(FilterIsAnimating(root));
ajuma315a4782015-07-24 21:16:348466 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
wkorman53a44322017-05-12 15:39:238467 EXPECT_FALSE(FilterIsAnimating(child));
ajuma315a4782015-07-24 21:16:348468 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
wkorman53a44322017-05-12 15:39:238469 EXPECT_FALSE(FilterIsAnimating(grandchild));
ajuma315a4782015-07-24 21:16:348470 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8471}
8472
vollick0120eb22015-03-02 03:07:348473// Ensures that the property tree code accounts for offsets between fixed
8474// position layers and their respective containers.
8475TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:598476 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148477 LayerImpl* child = AddChild<LayerImpl>(root);
8478 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348479
danakjf78fb272016-07-26 19:06:158480 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:348481 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528482 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158483 child->SetPosition(gfx::PointF(1000, 1000));
8484 child->SetBounds(gfx::Size(50, 50));
8485 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8486 grandchild->SetBounds(gfx::Size(50, 50));
8487 grandchild->SetDrawsContent(true);
8488
vollick0120eb22015-03-02 03:07:348489 LayerPositionConstraint constraint;
8490 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528491 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:348492
jaydasika6f972de2016-04-07 16:16:148493 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348494
jaydasika6f972de2016-04-07 16:16:148495 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348496}
8497
ajuma0178b522015-07-02 21:08:418498// Ensures that the property tree code accounts for offsets between fixed
8499// position containers and their transform tree parents, when a fixed position
8500// layer's container is its layer tree parent, but this parent doesn't have its
8501// own transform tree node.
8502TEST_F(LayerTreeHostCommonTest,
8503 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:598504 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148505 LayerImpl* child = AddChild<LayerImpl>(root);
8506 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418507
danakjf78fb272016-07-26 19:06:158508 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:418509 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158510 root->test_properties()->is_container_for_fixed_position_layers = true;
8511 child->SetPosition(gfx::PointF(1000, 1000));
8512 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:528513 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158514 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8515 grandchild->SetBounds(gfx::Size(50, 50));
8516 grandchild->SetDrawsContent(true);
8517
ajuma0178b522015-07-02 21:08:418518 LayerPositionConstraint constraint;
8519 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528520 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:418521
jaydasika6f972de2016-04-07 16:16:148522 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418523
jaydasika6f972de2016-04-07 16:16:148524 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418525}
8526
vollick8c824742015-03-20 22:21:088527TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:598528 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148529 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8530 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088531 gfx::Transform translate_z;
8532 translate_z.Translate3d(0, 0, 10);
8533
danakjf78fb272016-07-26 19:06:158534 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:528535 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088536
danakjf78fb272016-07-26 19:06:158537 frame_clip->SetPosition(gfx::PointF(500, 100));
8538 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:088539 frame_clip->SetMasksToBounds(true);
8540
danakjf78fb272016-07-26 19:06:158541 fixed->SetBounds(gfx::Size(1000, 1000));
8542 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088543
8544 LayerPositionConstraint constraint;
8545 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528546 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:088547
jaydasika6f972de2016-04-07 16:16:148548 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088549
8550 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148551 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088552}
8553
vollick06ca3e832015-03-31 19:37:128554TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:598555 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148556 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8557 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8558 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8559
danakjf78fb272016-07-26 19:06:158560 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:148561 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158562 root->test_properties()->is_container_for_fixed_position_layers = true;
8563 frame_clip->SetPosition(gfx::PointF(500, 100));
8564 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148565 frame_clip->SetMasksToBounds(true);
8566 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158567 scroller->SetBounds(gfx::Size(1000, 1000));
pdr54d038192017-06-08 22:44:138568 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
Philip Rogers4131a1c12017-07-21 19:36:508569 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
pdr54d038192017-06-08 22:44:138570 scroller->SetElementId(LayerIdToElementIdForTesting(scroller->id()));
pdrbbfd8822017-06-27 22:44:528571 scroller->SetScrollable(frame_clip->bounds());
jaydasika6f972de2016-04-07 16:16:148572 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158573 fixed->SetPosition(gfx::PointF(100, 100));
8574 fixed->SetBounds(gfx::Size(50, 50));
8575 fixed->SetMasksToBounds(true);
8576 fixed->SetDrawsContent(true);
8577 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:128578
8579 LayerPositionConstraint constraint;
8580 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528581 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128582
jaydasika6f972de2016-04-07 16:16:148583 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128584
8585 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148586 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128587}
8588
vollick5057e1e2015-04-17 19:12:328589TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:328590 gfx::Transform translate;
8591 gfx::Transform rotate;
8592
8593 translate.Translate(10, 10);
8594 rotate.Rotate(45);
8595
loyso0940d412016-03-14 01:30:318596 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:158597 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:328598 root->SetIsContainerForFixedPositionLayers(true);
8599
ennea7b43c32015-06-18 20:01:338600 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328601
jaydasika6ed869662016-09-21 14:29:598602 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ennea7b43c32015-06-18 20:01:338603 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328604
8605 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338606 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328607
8608 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338609 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328610}
8611
ajumab0e0c1c2015-04-23 00:29:238612TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:598613 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148614 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238615
ajumab0e0c1c2015-04-23 00:29:238616 gfx::Transform scale_matrix;
8617 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:238618
danakjf78fb272016-07-26 19:06:158619 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148620 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048621 child->test_properties()->transform = scale_matrix;
danakjf78fb272016-07-26 19:06:158622 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148623 child->SetDrawsContent(true);
8624
8625 ExecuteCalculateDrawProperties(root);
8626 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238627
jaydasika38be7a822016-04-21 16:07:068628 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238629
jaydasika6f972de2016-04-07 16:16:148630 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8631 ExecuteCalculateDrawProperties(root);
8632 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238633}
8634
ajumaf09db8962015-04-24 21:55:348635TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:598636 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148637 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8638 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348639
ajumaf09db8962015-04-24 21:55:348640 gfx::Transform scale;
8641 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:158642
8643 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:048644 scroll_child->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:158645 scroll_child->SetBounds(gfx::Size(40, 40));
8646 scroll_child->SetDrawsContent(true);
8647 scroll_parent->SetBounds(gfx::Size(30, 30));
8648 scroll_parent->SetDrawsContent(true);
8649
8650 scroll_child->test_properties()->scroll_parent = scroll_parent;
8651 scroll_parent->test_properties()->scroll_children =
8652 base::MakeUnique<std::set<LayerImpl*>>();
8653 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:348654
jaydasika6f972de2016-04-07 16:16:148655 ExecuteCalculateDrawProperties(root);
8656 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348657
8658 scroll_child->SetPosition(gfx::PointF(0, -10.f));
Philip Rogers4131a1c12017-07-21 19:36:508659 scroll_parent->SetElementId(
8660 LayerIdToElementIdForTesting(scroll_parent->id()));
jaydasika6f972de2016-04-07 16:16:148661 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
pdr80d5a3e2017-07-17 19:04:078662 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8663 ExecuteCalculateDrawProperties(root);
Philip Rogers4131a1c12017-07-21 19:36:508664 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348665}
8666
Fady Samueldfecb7d2017-07-26 11:41:048667static void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128668
jaydasikaebc94282017-04-24 20:34:018669TEST_F(LayerTreeHostCommonTest, HasCopyRequestsInTargetSubtree) {
loyso0940d412016-03-14 01:30:318670 scoped_refptr<Layer> root = Layer::Create();
8671 scoped_refptr<Layer> child1 = Layer::Create();
8672 scoped_refptr<Layer> child2 = Layer::Create();
8673 scoped_refptr<Layer> grandchild = Layer::Create();
8674 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028675
8676 root->AddChild(child1);
8677 root->AddChild(child2);
8678 child1->AddChild(grandchild);
8679 grandchild->AddChild(greatgrandchild);
8680 host()->SetRootLayer(root);
8681
Fady Samueldfecb7d2017-07-26 11:41:048682 child1->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
Yuri Wiitalab2511762017-07-19 00:17:538683 base::BindOnce(&CopyOutputCallback)));
Fady Samueldfecb7d2017-07-26 11:41:048684 greatgrandchild->RequestCopyOfOutput(
8685 viz::CopyOutputRequest::CreateBitmapRequest(
8686 base::BindOnce(&CopyOutputCallback)));
sunxded58688e2016-01-11 21:01:028687 child2->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598688 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:028689
jaydasikaebc94282017-04-24 20:34:018690 EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
8691 EXPECT_TRUE(child1->has_copy_requests_in_target_subtree());
8692 EXPECT_FALSE(child2->has_copy_requests_in_target_subtree());
8693 EXPECT_TRUE(grandchild->has_copy_requests_in_target_subtree());
8694 EXPECT_TRUE(greatgrandchild->has_copy_requests_in_target_subtree());
sunxded58688e2016-01-11 21:01:028695}
8696
vollick2175fae82015-04-27 21:18:128697TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:318698 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328699 FakeContentLayerClient client;
8700 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128701 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318702 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128703 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318704 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258705 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318706 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:158707
8708 root->SetBounds(gfx::Size(100, 100));
8709 child->SetBounds(gfx::Size(10, 10));
8710 grandchild->SetBounds(gfx::Size(10, 10));
8711 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128712
8713 root->AddChild(child);
8714 child->AddChild(grandchild);
8715 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:338716 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:078717 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278718
vollick2175fae82015-04-27 21:18:128719 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598720 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148721 const LayerList* update_list = GetUpdateLayerList();
8722 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128723
8724 // Now we will reset the visible rect from property trees for the grandchild,
8725 // and we will configure |child| in several ways that should force the subtree
8726 // to be skipped. The visible content rect for |grandchild| should, therefore,
8727 // remain empty.
vollick2175fae82015-04-27 21:18:128728 gfx::Transform singular;
8729 singular.matrix().set(0, 0, 0);
8730
8731 child->SetTransform(singular);
jaydasika6ed869662016-09-21 14:29:598732 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148733 update_list = GetUpdateLayerList();
8734 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
danakjf78fb272016-07-26 19:06:158735 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128736
8737 child->SetHideLayerAndSubtree(true);
jaydasika6ed869662016-09-21 14:29:598738 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148739 update_list = GetUpdateLayerList();
8740 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128741 child->SetHideLayerAndSubtree(false);
8742
ajuma315a4782015-07-24 21:16:348743 gfx::Transform zero_z_scale;
8744 zero_z_scale.Scale3d(1, 1, 0);
8745 child->SetTransform(zero_z_scale);
8746
8747 // Add a transform animation with a start delay. Now, even though |child| has
8748 // a singular transform, the subtree should still get processed.
8749 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488750 std::unique_ptr<Animation> animation = Animation::Create(
8751 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308752 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558753 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348754 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278755 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
8756 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598757 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148758 update_list = GetUpdateLayerList();
8759 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348760
vollickef2ae922016-06-29 17:54:278761 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
8762 animation_id);
danakjf78fb272016-07-26 19:06:158763 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128764 child->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598765 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148766 update_list = GetUpdateLayerList();
8767 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128768
8769 // Now, even though child has zero opacity, we will configure |grandchild| and
8770 // |greatgrandchild| in several ways that should force the subtree to be
8771 // processed anyhow.
Fady Samueldfecb7d2017-07-26 11:41:048772 grandchild->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
Yuri Wiitalab2511762017-07-19 00:17:538773 base::BindOnce(&CopyOutputCallback)));
jaydasika6ed869662016-09-21 14:29:598774 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148775 update_list = GetUpdateLayerList();
8776 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348777
8778 // Add an opacity animation with a start delay.
8779 animation_id = 1;
8780 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488781 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308782 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558783 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348784 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278785 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
8786 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598787 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148788 update_list = GetUpdateLayerList();
8789 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128790}
8791
sunxd71aea3e2016-04-01 23:48:058792TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168793 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568794 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228795 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
vollick2175fae82015-04-27 21:18:128796
danakj60bc3bc2016-04-09 00:24:488797 std::unique_ptr<LayerImpl> root =
8798 LayerImpl::Create(host_impl.active_tree(), 1);
8799 std::unique_ptr<LayerImpl> child =
8800 LayerImpl::Create(host_impl.active_tree(), 2);
8801 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:128802 LayerImpl::Create(host_impl.active_tree(), 3);
8803
danakj60bc3bc2016-04-09 00:24:488804 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:258805 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128806
danakjf78fb272016-07-26 19:06:158807 root->SetBounds(gfx::Size(100, 100));
8808 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128809 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158810 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128811 grandchild->SetDrawsContent(true);
8812 greatgrandchild->SetDrawsContent(true);
8813
jaydasika2411692c2016-03-23 01:56:098814 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128815 LayerImpl* child_ptr = child.get();
8816 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128817
jaydasika89f7b5a2016-06-22 02:08:398818 child->test_properties()->AddChild(std::move(grandchild));
8819 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:598820 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:128821
vollickef2ae922016-06-29 17:54:278822 host_impl.active_tree()->SetElementIdsForTesting();
8823
vollick2175fae82015-04-27 21:18:128824 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598825 // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058826 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128827
8828 // Now we will reset the visible rect from property trees for the grandchild,
8829 // and we will configure |child| in several ways that should force the subtree
8830 // to be skipped. The visible content rect for |grandchild| should, therefore,
8831 // remain empty.
weiliangcc97575c2016-03-03 18:34:278832 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058833
vollick2175fae82015-04-27 21:18:128834 gfx::Transform singular;
8835 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058836 // This line is used to make the results of skipping and not skipping layers
8837 // different.
8838 singular.matrix().set(0, 1, 1);
8839
8840 gfx::Transform rotate;
8841 rotate.Rotate(90);
8842
8843 gfx::Transform rotate_back_and_translate;
8844 rotate_back_and_translate.RotateAboutYAxis(180);
8845 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128846
jaydasika10d43fc2016-08-18 04:06:048847 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058848 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598849 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278850 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048851 child_ptr->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:128852
jaydasika5121caa82016-05-05 15:43:358853 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika6ed869662016-09-21 14:29:598854 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278855 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358856 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128857
weiliangcea09f3372017-03-29 16:43:248858 child_ptr->test_properties()->opacity = 0.f;
8859 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598860 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278861 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188862 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:128863
jaydasika10d43fc2016-08-18 04:06:048864 root_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058865 // Force transform tree to have a node for child, so that ancestor's
8866 // invertible transform can be tested.
jaydasika10d43fc2016-08-18 04:06:048867 child_ptr->test_properties()->transform = rotate;
sunxd71aea3e2016-04-01 23:48:058868 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598869 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058870 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048871 root_ptr->test_properties()->transform = gfx::Transform();
8872 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:058873
jaydasikaab317e02016-06-01 00:53:188874 root_ptr->test_properties()->opacity = 0.f;
8875 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:058876 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598877 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058878 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188879 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058880
jaydasikaab317e02016-06-01 00:53:188881 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:128882 // Now, even though child has zero opacity, we will configure |grandchild| and
8883 // |greatgrandchild| in several ways that should force the subtree to be
8884 // processed anyhow.
ajumae6f541b2016-05-31 16:50:508885 grandchild_ptr->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:048886 viz::CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:098887 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598888 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278889 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:508890
8891 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:188892 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058893
8894 // A double sided render surface with backface visible should not be skipped
8895 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
ajuma35b24f62017-01-27 21:23:098896 child_ptr->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:368897 child_ptr->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:048898 child_ptr->test_properties()->transform = rotate_back_and_translate;
sunxd71aea3e2016-04-01 23:48:058899 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598900 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058901 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048902 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:058903
danakj60bc3bc2016-04-09 00:24:488904 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058905 KeyframedTransformAnimationCurve::Create());
8906 TransformOperations start;
8907 start.AppendTranslate(1.f, 2.f, 3.f);
8908 gfx::Transform transform;
8909 transform.Scale3d(1.0, 2.0, 3.0);
8910 TransformOperations operation;
8911 operation.AppendMatrix(transform);
8912 curve->AddKeyframe(
8913 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8914 curve->AddKeyframe(TransformKeyframe::Create(
8915 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:488916 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:058917 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8918 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:088919 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
8920 player.get());
loysobb507792016-10-04 05:31:028921 player->AddAnimation(std::move(transform_animation));
sunxd71aea3e2016-04-01 23:48:058922 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
jaydasika10d43fc2016-08-18 04:06:048923 root_ptr->test_properties()->transform = singular;
8924 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058925 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598926 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:278927 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058928
loyso6d6356e2016-11-02 23:41:088929 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
8930 player.get());
sunxd71aea3e2016-04-01 23:48:058931}
8932
jaydasikaf187b06b2016-04-11 23:30:278933TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:598934 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:278935 LayerImpl* child = AddChild<LayerImpl>(root);
8936 LayerImpl* grand_child = AddChild<LayerImpl>(child);
8937
vollickef2ae922016-06-29 17:54:278938 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:278939
8940 gfx::Transform singular;
8941 singular.matrix().set(0, 0, 0);
8942 singular.matrix().set(0, 1, 1);
8943
danakjf78fb272016-07-26 19:06:158944 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:048945 child->test_properties()->transform = singular;
danakjf78fb272016-07-26 19:06:158946 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278947 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158948 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278949 grand_child->SetDrawsContent(true);
8950
danakj25c52c32016-04-12 21:51:088951 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:278952 KeyframedTransformAnimationCurve::Create());
8953 TransformOperations start;
8954 start.AppendTranslate(1.f, 2.f, 3.f);
8955 gfx::Transform transform;
8956 transform.Scale3d(1.0, 2.0, 3.0);
8957 TransformOperations operation;
8958 operation.AppendMatrix(transform);
8959 curve->AddKeyframe(
8960 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8961 curve->AddKeyframe(TransformKeyframe::Create(
8962 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:088963 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:278964 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8965 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:088966 host_impl()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278967 grand_child->element_id(), player.get());
loysobb507792016-10-04 05:31:028968 player->AddAnimation(std::move(transform_animation));
jaydasikaf187b06b2016-04-11 23:30:278969
8970 ExecuteCalculateDrawProperties(root);
8971 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
8972 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
8973
loyso6d6356e2016-11-02 23:41:088974 host_impl()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278975 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:278976}
8977
sunxd71aea3e2016-04-01 23:48:058978TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8979 FakeImplTaskRunnerProvider task_runner_provider;
sunxd71aea3e2016-04-01 23:48:058980 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228981 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
sunxd71aea3e2016-04-01 23:48:058982
sunxd71aea3e2016-04-01 23:48:058983 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:488984 std::unique_ptr<LayerImpl> root =
8985 LayerImpl::Create(host_impl.pending_tree(), 1);
8986 std::unique_ptr<LayerImpl> child =
8987 LayerImpl::Create(host_impl.pending_tree(), 2);
8988 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:058989 LayerImpl::Create(host_impl.pending_tree(), 3);
8990
danakj60bc3bc2016-04-09 00:24:488991 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:058992 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8993
danakjf78fb272016-07-26 19:06:158994 root->SetBounds(gfx::Size(100, 100));
8995 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058996 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158997 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058998 grandchild->SetDrawsContent(true);
8999 greatgrandchild->SetDrawsContent(true);
9000
sunxd71aea3e2016-04-01 23:48:059001 LayerImpl* root_ptr = root.get();
9002 LayerImpl* grandchild_ptr = grandchild.get();
9003
jaydasika89f7b5a2016-06-22 02:08:399004 child->test_properties()->AddChild(std::move(grandchild));
9005 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:059006
jaydasikabf1875a2016-06-28 03:39:599007 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:279008 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:059009
9010 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599011 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059012 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9013
danakj60bc3bc2016-04-09 00:24:489014 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059015 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:499016 std::unique_ptr<TimingFunction> func =
9017 CubicBezierTimingFunction::CreatePreset(
9018 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:059019 curve->AddKeyframe(
9020 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9021 curve->AddKeyframe(
9022 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489023 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059024 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9025 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089026 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
9027 player.get());
loysobb507792016-10-04 05:31:029028 player->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189029 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059030 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9031 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599032 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059033 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9034
loyso6d6356e2016-11-02 23:41:089035 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
9036 player.get());
vollick2175fae82015-04-27 21:18:129037}
9038
9039TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:599040 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149041 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129042
danakjf78fb272016-07-26 19:06:159043 root->SetBounds(gfx::Size(100, 100));
9044 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149045 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129046
jaydasika6f972de2016-04-07 16:16:149047 ExecuteCalculateDrawProperties(root);
9048 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279049 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129050
jaydasika5121caa82016-05-05 15:43:359051 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149052 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9053 ExecuteCalculateDrawProperties(root);
9054 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359055 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129056
9057 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149058 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9059 ExecuteCalculateDrawProperties(root);
9060 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129061 child->SetBounds(gfx::Size(10, 10));
9062
9063 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369064 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129065 rotate.RotateAboutXAxis(180.f);
jaydasika10d43fc2016-08-18 04:06:049066 child->test_properties()->transform = rotate;
jaydasika6f972de2016-04-07 16:16:149067 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9068 ExecuteCalculateDrawProperties(root);
9069 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369070 child->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049071 child->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129072
jaydasikaab317e02016-06-01 00:53:189073 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149074 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9075 ExecuteCalculateDrawProperties(root);
9076 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129077}
9078
jaydasika3d10aa62015-05-06 17:50:449079TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9080 // Ensure that the treewalk in LayerTreeHostCommom::
9081 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319082 scoped_refptr<Layer> root = Layer::Create();
9083 scoped_refptr<Layer> parent = Layer::Create();
9084 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449085
danakjf78fb272016-07-26 19:06:159086 root->SetBounds(gfx::Size(100, 100));
9087 parent->SetBounds(gfx::Size(100, 100));
9088 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:449089 child->SetClipParent(root.get());
9090
danakjf78fb272016-07-26 19:06:159091 root->AddChild(parent);
9092 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:339093 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449094
Fady Samueldfecb7d2017-07-26 11:41:049095 child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateRequest(
Yuri Wiitalab2511762017-07-19 00:17:539096 base::BindOnce(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029097
jaydasika6ed869662016-09-21 14:29:599098 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasikaebc94282017-04-24 20:34:019099 EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
jaydasika1553a142017-04-05 00:37:099100
jaydasika6ed869662016-09-21 14:29:599101 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasikaebc94282017-04-24 20:34:019102 EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
jaydasika3d10aa62015-05-06 17:50:449103}
9104
vollick692444f2015-05-20 15:39:149105TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:159106 scoped_refptr<Layer> root = Layer::Create();
9107 root->SetBounds(gfx::Size(800, 800));
9108
vollick692444f2015-05-20 15:39:149109 gfx::Transform translate_z;
9110 translate_z.Translate3d(0, 0, 10);
9111
loyso0940d412016-03-14 01:30:319112 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:159113 child->SetTransform(translate_z);
9114 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:149115
9116 root->AddChild(child);
9117
ennea7b43c32015-06-18 20:01:339118 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149119
jaydasika6ed869662016-09-21 14:29:599120 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149121 EXPECT_NE(-1, child->transform_tree_index());
9122
9123 child->RemoveFromParent();
9124
jaydasika6ed869662016-09-21 14:29:599125 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149126 EXPECT_EQ(-1, child->transform_tree_index());
9127}
9128
jaydasika67d7989e2015-08-06 21:55:349129TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9130 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:599131 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349132 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9133 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9134 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9135 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9136
jaydasika67d7989e2015-08-06 21:55:349137 // This transform should be a significant one so that a transform node is
9138 // formed for it.
9139 gfx::Transform transform1;
9140 transform1.RotateAboutYAxis(45);
9141 transform1.RotateAboutXAxis(30);
9142 // This transform should be a 3d transform as we want the render surface
9143 // to flatten the transform
9144 gfx::Transform transform2;
9145 transform2.Translate3d(10, 10, 10);
9146
danakjf78fb272016-07-26 19:06:159147 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049148 significant_transform->test_properties()->transform = transform1;
danakjf78fb272016-07-26 19:06:159149 significant_transform->SetBounds(gfx::Size(30, 30));
9150 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349151 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159152 layer_clips_subtree->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049153 render_surface->test_properties()->transform = transform2;
danakjf78fb272016-07-26 19:06:159154 render_surface->SetBounds(gfx::Size(30, 30));
9155 render_surface->test_properties()->force_render_surface = true;
9156 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349157 test_layer->SetDrawsContent(true);
9158
jaydasika5237db02016-09-20 01:34:309159 float device_scale_factor = 1.f;
9160 float page_scale_factor = 1.f;
9161 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:289162 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:429163 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika5237db02016-09-20 01:34:309164 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:289165 page_scale_layer, inner_viewport_scroll_layer,
jaydasika3a6b14432017-03-21 23:11:199166 outer_viewport_scroll_layer);
jaydasika67d7989e2015-08-06 21:55:349167
chrishtr7e3aaf22017-05-04 15:04:019168 EXPECT_TRUE(GetRenderSurface(root));
chrishtr5f60ca02017-05-11 23:09:499169 EXPECT_EQ(GetRenderSurface(significant_transform), GetRenderSurface(root));
chrishtr7e3aaf22017-05-04 15:04:019170 EXPECT_TRUE(GetRenderSurface(layer_clips_subtree));
chrishtr5f60ca02017-05-11 23:09:499171 EXPECT_NE(GetRenderSurface(render_surface), GetRenderSurface(root));
9172 EXPECT_EQ(GetRenderSurface(test_layer), GetRenderSurface(render_surface));
weiliangcc154ce22015-12-09 03:39:269173
jaydasika3a6b14432017-03-21 23:11:199174 EXPECT_EQ(gfx::Rect(30, 20), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349175}
9176
9177TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9178 // Ensure that when parent clip node's transform is an ancestor of current
9179 // clip node's target, clip is 'projected' from parent space to current
9180 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:599181 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349182 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9183 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9184 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9185
jaydasika67d7989e2015-08-06 21:55:349186 gfx::Transform transform;
9187 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:159188
9189 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049190 clip_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159191 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349192 clip_layer->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049193 target_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159194 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349195 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159196 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349197 test_layer->SetDrawsContent(true);
9198
jaydasika67d7989e2015-08-06 21:55:349199 ExecuteCalculateDrawProperties(root);
9200
weiliangcc97575c2016-03-03 18:34:279201 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349202}
9203
jaydasika7d5c1ed2015-08-14 14:27:029204TEST_F(LayerTreeHostCommonTest,
9205 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9206 // Ensure clip rect is calculated correctly when render surface has unclipped
9207 // descendants.
jaydasikabf1875a2016-06-28 03:39:599208 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:029209 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9210 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9211 LayerImpl* render_surface =
9212 AddChild<LayerImpl>(between_clip_parent_and_child);
9213 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9214
weiliangcbb2e8642016-03-04 00:24:429215 gfx::Transform translate;
9216 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029217
danakjf78fb272016-07-26 19:06:159218 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049219 clip_parent->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159220 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:429221 clip_parent->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049222 between_clip_parent_and_child->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159223 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
jaydasika1553a142017-04-05 00:37:099224 between_clip_parent_and_child->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159225 render_surface->SetBounds(gfx::Size(30, 30));
9226 render_surface->test_properties()->force_render_surface = true;
9227 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:029228 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159229
jaydasika1c0a27d42016-04-28 01:54:569230 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159231 clip_parent->test_properties()->clip_children =
9232 base::MakeUnique<std::set<LayerImpl*>>();
9233 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:029234
9235 ExecuteCalculateDrawProperties(root);
9236
weiliangcbb2e8642016-03-04 00:24:429237 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259238 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569239 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9240 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029241}
9242
jaydasika571dd2cf2015-09-25 20:55:429243TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089244 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9245 // Ensure that the visible layer rect of a descendant of a surface with
9246 // unclipped descendants is computed correctly, when the surface doesn't apply
9247 // a clip.
jaydasikabf1875a2016-06-28 03:39:599248 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:089249 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9250 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9251 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9252 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9253
danakjf78fb272016-07-26 19:06:159254 root->SetBounds(gfx::Size(30, 10));
9255 clip_parent->SetBounds(gfx::Size(30, 30));
9256 render_surface->SetBounds(gfx::Size(10, 15));
9257 render_surface->test_properties()->force_render_surface = true;
9258 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:089259 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159260 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:089261 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159262
jaydasika1c0a27d42016-04-28 01:54:569263 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159264 clip_parent->test_properties()->clip_children =
9265 base::MakeUnique<std::set<LayerImpl*>>();
9266 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:089267
9268 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:189269 EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect());
ajuma01734dd02015-10-07 01:22:089270}
9271
9272TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429273 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:599274 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429275 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9276 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9277 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9278 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9279 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9280
danakjf78fb272016-07-26 19:06:159281 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429282 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159283 clip_parent->SetBounds(gfx::Size(30, 30));
9284 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429285 render_surface->SetMasksToBounds(true);
9286 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159287 render_surface->test_properties()->force_render_surface = true;
9288 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429289 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159290 clip_child->SetBounds(gfx::Size(50, 50));
9291 clip_child->SetDrawsContent(true);
9292 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429293 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429294
danakjf78fb272016-07-26 19:06:159295 clip_child->test_properties()->clip_parent = clip_parent;
9296 clip_parent->test_properties()->clip_children =
9297 base::MakeUnique<std::set<LayerImpl*>>();
9298 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:429299
9300 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569301 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9302 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429303 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9304 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9305}
9306
ajumae2b7a5c2015-09-30 21:41:429307TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:599308 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:429309 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9310 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9311 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9312
danakjf78fb272016-07-26 19:06:159313 root->SetBounds(gfx::Size(50, 50));
9314 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429315 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159316 render_surface->SetBounds(gfx::Size(30, 30));
9317 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:429318 render_surface->SetMasksToBounds(true);
9319 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159320 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429321 clip_child->SetDrawsContent(true);
9322
jaydasika1c0a27d42016-04-28 01:54:569323 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159324 clip_parent->test_properties()->clip_children =
9325 base::MakeUnique<std::set<LayerImpl*>>();
9326 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:429327
9328 ExecuteCalculateDrawProperties(root);
9329
9330 // The clip child should inherit its clip parent's clipping state, not its
9331 // tree parent's clipping state.
9332 EXPECT_FALSE(clip_parent->is_clipped());
9333 EXPECT_TRUE(render_surface->is_clipped());
9334 EXPECT_FALSE(clip_child->is_clipped());
9335}
9336
jaydasika77a4a072015-10-20 21:47:279337TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9338 // Tests the value of render surface content rect when we have multiple types
9339 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9340 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:599341 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279342 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9343 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
jaydasika1553a142017-04-05 00:37:099344 LayerImpl* clip_layer = AddChild<LayerImpl>(clip_parent);
9345 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_layer);
jaydasika77a4a072015-10-20 21:47:279346 LayerImpl* unclipped_desc_surface2 =
9347 AddChild<LayerImpl>(unclipped_desc_surface);
9348 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9349 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9350
danakjf78fb272016-07-26 19:06:159351 root->SetBounds(gfx::Size(80, 80));
9352 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:279353 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159354 unclipped_surface->SetDrawsContent(true);
9355 unclipped_surface->test_properties()->force_render_surface = true;
9356 clip_parent->SetBounds(gfx::Size(50, 50));
9357 clip_parent->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:099358 clip_layer->SetMasksToBounds(true);
9359 clip_layer->SetBounds(gfx::Size(100, 100));
danakjf78fb272016-07-26 19:06:159360 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
danakjf78fb272016-07-26 19:06:159361 unclipped_desc_surface->SetDrawsContent(true);
9362 unclipped_desc_surface->test_properties()->force_render_surface = true;
9363 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
9364 unclipped_desc_surface2->SetDrawsContent(true);
9365 unclipped_desc_surface2->test_properties()->force_render_surface = true;
9366 clip_child->SetBounds(gfx::Size(100, 100));
9367 clipped_surface->SetBounds(gfx::Size(70, 70));
9368 clipped_surface->SetDrawsContent(true);
9369 clipped_surface->test_properties()->force_render_surface = true;
9370
9371 clip_child->test_properties()->clip_parent = clip_parent;
9372 clip_parent->test_properties()->clip_children =
9373 base::MakeUnique<std::set<LayerImpl*>>();
9374 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279375
9376 ExecuteCalculateDrawProperties(root);
9377 EXPECT_EQ(gfx::Rect(50, 50),
chrishtr7e3aaf22017-05-04 15:04:019378 GetRenderSurface(unclipped_surface)->content_rect());
weiliangc0e13ba602016-03-12 04:53:569379 EXPECT_EQ(gfx::Rect(50, 50),
chrishtr7e3aaf22017-05-04 15:04:019380 GetRenderSurface(unclipped_desc_surface)->content_rect());
jaydasika1553a142017-04-05 00:37:099381 EXPECT_EQ(gfx::Rect(60, 60),
chrishtr7e3aaf22017-05-04 15:04:019382 GetRenderSurface(unclipped_desc_surface2)->content_rect());
jaydasika77a4a072015-10-20 21:47:279383 EXPECT_EQ(gfx::Rect(50, 50),
chrishtr7e3aaf22017-05-04 15:04:019384 GetRenderSurface(clipped_surface)->content_rect());
jaydasika77a4a072015-10-20 21:47:279385}
9386
9387TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9388 // Tests the value of render surface content rect when we have a layer that
9389 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:599390 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279391 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9392 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9393 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9394 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9395 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9396
jaydasika77a4a072015-10-20 21:47:279397 gfx::Transform translate;
9398 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:159399
jaydasika778cb272016-08-15 19:00:549400 gfx::Transform rotate;
9401 rotate.RotateAboutXAxis(10);
9402
danakjf78fb272016-07-26 19:06:159403 root->SetBounds(gfx::Size(100, 100));
9404 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279405 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159406 surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049407 surface->test_properties()->transform = rotate;
danakjf78fb272016-07-26 19:06:159408 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:279409 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159410 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:049411 unclipped_desc_surface->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159412 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9413 unclipped_desc_surface->SetDrawsContent(true);
9414 unclipped_desc_surface->test_properties()->force_render_surface = true;
9415 clip_child->SetBounds(gfx::Size(100, 100));
9416 clip_child->SetDrawsContent(true);
9417
9418 clip_child->test_properties()->clip_parent = clip_parent;
9419 clip_parent->test_properties()->clip_children =
9420 base::MakeUnique<std::set<LayerImpl*>>();
9421 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279422
9423 ExecuteCalculateDrawProperties(root);
9424
9425 EXPECT_EQ(gfx::Rect(10, 10),
chrishtr7e3aaf22017-05-04 15:04:019426 GetRenderSurface(unclipped_desc_surface)->content_rect());
jaydasika77a4a072015-10-20 21:47:279427}
9428
jaydasika2c8c2872015-10-21 23:28:219429TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:599430 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:219431 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9432 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9433 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9434 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9435 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9436
jaydasika2c8c2872015-10-21 23:28:219437
jaydasika2c8c2872015-10-21 23:28:219438 gfx::Transform scale;
9439 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:159440
9441 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:049442 surface->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159443 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:219444 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159445 surface->test_properties()->force_render_surface = true;
9446 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:219447 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159448 clip_parent->SetBounds(gfx::Size(50, 50));
9449 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9450 unclipped_desc_surface->SetDrawsContent(true);
9451 unclipped_desc_surface->test_properties()->force_render_surface = true;
9452 clip_child->SetBounds(gfx::Size(100, 100));
9453 clip_child->SetDrawsContent(true);
9454
9455 clip_child->test_properties()->clip_parent = clip_parent;
9456 clip_parent->test_properties()->clip_children =
9457 base::MakeUnique<std::set<LayerImpl*>>();
9458 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:219459
9460 ExecuteCalculateDrawProperties(root);
9461
9462 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9463}
9464
jaydasika60f85862015-10-01 20:36:149465TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:599466 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:149467 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9468 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9469
jaydasika86654512016-01-27 17:05:079470 gfx::Transform translation;
9471 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:149472
danakjf78fb272016-07-26 19:06:159473 root->SetBounds(gfx::Size(30, 30));
9474 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:149475 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159476 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049477 test_layer->test_properties()->transform = translation;
danakjf78fb272016-07-26 19:06:159478 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:149479 test_layer->SetDrawsContent(true);
Hayley Ferrd9ee3a72017-06-16 14:16:099480
9481 TouchActionRegion touch_action_region;
9482 touch_action_region.Union(kTouchActionNone, gfx::Rect(0, 0, 20, 20));
9483 test_layer->SetTouchActionRegion(std::move(touch_action_region));
danakjf78fb272016-07-26 19:06:159484 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:149485
9486 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:029487 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
9488 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149489}
9490
jaydasikab874eddc2016-11-02 22:34:289491TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) {
9492 LayerImpl* root = root_layer_for_testing();
9493 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9494 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
jaydasika1553a142017-04-05 00:37:099495 LayerImpl* clip_parent_child = AddChild<LayerImpl>(clip_parent);
9496 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent_child);
jaydasikab874eddc2016-11-02 22:34:289497 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9498
9499 root->SetBounds(gfx::Size(100, 100));
9500 clip_layer->SetBounds(gfx::Size(20, 20));
9501 clip_layer->SetMasksToBounds(true);
9502 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika1553a142017-04-05 00:37:099503 clip_parent_child->SetBounds(gfx::Size(20, 20));
9504 clip_parent_child->SetMasksToBounds(true);
jaydasikab874eddc2016-11-02 22:34:289505 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9506 unclipped_desc_surface->SetDrawsContent(true);
9507 unclipped_desc_surface->test_properties()->force_render_surface = true;
9508 clip_child->SetBounds(gfx::Size(100, 100));
9509 clip_child->SetDrawsContent(true);
jaydasika264a0dd2017-02-24 23:17:279510 gfx::Transform translate;
9511 translate.Translate(10, 10);
9512 unclipped_desc_surface->test_properties()->transform = translate;
jaydasikab874eddc2016-11-02 22:34:289513
9514 clip_child->test_properties()->clip_parent = clip_parent;
9515 clip_parent->test_properties()->clip_children =
9516 base::MakeUnique<std::set<LayerImpl*>>();
9517 clip_parent->test_properties()->clip_children->insert(clip_child);
9518
9519 float device_scale_factor = 1.f;
9520 ExecuteCalculateDrawProperties(root, device_scale_factor);
jaydasika264a0dd2017-02-24 23:17:279521 EXPECT_EQ(gfx::Rect(-10, -10, 20, 20), clip_child->clip_rect());
9522 EXPECT_EQ(gfx::Rect(10, 10), clip_child->visible_layer_rect());
jaydasikab874eddc2016-11-02 22:34:289523
9524 device_scale_factor = 2.f;
9525 ExecuteCalculateDrawProperties(root, device_scale_factor);
jaydasika264a0dd2017-02-24 23:17:279526 EXPECT_EQ(gfx::Rect(-20, -20, 40, 40), clip_child->clip_rect());
9527 EXPECT_EQ(gfx::Rect(10, 10), clip_child->visible_layer_rect());
jaydasikab874eddc2016-11-02 22:34:289528}
9529
jaydasikae4910fa22015-10-09 00:52:099530TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:599531 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:099532 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9533 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9534 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9535
danakjf78fb272016-07-26 19:06:159536 root->SetBounds(gfx::Size(30, 30));
9537 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:099538 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159539 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099540 render_surface->SetMasksToBounds(true);
9541 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159542 render_surface->test_properties()->force_render_surface = true;
9543 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099544 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:099545
danakjf78fb272016-07-26 19:06:159546 clip_child->test_properties()->clip_parent = clip_parent;
9547 clip_parent->test_properties()->clip_children =
9548 base::MakeUnique<std::set<LayerImpl*>>();
9549 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:099550
9551 ExecuteCalculateDrawProperties(root);
jaydasikab4df4032016-09-13 18:38:499552 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
jaydasikae4910fa22015-10-09 00:52:099553}
9554
jaydasika571dd2cf2015-09-25 20:55:429555TEST_F(LayerTreeHostCommonTest,
9556 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:599557 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429558 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9559 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:159560
9561 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429562 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369563 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159564 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429565 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369566 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159567 render_surface->test_properties()->force_render_surface = true;
9568 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429569 test_layer->SetMasksToBounds(true);
9570 test_layer->SetDrawsContent(true);
9571 ExecuteCalculateDrawProperties(root);
9572
9573 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9574 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9575 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9576}
9577
jaydasikab5504ca2015-12-18 23:41:559578TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9579 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:599580 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:559581 LayerImpl* hidden = AddChild<LayerImpl>(root);
9582 LayerImpl* test = AddChild<LayerImpl>(hidden);
9583
danakjf78fb272016-07-26 19:06:159584 root->SetBounds(gfx::Size(30, 30));
9585 hidden->SetBounds(gfx::Size(30, 30));
9586 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:359587 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:159588 test->SetBounds(gfx::Size(30, 30));
9589 test->test_properties()->force_render_surface = true;
9590
jaydasikab5504ca2015-12-18 23:41:559591 ExecuteCalculateDrawProperties(root);
ajuma956219582017-04-04 19:58:149592 EXPECT_EQ(0.f,
chrishtr7e3aaf22017-05-04 15:04:019593 GetRenderSurface(test)->OwningEffectNode()->screen_space_opacity);
jaydasikab5504ca2015-12-18 23:41:559594
jaydasika5121caa82016-05-05 15:43:359595 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559596 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9597 ExecuteCalculateDrawProperties(root);
ajuma956219582017-04-04 19:58:149598 EXPECT_EQ(1.f,
chrishtr7e3aaf22017-05-04 15:04:019599 GetRenderSurface(test)->OwningEffectNode()->screen_space_opacity);
jaydasikab5504ca2015-12-18 23:41:559600}
9601
jaydasikac0137282015-10-01 15:50:309602TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:599603 LayerImpl* root = root_layer_for_testing();
jaydasika1553a142017-04-05 00:37:099604 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9605 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_layer);
jaydasikac0137282015-10-01 15:50:309606 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9607 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9608
danakjf78fb272016-07-26 19:06:159609 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309610 root->SetMasksToBounds(true);
jaydasika1553a142017-04-05 00:37:099611 clip_layer->SetBounds(gfx::Size(30, 30));
9612 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159613 render_surface1->SetPosition(gfx::PointF(10, 10));
9614 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309615 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159616 render_surface1->test_properties()->force_render_surface = true;
9617 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309618 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159619 render_surface2->test_properties()->force_render_surface = true;
9620 clip_child->SetBounds(gfx::Size(30, 30));
jaydasika1553a142017-04-05 00:37:099621 clip_child->SetDrawsContent(true);
jaydasikac0137282015-10-01 15:50:309622
danakjf78fb272016-07-26 19:06:159623 clip_child->test_properties()->clip_parent = root;
9624 root->test_properties()->clip_children =
9625 base::MakeUnique<std::set<LayerImpl*>>();
9626 root->test_properties()->clip_children->insert(clip_child);
9627
jaydasikac0137282015-10-01 15:50:309628 ExecuteCalculateDrawProperties(root);
9629
9630 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
9631}
9632
ajumadb6216f2c2016-06-07 21:44:059633TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
9634 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599635 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:099636 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509637 child->test_properties()->SetMaskLayer(
9638 LayerImpl::Create(root->layer_tree_impl(), 100));
9639 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:099640
jaydasika224bca02015-12-18 02:37:099641 gfx::Transform transform;
9642 transform.Translate(10, 10);
9643
danakjf78fb272016-07-26 19:06:159644 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:099645 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:049646 child->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159647 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:099648 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:159649 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:099650 ExecuteCalculateDrawProperties(root);
9651
ajumadb6216f2c2016-06-07 21:44:059652 // The render surface created for the mask has no contributing content, so the
ajuma651848a2017-05-01 21:23:459653 // mask doesn't contribute to a drawn render surface. This means it has an
9654 // empty visible rect, but its screen space transform can still be computed
9655 // correctly on-demand.
9656 EXPECT_FALSE(mask->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:509657 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
9658 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059659
9660 // Make the child's render surface have contributing content.
9661 child->SetDrawsContent(true);
9662 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9663 ExecuteCalculateDrawProperties(root);
ajuma651848a2017-05-01 21:23:459664 EXPECT_TRUE(mask->contributes_to_drawn_render_surface());
ajuma1d4026a32016-06-14 13:18:509665 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
9666 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059667
jaydasika224bca02015-12-18 02:37:099668 transform.Translate(10, 10);
jaydasika10d43fc2016-08-18 04:06:049669 child->test_properties()->transform = transform;
jaydasika224bca02015-12-18 02:37:099670 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9671 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509672 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
9673 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:059674}
9675
jaydasikaf62311f2016-04-20 14:38:459676TEST_F(LayerTreeHostCommonTest,
9677 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:599678 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:459679 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9680 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9681 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9682 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:459683
9684 gfx::Transform scale;
9685 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:159686
9687 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049688 render_surface1->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159689 render_surface1->SetBounds(gfx::Size(30, 30));
9690 render_surface1->test_properties()->force_render_surface = true;
9691 between_targets->SetBounds(gfx::Size(30, 30));
9692 render_surface2->SetBounds(gfx::Size(30, 30));
9693 render_surface2->test_properties()->force_render_surface = true;
9694 test_layer->SetBounds(gfx::Size(30, 30));
9695 test_layer->SetDrawsContent(true);
9696
jaydasikab433552b2016-10-26 18:49:449697 // We want layer between the two targets to create a clip node and effect
jaydasikaf62311f2016-04-20 14:38:459698 // node but it shouldn't create a render surface.
9699 between_targets->SetMasksToBounds(true);
jaydasikab433552b2016-10-26 18:49:449700 between_targets->test_properties()->opacity = 0.5f;
jaydasikaf62311f2016-04-20 14:38:459701
9702 ExecuteCalculateDrawProperties(root);
9703
jaydasikab433552b2016-10-26 18:49:449704 EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree;
9705 EffectNode* node = tree.Node(render_surface1->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439706 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459707
jaydasikab433552b2016-10-26 18:49:449708 node = tree.Node(between_targets->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439709 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:459710
jaydasikab433552b2016-10-26 18:49:449711 node = tree.Node(render_surface2->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439712 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459713
9714 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9715}
9716
jaydasika3c5633d2016-08-25 00:39:229717TEST_F(LayerTreeHostCommonTest, NoisyTransform) {
9718 LayerImpl* root = root_layer_for_testing();
9719 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9720 LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface);
9721 LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface);
9722 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip);
9723
9724 scroll_child->test_properties()->scroll_parent = scroll_parent;
9725 scroll_parent->test_properties()->scroll_children =
9726 base::MakeUnique<std::set<LayerImpl*>>();
9727 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika3c5633d2016-08-25 00:39:229728
9729 scroll_parent->SetDrawsContent(true);
9730 scroll_child->SetDrawsContent(true);
9731 render_surface->test_properties()->force_render_surface = true;
9732
9733 // A noisy transform that's invertible.
9734 gfx::Transform transform;
9735 transform.matrix().setDouble(0, 0, 6.12323e-17);
9736 transform.matrix().setDouble(0, 2, 1);
9737 transform.matrix().setDouble(2, 2, 6.12323e-17);
9738 transform.matrix().setDouble(2, 0, -1);
9739
9740 scroll_child->test_properties()->transform = transform;
9741 render_surface->test_properties()->transform = transform;
9742
9743 root->SetBounds(gfx::Size(30, 30));
9744 scroll_child->SetBounds(gfx::Size(30, 30));
9745 scroll_parent->SetBounds(gfx::Size(30, 30));
9746 ExecuteCalculateDrawProperties(root);
9747
9748 gfx::Transform expected;
9749 expected.matrix().setDouble(0, 0, 3.749395e-33);
9750 expected.matrix().setDouble(0, 2, 6.12323e-17);
9751 expected.matrix().setDouble(2, 0, -1);
9752 expected.matrix().setDouble(2, 2, 6.12323e-17);
9753 EXPECT_TRANSFORMATION_MATRIX_EQ(expected,
9754 scroll_child->ScreenSpaceTransform());
9755}
9756
jaydasika5160e672015-10-15 15:25:149757TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:599758 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:149759 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059760 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149761
sunxd71aea3e2016-04-01 23:48:059762 child->SetDrawsContent(true);
9763 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149764
9765 gfx::Transform large_transform;
9766 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9767 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9768 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9769 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9770
danakjf78fb272016-07-26 19:06:159771 root->SetBounds(gfx::Size(30, 30));
9772 render_surface1->SetBounds(gfx::Size(30, 30));
9773 render_surface1->test_properties()->force_render_surface = true;
9774
sunxd71aea3e2016-04-01 23:48:059775 // TODO(sunxd): we make child have no render surface, because if the
9776 // child has one, the large transform applied to child will result in NaNs in
9777 // the draw_transform of the render_surface, thus make draw property updates
9778 // skip the child layer. We need further investigation into this to know
9779 // what exactly happens here.
jaydasika10d43fc2016-08-18 04:06:049780 child->test_properties()->transform = large_transform;
danakjf78fb272016-07-26 19:06:159781 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:149782
9783 ExecuteCalculateDrawProperties(root);
9784
jaydasika5160e672015-10-15 15:25:149785 EXPECT_EQ(gfx::RectF(),
chrishtr7e3aaf22017-05-04 15:04:019786 GetRenderSurface(render_surface1)->DrawableContentRect());
sunxd71aea3e2016-04-01 23:48:059787
9788 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9789 std::isnan(child->DrawTransform().matrix().get(0, 0));
9790 EXPECT_TRUE(is_inf_or_nan);
9791
9792 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9793 std::isnan(child->DrawTransform().matrix().get(1, 1));
9794 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149795
ajumab784ef42017-04-28 23:01:529796 // The root layer should be in the RenderSurfaceList.
9797 const auto* rsl = render_surface_list_impl();
chrishtr7e3aaf22017-05-04 15:04:019798 EXPECT_NE(std::find(rsl->begin(), rsl->end(), GetRenderSurface(root)),
ajumab784ef42017-04-28 23:01:529799 rsl->end());
jaydasika5160e672015-10-15 15:25:149800}
9801
jaydasika8d6efe2e2016-05-17 15:37:219802TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:219803 scoped_refptr<Layer> root = Layer::Create();
9804 scoped_refptr<LayerWithForcedDrawsContent> child =
9805 make_scoped_refptr(new LayerWithForcedDrawsContent());
9806 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:219807 host()->SetRootLayer(root);
9808
danakjf78fb272016-07-26 19:06:159809 root->SetBounds(gfx::Size(100, 100));
9810 child->SetBounds(gfx::Size(20, 20));
jaydasika6ed869662016-09-21 14:29:599811 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219812
9813 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9814 // property trees as a new effect node will be created.
9815 child->SetOpacity(0.5f);
9816 PropertyTrees* property_trees = host()->property_trees();
9817 EXPECT_TRUE(property_trees->needs_rebuild);
9818
jaydasika6ed869662016-09-21 14:29:599819 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
Chris Harrelson84670c92017-06-06 05:39:069820 EXPECT_NE(property_trees->effect_tree.Node(child->effect_tree_index()),
9821 property_trees->effect_tree.Node(root->effect_tree_index()));
jaydasika8d6efe2e2016-05-17 15:37:219822
9823 // child already has an effect node. Changing its opacity shouldn't trigger
9824 // a property trees rebuild.
9825 child->SetOpacity(0.8f);
9826 property_trees = host()->property_trees();
9827 EXPECT_FALSE(property_trees->needs_rebuild);
9828
jaydasika6ed869662016-09-21 14:29:599829 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
Chris Harrelson84670c92017-06-06 05:39:069830 EXPECT_NE(property_trees->effect_tree.Node(child->effect_tree_index()),
9831 property_trees->effect_tree.Node(root->effect_tree_index()));
jaydasika8d6efe2e2016-05-17 15:37:219832
9833 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
9834 // property trees as the effect node may no longer be needed.
9835 child->SetOpacity(1.f);
9836 property_trees = host()->property_trees();
9837 EXPECT_TRUE(property_trees->needs_rebuild);
9838
jaydasika6ed869662016-09-21 14:29:599839 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
Chris Harrelson84670c92017-06-06 05:39:069840 EXPECT_EQ(property_trees->effect_tree.Node(child->effect_tree_index()),
9841 property_trees->effect_tree.Node(root->effect_tree_index()));
jaydasika8d6efe2e2016-05-17 15:37:219842}
9843
jaydasika9cb21c772016-05-10 22:37:089844TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:089845 scoped_refptr<Layer> root = Layer::Create();
9846 scoped_refptr<LayerWithForcedDrawsContent> animated =
9847 make_scoped_refptr(new LayerWithForcedDrawsContent());
9848 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:089849 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:079850 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279851
danakjf78fb272016-07-26 19:06:159852 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:089853 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159854 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:089855 animated->SetOpacity(0.f);
9856
9857 scoped_refptr<AnimationPlayer> player =
9858 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9859 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279860
9861 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:089862
9863 int animation_id = 0;
9864 std::unique_ptr<Animation> animation = Animation::Create(
9865 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
9866 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559867 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:089868 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9869 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279870 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9871 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:089872
jaydasika6ed869662016-09-21 14:29:599873 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika9cb21c772016-05-10 22:37:089874
khushalsagarb69ba9452017-01-27 22:20:079875 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree;
jaydasika9cb21c772016-05-10 22:37:089876 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019877 EXPECT_FALSE(node->is_currently_animating_opacity);
9878 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089879
9880 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
Yuri Wiitalad0611762017-07-22 02:33:219881 host()->AnimateLayers(base::TimeTicks::Max());
jaydasika9cb21c772016-05-10 22:37:089882 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019883 EXPECT_TRUE(node->is_currently_animating_opacity);
9884 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089885
9886 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
9887 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019888 EXPECT_FALSE(node->is_currently_animating_opacity);
9889 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089890}
9891
jaydasika6c3404e92016-05-19 02:40:369892TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:369893 scoped_refptr<Layer> root = Layer::Create();
9894 scoped_refptr<LayerWithForcedDrawsContent> animated =
9895 make_scoped_refptr(new LayerWithForcedDrawsContent());
9896 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:369897 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:079898 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279899
danakjf78fb272016-07-26 19:06:159900 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:369901 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159902 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:369903
9904 scoped_refptr<AnimationPlayer> player =
9905 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9906 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279907 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:369908
9909 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
9910 KeyframedTransformAnimationCurve::Create());
9911 TransformOperations start;
9912 start.AppendTranslate(1.f, 2.f, 3.f);
9913 gfx::Transform transform;
9914 transform.Scale3d(1.0, 2.0, 3.0);
9915 TransformOperations operation;
9916 operation.AppendMatrix(transform);
9917 curve->AddKeyframe(
9918 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9919 curve->AddKeyframe(TransformKeyframe::Create(
9920 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
9921 std::unique_ptr<Animation> animation(
9922 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9923 animation->set_fill_mode(Animation::FillMode::NONE);
9924 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9925 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279926 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9927 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:369928
jaydasika6ed869662016-09-21 14:29:599929 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika6c3404e92016-05-19 02:40:369930
khushalsagarb69ba9452017-01-27 22:20:079931 TransformTree& tree =
9932 root->layer_tree_host()->property_trees()->transform_tree;
jaydasika6c3404e92016-05-19 02:40:369933 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019934 EXPECT_FALSE(node->is_currently_animating);
9935 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369936
9937 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
Yuri Wiitalad0611762017-07-22 02:33:219938 host()->AnimateLayers(base::TimeTicks::Max());
jaydasika6c3404e92016-05-19 02:40:369939 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019940 EXPECT_TRUE(node->is_currently_animating);
9941 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369942
9943 player->AbortAnimations(TargetProperty::TRANSFORM,
9944 false /*needs_completion*/);
9945 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019946 EXPECT_FALSE(node->is_currently_animating);
9947 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369948}
9949
sunxdea1df782016-01-28 00:12:339950TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9951 // Test the behavior of scroll tree builder
9952 // Topology:
sunxdcfccd1b32016-02-11 00:54:209953 // +root1(1)[inner_viewport_container_layer]
9954 // +-page_scale_layer
9955 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9956 // scrollable, inner_viewport_scroll_layer]
9957 // +------child6(6)[kScrollbarScrolling]
9958 // +--------grand_child10(10)[kScrollbarScrolling]
9959 // +----parent3(3)
9960 // +------child7(7)[scrollable]
9961 // +------child8(8)[scroll_parent=7]
9962 // +--------grand_child11(11)[scrollable]
9963 // +----parent4(4)
9964 // +------child9(9)
9965 // +--------grand_child12(12)
9966 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339967 //
9968 // Expected scroll tree topology:
9969 // +property_tree_root---owner:-1
9970 // +--root---owner:1, id:1
9971 // +----node---owner:2, id:2
9972 // +------node---owner:6, id:3
9973 // +----node---owner:7, id:4
9974 // +------node---owner:11, id:5
9975 // +----node---owner:5, id:6
9976 //
9977 // Extra check:
9978 // scroll_tree_index() of:
9979 // grand_child10:3
9980 // parent3:1
9981 // child8:4
9982 // parent4:1
9983 // child9:1
9984 // grand_child12:1
loyso0940d412016-03-14 01:30:319985 scoped_refptr<Layer> root1 = Layer::Create();
9986 scoped_refptr<Layer> page_scale_layer = Layer::Create();
9987 scoped_refptr<Layer> parent2 = Layer::Create();
9988 scoped_refptr<Layer> parent3 = Layer::Create();
9989 scoped_refptr<Layer> parent4 = Layer::Create();
9990 scoped_refptr<Layer> parent5 = Layer::Create();
9991 scoped_refptr<Layer> child6 = Layer::Create();
9992 scoped_refptr<Layer> child7 = Layer::Create();
9993 scoped_refptr<Layer> child8 = Layer::Create();
9994 scoped_refptr<Layer> child9 = Layer::Create();
9995 scoped_refptr<Layer> grand_child10 = Layer::Create();
9996 scoped_refptr<Layer> grand_child11 = Layer::Create();
9997 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:339998
sunxdcfccd1b32016-02-11 00:54:209999 root1->AddChild(page_scale_layer);
10000 page_scale_layer->AddChild(parent2);
10001 page_scale_layer->AddChild(parent3);
10002 page_scale_layer->AddChild(parent4);
10003 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310004 parent2->AddChild(child6);
10005 parent3->AddChild(child7);
10006 parent3->AddChild(child8);
10007 parent4->AddChild(child9);
10008 child6->AddChild(grand_child10);
10009 child8->AddChild(grand_child11);
10010 child9->AddChild(grand_child12);
10011 host()->SetRootLayer(root1);
10012
pdrbbfd8822017-06-27 22:44:5210013 root1->SetBounds(gfx::Size(1, 1));
sunxdea1df782016-01-28 00:12:3310014 parent2->AddMainThreadScrollingReasons(
10015 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf2016-02-03 02:47:4810016 parent2->AddMainThreadScrollingReasons(
10017 MainThreadScrollingReason::kScrollbarScrolling);
pdr54d038192017-06-08 22:44:1310018 parent2->SetElementId(LayerIdToElementIdForTesting(parent2->id()));
pdrbbfd8822017-06-27 22:44:5210019 parent2->SetScrollable(root1->bounds());
sunxdea1df782016-01-28 00:12:3310020 child6->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810021 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310022 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810023 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310024
pdrbbfd8822017-06-27 22:44:5210025 parent3->SetBounds(gfx::Size(2, 2));
10026 child7->SetScrollable(parent3->bounds());
pdr54d038192017-06-08 22:44:1310027 child7->SetElementId(LayerIdToElementIdForTesting(child7->id()));
sunxdcfccd1b32016-02-11 00:54:2010028
sunxdea1df782016-01-28 00:12:3310029 child8->SetScrollParent(child7.get());
pdrbbfd8822017-06-27 22:44:5210030 child8->SetBounds(gfx::Size(3, 3));
10031 grand_child11->SetScrollable(child8->bounds());
pdr54d038192017-06-08 22:44:1310032 grand_child11->SetElementId(
10033 LayerIdToElementIdForTesting(grand_child11->id()));
sunxdea1df782016-01-28 00:12:3310034
10035 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010036 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310037
pdr5200a052017-05-21 22:50:5810038 LayerTreeHost::ViewportLayers viewport_layers;
10039 viewport_layers.page_scale = page_scale_layer;
10040 viewport_layers.inner_viewport_container = root1;
10041 viewport_layers.inner_viewport_scroll = parent2;
10042 host()->RegisterViewportLayers(viewport_layers);
jaydasika6ed869662016-09-21 14:29:5910043 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get());
sunxdea1df782016-01-28 00:12:3310044
sunxdea1df782016-01-28 00:12:3310045 const int kRootPropertyTreeNodeId = 0;
10046
10047 // Property tree root
ajumae4af47062016-05-24 23:59:0410048 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010049 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010050 property_trees.is_main_thread = true;
10051 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410052 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310053 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10054 property_tree_root->id = kRootPropertyTreeNodeId;
ajumaf884cfb2017-01-16 22:27:5210055 property_tree_root->parent_id = ScrollTree::kInvalidNodeId;
trchendba8b1502016-07-08 09:47:0110056 property_tree_root->scrollable = false;
10057 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf2016-02-03 02:47:4810058 MainThreadScrollingReason::kNotScrollingOnMain;
pdr0283fabf2017-02-28 23:53:2410059 property_tree_root->non_fast_scrollable_region = Region();
trchendba8b1502016-07-08 09:47:0110060 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310061
10062 // The node owned by root1
10063 ScrollNode scroll_root1;
10064 scroll_root1.id = 1;
pdrbbfd8822017-06-27 22:44:5210065 scroll_root1.bounds = root1->bounds();
trchendba8b1502016-07-08 09:47:0110066 scroll_root1.user_scrollable_horizontal = true;
10067 scroll_root1.user_scrollable_vertical = true;
10068 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310069 expected_scroll_tree.Insert(scroll_root1, 0);
sunxdea1df782016-01-28 00:12:3310070
10071 // The node owned by parent2
10072 ScrollNode scroll_parent2;
10073 scroll_parent2.id = 2;
pdr54d038192017-06-08 22:44:1310074 scroll_parent2.element_id = parent2->element_id();
trchendba8b1502016-07-08 09:47:0110075 scroll_parent2.scrollable = true;
10076 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf2016-02-03 02:47:4810077 parent2->main_thread_scrolling_reasons();
Philip Rogers0dd36f42017-06-30 23:33:3710078 scroll_parent2.container_bounds = root1->bounds();
trchendba8b1502016-07-08 09:47:0110079 scroll_parent2.bounds = parent2->bounds();
10080 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
pdrabe15522017-02-24 19:15:5610081 scroll_parent2.scrolls_inner_viewport = true;
trchendba8b1502016-07-08 09:47:0110082 scroll_parent2.user_scrollable_horizontal = true;
10083 scroll_parent2.user_scrollable_vertical = true;
10084 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310085 expected_scroll_tree.Insert(scroll_parent2, 1);
sunxdea1df782016-01-28 00:12:3310086
10087 // The node owned by child6
10088 ScrollNode scroll_child6;
10089 scroll_child6.id = 3;
trchendba8b1502016-07-08 09:47:0110090 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf2016-02-03 02:47:4810091 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110092 scroll_child6.should_flatten = true;
10093 scroll_child6.user_scrollable_horizontal = true;
10094 scroll_child6.user_scrollable_vertical = true;
10095 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310096 expected_scroll_tree.Insert(scroll_child6, 2);
sunxdea1df782016-01-28 00:12:3310097
10098 // The node owned by child7, child7 also owns a transform node
10099 ScrollNode scroll_child7;
10100 scroll_child7.id = 4;
pdr54d038192017-06-08 22:44:1310101 scroll_child7.element_id = child7->element_id();
trchendba8b1502016-07-08 09:47:0110102 scroll_child7.scrollable = true;
Philip Rogers0dd36f42017-06-30 23:33:3710103 scroll_child7.container_bounds = parent3->bounds();
trchendba8b1502016-07-08 09:47:0110104 scroll_child7.bounds = child7->bounds();
10105 scroll_child7.user_scrollable_horizontal = true;
10106 scroll_child7.user_scrollable_vertical = true;
10107 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310108 expected_scroll_tree.Insert(scroll_child7, 1);
sunxdea1df782016-01-28 00:12:3310109
10110 // The node owned by grand_child11, grand_child11 also owns a transform node
10111 ScrollNode scroll_grand_child11;
10112 scroll_grand_child11.id = 5;
pdr54d038192017-06-08 22:44:1310113 scroll_grand_child11.element_id = grand_child11->element_id();
trchendba8b1502016-07-08 09:47:0110114 scroll_grand_child11.scrollable = true;
Philip Rogers0dd36f42017-06-30 23:33:3710115 scroll_grand_child11.container_bounds = child8->bounds();
trchendba8b1502016-07-08 09:47:0110116 scroll_grand_child11.user_scrollable_horizontal = true;
10117 scroll_grand_child11.user_scrollable_vertical = true;
10118 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310119 expected_scroll_tree.Insert(scroll_grand_child11, 4);
sunxdea1df782016-01-28 00:12:3310120
10121 // The node owned by parent5
10122 ScrollNode scroll_parent5;
10123 scroll_parent5.id = 8;
pdr0283fabf2017-02-28 23:53:2410124 scroll_parent5.non_fast_scrollable_region = gfx::Rect(0, 0, 50, 50);
trchendba8b1502016-07-08 09:47:0110125 scroll_parent5.bounds = gfx::Size(10, 10);
10126 scroll_parent5.should_flatten = true;
10127 scroll_parent5.user_scrollable_horizontal = true;
10128 scroll_parent5.user_scrollable_vertical = true;
10129 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310130 expected_scroll_tree.Insert(scroll_parent5, 1);
sunxdea1df782016-01-28 00:12:3310131
pdr54d038192017-06-08 22:44:1310132 expected_scroll_tree.SetScrollOffset(parent2->element_id(),
10133 gfx::ScrollOffset(0, 0));
10134 expected_scroll_tree.SetScrollOffset(child7->element_id(),
10135 gfx::ScrollOffset(0, 0));
10136 expected_scroll_tree.SetScrollOffset(grand_child11->element_id(),
sunxdc044b11a2016-03-16 16:23:2010137 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310138 expected_scroll_tree.set_needs_update(false);
10139
10140 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10141
10142 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010143 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310144 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10145 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10146 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10147 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10148 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10149 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10150}
10151
revemanb2b99a3b2017-04-06 23:39:0810152TEST_F(LayerTreeHostCommonTest, CanAdjustRasterScaleTest) {
10153 LayerImpl* root = root_layer_for_testing();
10154 LayerImpl* render_surface = AddChild<LayerImpl>(root);
10155 LayerImpl* child = AddChild<LayerImpl>(render_surface);
10156
10157 root->SetBounds(gfx::Size(50, 50));
10158
10159 render_surface->SetBounds(gfx::Size(10, 10));
10160 render_surface->test_properties()->force_render_surface = true;
10161 gfx::Transform transform;
10162 transform.Scale(5.f, 5.f);
10163 render_surface->test_properties()->transform = transform;
10164
10165 child->SetDrawsContent(true);
10166 child->SetMasksToBounds(true);
10167 child->SetBounds(gfx::Size(10, 10));
10168
10169 ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root);
10170
10171 // Check surface draw properties.
10172 EXPECT_EQ(gfx::Rect(10, 10),
chrishtr7e3aaf22017-05-04 15:04:0110173 GetRenderSurface(render_surface)->content_rect());
10174 EXPECT_EQ(transform, GetRenderSurface(render_surface)->draw_transform());
revemanb2b99a3b2017-04-06 23:39:0810175 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
chrishtr7e3aaf22017-05-04 15:04:0110176 GetRenderSurface(render_surface)->DrawableContentRect());
revemanb2b99a3b2017-04-06 23:39:0810177
10178 // Check child layer draw properties.
10179 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
10180 EXPECT_EQ(gfx::Transform(), child->DrawTransform());
10181 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect());
10182 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect());
10183}
10184
wutao834bd202017-07-14 01:12:5310185TEST_F(LayerTreeHostCommonTest, SurfaceContentsScaleChangeWithCopyRequestTest) {
10186 LayerImpl* root = root_layer_for_testing();
10187 LayerImpl* scale_layer = AddChild<LayerImpl>(root);
10188 LayerImpl* copy_layer = AddChild<LayerImpl>(scale_layer);
10189 LayerImpl* clip_layer = AddChild<LayerImpl>(copy_layer);
10190 LayerImpl* test_layer = AddChild<LayerImpl>(clip_layer);
10191
10192 root->SetBounds(gfx::Size(150, 150));
10193
10194 scale_layer->SetBounds(gfx::Size(30, 30));
10195 gfx::Transform transform;
10196 transform.Scale(5.f, 5.f);
10197 scale_layer->test_properties()->transform = transform;
10198
10199 // Need to persist the render surface after copy request is cleared.
10200 copy_layer->test_properties()->force_render_surface = true;
10201 copy_layer->test_properties()->copy_requests.push_back(
Fady Samueldfecb7d2017-07-26 11:41:0410202 viz::CopyOutputRequest::CreateRequest(
10203 base::Bind(&EmptyCopyOutputCallback)));
wutao834bd202017-07-14 01:12:5310204
10205 clip_layer->SetDrawsContent(true);
10206 clip_layer->SetMasksToBounds(true);
10207 clip_layer->SetBounds(gfx::Size(10, 10));
10208
10209 test_layer->SetDrawsContent(true);
10210 test_layer->SetMasksToBounds(true);
10211 test_layer->SetBounds(gfx::Size(20, 20));
10212
10213 ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root);
10214
10215 // Check surface with copy request draw properties.
10216 EXPECT_EQ(gfx::Rect(50, 50), GetRenderSurface(copy_layer)->content_rect());
10217 EXPECT_EQ(gfx::Transform(), GetRenderSurface(copy_layer)->draw_transform());
10218 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
10219 GetRenderSurface(copy_layer)->DrawableContentRect());
10220
10221 // Check test layer draw properties.
10222 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect());
10223 EXPECT_EQ(transform, test_layer->DrawTransform());
10224 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
10225 EXPECT_EQ(gfx::Rect(50, 50), test_layer->drawable_content_rect());
10226
10227 // Clear the copy request and call UpdateSurfaceContentsScale.
10228 host_impl()->active_tree()->property_trees()->effect_tree.ClearCopyRequests();
10229 ExecuteCalculateDrawPropertiesWithoutAdjustingRasterScales(root);
10230
10231 // Check surface draw properties without copy request.
10232 EXPECT_EQ(gfx::Rect(10, 10), GetRenderSurface(copy_layer)->content_rect());
10233 EXPECT_EQ(transform, GetRenderSurface(copy_layer)->draw_transform());
10234 EXPECT_EQ(gfx::RectF(50.0f, 50.0f),
10235 GetRenderSurface(copy_layer)->DrawableContentRect());
10236
10237 // Check test layer draw properties without copy request.
10238 EXPECT_EQ(gfx::Rect(10, 10), test_layer->visible_layer_rect());
10239 EXPECT_EQ(gfx::Transform(), test_layer->DrawTransform());
10240 EXPECT_EQ(gfx::Rect(10, 10), test_layer->clip_rect());
10241 EXPECT_EQ(gfx::Rect(10, 10), test_layer->drawable_content_rect());
10242}
10243
[email protected]ba565742012-11-10 09:29:4810244} // namespace
10245} // namespace cc