blob: 1f04cb550493f31bc28bc6381c6ef73623da2099 [file] [log] [blame]
ajumae2b7a5c2015-09-30 21:41:421// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_common.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj6496cba2014-10-16 01:31:089#include <algorithm>
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]995708c52013-10-17 20:52:5911#include <set>
vmpstra370ef52015-11-18 10:41:2812#include <vector>
[email protected]995708c52013-10-17 20:52:5913
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
loyso968163c92016-01-04 23:18:4815#include "cc/animation/animation_host.h"
16#include "cc/animation/animation_id_provider.h"
sunxd71aea3e2016-04-01 23:48:0517#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3418#include "cc/animation/keyframed_animation_curve.h"
[email protected]1c3626e2014-04-09 17:49:2219#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5220#include "cc/base/math_util.h"
sunxd29f17bf422016-02-03 02:47:4821#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5924#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5225#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4026#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2827#include "cc/layers/render_surface_impl.h"
jaydasika69c77aa2016-07-14 22:48:4828#include "cc/layers/texture_layer_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4529#include "cc/output/copy_output_request.h"
30#include "cc/output/copy_output_result.h"
khushalsagar37694212016-01-15 20:46:4831#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
32#include "cc/proto/gfx_conversions.h"
[email protected]101441ce2012-10-16 01:45:0333#include "cc/test/animation_test_common.h"
danakj1120f4c2016-09-15 02:05:3234#include "cc/test/fake_compositor_frame_sink.h"
vollick2175fae82015-04-27 21:18:1235#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1636#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2837#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4538#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5939#include "cc/test/fake_picture_layer.h"
40#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0341#include "cc/test/geometry_test_utils.h"
danakj59931942016-07-26 22:11:2942#include "cc/test/layer_test_common.h"
reveman34b7a1522015-03-23 20:27:4743#include "cc/test/test_task_graph_runner.h"
trchendba8b1502016-07-08 09:47:0144#include "cc/trees/clip_node.h"
ennef6903532015-08-18 05:10:1545#include "cc/trees/draw_property_utils.h"
trchendba8b1502016-07-08 09:47:0146#include "cc/trees/effect_node.h"
[email protected]556fd292013-03-18 08:03:0447#include "cc/trees/layer_tree_impl.h"
danakj59931942016-07-26 22:11:2948#include "cc/trees/property_tree_builder.h"
trchendba8b1502016-07-08 09:47:0149#include "cc/trees/scroll_node.h"
[email protected]556fd292013-03-18 08:03:0450#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1651#include "cc/trees/task_runner_provider.h"
trchendba8b1502016-07-08 09:47:0152#include "cc/trees/transform_node.h"
[email protected]7f0c53db2012-10-02 00:23:1853#include "testing/gtest/include/gtest/gtest.h"
jbroman1c44d5b52016-06-06 21:19:3054#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2055#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3756#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0057#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1458
[email protected]ba565742012-11-10 09:29:4859namespace cc {
[email protected]94f206c12012-08-25 00:09:1460namespace {
61
danakj59931942016-07-26 22:11:2962class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings {
63 public:
64 VerifyTreeCalcsLayerTreeSettings() {
jaydasika853306a2016-07-29 19:28:3465 verify_clip_tree_calculations = true;
danakj59931942016-07-26 22:11:2966 }
67};
68
69class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest {
70 public:
71 LayerTreeHostCommonTestBase()
72 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {}
73 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings)
74 : LayerTestCommon::LayerImplTest(settings) {}
75
76 static void SetScrollOffsetDelta(LayerImpl* layer_impl,
77 const gfx::Vector2dF& delta) {
78 if (layer_impl->layer_tree_impl()
79 ->property_trees()
80 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(),
81 delta))
vollickc9696912016-09-16 16:02:4782 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id());
danakj59931942016-07-26 22:11:2983 }
84
85 static float GetMaximumAnimationScale(LayerImpl* layer_impl) {
86 return layer_impl->layer_tree_impl()
87 ->property_trees()
88 ->GetAnimationScales(layer_impl->transform_tree_index(),
89 layer_impl->layer_tree_impl())
90 .maximum_animation_scale;
91 }
92
93 static float GetStartingAnimationScale(LayerImpl* layer_impl) {
94 return layer_impl->layer_tree_impl()
95 ->property_trees()
96 ->GetAnimationScales(layer_impl->transform_tree_index(),
97 layer_impl->layer_tree_impl())
98 .starting_animation_scale;
99 }
100
101 void ExecuteCalculateDrawProperties(Layer* root_layer,
102 float device_scale_factor,
103 float page_scale_factor,
flackre310f292016-10-12 21:09:28104 Layer* page_scale_layer,
105 Layer* inner_viewport_scroll_layer) {
danakj59931942016-07-26 22:11:29106 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer);
107
108 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
109 gfx::Size device_viewport_size =
110 gfx::Size(root_layer->bounds().width() * device_scale_factor,
111 root_layer->bounds().height() * device_scale_factor);
112
113 // We are probably not testing what is intended if the root_layer bounds are
114 // empty.
115 DCHECK(!root_layer->bounds().IsEmpty());
116 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
117 root_layer, device_viewport_size);
118 inputs.device_scale_factor = device_scale_factor;
119 inputs.page_scale_factor = page_scale_factor;
120 inputs.page_scale_layer = page_scale_layer;
flackre310f292016-10-12 21:09:28121 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
danakj59931942016-07-26 22:11:29122 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
123 }
124
jaydasika5237db02016-09-20 01:34:30125 void ExecuteCalculateDrawProperties(
126 LayerImpl* root_layer,
127 float device_scale_factor,
128 float page_scale_factor,
129 LayerImpl* page_scale_layer,
flackre310f292016-10-12 21:09:28130 LayerImpl* inner_viewport_scroll_layer,
jaydasika5237db02016-09-20 01:34:30131 bool skip_verify_visible_rect_calculations = false) {
danakj59931942016-07-26 22:11:29132 if (device_scale_factor !=
133 root_layer->layer_tree_impl()->device_scale_factor())
134 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
135
136 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
137
138 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
139
140 gfx::Size device_viewport_size =
141 gfx::Size(root_layer->bounds().width() * device_scale_factor,
142 root_layer->bounds().height() * device_scale_factor);
143
144 render_surface_layer_list_impl_.reset(new LayerImplList);
145
146 // We are probably not testing what is intended if the root_layer bounds are
147 // empty.
148 DCHECK(!root_layer->bounds().IsEmpty());
149 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
150 root_layer, device_viewport_size,
151 render_surface_layer_list_impl_.get());
152 inputs.device_scale_factor = device_scale_factor;
153 inputs.page_scale_factor = page_scale_factor;
154 inputs.page_scale_layer = page_scale_layer;
flackre310f292016-10-12 21:09:28155 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
danakj59931942016-07-26 22:11:29156 inputs.can_adjust_raster_scales = true;
jaydasika5237db02016-09-20 01:34:30157 if (skip_verify_visible_rect_calculations)
158 inputs.verify_visible_rect_calculations = false;
danakj59931942016-07-26 22:11:29159
160 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
161 }
162
163 template <class LayerType>
164 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
165 LayerType* page_scale_application_layer = nullptr;
flackre310f292016-10-12 21:09:28166 LayerType* inner_viewport_scroll_layer = nullptr;
danakj59931942016-07-26 22:11:29167 ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f,
flackre310f292016-10-12 21:09:28168 page_scale_application_layer,
169 inner_viewport_scroll_layer);
danakj59931942016-07-26 22:11:29170 }
171
172 template <class LayerType>
173 void ExecuteCalculateDrawProperties(LayerType* root_layer,
174 float device_scale_factor) {
175 LayerType* page_scale_application_layer = nullptr;
flackre310f292016-10-12 21:09:28176 LayerType* inner_viewport_scroll_layer = nullptr;
danakj59931942016-07-26 22:11:29177 ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f,
flackre310f292016-10-12 21:09:28178 page_scale_application_layer,
179 inner_viewport_scroll_layer);
danakj59931942016-07-26 22:11:29180 }
181
sunxd713aedbd2016-08-10 22:22:14182 const LayerList* GetUpdateLayerList() { return &update_layer_list_; }
183
jaydasika6ed869662016-09-21 14:29:59184 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) {
khushalsagar86928f92016-08-17 21:49:05185 DCHECK(root_layer->GetLayerTree());
danakj59931942016-07-26 22:11:29186 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer);
187
188 bool can_render_to_separate_surface = true;
189
190 const Layer* page_scale_layer =
khushalsagar86928f92016-08-17 21:49:05191 root_layer->GetLayerTree()->page_scale_layer();
danakj59931942016-07-26 22:11:29192 Layer* inner_viewport_scroll_layer =
khushalsagar86928f92016-08-17 21:49:05193 root_layer->GetLayerTree()->inner_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29194 Layer* outer_viewport_scroll_layer =
khushalsagar86928f92016-08-17 21:49:05195 root_layer->GetLayerTree()->outer_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29196 const Layer* overscroll_elasticity_layer =
khushalsagar86928f92016-08-17 21:49:05197 root_layer->GetLayerTree()->overscroll_elasticity_layer();
danakj59931942016-07-26 22:11:29198 gfx::Vector2dF elastic_overscroll =
khushalsagar86928f92016-08-17 21:49:05199 root_layer->GetLayerTree()->elastic_overscroll();
danakj59931942016-07-26 22:11:29200 float page_scale_factor = 1.f;
201 float device_scale_factor = 1.f;
202 gfx::Size device_viewport_size =
203 gfx::Size(root_layer->bounds().width() * device_scale_factor,
204 root_layer->bounds().height() * device_scale_factor);
205 PropertyTrees* property_trees =
khushalsagar86928f92016-08-17 21:49:05206 root_layer->GetLayerTree()->property_trees();
danakj59931942016-07-26 22:11:29207 update_layer_list_.clear();
208 PropertyTreeBuilder::BuildPropertyTrees(
209 root_layer, page_scale_layer, inner_viewport_scroll_layer,
210 outer_viewport_scroll_layer, overscroll_elasticity_layer,
211 elastic_overscroll, page_scale_factor, device_scale_factor,
212 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees);
213 draw_property_utils::UpdatePropertyTrees(property_trees,
214 can_render_to_separate_surface);
215 draw_property_utils::FindLayersThatNeedUpdates(
jaydasikab433552b2016-10-26 18:49:44216 root_layer->GetLayerTree(), property_trees, &update_layer_list_);
danakj59931942016-07-26 22:11:29217 }
218
jaydasika6ed869662016-09-21 14:29:59219 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
220 LayerImpl* root_layer,
221 bool skip_verify_visible_rect_calculations = false) {
danakj59931942016-07-26 22:11:29222 DCHECK(root_layer->layer_tree_impl());
223 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer);
224
225 bool can_render_to_separate_surface = true;
226
227 LayerImpl* page_scale_layer = nullptr;
228 LayerImpl* inner_viewport_scroll_layer =
229 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
230 LayerImpl* outer_viewport_scroll_layer =
231 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
232 LayerImpl* overscroll_elasticity_layer =
233 root_layer->layer_tree_impl()->OverscrollElasticityLayer();
234 gfx::Vector2dF elastic_overscroll =
235 root_layer->layer_tree_impl()->elastic_overscroll()->Current(
236 root_layer->layer_tree_impl()->IsActiveTree());
237 float page_scale_factor = 1.f;
238 float device_scale_factor = 1.f;
239 gfx::Size device_viewport_size =
240 gfx::Size(root_layer->bounds().width() * device_scale_factor,
241 root_layer->bounds().height() * device_scale_factor);
242 update_layer_list_impl_.reset(new LayerImplList);
243 root_layer->layer_tree_impl()->BuildLayerListForTesting();
jaydasika6ed869662016-09-21 14:29:59244 PropertyTrees* property_trees =
245 root_layer->layer_tree_impl()->property_trees();
danakj59931942016-07-26 22:11:29246 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects(
247 root_layer, page_scale_layer, inner_viewport_scroll_layer,
248 outer_viewport_scroll_layer, overscroll_elasticity_layer,
249 elastic_overscroll, page_scale_factor, device_scale_factor,
250 gfx::Rect(device_viewport_size), gfx::Transform(),
jaydasika6ed869662016-09-21 14:29:59251 can_render_to_separate_surface, property_trees,
danakj59931942016-07-26 22:11:29252 update_layer_list_impl_.get());
jaydasika6ed869662016-09-21 14:29:59253 draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_,
254 property_trees);
255 if (!skip_verify_visible_rect_calculations)
256 draw_property_utils::VerifyVisibleRectsCalculations(
257 *update_layer_list_impl_, property_trees);
danakj59931942016-07-26 22:11:29258 }
259
260 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(
261 LayerImpl* root_layer) {
262 gfx::Size device_viewport_size =
263 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height());
264 render_surface_layer_list_impl_.reset(new LayerImplList);
265
266 DCHECK(!root_layer->bounds().IsEmpty());
267 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
268 root_layer, device_viewport_size,
269 render_surface_layer_list_impl_.get());
270 inputs.can_adjust_raster_scales = true;
271 inputs.can_render_to_separate_surface = false;
272
273 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
274 }
275
276 bool UpdateLayerListImplContains(int id) const {
277 for (auto* layer : *update_layer_list_impl_) {
278 if (layer->id() == id)
279 return true;
280 }
281 return false;
282 }
283
284 bool UpdateLayerListContains(int id) const {
285 for (const auto& layer : update_layer_list_) {
286 if (layer->id() == id)
287 return true;
288 }
289 return false;
290 }
291
292 const LayerImplList* render_surface_layer_list_impl() const {
293 return render_surface_layer_list_impl_.get();
294 }
295 const LayerImplList* update_layer_list_impl() const {
296 return update_layer_list_impl_.get();
297 }
298 const LayerList& update_layer_list() const { return update_layer_list_; }
299
sunxd713aedbd2016-08-10 22:22:14300 bool VerifyLayerInList(scoped_refptr<Layer> layer,
301 const LayerList* layer_list) {
302 return std::find(layer_list->begin(), layer_list->end(), layer) !=
303 layer_list->end();
304 }
305
danakj59931942016-07-26 22:11:29306 private:
307 std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_;
308 LayerList update_layer_list_;
309 std::unique_ptr<LayerImplList> update_layer_list_impl_;
310};
311
312class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
313 public testing::Test {};
314
[email protected]96baf3e2012-10-22 23:09:55315class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32316 public:
loyso0940d412016-03-14 01:30:31317 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14318
danakj59931942016-07-26 22:11:29319 bool DrawsContent() const override { return true; }
[email protected]d58499a2012-10-09 22:27:47320
[email protected]fb661802013-03-25 01:59:32321 private:
dcheng716bedf2014-10-21 09:51:08322 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:14323};
324
danakj59931942016-07-26 22:11:29325class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings {
enne637715732015-07-07 02:05:26326 public:
327 LayerTreeSettingsScaleContent() {
328 layer_transforms_should_scale_layer_contents = true;
329 }
330};
331
danakj59931942016-07-26 22:11:29332class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase,
333 public testing::Test {
enne637715732015-07-07 02:05:26334 public:
335 LayerTreeHostCommonScalingTest()
danakj59931942016-07-26 22:11:29336 : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {}
enne637715732015-07-07 02:05:26337};
338
weiliangc6da32862016-04-20 16:40:11339class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
340 public:
341 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
342
343 LayerImpl* TestVisibleRectAndDrawableContentRect(
344 const gfx::Rect& target_rect,
345 const gfx::Transform& layer_transform,
346 const gfx::Rect& layer_rect) {
jaydasikabf1875a2016-06-28 03:39:59347 LayerImpl* root = root_layer_for_testing();
weiliangc6da32862016-04-20 16:40:11348 LayerImpl* target = AddChild<LayerImpl>(root);
349 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
350
351 root->SetDrawsContent(true);
352 target->SetDrawsContent(true);
353 target->SetMasksToBounds(true);
354 drawing_layer->SetDrawsContent(true);
355
danakje4fa7b72016-07-25 22:00:06356 root->SetBounds(gfx::Size(500, 500));
357 root->test_properties()->force_render_surface = true;
358 target->SetPosition(gfx::PointF(target_rect.origin()));
359 target->SetBounds(target_rect.size());
360 target->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:04361 drawing_layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06362 drawing_layer->SetPosition(gfx::PointF(layer_rect.origin()));
363 drawing_layer->SetBounds(layer_rect.size());
364 drawing_layer->test_properties()->should_flatten_transform = false;
weiliangc6da32862016-04-20 16:40:11365
366 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
367 ExecuteCalculateDrawProperties(root);
368
369 return drawing_layer;
370 }
371};
372
[email protected]989386c2013-07-18 21:37:23373TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32374 // Sanity check: For layers positioned at zero, with zero size,
375 // and with identity transforms, then the draw transform,
376 // screen space transform, and the hierarchy passed on to children
377 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14378
jaydasikabf1875a2016-06-28 03:39:59379 LayerImpl* parent = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51380 LayerImpl* child = AddChild<LayerImpl>(parent);
381 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28382
danakje4fa7b72016-07-25 22:00:06383 parent->SetBounds(gfx::Size(100, 100));
[email protected]94f206c12012-08-25 00:09:14384
sunxdfd920f3f2016-04-05 16:17:51385 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14386
danakjf78fb272016-07-26 19:06:15387 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
388 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51389 child->ScreenSpaceTransform());
danakjf78fb272016-07-26 19:06:15390 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51391 grand_child->DrawTransform());
danakjf78fb272016-07-26 19:06:15392 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51393 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14394}
395
jaydasika322436372015-12-16 23:42:38396TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
397 // Tests that effect tree node gets a valid transform id when a layer
398 // has opacity but doesn't create a render surface.
jaydasikabf1875a2016-06-28 03:39:59399 LayerImpl* parent = root_layer_for_testing();
jaydasika322436372015-12-16 23:42:38400 LayerImpl* child = AddChild<LayerImpl>(parent);
401 child->SetDrawsContent(true);
402
danakje4fa7b72016-07-25 22:00:06403 parent->SetBounds(gfx::Size(100, 100));
404 child->SetPosition(gfx::PointF(10, 10));
405 child->SetBounds(gfx::Size(100, 100));
jaydasikaab317e02016-06-01 00:53:18406 child->test_properties()->opacity = 0.f;
jaydasika322436372015-12-16 23:42:38407 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04408 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38409 parent->layer_tree_impl()->property_trees()->effect_tree;
410 EffectNode* node = effect_tree.Node(child->effect_tree_index());
411 const int transform_tree_size = parent->layer_tree_impl()
412 ->property_trees()
413 ->transform_tree.next_available_id();
trchendba8b1502016-07-08 09:47:01414 EXPECT_LT(node->transform_id, transform_tree_size);
jaydasika322436372015-12-16 23:42:38415}
416
[email protected]989386c2013-07-18 21:37:23417TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
jaydasikabf1875a2016-06-28 03:39:59418 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51419 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14420
jaydasikabaede2d92016-07-20 00:34:32421 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51422 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32423 EffectTree& effect_tree =
424 host_impl()->active_tree()->property_trees()->effect_tree;
enne826452722015-08-18 22:22:31425
danakje4fa7b72016-07-25 22:00:06426 root->SetBounds(gfx::Size(1, 2));
427
428 // Case 1: Setting the bounds of the layer should not affect either the draw
[email protected]fb661802013-03-25 01:59:32429 // transform or the screenspace transform.
danakje4fa7b72016-07-25 22:00:06430 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51431 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31432 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15433 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32434 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31435 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15436 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32437 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14438
danakje4fa7b72016-07-25 22:00:06439 // Case 2: The anchor point by itself (without a layer transform) should have
[email protected]fb661802013-03-25 01:59:32440 // no effect on the transforms.
danakje4fa7b72016-07-25 22:00:06441 layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
442 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51443 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
444 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31445 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15446 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32447 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31448 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15449 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32450 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14451
danakje4fa7b72016-07-25 22:00:06452 // Case 3: A change in actual position affects both the draw transform and
[email protected]fb661802013-03-25 01:59:32453 // screen space transform.
454 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05455 position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06456 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51457 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
458 ExecuteCalculateDrawProperties(root);
459 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32460 position_transform,
461 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31462 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27463 position_transform,
jaydasikabaede2d92016-07-20 00:34:32464 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14465
danakje4fa7b72016-07-25 22:00:06466 // Case 4: In the correct sequence of transforms, the layer transform should
467 // pre-multiply the translation-to-center. This is easily tested by using a
[email protected]fb661802013-03-25 01:59:32468 // scale transform, because scale and translation are not commutative.
469 gfx::Transform layer_transform;
470 layer_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:04471 layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06472 layer->test_properties()->transform_origin = gfx::Point3F();
473 layer->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51474 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
475 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31476 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32477 layer_transform,
478 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31479 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32480 layer_transform,
481 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14482
danakje4fa7b72016-07-25 22:00:06483 // Case 5: The layer transform should occur with respect to the anchor point.
[email protected]fb661802013-03-25 01:59:32484 gfx::Transform translation_to_anchor;
485 translation_to_anchor.Translate(5.0, 0.0);
486 gfx::Transform expected_result =
487 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06488 layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f);
sunxdfd920f3f2016-04-05 16:17:51489 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
490 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31491 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32492 expected_result,
493 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31494 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32495 expected_result,
496 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14497
danakje4fa7b72016-07-25 22:00:06498 // Case 6: Verify that position pre-multiplies the layer transform. The
[email protected]fb661802013-03-25 01:59:32499 // current implementation of CalculateDrawProperties does this implicitly, but
500 // it is still worth testing to detect accidental regressions.
501 expected_result = position_transform * translation_to_anchor *
502 layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06503 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51504 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
505 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31506 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32507 expected_result,
508 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31509 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32510 expected_result,
511 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14512}
513
[email protected]989386c2013-07-18 21:37:23514TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13515 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32516 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01517 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32518 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
519 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16520 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32521 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20522
khushalsagarb64b360d2015-10-21 19:25:16523 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:56524 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:22525 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20526
danakj60bc3bc2016-04-09 00:24:48527 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32528 LayerImpl::Create(host_impl.active_tree(), 1));
529 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28530 sublayer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:06531 sublayer->SetBounds(gfx::Size(500, 500));
[email protected]657b24c2013-03-06 09:01:20532
danakj60bc3bc2016-04-09 00:24:48533 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32534 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47535 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
danakje4fa7b72016-07-25 22:00:06536 scroll_layer->SetBounds(gfx::Size(10, 20));
danakj60bc3bc2016-04-09 00:24:48537 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
[email protected]adeda572014-01-31 00:49:47538 LayerImpl::Create(host_impl.active_tree(), 4));
539 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
540
541 scroll_layer->SetScrollClipLayer(clip_layer->id());
542 clip_layer->SetBounds(
543 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
544 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
545 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42546 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32547 gfx::Transform impl_transform;
jaydasika89f7b5a2016-06-22 02:08:39548 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47549 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
jaydasika89f7b5a2016-06-22 02:08:39550 clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42551 scroll_layer_raw_ptr->layer_tree_impl()
552 ->property_trees()
553 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
554 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20555
danakj60bc3bc2016-04-09 00:24:48556 std::unique_ptr<LayerImpl> root(
557 LayerImpl::Create(host_impl.active_tree(), 3));
danakje4fa7b72016-07-25 22:00:06558 root->SetBounds(gfx::Size(3, 4));
jaydasika89f7b5a2016-06-22 02:08:39559 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00560 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09561 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59562 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
[email protected]657b24c2013-03-06 09:01:20563
jaydasikaa534a472016-03-31 01:12:16564 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28565 scroll_layer->test_properties()->parent,
566 nullptr);
danakjf78fb272016-07-26 19:06:15567 gfx::Transform expected_transform;
[email protected]fb661802013-03-25 01:59:32568 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33569 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16570 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33571 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16572 page_scale * kDeviceScale));
573 expected_transform.Scale(page_scale * kDeviceScale,
574 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32575 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44576 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32577 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10578 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20579
[email protected]fb661802013-03-25 01:59:32580 gfx::Transform arbitrary_translate;
581 const float kTranslateX = 10.6f;
582 const float kTranslateY = 20.6f;
583 arbitrary_translate.Translate(kTranslateX, kTranslateY);
jaydasika10d43fc2016-08-18 04:06:04584 scroll_layer->test_properties()->transform = arbitrary_translate;
jaydasika2411692c2016-03-23 01:56:09585 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16586 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28587 scroll_layer->test_properties()->parent,
588 nullptr);
[email protected]fb661802013-03-25 01:59:32589 expected_transform.MakeIdentity();
590 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16591 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
592 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33593 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16594 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
595 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33596 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16597 expected_transform.Scale(page_scale * kDeviceScale,
598 page_scale * kDeviceScale);
599 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
600 sublayer->DrawTransform());
601
602 // Test that page scale is updated even when we don't rebuild property trees.
603 page_scale = 1.888f;
604 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
jaydasikaf419bf72016-06-15 10:21:21605 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(),
606 Layer::INVALID_ID, Layer::INVALID_ID);
jaydasikaa534a472016-03-31 01:12:16607 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
608 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
609 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28610 scroll_layer->test_properties()->parent,
611 nullptr);
jaydasikaa534a472016-03-31 01:12:16612
613 expected_transform.MakeIdentity();
614 expected_transform.Translate(
615 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
616 sub_layer_screen_position.x() * page_scale *
617 kDeviceScale),
618 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
619 sub_layer_screen_position.y() * page_scale *
620 kDeviceScale));
621 expected_transform.Scale(page_scale * kDeviceScale,
622 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32623 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44624 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20625}
626
[email protected]989386c2013-07-18 21:37:23627TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
jaydasikabf1875a2016-06-28 03:39:59628 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51629 LayerImpl* parent = AddChild<LayerImpl>(root);
630 LayerImpl* child = AddChild<LayerImpl>(parent);
631 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28632
[email protected]fb661802013-03-25 01:59:32633 // One-time setup of root layer
danakje4fa7b72016-07-25 22:00:06634 root->SetBounds(gfx::Size(1, 2));
enne826452722015-08-18 22:22:31635
jaydasikabaede2d92016-07-20 00:34:32636 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51637 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32638 EffectTree& effect_tree =
639 host_impl()->active_tree()->property_trees()->effect_tree;
[email protected]ecc12622012-10-30 20:45:42640
[email protected]fb661802013-03-25 01:59:32641 // Case 1: parent's anchor point should not affect child or grand_child.
danakje4fa7b72016-07-25 22:00:06642 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
643 parent->SetBounds(gfx::Size(10, 12));
644 child->SetBounds(gfx::Size(16, 18));
645 grand_child->SetBounds(gfx::Size(76, 78));
sunxdfd920f3f2016-04-05 16:17:51646 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31647
648 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15649 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32650 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31651 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15652 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32653 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
654 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15655 gfx::Transform(), draw_property_utils::DrawTransform(
656 grand_child, transform_tree, effect_tree));
jaydasikabaede2d92016-07-20 00:34:32657 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15658 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32659 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14660
[email protected]fb661802013-03-25 01:59:32661 // Case 2: parent's position affects child and grand_child.
662 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05663 parent_position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06664 parent->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51665 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
666 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31667 EXPECT_TRANSFORMATION_MATRIX_EQ(
668 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32669 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31670 EXPECT_TRANSFORMATION_MATRIX_EQ(
671 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32672 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
673 EXPECT_TRANSFORMATION_MATRIX_EQ(
674 parent_position_transform, draw_property_utils::DrawTransform(
675 grand_child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31676 EXPECT_TRANSFORMATION_MATRIX_EQ(
677 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32678 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14679
[email protected]fb661802013-03-25 01:59:32680 // Case 3: parent's local transform affects child and grandchild
681 gfx::Transform parent_layer_transform;
682 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
683 gfx::Transform parent_translation_to_anchor;
684 parent_translation_to_anchor.Translate(2.5, 3.0);
685 gfx::Transform parent_composite_transform =
686 parent_translation_to_anchor * parent_layer_transform *
687 Inverse(parent_translation_to_anchor);
jaydasika10d43fc2016-08-18 04:06:04688 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06689 parent->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51690 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
691 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31692 EXPECT_TRANSFORMATION_MATRIX_EQ(
693 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32694 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31695 EXPECT_TRANSFORMATION_MATRIX_EQ(
696 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32697 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
enne826452722015-08-18 22:22:31698 EXPECT_TRANSFORMATION_MATRIX_EQ(
699 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32700 draw_property_utils::DrawTransform(grand_child, transform_tree,
701 effect_tree));
enne826452722015-08-18 22:22:31702 EXPECT_TRANSFORMATION_MATRIX_EQ(
703 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32704 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14705}
706
[email protected]989386c2013-07-18 21:37:23707TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:59708 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28709 LayerImpl* parent = AddChildToRoot<LayerImpl>();
710 LayerImpl* child = AddChild<LayerImpl>(parent);
711 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]94f206c12012-08-25 00:09:14712
[email protected]fb661802013-03-25 01:59:32713 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05714 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32715 gfx::Transform parent_translation_to_anchor;
716 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44717
[email protected]fb661802013-03-25 01:59:32718 gfx::Transform parent_composite_transform =
719 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39720 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32721 gfx::Vector2dF parent_composite_scale =
722 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
723 1.f);
724 gfx::Transform surface_sublayer_transform;
725 surface_sublayer_transform.Scale(parent_composite_scale.x(),
726 parent_composite_scale.y());
727 gfx::Transform surface_sublayer_composite_transform =
728 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14729
danakje4fa7b72016-07-25 22:00:06730 root->SetBounds(gfx::Size(1, 2));
jaydasika10d43fc2016-08-18 04:06:04731 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06732 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
733 parent->SetBounds(gfx::Size(100, 120));
734 child->SetBounds(gfx::Size(16, 18));
735 child->test_properties()->force_render_surface = true;
736 grand_child->SetBounds(gfx::Size(8, 10));
737 grand_child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28738 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14739
[email protected]fb661802013-03-25 01:59:32740 // Render surface should have been created now.
741 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25742 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14743
[email protected]fb661802013-03-25 01:59:32744 // The child layer's draw transform should refer to its new render surface.
745 // The screen-space transform, however, should still refer to the root.
746 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44747 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32748 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10749 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14750
[email protected]fb661802013-03-25 01:59:32751 // Because the grand_child is the only drawable content, the child's render
752 // surface will tighten its bounds to the grand_child. The scale at which the
753 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25754 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
755 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14756
[email protected]fb661802013-03-25 01:59:32757 // The screen space is the same as the target since the child surface draws
758 // into the root.
759 EXPECT_TRANSFORMATION_MATRIX_EQ(
760 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25761 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14762}
763
ajuma51d73f72015-10-19 19:43:58764TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:59765 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:58766 LayerImpl* parent = AddChildToRoot<LayerImpl>();
767 LayerImpl* child = AddChild<LayerImpl>(parent);
768 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma51d73f72015-10-19 19:43:58769
770 gfx::Transform parent_transform;
771 parent_transform.Translate(10.0, 10.0);
772
773 gfx::Transform child_transform;
774 child_transform.Rotate(45.0);
775
danakje4fa7b72016-07-25 22:00:06776 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:04777 parent->test_properties()->transform = parent_transform;
danakje4fa7b72016-07-25 22:00:06778 parent->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:04779 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:06780 child->SetBounds(gfx::Size(10, 10));
781 child->test_properties()->force_render_surface = true;
782 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
783 grand_child->SetBounds(gfx::Size(20, 20));
784 grand_child->SetDrawsContent(true);
ajuma51d73f72015-10-19 19:43:58785
786 gfx::Transform expected_grand_child_screen_space_transform;
787 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
788 expected_grand_child_screen_space_transform.Rotate(45.0);
789 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
790
791 // First compute draw properties with separate surfaces enabled.
792 ExecuteCalculateDrawProperties(root);
793
794 // The grand child's draw transform should be its offset wrt the child.
795 gfx::Transform expected_grand_child_draw_transform;
796 expected_grand_child_draw_transform.Translate(2.0, 2.0);
797 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44798 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58799 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10800 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58801
802 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
803
804 // With separate surfaces disabled, the grand child's draw transform should be
805 // the same as its screen space transform.
806 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44807 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58808 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10809 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58810}
811
[email protected]989386c2013-07-18 21:37:23812TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32813 // This test creates a more complex tree and verifies it all at once. This
814 // covers the following cases:
815 // - layers that are described w.r.t. a render surface: should have draw
816 // transforms described w.r.t. that surface
817 // - A render surface described w.r.t. an ancestor render surface: should
818 // have a draw transform described w.r.t. that ancestor surface
[email protected]fb661802013-03-25 01:59:32819 // - Sanity check on recursion: verify transforms of layers described w.r.t.
820 // a render surface that is described w.r.t. an ancestor render surface.
821 // - verifying that each layer has a reference to the correct render surface
822 // and render target values.
823
jaydasikabf1875a2016-06-28 03:39:59824 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28825 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36826 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28827 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36828 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28829 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36830 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28831 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36832 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28833 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36834 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28835 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36836 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28837 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36838 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28839 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
840 grand_child_of_rs1->SetDrawsContent(true);
841 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
842 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32843
[email protected]fb661802013-03-25 01:59:32844 // In combination with descendant draws content, opacity != 1 forces the layer
845 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18846 render_surface1->test_properties()->opacity = 0.5f;
847 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32848
[email protected]fb661802013-03-25 01:59:32849 // All layers in the tree are initialized with an anchor at .25 and a size of
wangxianzhu932d7f12016-09-30 05:47:00850 // (10,10). Matrix "A" is the composite layer transform used in all layers.
[email protected]fb661802013-03-25 01:59:32851 gfx::Transform translation_to_anchor;
852 translation_to_anchor.Translate(2.5, 0.0);
853 gfx::Transform layer_transform;
854 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32855
856 gfx::Transform A =
857 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32858
859 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39860 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32861 gfx::Transform surface1_sublayer_transform;
862 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
863 surface1_parent_transform_scale.y());
864
865 // SS1 = transform given to the subtree of render_surface1
866 gfx::Transform SS1 = surface1_sublayer_transform;
867 // S1 = transform to move from render_surface1 pixels to the layer space of
868 // the owning layer
869 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
870
871 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39872 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32873 gfx::Transform surface2_sublayer_transform;
874 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
875 surface2_parent_transform_scale.y());
876
877 // SS2 = transform given to the subtree of render_surface2
878 gfx::Transform SS2 = surface2_sublayer_transform;
879 // S2 = transform to move from render_surface2 pixels to the layer space of
880 // the owning layer
881 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
882
danakje4fa7b72016-07-25 22:00:06883 root->SetBounds(gfx::Size(1, 2));
884 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04885 parent->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06886 parent->SetBounds(gfx::Size(10, 10));
887 render_surface1->test_properties()->transform_origin =
888 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04889 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06890 render_surface1->SetBounds(gfx::Size(10, 10));
891 render_surface1->test_properties()->force_render_surface = true;
892 render_surface2->test_properties()->transform_origin =
893 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04894 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06895 render_surface2->SetBounds(gfx::Size(10, 10));
896 render_surface2->test_properties()->force_render_surface = true;
897 child_of_root->test_properties()->transform_origin =
898 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04899 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06900 child_of_root->SetBounds(gfx::Size(10, 10));
901 child_of_rs1->test_properties()->transform_origin =
902 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04903 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06904 child_of_rs1->SetBounds(gfx::Size(10, 10));
905 child_of_rs2->test_properties()->transform_origin =
906 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04907 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06908 child_of_rs2->SetBounds(gfx::Size(10, 10));
909 grand_child_of_root->test_properties()->transform_origin =
910 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04911 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06912 grand_child_of_root->SetBounds(gfx::Size(10, 10));
913 grand_child_of_rs1->test_properties()->transform_origin =
914 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04915 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06916 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
917 grand_child_of_rs2->test_properties()->transform_origin =
918 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04919 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06920 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:32921
enne25dea3f2015-07-27 16:44:28922 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32923
924 // Only layers that are associated with render surfaces should have an actual
925 // RenderSurface() value.
926 ASSERT_TRUE(root->render_surface());
927 ASSERT_FALSE(child_of_root->render_surface());
928 ASSERT_FALSE(grand_child_of_root->render_surface());
929
930 ASSERT_TRUE(render_surface1->render_surface());
931 ASSERT_FALSE(child_of_rs1->render_surface());
932 ASSERT_FALSE(grand_child_of_rs1->render_surface());
933
934 ASSERT_TRUE(render_surface2->render_surface());
935 ASSERT_FALSE(child_of_rs2->render_surface());
936 ASSERT_FALSE(grand_child_of_rs2->render_surface());
937
938 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25939 EXPECT_EQ(root->render_surface(), parent->render_target());
940 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
941 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32942
weiliangc189c1a12016-04-11 16:16:25943 EXPECT_EQ(render_surface1->render_surface(),
944 render_surface1->render_target());
945 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
946 EXPECT_EQ(render_surface1->render_surface(),
947 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32948
weiliangc189c1a12016-04-11 16:16:25949 EXPECT_EQ(render_surface2->render_surface(),
950 render_surface2->render_target());
951 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
952 EXPECT_EQ(render_surface2->render_surface(),
953 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32954
955 // Verify layer draw transforms note that draw transforms are described with
956 // respect to the nearest ancestor render surface but screen space transforms
957 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44958 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
959 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39960 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44961 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32962
ajumad9432e32015-11-30 19:43:44963 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
964 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39965 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44966 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32967
ajumad9432e32015-11-30 19:43:44968 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
969 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39970 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44971 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32972
973 // Verify layer screen-space transforms
974 //
ajumab6aa1c62015-12-01 21:01:10975 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
976 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
977 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
978 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32979
[email protected]baf64d062014-02-16 22:10:39980 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10981 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39982 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10983 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39984 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10985 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32986
[email protected]baf64d062014-02-16 22:10:39987 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10988 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39989 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10990 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39991 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10992 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32993
994 // Verify render surface transforms.
995 //
996 // Draw transform of render surface 1 is described with respect to root.
997 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39998 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32999 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391000 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321001 // Draw transform of render surface 2 is described with respect to render
1002 // surface 1.
1003 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391004 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321005 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391006 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321007 render_surface2->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321008
1009 // Sanity check. If these fail there is probably a bug in the test itself. It
1010 // is expected that we correctly set up transforms so that the y-component of
1011 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:101012 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:261013 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101014 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321015 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101016 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321017
[email protected]803f6b52013-09-12 00:51:261018 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101019 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
1020 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321021 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101022 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321023
[email protected]803f6b52013-09-12 00:51:261024 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:101025 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
1026 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321027 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101028 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321029}
1030
[email protected]989386c2013-07-18 21:37:231031TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321032 // For layers that flatten their subtree, there should be an orthographic
1033 // projection (for x and y values) in the middle of the transform sequence.
1034 // Note that the way the code is currently implemented, it is not expected to
1035 // use a canonical orthographic projection.
1036
jaydasikabf1875a2016-06-28 03:39:591037 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:281038 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:361039 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:281040 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1041 grand_child->SetDrawsContent(true);
1042 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1043 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321044
1045 gfx::Transform rotation_about_y_axis;
1046 rotation_about_y_axis.RotateAboutYAxis(30.0);
1047
danakje4fa7b72016-07-25 22:00:061048 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041049 child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061050 child->SetBounds(gfx::Size(10, 10));
1051 child->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041052 grand_child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061053 grand_child->SetBounds(gfx::Size(10, 10));
1054 great_grand_child->SetBounds(gfx::Size(10, 10));
[email protected]d600df7d2013-08-03 02:34:281055
[email protected]fb661802013-03-25 01:59:321056 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521057 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
1058 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
1059 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
1060 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:321061
1062 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1063 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1064 gfx::Transform expected_grand_child_draw_transform =
1065 rotation_about_y_axis; // draws onto child's render surface
1066 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1067 flattened_rotation_about_y.FlattenTo2d();
1068 gfx::Transform expected_grand_child_screen_space_transform =
1069 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081070 gfx::Transform expected_great_grand_child_draw_transform =
1071 flattened_rotation_about_y;
1072 gfx::Transform expected_great_grand_child_screen_space_transform =
1073 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321074
enne25dea3f2015-07-27 16:44:281075 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321076
1077 // The child's draw transform should have been taken by its surface.
1078 ASSERT_TRUE(child->render_surface());
1079 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1080 child->render_surface()->draw_transform());
1081 EXPECT_TRANSFORMATION_MATRIX_EQ(
1082 expected_child_screen_space_transform,
1083 child->render_surface()->screen_space_transform());
danakje4fa7b72016-07-25 22:00:061084 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321085 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101086 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321087 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441088 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321089 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101090 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081091 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441092 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081093 EXPECT_TRANSFORMATION_MATRIX_EQ(
1094 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101095 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321096}
1097
ajumadbd92cb2015-07-16 13:47:061098TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasikabf1875a2016-06-28 03:39:591099 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:141100 LayerImpl* child = AddChild<LayerImpl>(root);
1101 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061102
1103 gfx::Transform child_transform;
1104 child_transform.Translate(50.0, 50.0);
1105 child_transform.RotateAboutZAxis(30.0);
1106
1107 gfx::Transform grand_child_transform;
1108 grand_child_transform.RotateAboutYAxis(90.0);
1109
danakje4fa7b72016-07-25 22:00:061110 root->SetBounds(gfx::Size(200, 200));
jaydasika10d43fc2016-08-18 04:06:041111 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:061112 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:041113 grand_child->test_properties()->transform = grand_child_transform;
danakje4fa7b72016-07-25 22:00:061114 grand_child->SetBounds(gfx::Size(100, 100));
jaydasikaca2605e2016-04-23 02:52:521115 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141116 grand_child->SetDrawsContent(true);
jaydasika6ed869662016-09-21 14:29:591117 float device_scale_factor = 1.f;
1118 float page_scale_factor = 1.f;
1119 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:281120 LayerImpl* inner_viewport_scroll_layer = nullptr;
jaydasika6ed869662016-09-21 14:29:591121 // Visible rects computed by combining clips in target space and root space
1122 // don't match because of rotation transforms. So, we skip
1123 // verify_visible_rect_calculations.
1124 bool skip_verify_visible_rect_calculations = true;
1125 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:281126 page_scale_layer, inner_viewport_scroll_layer,
jaydasika6ed869662016-09-21 14:29:591127 skip_verify_visible_rect_calculations);
ajumadbd92cb2015-07-16 13:47:061128
1129 // Mapping grand_child's bounds to target space produces a non-empty rect
1130 // that is fully contained within the target's bounds, so grand_child should
1131 // be considered fully visible.
1132 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141133 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061134}
1135
[email protected]989386c2013-07-18 21:37:231136TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321137 // A layer that is empty in one axis, but not the other, was accidentally
1138 // skipping a necessary translation. Without that translation, the coordinate
1139 // space of the layer's draw transform is incorrect.
1140 //
1141 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1142 // but if that layer becomes a render surface, then its draw transform is
1143 // implicitly inherited by the rest of the subtree, which then is positioned
1144 // incorrectly as a result.
1145
jaydasikabf1875a2016-06-28 03:39:591146 LayerImpl* root = root_layer_for_testing();
ennec1332992015-08-24 19:45:091147 LayerImpl* child = AddChild<LayerImpl>(root);
1148 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1149 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321150
danakje4fa7b72016-07-25 22:00:061151 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:321152 // The child height is zero, but has non-zero width that should be accounted
1153 // for while computing draw transforms.
danakje4fa7b72016-07-25 22:00:061154 child->SetBounds(gfx::Size(10, 0));
1155 child->test_properties()->force_render_surface = true;
1156 grand_child->SetBounds(gfx::Size(10, 10));
ennec1332992015-08-24 19:45:091157 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321158
ennec1332992015-08-24 19:45:091159 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321160 // This is the real test, the rest are sanity checks.
danakje4fa7b72016-07-25 22:00:061161 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:321162 child->render_surface()->draw_transform());
danakje4fa7b72016-07-25 22:00:061163 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1164 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441165 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321166}
1167
jaydasika9bbee9b2016-01-13 00:36:481168TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
jaydasikabf1875a2016-06-28 03:39:591169 LayerImpl* root = root_layer_for_testing();
jaydasika9bbee9b2016-01-13 00:36:481170 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1171 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1172 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1173
jaydasika9bbee9b2016-01-13 00:36:481174 gfx::Transform translate;
1175 translate.Translate3d(5, 5, 5);
danakje4fa7b72016-07-25 22:00:061176
1177 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041178 render_surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061179 render_surface->SetBounds(gfx::Size(100, 100));
1180 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041181 child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061182 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041183 grand_child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061184 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika9bbee9b2016-01-13 00:36:481185 grand_child->SetDrawsContent(true);
1186
1187 // render_surface will have a sublayer scale because of device scale factor.
1188 float device_scale_factor = 2.0f;
1189 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481190 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381191 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481192 inputs.device_scale_factor = device_scale_factor;
1193 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571194 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481195
1196 // Between grand_child and render_surface, we translate by (10, 10) and scale
1197 // by a factor of 2.
1198 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1199 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1200 expected_translation);
1201}
1202
[email protected]989386c2013-07-18 21:37:231203TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321204 // Transformations applied at the root of the tree should be forwarded
1205 // to child layers instead of applied to the root RenderSurface.
jaydasikabf1875a2016-06-28 03:39:591206 LayerImpl* root = root_layer_for_testing();
enned3f61fb02015-08-18 22:54:391207 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061208
1209 root->SetDrawsContent(true);
1210 root->SetBounds(gfx::Size(20, 20));
enned3f61fb02015-08-18 22:54:391211 child->SetDrawsContent(true);
enned3f61fb02015-08-18 22:54:391212 child->SetScrollClipLayer(root->id());
danakje4fa7b72016-07-25 22:00:061213 child->SetBounds(gfx::Size(20, 20));
[email protected]f224cc92013-06-06 23:23:321214
[email protected]f224cc92013-06-06 23:23:321215 gfx::Transform translate;
1216 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231217 {
enned3f61fb02015-08-18 22:54:391218 LayerImplList render_surface_layer_list_impl;
1219 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381220 root, root->bounds(), translate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321221 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571222 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021223 EXPECT_TRANSFORMATION_MATRIX_EQ(
1224 translate, root->draw_properties().target_space_transform);
1225 EXPECT_TRANSFORMATION_MATRIX_EQ(
1226 translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151227 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021228 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231229 }
[email protected]f224cc92013-06-06 23:23:321230
1231 gfx::Transform scale;
1232 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231233 {
enned3f61fb02015-08-18 22:54:391234 LayerImplList render_surface_layer_list_impl;
1235 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381236 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321237 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571238 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021239 EXPECT_TRANSFORMATION_MATRIX_EQ(
1240 scale, root->draw_properties().target_space_transform);
1241 EXPECT_TRANSFORMATION_MATRIX_EQ(
1242 scale, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151243 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021244 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231245 }
[email protected]f224cc92013-06-06 23:23:321246
1247 gfx::Transform rotate;
1248 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231249 {
enned3f61fb02015-08-18 22:54:391250 LayerImplList render_surface_layer_list_impl;
1251 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381252 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321253 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571254 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021255 EXPECT_TRANSFORMATION_MATRIX_EQ(
1256 rotate, root->draw_properties().target_space_transform);
1257 EXPECT_TRANSFORMATION_MATRIX_EQ(
1258 rotate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151259 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021260 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231261 }
[email protected]f224cc92013-06-06 23:23:321262
1263 gfx::Transform composite;
1264 composite.ConcatTransform(translate);
1265 composite.ConcatTransform(scale);
1266 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231267 {
enned3f61fb02015-08-18 22:54:391268 LayerImplList render_surface_layer_list_impl;
1269 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381270 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321271 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571272 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021273 EXPECT_TRANSFORMATION_MATRIX_EQ(
1274 composite, root->draw_properties().target_space_transform);
1275 EXPECT_TRANSFORMATION_MATRIX_EQ(
1276 composite, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151277 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021278 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231279 }
[email protected]f224cc92013-06-06 23:23:321280
[email protected]9781afa2013-07-17 23:15:321281 // Verify it composes correctly with device scale.
1282 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231283
1284 {
enned3f61fb02015-08-18 22:54:391285 LayerImplList render_surface_layer_list_impl;
1286 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381287 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531288 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321289 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571290 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231291 gfx::Transform device_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101292 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
weiliangcc3517722016-06-28 22:52:021293 EXPECT_TRANSFORMATION_MATRIX_EQ(
1294 device_scaled_translate,
1295 root->draw_properties().target_space_transform);
1296 EXPECT_TRANSFORMATION_MATRIX_EQ(
1297 device_scaled_translate,
1298 child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151299 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021300 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231301 }
[email protected]9781afa2013-07-17 23:15:321302
1303 // Verify it composes correctly with page scale.
1304 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231305
1306 {
enned3f61fb02015-08-18 22:54:391307 LayerImplList render_surface_layer_list_impl;
1308 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381309 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531310 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391311 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321312 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571313 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231314 gfx::Transform page_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101315 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
weiliangcc3517722016-06-28 22:52:021316 EXPECT_TRANSFORMATION_MATRIX_EQ(
1317 page_scaled_translate, root->draw_properties().target_space_transform);
1318 EXPECT_TRANSFORMATION_MATRIX_EQ(
1319 page_scaled_translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151320 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021321 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231322 }
[email protected]9781afa2013-07-17 23:15:321323
[email protected]f224cc92013-06-06 23:23:321324 // Verify that it composes correctly with transforms directly on root layer.
jaydasika10d43fc2016-08-18 04:06:041325 root->test_properties()->transform = composite;
[email protected]989386c2013-07-18 21:37:231326
1327 {
enned3f61fb02015-08-18 22:54:391328 LayerImplList render_surface_layer_list_impl;
1329 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381330 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391331 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571332 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231333 gfx::Transform compositeSquared = composite;
1334 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261335 EXPECT_TRANSFORMATION_MATRIX_EQ(
1336 compositeSquared, root->draw_properties().target_space_transform);
1337 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391338 compositeSquared, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151339 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021340 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231341 }
[email protected]f224cc92013-06-06 23:23:321342}
1343
[email protected]989386c2013-07-18 21:37:231344TEST_F(LayerTreeHostCommonTest,
1345 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
danakje4fa7b72016-07-25 22:00:061346 LayerImpl* root = root_layer_for_testing();
enneea850232015-07-27 16:43:121347 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1348 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
danakje4fa7b72016-07-25 22:00:061349
1350 root->SetBounds(gfx::Size(10, 10));
1351 root->SetMasksToBounds(true);
1352 render_surface1->SetBounds(gfx::Size(10, 10));
1353 render_surface1->test_properties()->force_render_surface = true;
enneea850232015-07-27 16:43:121354 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061355 child->SetPosition(gfx::PointF(30.f, 30.f));
1356 child->SetBounds(gfx::Size(10, 10));
1357 ExecuteCalculateDrawProperties(root);
[email protected]d600df7d2013-08-03 02:34:281358
danakje4fa7b72016-07-25 22:00:061359 // The child layer's content is entirely outside the root's clip rect, so
[email protected]fb661802013-03-25 01:59:321360 // the intermediate render surface should not be listed here, even if it was
1361 // forced to be created. Render surfaces without children or visible content
1362 // are unexpected at draw time (e.g. we might try to create a content texture
1363 // of size 0).
danakje4fa7b72016-07-25 22:00:061364 ASSERT_TRUE(root->render_surface());
enneea850232015-07-27 16:43:121365 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321366}
1367
[email protected]989386c2013-07-18 21:37:231368TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
danakje4fa7b72016-07-25 22:00:061369 LayerImpl* root = root_layer_for_testing();
1370 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
enne03b0e9a2015-06-19 00:08:021371 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
[email protected]d600df7d2013-08-03 02:34:281372
danakje4fa7b72016-07-25 22:00:061373 render_surface1->SetBounds(gfx::Size(10, 10));
1374 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181375 render_surface1->test_properties()->opacity = 0.f;
danakje4fa7b72016-07-25 22:00:061376 child->SetBounds(gfx::Size(10, 10));
1377 child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321378
enne03b0e9a2015-06-19 00:08:021379 LayerImplList render_surface_layer_list;
1380 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061381 root, root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531382 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571383 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321384
1385 // Since the layer is transparent, render_surface1->render_surface() should
1386 // not have gotten added anywhere. Also, the drawable content rect should not
1387 // have been extended by the children.
danakje4fa7b72016-07-25 22:00:061388 ASSERT_TRUE(root->render_surface());
1389 EXPECT_EQ(0U, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:321390 EXPECT_EQ(1U, render_surface_layer_list.size());
danakje4fa7b72016-07-25 22:00:061391 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
1392 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321393}
1394
hendrikwc266f7b2015-08-21 23:41:341395TEST_F(LayerTreeHostCommonTest,
1396 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
danakje4fa7b72016-07-25 22:00:061397 LayerImpl* root = root_layer_for_testing();
1398 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
hendrikwc266f7b2015-08-21 23:41:341399 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
hendrikwc266f7b2015-08-21 23:41:341400
danakje4fa7b72016-07-25 22:00:061401 root->SetBounds(gfx::Size(10, 10));
1402 render_surface1->SetBounds(gfx::Size(10, 10));
1403 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181404 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071405 render_surface1->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341406 FilterOperations filters;
1407 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
ajuma50bce7e2016-06-24 20:56:041408 render_surface1->test_properties()->background_filters = filters;
danakje4fa7b72016-07-25 22:00:061409 child->SetBounds(gfx::Size(10, 10));
1410 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341411
jaydasika369c24b2016-04-06 23:44:161412 {
1413 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161414 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061415 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161416 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571417 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161418 EXPECT_EQ(2U, render_surface_layer_list.size());
1419 }
hendrikwc266f7b2015-08-21 23:41:341420 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161421 // shouldn't be skipped and should be drawn.
danakje4fa7b72016-07-25 22:00:061422 ASSERT_TRUE(root->render_surface());
1423 EXPECT_EQ(1U, root->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361424 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
danakje4fa7b72016-07-25 22:00:061425 root->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161426 EffectTree& effect_tree =
danakje4fa7b72016-07-25 22:00:061427 root->layer_tree_impl()->property_trees()->effect_tree;
jaydasika369c24b2016-04-06 23:44:161428 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011429 EXPECT_TRUE(node->is_drawn);
jaydasika369c24b2016-04-06 23:44:161430
danakje4fa7b72016-07-25 22:00:061431 // When root is transparent, the layer should not be drawn.
jaydasika898b2f12016-08-20 04:22:091432 effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(),
1433 root->layer_tree_impl());
1434 effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(),
1435 root->layer_tree_impl());
jaydasika8185d302016-04-14 15:20:061436 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161437 {
1438 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161439 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061440 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161441 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571442 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161443 }
1444
1445 node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011446 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:061447 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341448}
1449
senorblanco38858c52016-01-20 23:15:001450TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
jaydasikabf1875a2016-06-28 03:39:591451 LayerImpl* root = root_layer_for_testing();
senorblanco38858c52016-01-20 23:15:001452 LayerImpl* parent = AddChild<LayerImpl>(root);
1453 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1454 LayerImpl* child2 = AddChild<LayerImpl>(parent);
senorblanco38858c52016-01-20 23:15:001455
senorblanco38858c52016-01-20 23:15:001456 gfx::Transform scale_matrix;
1457 scale_matrix.Scale(2.0f, 2.0f);
danakje4fa7b72016-07-25 22:00:061458
1459 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041460 parent->test_properties()->transform = scale_matrix;
senorblanco38858c52016-01-20 23:15:001461 FilterOperations filters;
1462 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
ajumacb2b74432016-07-21 19:11:151463 parent->test_properties()->filters = filters;
danakje4fa7b72016-07-25 22:00:061464 parent->test_properties()->force_render_surface = true;
1465 child1->SetBounds(gfx::Size(25, 25));
1466 child1->SetDrawsContent(true);
1467 child1->test_properties()->force_render_surface = true;
1468 child2->SetPosition(gfx::PointF(25, 25));
1469 child2->SetBounds(gfx::Size(25, 25));
1470 child2->SetDrawsContent(true);
1471 child2->test_properties()->force_render_surface = true;
senorblanco38858c52016-01-20 23:15:001472
1473 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001474 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381475 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001476 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571477 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001478
1479 ASSERT_TRUE(parent->render_surface());
1480 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1481 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman1c44d5b52016-06-06 21:19:301482
1483 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1484 // blur (-30,-30 110x110), and then scaled by the scale matrix
1485 // (-60,-60 220x220).
1486 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
senorblanco38858c52016-01-20 23:15:001487 parent->render_surface()->DrawableContentRect());
1488}
1489
jbroman1c44d5b52016-06-06 21:19:301490TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
jaydasikabf1875a2016-06-28 03:39:591491 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301492 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061493
1494 root->SetBounds(gfx::Size(100, 100));
1495 child->SetBounds(gfx::Size(25, 25));
jbroman1c44d5b52016-06-06 21:19:301496 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061497 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301498 FilterOperations filters;
1499 filters.Append(FilterOperation::CreateReferenceFilter(
1500 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151501 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301502 ExecuteCalculateDrawProperties(root);
1503
1504 // The render surface's size should be unaffected by the offset image filter;
1505 // it need only have a drawable content rect large enough to contain the
1506 // contents (at the new offset).
1507 ASSERT_TRUE(child->render_surface());
1508 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1509 child->render_surface()->DrawableContentRect());
1510}
1511
1512TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1513 const float device_scale_factor = 2.0f;
1514
jaydasikabf1875a2016-06-28 03:39:591515 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301516 LayerImpl* child = AddChild<LayerImpl>(root);
jbroman1c44d5b52016-06-06 21:19:301517
danakje4fa7b72016-07-25 22:00:061518 root->SetBounds(gfx::Size(100, 100));
1519 child->SetBounds(gfx::Size(25, 25));
1520 child->SetDrawsContent(true);
1521 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301522
1523 FilterOperations filters;
1524 filters.Append(FilterOperation::CreateReferenceFilter(
1525 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151526 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301527
1528 ExecuteCalculateDrawProperties(root, device_scale_factor);
1529
1530 // The render surface's size should be unaffected by the offset image filter;
1531 // it need only have a drawable content rect large enough to contain the
1532 // contents (at the new offset). All coordinates should be scaled by 2,
1533 // corresponding to the device scale factor.
1534 ASSERT_TRUE(child->render_surface());
1535 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1536 child->render_surface()->DrawableContentRect());
1537}
1538
rosca948d29d2014-11-09 10:25:131539TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
danakje4fa7b72016-07-25 22:00:061540 LayerImpl* root = root_layer_for_testing();
1541 LayerImpl* child = AddChild<LayerImpl>(root);
1542
1543 root->SetBounds(gfx::Size(10, 10));
1544 child->SetBounds(gfx::Size(10, 10));
enned5f4ddd2015-08-18 16:50:061545 child->SetDrawsContent(true);
ajuma4c14b252016-07-26 20:10:591546 child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode;
jaydasikaab317e02016-06-01 00:53:181547 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061548 child->test_properties()->force_render_surface = true;
1549 ExecuteCalculateDrawProperties(root);
rosca948d29d2014-11-09 10:25:131550
1551 // Since the child layer has a blend mode other than normal, it should get
1552 // its own render surface. Also, layer's draw_properties should contain the
1553 // default blend mode, since the render surface becomes responsible for
1554 // applying the blend mode.
1555 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291556 EXPECT_EQ(1.0f, child->draw_opacity());
1557 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261558 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131559}
1560
jaydasikafbdb86e2016-01-21 18:57:511561TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
jaydasikabf1875a2016-06-28 03:39:591562 LayerImpl* root = root_layer_for_testing();
jaydasikafbdb86e2016-01-21 18:57:511563 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1564 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1565 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1566
danakje4fa7b72016-07-25 22:00:061567 root->SetBounds(gfx::Size(10, 10));
1568 surface1->SetBounds(gfx::Size(10, 10));
jaydasikafbdb86e2016-01-21 18:57:511569 surface1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181570 surface1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061571 surface1->test_properties()->force_render_surface = true;
1572 not_surface->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:181573 not_surface->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061574 surface2->SetBounds(gfx::Size(10, 10));
1575 surface2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181576 surface2->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061577 surface2->test_properties()->force_render_surface = true;
jaydasikafbdb86e2016-01-21 18:57:511578 ExecuteCalculateDrawProperties(root);
1579
1580 ASSERT_TRUE(surface1->render_surface());
1581 ASSERT_FALSE(not_surface->render_surface());
1582 ASSERT_TRUE(surface2->render_surface());
1583 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1584 // surface2's draw opacity should include the opacity of not-surface and
1585 // itself, but not the opacity of surface1.
1586 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1587}
1588
ajuma51d73f72015-10-19 19:43:581589TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1590 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1591 // the product of all ancestor layer opacties and the layer's own opacity.
1592 // (Rendering will still be incorrect in situations where we really do need
1593 // surfaces to apply opacity, such as when we have overlapping layers with an
1594 // ancestor whose opacity is <1.)
jaydasikabf1875a2016-06-28 03:39:591595 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581596 LayerImpl* parent = AddChild<LayerImpl>(root);
1597 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1598 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1599 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1600 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1601 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1602
danakje4fa7b72016-07-25 22:00:061603 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581604 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061605 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581606 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061607 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581608 child1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181609 child1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061610 child1->test_properties()->force_render_surface = true;
1611 child2->SetBounds(gfx::Size(100, 100));
1612 child2->SetDrawsContent(true);
1613 grand_child->SetBounds(gfx::Size(100, 100));
1614 grand_child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181615 grand_child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061616 grand_child->test_properties()->force_render_surface = true;
1617 leaf_node1->SetBounds(gfx::Size(100, 100));
1618 leaf_node1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181619 leaf_node1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061620 leaf_node2->SetBounds(gfx::Size(100, 100));
1621 leaf_node2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181622 leaf_node2->test_properties()->opacity = 0.5f;
ajuma51d73f72015-10-19 19:43:581623
1624 // With surfaces enabled, each layer's draw opacity is the product of layer
1625 // opacities on the path from the layer to its render target, not including
1626 // the opacity of the layer that owns the target surface (since that opacity
1627 // is applied by the surface).
1628 ExecuteCalculateDrawProperties(root);
1629 EXPECT_EQ(1.f, root->draw_opacity());
1630 EXPECT_EQ(1.f, parent->draw_opacity());
1631 EXPECT_EQ(1.f, child1->draw_opacity());
1632 EXPECT_EQ(1.f, child2->draw_opacity());
1633 EXPECT_EQ(1.f, grand_child->draw_opacity());
1634 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1635 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1636
1637 // With surfaces disabled, each layer's draw opacity is the product of layer
1638 // opacities on the path from the layer to the root.
1639 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1640 EXPECT_EQ(1.f, root->draw_opacity());
1641 EXPECT_EQ(1.f, parent->draw_opacity());
1642 EXPECT_EQ(0.5f, child1->draw_opacity());
1643 EXPECT_EQ(1.f, child2->draw_opacity());
1644 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1645 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1646 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1647}
1648
[email protected]989386c2013-07-18 21:37:231649TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
danakje4fa7b72016-07-25 22:00:061650 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:261651 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1652 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261653
danakje4fa7b72016-07-25 22:00:061654 root->SetBounds(gfx::Size(10, 10));
1655 render_surface1->SetBounds(gfx::Size(10, 10));
jaydasika6b5a32bf2016-04-22 21:56:361656 render_surface1->test_properties()->force_render_surface = true;
danakje4fa7b72016-07-25 22:00:061657 child->SetBounds(gfx::Size(10, 10));
1658 child->SetDrawsContent(true);
weiliangceffae0462015-12-08 23:17:261659
[email protected]989386c2013-07-18 21:37:231660 {
jaydasika6ed869662016-09-21 14:29:591661 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:321662
[email protected]989386c2013-07-18 21:37:231663 // The root layer always creates a render surface
danakje4fa7b72016-07-25 22:00:061664 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091665 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231666 }
[email protected]fb661802013-03-25 01:59:321667
[email protected]989386c2013-07-18 21:37:231668 {
jaydasika6b5a32bf2016-04-22 21:56:361669 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261670 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:591671 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
danakje4fa7b72016-07-25 22:00:061672 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091673 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231674 }
[email protected]fb661802013-03-25 01:59:321675}
1676
ajuma246190a2015-03-11 20:56:031677TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1678 // Render surfaces act as a flattening point for their subtree, so should
1679 // always flatten the target-to-screen space transform seen by descendants.
jaydasikabf1875a2016-06-28 03:39:591680 LayerImpl* root = root_layer_for_testing();
enne1a79c5542015-08-18 19:43:571681 LayerImpl* parent = AddChild<LayerImpl>(root);
1682 LayerImpl* child = AddChild<LayerImpl>(parent);
1683 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1684
ajuma246190a2015-03-11 20:56:031685 gfx::Transform rotation_about_y_axis;
1686 rotation_about_y_axis.RotateAboutYAxis(30.0);
ajuma246190a2015-03-11 20:56:031687
danakje4fa7b72016-07-25 22:00:061688 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041689 parent->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061690 parent->SetBounds(gfx::Size(10, 10));
1691 parent->test_properties()->force_render_surface = true;
1692 child->SetBounds(gfx::Size(10, 10));
1693 child->SetDrawsContent(true);
1694 grand_child->SetBounds(gfx::Size(10, 10));
1695 grand_child->SetDrawsContent(true);
jaydasikaca2605e2016-04-23 02:52:521696 grand_child->test_properties()->should_flatten_transform = false;
enne1a79c5542015-08-18 19:43:571697 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031698
1699 EXPECT_TRUE(parent->render_surface());
1700 EXPECT_FALSE(child->render_surface());
1701 EXPECT_FALSE(grand_child->render_surface());
1702
danakje4fa7b72016-07-25 22:00:061703 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1704 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441705 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031706
1707 // The screen-space transform inherited by |child| and |grand_child| should
1708 // have been flattened at their render target. In particular, the fact that
1709 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
danakje4fa7b72016-07-25 22:00:061710 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1711 flattened_rotation_about_y.FlattenTo2d();
ajuma246190a2015-03-11 20:56:031712 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101713 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031714 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101715 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031716}
1717
[email protected]989386c2013-07-18 21:37:231718TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321719 // The entire subtree of layers that are outside the clip rect should be
1720 // culled away, and should not affect the render_surface_layer_list.
1721 //
1722 // The test tree is set up as follows:
1723 // - all layers except the leaf_nodes are forced to be a new render surface
1724 // that have something to draw.
1725 // - parent is a large container layer.
danakje4fa7b72016-07-25 22:00:061726 // - child has MasksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321727 // - grand_child is positioned outside of the child's bounds
1728 // - great_grand_child is also kept outside child's bounds.
1729 //
1730 // In this configuration, grand_child and great_grand_child are completely
1731 // outside the clip rect, and they should never get scheduled on the list of
1732 // render surfaces.
[email protected]fb661802013-03-25 01:59:321733
danakje4fa7b72016-07-25 22:00:061734 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571735 LayerImpl* child = AddChildToRoot<LayerImpl>();
1736 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1737 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281738
danakje4fa7b72016-07-25 22:00:061739 // leaf_node1 ensures that root and child are kept on the
[email protected]fb661802013-03-25 01:59:321740 // render_surface_layer_list, even though grand_child and great_grand_child
1741 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571742 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
weiliangcfb3d5eaa2015-07-28 23:54:571743 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
[email protected]fb661802013-03-25 01:59:321744
danakje4fa7b72016-07-25 22:00:061745 root->SetBounds(gfx::Size(500, 500));
1746 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321747 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061748 child->test_properties()->force_render_surface = true;
1749 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1750 grand_child->SetBounds(gfx::Size(10, 10));
1751 great_grand_child->SetBounds(gfx::Size(10, 10));
1752 leaf_node1->SetBounds(gfx::Size(500, 500));
1753 leaf_node1->SetDrawsContent(true);
1754 leaf_node1->SetBounds(gfx::Size(20, 20));
1755 leaf_node2->SetDrawsContent(true);
1756 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321757
weiliangcfb3d5eaa2015-07-28 23:54:571758 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061759 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
weiliangcfb3d5eaa2015-07-28 23:54:571760 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321761}
1762
[email protected]989386c2013-07-18 21:37:231763TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321764 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571765 // of the surface.
[email protected]fb661802013-03-25 01:59:321766
1767 // The test tree is set up as follows:
danakje4fa7b72016-07-25 22:00:061768 // - root is a container layer that masksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321769 // - child is a render surface, which has a clip rect set to the bounds of
danakje4fa7b72016-07-25 22:00:061770 // the root.
[email protected]fb661802013-03-25 01:59:321771 // - grand_child is a render surface, and the only visible content in child.
danakje4fa7b72016-07-25 22:00:061772 // It is positioned outside of the clip rect from root.
[email protected]fb661802013-03-25 01:59:321773
1774 // In this configuration, grand_child should be outside the clipped
1775 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571776 // render_surface_layer_list.
1777
danakje4fa7b72016-07-25 22:00:061778 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571779 LayerImpl* child = AddChildToRoot<LayerImpl>();
1780 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1781 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
[email protected]fb661802013-03-25 01:59:321782
danakje4fa7b72016-07-25 22:00:061783 root->SetMasksToBounds(true);
1784 root->SetBounds(gfx::Size(100, 100));
1785 child->SetBounds(gfx::Size(20, 20));
1786 child->test_properties()->force_render_surface = true;
1787 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1788 grand_child->SetBounds(gfx::Size(10, 10));
1789 grand_child->test_properties()->force_render_surface = true;
1790 leaf_node->SetBounds(gfx::Size(10, 10));
1791 leaf_node->SetDrawsContent(true);
1792 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321793
weiliangcfb3d5eaa2015-07-28 23:54:571794 // We should cull child and grand_child from the
1795 // render_surface_layer_list.
1796 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061797 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321798}
1799
ajumae2b7a5c2015-09-30 21:41:421800TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1801 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321802 // - the layer clips its subtree, e.g. masks to bounds,
1803 // - the layer is clipped by an ancestor that contributes to the same
1804 // render target,
1805 // - a surface is clipped by an ancestor that contributes to the same
1806 // render target.
1807 //
1808 // In particular, for a layer that owns a render surface:
1809 // - the render surface inherits any clip from ancestors, and does NOT
1810 // pass that clipped status to the layer itself.
1811 // - but if the layer itself masks to bounds, it is considered clipped
1812 // and propagates the clip to the subtree.
1813
jaydasikabf1875a2016-06-28 03:39:591814 LayerImpl* root = root_layer_for_testing();
enne76bf8982015-08-18 17:55:331815 LayerImpl* parent = AddChild<LayerImpl>(root);
1816 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1817 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1818 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1819 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
enne76bf8982015-08-18 17:55:331820 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
enne76bf8982015-08-18 17:55:331821
danakje4fa7b72016-07-25 22:00:061822 root->SetBounds(gfx::Size(100, 100));
1823 parent->SetBounds(gfx::Size(100, 100));
1824 parent->SetDrawsContent(true);
1825 child1->SetBounds(gfx::Size(100, 100));
1826 child1->SetDrawsContent(true);
1827 child2->SetBounds(gfx::Size(100, 100));
1828 child2->SetDrawsContent(true);
1829 child2->test_properties()->force_render_surface = true;
1830 grand_child->SetBounds(gfx::Size(100, 100));
1831 grand_child->SetDrawsContent(true);
1832 leaf_node1->SetBounds(gfx::Size(100, 100));
1833 leaf_node1->SetDrawsContent(true);
1834 leaf_node2->SetBounds(gfx::Size(100, 100));
1835 leaf_node2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331836
1837 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521838 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331839
weiliangce3f09a612016-03-16 17:02:521840 ASSERT_TRUE(root->render_surface());
1841 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331842
weiliangce3f09a612016-03-16 17:02:521843 EXPECT_FALSE(root->is_clipped());
1844 EXPECT_TRUE(root->render_surface()->is_clipped());
1845 EXPECT_FALSE(parent->is_clipped());
1846 EXPECT_FALSE(child1->is_clipped());
1847 EXPECT_FALSE(child2->is_clipped());
1848 EXPECT_FALSE(child2->render_surface()->is_clipped());
1849 EXPECT_FALSE(grand_child->is_clipped());
1850 EXPECT_FALSE(leaf_node1->is_clipped());
1851 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331852
danakje4fa7b72016-07-25 22:00:061853 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
enne76bf8982015-08-18 17:55:331854 // surface are clipped. But layers that contribute to child2's surface are
1855 // not clipped explicitly because child2's surface already accounts for
1856 // that clip.
weiliangce3f09a612016-03-16 17:02:521857 parent->SetMasksToBounds(true);
1858 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331859
weiliangce3f09a612016-03-16 17:02:521860 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331861
weiliangce3f09a612016-03-16 17:02:521862 ASSERT_TRUE(root->render_surface());
1863 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331864
weiliangce3f09a612016-03-16 17:02:521865 EXPECT_FALSE(root->is_clipped());
1866 EXPECT_TRUE(root->render_surface()->is_clipped());
1867 EXPECT_TRUE(parent->is_clipped());
1868 EXPECT_TRUE(child1->is_clipped());
1869 EXPECT_FALSE(child2->is_clipped());
1870 EXPECT_TRUE(child2->render_surface()->is_clipped());
1871 EXPECT_TRUE(grand_child->is_clipped());
1872 EXPECT_TRUE(leaf_node1->is_clipped());
1873 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331874
weiliangce3f09a612016-03-16 17:02:521875 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331876
danakje4fa7b72016-07-25 22:00:061877 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
enne76bf8982015-08-18 17:55:331878 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521879 child2->SetMasksToBounds(true);
1880 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331881
weiliangce3f09a612016-03-16 17:02:521882 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331883
weiliangce3f09a612016-03-16 17:02:521884 ASSERT_TRUE(root->render_surface());
1885 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331886
weiliangce3f09a612016-03-16 17:02:521887 EXPECT_FALSE(root->is_clipped());
1888 EXPECT_TRUE(root->render_surface()->is_clipped());
1889 EXPECT_FALSE(parent->is_clipped());
1890 EXPECT_FALSE(child1->is_clipped());
1891 EXPECT_TRUE(child2->is_clipped());
1892 EXPECT_FALSE(child2->render_surface()->is_clipped());
1893 EXPECT_FALSE(grand_child->is_clipped());
1894 EXPECT_FALSE(leaf_node1->is_clipped());
1895 EXPECT_TRUE(leaf_node2->is_clipped());
1896}
1897
1898TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1899 // Tests that when as long as layer is clipped, it's clip rect is set to
1900 // correct value.
jaydasikabf1875a2016-06-28 03:39:591901 LayerImpl* root = root_layer_for_testing();
weiliangce3f09a612016-03-16 17:02:521902 LayerImpl* parent = AddChild<LayerImpl>(root);
1903 LayerImpl* child = AddChild<LayerImpl>(parent);
1904
danakje4fa7b72016-07-25 22:00:061905 root->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521906 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061907 parent->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521908 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061909 child->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521910 child->SetDrawsContent(true);
weiliangce3f09a612016-03-16 17:02:521911 child->SetMasksToBounds(true);
1912
1913 ExecuteCalculateDrawProperties(root);
1914
1915 EXPECT_FALSE(root->is_clipped());
1916 EXPECT_FALSE(parent->is_clipped());
1917 EXPECT_TRUE(child->is_clipped());
1918 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1919
1920 parent->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061921 child->SetPosition(gfx::PointF(100.f, 100.f));
weiliangce3f09a612016-03-16 17:02:521922 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1923
1924 ExecuteCalculateDrawProperties(root);
1925
1926 EXPECT_FALSE(root->is_clipped());
1927 EXPECT_TRUE(parent->is_clipped());
1928 EXPECT_TRUE(child->is_clipped());
1929 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321930}
1931
ajuma51d73f72015-10-19 19:43:581932TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1933 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1934 // when a layer or its ancestor has a clip; in particular, if a layer
1935 // is_clipped, so is its entire subtree (since there are no render surfaces
1936 // that can reset is_clipped).
jaydasikabf1875a2016-06-28 03:39:591937 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581938 LayerImpl* parent = AddChild<LayerImpl>(root);
1939 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1940 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1941 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1942 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1943 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1944
danakje4fa7b72016-07-25 22:00:061945 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581946 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061947 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581948 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061949 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581950 child1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061951 child1->test_properties()->force_render_surface = true;
1952 child2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581953 child2->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061954 grand_child->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581955 grand_child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061956 grand_child->test_properties()->force_render_surface = true;
1957 leaf_node1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581958 leaf_node1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061959 leaf_node2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581960 leaf_node2->SetDrawsContent(true);
1961
ajuma51d73f72015-10-19 19:43:581962 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1963 // or without surfaces.
1964 ExecuteCalculateDrawProperties(root);
1965 EXPECT_FALSE(root->is_clipped());
1966 EXPECT_FALSE(parent->is_clipped());
1967 EXPECT_FALSE(child1->is_clipped());
1968 EXPECT_FALSE(child2->is_clipped());
1969 EXPECT_FALSE(grand_child->is_clipped());
1970 EXPECT_FALSE(leaf_node1->is_clipped());
1971 EXPECT_FALSE(leaf_node2->is_clipped());
1972
1973 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1974 EXPECT_FALSE(root->is_clipped());
1975 EXPECT_FALSE(parent->is_clipped());
1976 EXPECT_FALSE(child1->is_clipped());
1977 EXPECT_FALSE(child2->is_clipped());
1978 EXPECT_FALSE(grand_child->is_clipped());
1979 EXPECT_FALSE(leaf_node1->is_clipped());
1980 EXPECT_FALSE(leaf_node2->is_clipped());
1981
1982 // Case 2: The root is clipped. With surfaces, this only persists until the
1983 // next render surface. Without surfaces, the entire tree is clipped.
1984 root->SetMasksToBounds(true);
1985 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1986 ExecuteCalculateDrawProperties(root);
1987 EXPECT_TRUE(root->is_clipped());
1988 EXPECT_TRUE(parent->is_clipped());
1989 EXPECT_FALSE(child1->is_clipped());
1990 EXPECT_TRUE(child2->is_clipped());
1991 EXPECT_FALSE(grand_child->is_clipped());
1992 EXPECT_FALSE(leaf_node1->is_clipped());
1993 EXPECT_TRUE(leaf_node2->is_clipped());
1994
1995 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1996 EXPECT_TRUE(root->is_clipped());
1997 EXPECT_TRUE(parent->is_clipped());
1998 EXPECT_TRUE(child1->is_clipped());
1999 EXPECT_TRUE(child2->is_clipped());
2000 EXPECT_TRUE(grand_child->is_clipped());
2001 EXPECT_TRUE(leaf_node1->is_clipped());
2002 EXPECT_TRUE(leaf_node2->is_clipped());
2003
2004 root->SetMasksToBounds(false);
2005
2006 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2007 // until the next render surface. Without surfaces, parent's entire subtree is
2008 // clipped.
2009 parent->SetMasksToBounds(true);
2010 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2011 ExecuteCalculateDrawProperties(root);
2012 EXPECT_FALSE(root->is_clipped());
2013 EXPECT_TRUE(parent->is_clipped());
2014 EXPECT_FALSE(child1->is_clipped());
2015 EXPECT_TRUE(child2->is_clipped());
2016 EXPECT_FALSE(grand_child->is_clipped());
2017 EXPECT_FALSE(leaf_node1->is_clipped());
2018 EXPECT_TRUE(leaf_node2->is_clipped());
2019
2020 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2021 EXPECT_FALSE(root->is_clipped());
2022 EXPECT_TRUE(parent->is_clipped());
2023 EXPECT_TRUE(child1->is_clipped());
2024 EXPECT_TRUE(child2->is_clipped());
2025 EXPECT_TRUE(grand_child->is_clipped());
2026 EXPECT_TRUE(leaf_node1->is_clipped());
2027 EXPECT_TRUE(leaf_node2->is_clipped());
2028
2029 parent->SetMasksToBounds(false);
2030
2031 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2032 // has no non-surface children. Without surfaces, child1's entire subtree is
2033 // clipped.
2034 child1->SetMasksToBounds(true);
2035 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2036 ExecuteCalculateDrawProperties(root);
2037 EXPECT_FALSE(root->is_clipped());
2038 EXPECT_FALSE(parent->is_clipped());
2039 EXPECT_TRUE(child1->is_clipped());
2040 EXPECT_FALSE(child2->is_clipped());
2041 EXPECT_FALSE(grand_child->is_clipped());
2042 EXPECT_FALSE(leaf_node1->is_clipped());
2043 EXPECT_FALSE(leaf_node2->is_clipped());
2044
2045 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2046 EXPECT_FALSE(root->is_clipped());
2047 EXPECT_FALSE(parent->is_clipped());
2048 EXPECT_TRUE(child1->is_clipped());
2049 EXPECT_FALSE(child2->is_clipped());
2050 EXPECT_TRUE(grand_child->is_clipped());
2051 EXPECT_TRUE(leaf_node1->is_clipped());
2052 EXPECT_FALSE(leaf_node2->is_clipped());
2053
2054 child1->SetMasksToBounds(false);
2055
2056 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2057 // surfaces is the same.
2058 leaf_node1->SetMasksToBounds(true);
2059 leaf_node2->SetMasksToBounds(true);
2060 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2061 ExecuteCalculateDrawProperties(root);
2062 EXPECT_FALSE(root->is_clipped());
2063 EXPECT_FALSE(parent->is_clipped());
2064 EXPECT_FALSE(child1->is_clipped());
2065 EXPECT_FALSE(child2->is_clipped());
2066 EXPECT_FALSE(grand_child->is_clipped());
2067 EXPECT_TRUE(leaf_node1->is_clipped());
2068 EXPECT_TRUE(leaf_node2->is_clipped());
2069
2070 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2071 EXPECT_FALSE(root->is_clipped());
2072 EXPECT_FALSE(parent->is_clipped());
2073 EXPECT_FALSE(child1->is_clipped());
2074 EXPECT_FALSE(child2->is_clipped());
2075 EXPECT_FALSE(grand_child->is_clipped());
2076 EXPECT_TRUE(leaf_node1->is_clipped());
2077 EXPECT_TRUE(leaf_node2->is_clipped());
2078}
2079
[email protected]fd9a3b6d2013-08-03 00:46:172080TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322081 // Verify that layers get the appropriate DrawableContentRect when their
danakje4fa7b72016-07-25 22:00:062082 // parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322083 //
2084 // grand_child1 - completely inside the region; DrawableContentRect should
2085 // be the layer rect expressed in target space.
danakje4fa7b72016-07-25 22:00:062086 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
[email protected]fb661802013-03-25 01:59:322087 // will be the intersection of layer bounds and the mask region.
danakje4fa7b72016-07-25 22:00:062088 // grand_child3 - partially clipped and MasksToBounds; the
[email protected]fb661802013-03-25 01:59:322089 // DrawableContentRect will still be the intersection of layer bounds and
2090 // the mask region.
2091 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2092 // be empty.
[email protected]fb661802013-03-25 01:59:322093
jaydasikabf1875a2016-06-28 03:39:592094 LayerImpl* parent = root_layer_for_testing();
enne07405c772015-08-18 17:56:452095 LayerImpl* child = AddChild<LayerImpl>(parent);
2096 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2097 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2098 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2099 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322100
danakje4fa7b72016-07-25 22:00:062101 parent->SetBounds(gfx::Size(500, 500));
[email protected]fb661802013-03-25 01:59:322102 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062103 child->SetBounds(gfx::Size(20, 20));
2104 child->test_properties()->force_render_surface = true;
2105 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2106 grand_child1->SetBounds(gfx::Size(10, 10));
2107 grand_child1->SetDrawsContent(true);
2108 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2109 grand_child2->SetBounds(gfx::Size(10, 10));
2110 grand_child2->SetDrawsContent(true);
2111 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
[email protected]fb661802013-03-25 01:59:322112 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062113 grand_child3->SetBounds(gfx::Size(10, 10));
2114 grand_child3->SetDrawsContent(true);
2115 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2116 grand_child4->SetBounds(gfx::Size(10, 10));
2117 grand_child4->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452118 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322119
hush6b614212014-12-04 22:37:322120 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2121 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2122 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322123 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2124}
2125
[email protected]989386c2013-07-18 21:37:232126TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322127 // Verify that render surfaces (and their layers) get the appropriate
danakje4fa7b72016-07-25 22:00:062128 // clip rects when their parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322129 //
2130 // Layers that own render surfaces (at least for now) do not inherit any
2131 // clipping; instead the surface will enforce the clip for the entire subtree.
2132 // They may still have a clip rect of their own layer bounds, however, if
danakje4fa7b72016-07-25 22:00:062133 // MasksToBounds was true.
jaydasikabf1875a2016-06-28 03:39:592134 LayerImpl* parent = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:572135 LayerImpl* child = AddChildToRoot<LayerImpl>();
2136 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2137 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2138 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2139 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:062140 // The leaf nodes ensure that these grand_children become render surfaces for
[email protected]fb661802013-03-25 01:59:322141 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572142 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
weiliangcfb3d5eaa2015-07-28 23:54:572143 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
weiliangcfb3d5eaa2015-07-28 23:54:572144 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
weiliangcfb3d5eaa2015-07-28 23:54:572145 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
[email protected]fb661802013-03-25 01:59:322146
danakje4fa7b72016-07-25 22:00:062147 parent->SetBounds(gfx::Size(500, 500));
2148 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:322149 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062150 child->test_properties()->force_render_surface = true;
2151 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2152 grand_child1->SetBounds(gfx::Size(10, 10));
2153 grand_child1->test_properties()->force_render_surface = true;
2154 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2155 grand_child2->SetBounds(gfx::Size(10, 10));
2156 grand_child2->test_properties()->force_render_surface = true;
2157 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
2158 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322159 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062160 grand_child3->test_properties()->force_render_surface = true;
2161 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2162 grand_child4->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322163 grand_child4->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062164 grand_child4->test_properties()->force_render_surface = true;
2165 leaf_node1->SetBounds(gfx::Size(10, 10));
2166 leaf_node1->SetDrawsContent(true);
2167 leaf_node2->SetBounds(gfx::Size(10, 10));
2168 leaf_node2->SetDrawsContent(true);
2169 leaf_node3->SetBounds(gfx::Size(10, 10));
2170 leaf_node3->SetDrawsContent(true);
2171 leaf_node4->SetBounds(gfx::Size(10, 10));
2172 leaf_node4->SetDrawsContent(true);
weiliangcfb3d5eaa2015-07-28 23:54:572173 ExecuteCalculateDrawProperties(parent);
2174
[email protected]fb661802013-03-25 01:59:322175 ASSERT_TRUE(grand_child1->render_surface());
2176 ASSERT_TRUE(grand_child2->render_surface());
2177 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322178
2179 // Surfaces are clipped by their parent, but un-affected by the owning layer's
danakje4fa7b72016-07-25 22:00:062180 // MasksToBounds.
hush6b614212014-12-04 22:37:322181 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2182 grand_child1->render_surface()->clip_rect());
2183 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2184 grand_child2->render_surface()->clip_rect());
2185 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2186 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322187}
2188
ajuma51d73f72015-10-19 19:43:582189TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2190 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2191 // intersection of all ancestor clips in screen space; in particular, if a
2192 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2193 // subtree (since there are no render surfaces that can reset the clip_rect).
jaydasikabf1875a2016-06-28 03:39:592194 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582195 LayerImpl* parent = AddChild<LayerImpl>(root);
2196 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2197 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2198 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2199 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2200 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2201
danakje4fa7b72016-07-25 22:00:062202 root->SetBounds(gfx::Size(100, 100));
2203 parent->SetPosition(gfx::PointF(2.f, 2.f));
2204 parent->SetBounds(gfx::Size(400, 400));
2205 child1->SetPosition(gfx::PointF(4.f, 4.f));
2206 child1->SetBounds(gfx::Size(800, 800));
2207 child2->SetPosition(gfx::PointF(3.f, 3.f));
2208 child2->SetBounds(gfx::Size(800, 800));
2209 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2210 grand_child->SetBounds(gfx::Size(1500, 1500));
2211 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
2212 leaf_node1->SetBounds(gfx::Size(2000, 2000));
2213 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
2214 leaf_node2->SetBounds(gfx::Size(2000, 2000));
2215
ajuma51d73f72015-10-19 19:43:582216 root->SetDrawsContent(true);
2217 parent->SetDrawsContent(true);
2218 child1->SetDrawsContent(true);
2219 child2->SetDrawsContent(true);
2220 grand_child->SetDrawsContent(true);
2221 leaf_node1->SetDrawsContent(true);
2222 leaf_node2->SetDrawsContent(true);
2223
danakje4fa7b72016-07-25 22:00:062224 root->test_properties()->force_render_surface = true;
2225 child1->test_properties()->force_render_surface = true;
2226 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582227
2228 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2229 // bounds in target space. The only thing that changes when surfaces are
2230 // disabled is that target space is always screen space.
2231 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262232 EXPECT_TRUE(root->has_render_surface());
2233 EXPECT_FALSE(parent->has_render_surface());
2234 EXPECT_TRUE(child1->has_render_surface());
2235 EXPECT_FALSE(child2->has_render_surface());
2236 EXPECT_TRUE(grand_child->has_render_surface());
2237 EXPECT_FALSE(leaf_node1->has_render_surface());
2238 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422239 EXPECT_FALSE(root->is_clipped());
2240 EXPECT_FALSE(parent->is_clipped());
2241 EXPECT_FALSE(child1->is_clipped());
2242 EXPECT_FALSE(child2->is_clipped());
2243 EXPECT_FALSE(grand_child->is_clipped());
2244 EXPECT_FALSE(leaf_node1->is_clipped());
2245 EXPECT_FALSE(leaf_node2->is_clipped());
2246 EXPECT_TRUE(root->render_surface()->is_clipped());
2247 EXPECT_FALSE(child1->render_surface()->is_clipped());
2248 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2249 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582250
2251 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422252 EXPECT_FALSE(root->is_clipped());
2253 EXPECT_FALSE(parent->is_clipped());
2254 EXPECT_FALSE(child1->is_clipped());
2255 EXPECT_FALSE(child2->is_clipped());
2256 EXPECT_FALSE(grand_child->is_clipped());
2257 EXPECT_FALSE(leaf_node1->is_clipped());
2258 EXPECT_FALSE(leaf_node2->is_clipped());
2259 EXPECT_TRUE(root->render_surface()->is_clipped());
2260 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582261
2262 // Case 2: The root is clipped. In this case, layers that draw into the root
2263 // render surface are clipped by the root's bounds.
2264 root->SetMasksToBounds(true);
2265 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362266 root->test_properties()->force_render_surface = true;
2267 child1->test_properties()->force_render_surface = true;
2268 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582269 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262270 EXPECT_TRUE(root->has_render_surface());
2271 EXPECT_FALSE(parent->has_render_surface());
2272 EXPECT_TRUE(child1->has_render_surface());
2273 EXPECT_FALSE(child2->has_render_surface());
2274 EXPECT_TRUE(grand_child->has_render_surface());
2275 EXPECT_FALSE(leaf_node1->has_render_surface());
2276 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422277 EXPECT_TRUE(root->is_clipped());
2278 EXPECT_TRUE(parent->is_clipped());
2279 EXPECT_FALSE(child1->is_clipped());
2280 EXPECT_TRUE(child1->render_surface()->is_clipped());
2281 EXPECT_TRUE(child2->is_clipped());
2282 EXPECT_FALSE(grand_child->is_clipped());
2283 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2284 EXPECT_FALSE(leaf_node1->is_clipped());
2285 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582286 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2287 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422288 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582289 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582290 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2291
2292 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422293 EXPECT_TRUE(root->is_clipped());
2294 EXPECT_TRUE(parent->is_clipped());
2295 EXPECT_TRUE(child1->is_clipped());
2296 EXPECT_TRUE(child2->is_clipped());
2297 EXPECT_TRUE(grand_child->is_clipped());
2298 EXPECT_TRUE(leaf_node1->is_clipped());
2299 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582300 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2301 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2302 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2303 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2304 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2305 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2306 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2307
2308 root->SetMasksToBounds(false);
2309
2310 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2311 // parent clip rect only contributes to the subtree rooted at child2, since
2312 // the subtree rooted at child1 renders into a separate surface. Similarly,
2313 // child1's clip rect doesn't contribute to its descendants, since its only
2314 // child is a render surface. However, without surfaces, these clip rects
2315 // contribute to all descendants.
2316 parent->SetMasksToBounds(true);
2317 child1->SetMasksToBounds(true);
2318 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362319 root->test_properties()->force_render_surface = true;
2320 child1->test_properties()->force_render_surface = true;
2321 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582322 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262323 EXPECT_TRUE(root->has_render_surface());
2324 EXPECT_FALSE(parent->has_render_surface());
2325 EXPECT_TRUE(child1->has_render_surface());
2326 EXPECT_FALSE(child2->has_render_surface());
2327 EXPECT_TRUE(grand_child->has_render_surface());
2328 EXPECT_FALSE(leaf_node1->has_render_surface());
2329 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422330 EXPECT_FALSE(root->is_clipped());
2331 EXPECT_TRUE(root->render_surface()->is_clipped());
2332 EXPECT_TRUE(parent->is_clipped());
2333 EXPECT_TRUE(child1->is_clipped());
2334 EXPECT_TRUE(child2->is_clipped());
2335 EXPECT_FALSE(grand_child->is_clipped());
2336 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2337 EXPECT_FALSE(leaf_node1->is_clipped());
2338 EXPECT_TRUE(leaf_node2->is_clipped());
2339 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582340 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2341 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2342 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422343 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582344 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2345
2346 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422347 EXPECT_FALSE(root->is_clipped());
2348 EXPECT_TRUE(root->render_surface()->is_clipped());
2349 EXPECT_TRUE(parent->is_clipped());
2350 EXPECT_TRUE(child1->is_clipped());
2351 EXPECT_TRUE(child2->is_clipped());
2352 EXPECT_TRUE(grand_child->is_clipped());
2353 EXPECT_TRUE(leaf_node1->is_clipped());
2354 EXPECT_TRUE(leaf_node2->is_clipped());
2355 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582356 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2357 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2358 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2359 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2360 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2361 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2362}
2363
jaydasika8d0064f2016-06-02 23:34:542364TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
jaydasikabf1875a2016-06-28 03:39:592365 LayerImpl* root = root_layer_for_testing();
jaydasika8d0064f2016-06-02 23:34:542366 LayerImpl* parent = AddChild<LayerImpl>(root);
2367 LayerImpl* child = AddChild<LayerImpl>(parent);
2368 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2369 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2370
danakje4fa7b72016-07-25 22:00:062371 root->SetBounds(gfx::Size(100, 100));
2372 parent->SetPosition(gfx::PointF(2.f, 2.f));
2373 parent->SetBounds(gfx::Size(400, 400));
2374 parent->SetMasksToBounds(true);
2375 child->SetPosition(gfx::PointF(4.f, 4.f));
2376 child->SetBounds(gfx::Size(800, 800));
2377 child->SetMasksToBounds(true);
2378 child->test_properties()->force_render_surface = true;
2379 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2380 grand_child->SetBounds(gfx::Size(1500, 1500));
2381 grand_child->test_properties()->force_render_surface = true;
2382 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2383 leaf_node->SetBounds(gfx::Size(2000, 2000));
2384
jaydasika8d0064f2016-06-02 23:34:542385 root->SetDrawsContent(true);
2386 parent->SetDrawsContent(true);
2387 child->SetDrawsContent(true);
2388 grand_child->SetDrawsContent(true);
2389 leaf_node->SetDrawsContent(true);
2390
jaydasika8d0064f2016-06-02 23:34:542391 host_impl()->set_resourceless_software_draw_for_testing();
2392 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2393 gfx::PointF test_point(90.f, 90.f);
2394 LayerImpl* result_layer =
2395 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2396 ASSERT_TRUE(result_layer);
2397 EXPECT_EQ(leaf_node, result_layer);
2398}
2399
ajuma51d73f72015-10-19 19:43:582400TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2401 // Tests that draw properties are computed correctly when we disable and then
2402 // re-enable separate surfaces.
jaydasikabf1875a2016-06-28 03:39:592403 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582404 LayerImpl* parent = AddChild<LayerImpl>(root);
2405 LayerImpl* child = AddChild<LayerImpl>(parent);
2406 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2407 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2408
danakje4fa7b72016-07-25 22:00:062409 root->SetBounds(gfx::Size(100, 100));
2410 parent->SetPosition(gfx::PointF(2.f, 2.f));
2411 parent->SetBounds(gfx::Size(400, 400));
2412 parent->SetMasksToBounds(true);
2413 child->SetPosition(gfx::PointF(4.f, 4.f));
2414 child->SetBounds(gfx::Size(800, 800));
2415 child->SetMasksToBounds(true);
2416 child->test_properties()->force_render_surface = true;
2417 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2418 grand_child->SetBounds(gfx::Size(1500, 1500));
2419 grand_child->test_properties()->force_render_surface = true;
2420 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2421 leaf_node->SetBounds(gfx::Size(2000, 2000));
2422
ajuma51d73f72015-10-19 19:43:582423 root->SetDrawsContent(true);
2424 parent->SetDrawsContent(true);
2425 child->SetDrawsContent(true);
2426 grand_child->SetDrawsContent(true);
2427 leaf_node->SetDrawsContent(true);
2428
ajuma51d73f72015-10-19 19:43:582429 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2430 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2431
2432 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2433 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2434
2435 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422436 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252437 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582438 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022439 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2440 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582441
2442 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422443 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582444 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2445 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022446 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces,
2447 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582448
2449 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422450 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252451 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582452 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022453 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2454 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582455}
2456
[email protected]989386c2013-07-18 21:37:232457TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
danakje4fa7b72016-07-25 22:00:062458 LayerImpl* root = root_layer_for_testing();
enneab0fee42015-07-07 17:36:422459 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2460 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2461 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2462 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2463 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2464 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2465 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2466 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322467
danakje4fa7b72016-07-25 22:00:062468 root->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362469 render_surface1->SetDrawsContent(true);
2470 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422471 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362472 render_surface2->SetDrawsContent(true);
2473 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422474 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362475 child_of_root->SetDrawsContent(true);
2476 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322477
2478 gfx::Transform layer_transform;
2479 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322480
jaydasika10d43fc2016-08-18 04:06:042481 root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062482 root->SetPosition(gfx::PointF(2.5f, 0.f));
2483 root->SetBounds(gfx::Size(10, 10));
2484 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042485 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062486 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2487 render_surface1->SetBounds(gfx::Size(10, 10));
2488 render_surface1->test_properties()->transform_origin =
2489 gfx::Point3F(0.25f, 0.f, 0.f);
2490 render_surface1->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042491 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062492 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2493 render_surface2->SetBounds(gfx::Size(10, 10));
2494 render_surface2->test_properties()->transform_origin =
2495 gfx::Point3F(0.25f, 0.f, 0.f);
2496 render_surface2->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042497 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062498 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2499 child_of_root->SetBounds(gfx::Size(10, 10));
2500 child_of_root->test_properties()->transform_origin =
2501 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042502 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062503 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2504 child_of_rs1->SetBounds(gfx::Size(10, 10));
2505 child_of_rs1->test_properties()->transform_origin =
2506 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042507 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062508 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2509 child_of_rs2->SetBounds(gfx::Size(10, 10));
2510 child_of_rs2->test_properties()->transform_origin =
2511 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042512 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062513 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2514 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2515 grand_child_of_root->test_properties()->transform_origin =
2516 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042517 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062518 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2519 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2520 grand_child_of_rs1->test_properties()->transform_origin =
2521 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042522 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062523 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2524 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2525 grand_child_of_rs2->test_properties()->transform_origin =
2526 gfx::Point3F(0.25f, 0.f, 0.f);
[email protected]fb661802013-03-25 01:59:322527
danakje4fa7b72016-07-25 22:00:062528 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:272529 SetElementIdsForTesting();
jaydasika9cb21c772016-05-10 22:37:082530
loyso9556c732016-03-11 07:54:582531 // Put an animated opacity on the render surface.
vollickef2ae922016-06-29 17:54:272532 AddOpacityTransitionToElementWithPlayer(
2533 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322534
loyso9556c732016-03-11 07:54:582535 // Also put an animated opacity on a layer without descendants.
vollickef2ae922016-06-29 17:54:272536 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2537 timeline_impl(), 10.0, 1.f, 0.f,
2538 false);
[email protected]fb661802013-03-25 01:59:322539
loyso9556c732016-03-11 07:54:582540 // Put a transform animation on the render surface.
vollickef2ae922016-06-29 17:54:272541 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2542 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322543
loyso9556c732016-03-11 07:54:582544 // Also put transform animations on grand_child_of_root, and
2545 // grand_child_of_rs2
vollickef2ae922016-06-29 17:54:272546 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2547 timeline_impl(), 10.0, 30, 0);
2548 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2549 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322550
danakje4fa7b72016-07-25 22:00:062551 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2552 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322553
2554 // Only layers that are associated with render surfaces should have an actual
2555 // RenderSurface() value.
danakje4fa7b72016-07-25 22:00:062556 ASSERT_TRUE(root->render_surface());
[email protected]fb661802013-03-25 01:59:322557 ASSERT_FALSE(child_of_root->render_surface());
2558 ASSERT_FALSE(grand_child_of_root->render_surface());
2559
2560 ASSERT_TRUE(render_surface1->render_surface());
2561 ASSERT_FALSE(child_of_rs1->render_surface());
2562 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2563
2564 ASSERT_TRUE(render_surface2->render_surface());
2565 ASSERT_FALSE(child_of_rs2->render_surface());
2566 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2567
2568 // Verify all render target accessors
danakje4fa7b72016-07-25 22:00:062569 EXPECT_EQ(root->render_surface(), root->render_target());
2570 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
2571 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322572
weiliangc189c1a12016-04-11 16:16:252573 EXPECT_EQ(render_surface1->render_surface(),
2574 render_surface1->render_target());
2575 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2576 EXPECT_EQ(render_surface1->render_surface(),
2577 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322578
weiliangc189c1a12016-04-11 16:16:252579 EXPECT_EQ(render_surface2->render_surface(),
2580 render_surface2->render_target());
2581 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2582 EXPECT_EQ(render_surface2->render_surface(),
2583 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322584
[email protected]fb661802013-03-25 01:59:322585 // Verify screen_space_transform_is_animating values
danakje4fa7b72016-07-25 22:00:062586 EXPECT_FALSE(root->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322587 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2588 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2589 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322590 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2591 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2592 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322593 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2594 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2595
2596 // Sanity check. If these fail there is probably a bug in the test itself.
2597 // It is expected that we correctly set up transforms so that the y-component
2598 // of the screen-space transform encodes the "depth" of the layer in the tree.
danakje4fa7b72016-07-25 22:00:062599 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262600 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102601 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322602 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102603 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322604
[email protected]803f6b52013-09-12 00:51:262605 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102606 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2607 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322608 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102609 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322610
[email protected]803f6b52013-09-12 00:51:262611 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102612 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2613 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322614 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102615 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322616}
2617
ajuma9384b9c22015-09-17 20:35:032618TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
danakje4fa7b72016-07-25 22:00:062619 LayerImpl* root = root_layer_for_testing();
ajuma9384b9c22015-09-17 20:35:032620 LayerImpl* child = AddChildToRoot<LayerImpl>();
2621 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2622
ajuma9384b9c22015-09-17 20:35:032623 gfx::Transform large_transform;
2624 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2625
danakje4fa7b72016-07-25 22:00:062626 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042627 child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062628 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042629 grand_child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062630 grand_child->SetBounds(gfx::Size(10, 10));
2631 grand_child->SetDrawsContent(true);
2632 ExecuteCalculateDrawProperties(root);
ajuma9384b9c22015-09-17 20:35:032633
2634 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2635}
2636
ajuma315a4782015-07-24 21:16:342637TEST_F(LayerTreeHostCommonTest,
2638 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
danakje4fa7b72016-07-25 22:00:062639 LayerImpl* root = root_layer_for_testing();
2640 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma315a4782015-07-24 21:16:342641 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2642 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2643
danakje4fa7b72016-07-25 22:00:062644 root->SetDrawsContent(true);
ajuma315a4782015-07-24 21:16:342645 child->SetDrawsContent(true);
2646 grand_child->SetDrawsContent(true);
2647 great_grand_child->SetDrawsContent(true);
2648
danakje4fa7b72016-07-25 22:00:062649 root->SetBounds(gfx::Size(10, 10));
2650 child->SetBounds(gfx::Size(10, 10));
2651 grand_child->SetBounds(gfx::Size(10, 10));
2652 great_grand_child->SetBounds(gfx::Size(10, 10));
ajuma315a4782015-07-24 21:16:342653
vollickef2ae922016-06-29 17:54:272654 SetElementIdsForTesting();
2655
ajuma315a4782015-07-24 21:16:342656 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482657 std::unique_ptr<Animation> animation = Animation::Create(
2658 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302659 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552660 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342661 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:272662 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2663 std::move(animation));
danakje4fa7b72016-07-25 22:00:062664 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:342665
danakje4fa7b72016-07-25 22:00:062666 EXPECT_FALSE(root->screen_space_transform_is_animating());
ajuma315a4782015-07-24 21:16:342667 EXPECT_FALSE(child->screen_space_transform_is_animating());
2668
2669 EXPECT_FALSE(grand_child->TransformIsAnimating());
2670 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2671 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2672 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2673}
2674
weiliangc6da32862016-04-20 16:40:112675TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2676 // Test visible layer rect and drawable content rect are calculated correctly
2677 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322678
[email protected]2c7c6702013-03-26 03:14:052679 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322680 gfx::Transform layer_to_surface_transform;
2681
2682 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232683 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112684 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2685 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2686 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2687 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2688 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2689 EXPECT_EQ(expected_drawable_content_rect,
2690 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322691
2692 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052693 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112694 expected_visible_layer_rect = gfx::Rect();
2695 expected_drawable_content_rect = gfx::Rect();
2696 drawing_layer = TestVisibleRectAndDrawableContentRect(
2697 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2698 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2699 EXPECT_EQ(expected_drawable_content_rect,
2700 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322701
2702 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052703 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112704 expected_visible_layer_rect = gfx::Rect(20, 20);
2705 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2706 drawing_layer = TestVisibleRectAndDrawableContentRect(
2707 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2708 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2709 EXPECT_EQ(expected_drawable_content_rect,
2710 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322711}
2712
weiliangc6da32862016-04-20 16:40:112713TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2714 // Test visible layer rect and drawable content rect are calculated correctly
2715 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322716
[email protected]2c7c6702013-03-26 03:14:052717 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2718 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322719 gfx::Transform layer_to_surface_transform;
2720
2721 // Case 1: Layer is contained within the surface.
2722 layer_to_surface_transform.MakeIdentity();
2723 layer_to_surface_transform.Translate(50.0, 50.0);
2724 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112725 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2726 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2727 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2728 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2729 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2730 EXPECT_EQ(expected_drawable_content_rect,
2731 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322732
2733 // Case 2: Layer is outside the surface rect.
2734 layer_to_surface_transform.MakeIdentity();
2735 layer_to_surface_transform.Translate(-50.0, 0.0);
2736 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112737 expected_visible_layer_rect = gfx::Rect();
2738 expected_drawable_content_rect = gfx::Rect();
2739 drawing_layer = TestVisibleRectAndDrawableContentRect(
2740 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2741 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2742 EXPECT_EQ(expected_drawable_content_rect,
2743 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322744
2745 // Case 3: The layer is rotated about its top-left corner. In surface space,
2746 // the layer is oriented diagonally, with the left half outside of the render
2747 // surface. In this case, the g should still be the entire layer
2748 // (remember the g is computed in layer space); both the top-left
2749 // and bottom-right corners of the layer are still visible.
2750 layer_to_surface_transform.MakeIdentity();
2751 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112752 expected_visible_layer_rect = gfx::Rect(30, 30);
2753 expected_drawable_content_rect = gfx::Rect(22, 43);
2754 drawing_layer = TestVisibleRectAndDrawableContentRect(
2755 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2756 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2757 EXPECT_EQ(expected_drawable_content_rect,
2758 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322759
2760 // Case 4: The layer is rotated about its top-left corner, and translated
2761 // upwards. In surface space, the layer is oriented diagonally, with only the
2762 // top corner of the surface overlapping the layer. In layer space, the render
2763 // surface overlaps the right side of the layer. The g should be
2764 // the layer's right half.
2765 layer_to_surface_transform.MakeIdentity();
2766 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2767 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112768 // Right half of layer bounds.
2769 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2770 expected_drawable_content_rect = gfx::Rect(22, 22);
2771 drawing_layer = TestVisibleRectAndDrawableContentRect(
2772 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2773 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2774 EXPECT_EQ(expected_drawable_content_rect,
2775 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322776}
2777
weiliangc6da32862016-04-20 16:40:112778TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2779 // Test visible layer rect and drawable content rect are calculated correctly
2780 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322781
[email protected]2c7c6702013-03-26 03:14:052782 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2783 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322784 gfx::Transform layer_to_surface_transform;
2785
2786 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2787 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112788 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322789 layer_to_surface_transform.MakeIdentity();
2790 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112791 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2792 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2793 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2794 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2795 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2796 EXPECT_EQ(expected_drawable_content_rect,
2797 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322798
2799 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2800 // degrees, but shifted to the side so only the right-half the layer would be
2801 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112802 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262803 SkMScalar half_width_of_rotated_layer =
2804 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322805 layer_to_surface_transform.MakeIdentity();
2806 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232807 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2808 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112809 // Tight half of the layer.
2810 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2811 expected_drawable_content_rect = gfx::Rect(36, 100);
2812 drawing_layer = TestVisibleRectAndDrawableContentRect(
2813 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2814 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2815 EXPECT_EQ(expected_drawable_content_rect,
2816 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322817}
2818
weiliangc6da32862016-04-20 16:40:112819TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2820 // Test visible layer rect and drawable content rect are calculated correctly
2821 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322822
[email protected]2c7c6702013-03-26 03:14:052823 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2824 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322825 gfx::Transform layer_to_surface_transform;
2826
2827 // Case 1: Even though the layer is twice as large as the surface, due to
2828 // perspective foreshortening, the layer will fit fully in the surface when
2829 // its translated more than the perspective amount.
2830 layer_to_surface_transform.MakeIdentity();
2831
2832 // The following sequence of transforms applies the perspective about the
2833 // center of the surface.
2834 layer_to_surface_transform.Translate(50.0, 50.0);
2835 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2836 layer_to_surface_transform.Translate(-50.0, -50.0);
2837
2838 // This translate places the layer in front of the surface's projection plane.
2839 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2840
weiliangc6da32862016-04-20 16:40:112841 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2842 // offset by layer position.
2843 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2844 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2845 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2846 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2847 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2848 EXPECT_EQ(expected_drawable_content_rect,
2849 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322850
2851 // Case 2: same projection as before, except that the layer is also translated
2852 // to the side, so that only the right half of the layer should be visible.
2853 //
2854 // Explanation of expected result: The perspective ratio is (z distance
2855 // between layer and camera origin) / (z distance between projection plane and
2856 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112857 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322858 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112859 // -25 == -100 in the layer's units.
2860 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2861 // Visible layer rect is moved by 100, and drawable content rect is in target
2862 // space and is moved by 25.
2863 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2864 expected_drawable_content_rect = gfx::Rect(13, 38);
2865 drawing_layer = TestVisibleRectAndDrawableContentRect(
2866 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2867 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2868 EXPECT_EQ(expected_drawable_content_rect,
2869 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322870}
2871
weiliangc6da32862016-04-20 16:40:112872TEST_F(LayerTreeHostCommonDrawRectsTest,
2873 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322874 // There is currently no explicit concept of an orthographic projection plane
2875 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2876 // are technically behind the surface in an orthographic world should not be
2877 // clipped when they are flattened to the surface.
2878
[email protected]2c7c6702013-03-26 03:14:052879 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2880 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322881 gfx::Transform layer_to_surface_transform;
2882
2883 // This sequence of transforms effectively rotates the layer about the y-axis
2884 // at the center of the layer.
2885 layer_to_surface_transform.MakeIdentity();
2886 layer_to_surface_transform.Translate(50.0, 0.0);
2887 layer_to_surface_transform.RotateAboutYAxis(45.0);
2888 layer_to_surface_transform.Translate(-50.0, 0.0);
2889
weiliangc6da32862016-04-20 16:40:112890 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2891 // space.
2892 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2893 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2894 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2895 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2896 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2897 EXPECT_EQ(expected_drawable_content_rect,
2898 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322899}
2900
weiliangc6da32862016-04-20 16:40:112901TEST_F(LayerTreeHostCommonDrawRectsTest,
2902 DrawRectsFor3dPerspectiveWhenClippedByW) {
2903 // Test visible layer rect and drawable content rect are calculated correctly
2904 // when projecting a surface onto a layer, but the layer is partially behind
2905 // the camera (not just behind the projection plane). In this case, the
2906 // cartesian coordinates may seem to be valid, but actually they are not. The
2907 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2908 // coordinates before converting to cartesian coordinates. The drawable
2909 // content rect would be entire surface rect because layer is rotated at the
2910 // camera position.
[email protected]fb661802013-03-25 01:59:322911
weiliangc6da32862016-04-20 16:40:112912 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2913 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322914 gfx::Transform layer_to_surface_transform;
2915
2916 // The layer is positioned so that the right half of the layer should be in
2917 // front of the camera, while the other half is behind the surface's
2918 // projection plane. The following sequence of transforms applies the
2919 // perspective and rotation about the center of the layer.
2920 layer_to_surface_transform.MakeIdentity();
2921 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112922 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2923 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2924 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322925
2926 // Sanity check that this transform does indeed cause w < 0 when applying the
2927 // transform, otherwise this code is not testing the intended scenario.
2928 bool clipped;
2929 MathUtil::MapQuad(layer_to_surface_transform,
2930 gfx::QuadF(gfx::RectF(layer_content_rect)),
2931 &clipped);
2932 ASSERT_TRUE(clipped);
2933
weiliangc6da32862016-04-20 16:40:112934 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2935 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2936 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2937 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2938 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2939 EXPECT_EQ(expected_drawable_content_rect,
2940 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322941}
2942
weiliangc6da32862016-04-20 16:40:112943TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322944 // To determine visible rect in layer space, there needs to be an
2945 // un-projection from surface space to layer space. When the original
2946 // transform was a perspective projection that was clipped, it returns a rect
2947 // that encloses the clipped bounds. Un-projecting this new rect may require
2948 // clipping again.
2949
2950 // This sequence of transforms causes one corner of the layer to protrude
2951 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:112952 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
2953 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322954 gfx::Transform layer_to_surface_transform;
2955 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:112956 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:322957 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2958 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2959 layer_to_surface_transform.RotateAboutYAxis(45.0);
2960 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:112961 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:322962
2963 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2964 // code is not testing the intended scenario.
2965 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442966 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2967 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322968 MathUtil::ProjectQuad(
2969 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2970 ASSERT_TRUE(clipped);
2971
2972 // Only the corner of the layer is not visible on the surface because of being
2973 // clipped. But, the net result of rounding visible region to an axis-aligned
2974 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:112975 gfx::Rect expected_visible_layer_rect = layer_content_rect;
2976 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2977 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2978 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2979 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2980 EXPECT_EQ(expected_drawable_content_rect,
2981 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322982}
2983
miletus9d3da522015-06-05 19:45:072984TEST_F(LayerTreeHostCommonTest,
2985 VisibleRectsForPositionedRootLayerClippedByViewport) {
jaydasikabf1875a2016-06-28 03:39:592986 LayerImpl* root = root_layer_for_testing();
miletus9d3da522015-06-05 19:45:072987
danakje4fa7b72016-07-25 22:00:062988 root->SetPosition(gfx::PointF(60, 70));
2989 root->SetBounds(gfx::Size(100, 100));
2990 root->SetDrawsContent(true);
enne6c281f6e2015-08-18 23:23:002991 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:072992
danakj5e6ff6d2015-09-05 04:43:442993 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:072994 root->render_surface()->DrawableContentRect());
2995 // In target space, not clipped.
2996 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2997 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:442998 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:072999}
3000
[email protected]989386c2013-07-18 21:37:233001TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
jaydasikabf1875a2016-06-28 03:39:593002 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173003 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173004 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173005 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063006
3007 root->SetBounds(gfx::Size(100, 100));
3008 child1_layer->SetBounds(gfx::Size(50, 50));
3009 child1_layer->SetDrawsContent(true);
3010 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
3011 child2_layer->SetBounds(gfx::Size(50, 50));
3012 child2_layer->SetDrawsContent(true);
3013 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
3014 child3_layer->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173015 child3_layer->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173016 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323017
danakj5e6ff6d2015-09-05 04:43:443018 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323019 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323020
danakj64767d902015-06-19 00:10:433021 // Layers that do not draw content should have empty visible_layer_rects.
3022 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323023
danakj64767d902015-06-19 00:10:433024 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173025 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3026 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3027 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323028
3029 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173030 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3031 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3032 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323033}
3034
[email protected]989386c2013-07-18 21:37:233035TEST_F(LayerTreeHostCommonTest,
3036 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
jaydasikabf1875a2016-06-28 03:39:593037 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173038 LayerImpl* child = AddChildToRoot<LayerImpl>();
3039 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173040 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173041 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:283042
danakje4fa7b72016-07-25 22:00:063043 root->SetBounds(gfx::Size(100, 100));
3044 child->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323045 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063046 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
3047 grand_child1->SetBounds(gfx::Size(50, 50));
3048 grand_child1->SetDrawsContent(true);
3049 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
3050 grand_child2->SetBounds(gfx::Size(50, 50));
3051 grand_child2->SetDrawsContent(true);
3052 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
3053 grand_child3->SetBounds(gfx::Size(50, 50));
3054 grand_child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173055 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323056
danakj5e6ff6d2015-09-05 04:43:443057 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323058 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323059
3060 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433061 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3062 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323063
3064 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433065 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3066 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3067 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323068
3069 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323070 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3071 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323072 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3073}
3074
ajuma27442dd2015-03-30 19:19:483075TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasikabf1875a2016-06-28 03:39:593076 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:143077 LayerImpl* child = AddChild<LayerImpl>(root);
3078 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483079
ajuma27442dd2015-03-30 19:19:483080 gfx::Transform child_scale_matrix;
3081 child_scale_matrix.Scale(0.25f, 0.25f);
3082 gfx::Transform grand_child_scale_matrix;
3083 grand_child_scale_matrix.Scale(0.246f, 0.246f);
ajuma27442dd2015-03-30 19:19:483084
danakje4fa7b72016-07-25 22:00:063085 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043086 child->test_properties()->transform = child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063087 child->SetBounds(gfx::Size(10, 10));
ajuma27442dd2015-03-30 19:19:483088 child->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:043089 grand_child->test_properties()->transform = grand_child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063090 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:143091 grand_child->SetDrawsContent(true);
3092 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483093
weiliangcd15784432016-06-07 17:57:333094 // The visible rect is expanded to integer coordinates.
3095 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483096}
3097
[email protected]989386c2013-07-18 21:37:233098TEST_F(LayerTreeHostCommonTest,
3099 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593100 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173101 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3102 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173103 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173104 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
danakje4fa7b72016-07-25 22:00:063105
3106 root->SetBounds(gfx::Size(100, 100));
3107 render_surface->SetBounds(gfx::Size(3, 4));
3108 render_surface->test_properties()->force_render_surface = true;
3109 child1->SetPosition(gfx::PointF(5.f, 5.f));
3110 child1->SetBounds(gfx::Size(50, 50));
3111 child1->SetDrawsContent(true);
3112 child2->SetPosition(gfx::PointF(75.f, 75.f));
3113 child2->SetBounds(gfx::Size(50, 50));
3114 child2->SetDrawsContent(true);
3115 child3->SetPosition(gfx::PointF(125.f, 125.f));
3116 child3->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173117 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173118 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323119
weiliangc0dece732015-07-27 19:06:173120 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323121
danakj5e6ff6d2015-09-05 04:43:443122 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323123 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323124
3125 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433126 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173127 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323128
3129 // An unclipped surface grows its DrawableContentRect to include all drawable
3130 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443131 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173132 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323133
3134 // All layers that draw content into the unclipped surface are also unclipped.
jaydasika94bebdd2016-09-16 22:11:183135 // Only the viewport clip should apply
danakj64767d902015-06-19 00:10:433136 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183137 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3138 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323139
hush6b614212014-12-04 22:37:323140 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3141 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3142 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323143}
3144
[email protected]989386c2013-07-18 21:37:233145TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583146 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:593147 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:583148 LayerImpl* parent = AddChild<LayerImpl>(root);
3149 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3150 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3151 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3152 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3153 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3154 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3155
danakje4fa7b72016-07-25 22:00:063156 root->SetBounds(gfx::Size(100, 100));
3157 parent->SetPosition(gfx::PointF(2.f, 2.f));
3158 parent->SetBounds(gfx::Size(400, 400));
3159 child1->SetPosition(gfx::PointF(4.f, 4.f));
3160 child1->SetBounds(gfx::Size(800, 800));
3161 child1->test_properties()->force_render_surface = true;
3162 child2->SetPosition(gfx::PointF(3.f, 3.f));
3163 child2->SetBounds(gfx::Size(800, 800));
3164 child2->test_properties()->force_render_surface = true;
3165 grand_child1->SetPosition(gfx::PointF(8.f, 8.f));
3166 grand_child1->SetBounds(gfx::Size(1500, 1500));
3167 grand_child2->SetPosition(gfx::PointF(7.f, 7.f));
3168 grand_child2->SetBounds(gfx::Size(1500, 1500));
3169 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
3170 leaf_node1->SetBounds(gfx::Size(2000, 2000));
3171 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
3172 leaf_node2->SetBounds(gfx::Size(2000, 2000));
3173
ajuma51d73f72015-10-19 19:43:583174 root->SetDrawsContent(true);
3175 parent->SetDrawsContent(true);
3176 child1->SetDrawsContent(true);
3177 child2->SetDrawsContent(true);
3178 grand_child1->SetDrawsContent(true);
3179 grand_child2->SetDrawsContent(true);
3180 leaf_node1->SetDrawsContent(true);
3181 leaf_node2->SetDrawsContent(true);
3182
jaydasika94bebdd2016-09-16 22:11:183183 // Case 1: No layers clip. Visible rects are clipped by the viewport.
ajuma51d73f72015-10-19 19:43:583184 // Each layer's drawable content rect is its bounds in target space; the only
3185 // thing that changes with surfaces disabled is that target space is always
3186 // screen space.
weiliangcc154ce22015-12-09 03:39:263187 root->SetHasRenderSurface(true);
3188 child1->SetHasRenderSurface(true);
3189 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583190 ExecuteCalculateDrawProperties(root);
3191 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3192 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183193 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3194 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3195 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3196 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3197 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3198 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583199
3200 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3201 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3202 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3203 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3204 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3205 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3206 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3207 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3208
3209 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3210 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3211 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3212 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3213 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3214 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3215 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3216 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3217 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3218
3219 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3220 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3221 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3222 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3223 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3224 grand_child1->drawable_content_rect());
3225 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3226 grand_child2->drawable_content_rect());
3227 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3228 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3229
3230 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3231 // all visible layer rects are clipped by the intersection of all ancestor
3232 // clips, whether or not surfaces are disabled. However, drawable content
3233 // rects are clipped only until the next render surface is reached, so
3234 // descendants of parent have their drawable content rects clipped only when
3235 // surfaces are disabled.
3236 parent->SetMasksToBounds(true);
3237 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3238 ExecuteCalculateDrawProperties(root);
3239 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3240 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3241 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3242 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3243 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3244 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3245 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3246 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3247
3248 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3249 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3250 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3251 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3252 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3253 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3254 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3255 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3256
3257 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3258 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3259 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3260 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3261 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3262 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3263 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3264 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3265 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3266
3267 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3268 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3269 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3270 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3271 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3272 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3273 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3274 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3275
3276 parent->SetMasksToBounds(false);
3277
3278 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
jaydasika526eae0a2016-09-02 01:47:593279 // layers have their visible rects clipped by them; Similarly, descendants of
3280 // these layers have their drawable content rects clipped by them.
ajuma51d73f72015-10-19 19:43:583281 child1->SetMasksToBounds(true);
3282 grand_child2->SetMasksToBounds(true);
3283 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3284 ExecuteCalculateDrawProperties(root);
3285 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3286 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593287 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183288 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593289 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3290 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3291 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3292 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583293
3294 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3295 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3296 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3297 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3298 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3299 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3300 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3301 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3302
3303 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3304 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3305 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3306 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3307 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3308 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3309 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3310 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3311 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3312
3313 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3314 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3315 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3316 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3317 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3318 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3319 grand_child2->drawable_content_rect());
3320 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3321 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3322}
3323
3324TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023325 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
jaydasikabf1875a2016-06-28 03:39:593326 LayerImpl* root = root_layer_for_testing();
enne6c281f6e2015-08-18 23:23:003327 LayerImpl* child1 = AddChild<LayerImpl>(root);
3328 LayerImpl* child2 = AddChild<LayerImpl>(root);
3329 LayerImpl* child3 = AddChild<LayerImpl>(root);
hush887bb542014-12-02 22:49:023330
danakje4fa7b72016-07-25 22:00:063331 root->SetBounds(gfx::Size(100, 100));
3332 child1->SetPosition(gfx::PointF(5.f, 5.f));
3333 child1->SetBounds(gfx::Size(50, 50));
3334 child1->SetDrawsContent(true);
3335 child2->SetPosition(gfx::PointF(75.f, 75.f));
3336 child2->SetBounds(gfx::Size(50, 50));
3337 child2->SetDrawsContent(true);
3338 child3->SetPosition(gfx::PointF(125.f, 125.f));
3339 child3->SetBounds(gfx::Size(50, 50));
3340 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023341
enne6c281f6e2015-08-18 23:23:003342 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023343 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003344 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383345 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023346
sunxdb365de02016-04-28 20:32:573347 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023348 ASSERT_TRUE(root->render_surface());
3349 EXPECT_FALSE(root->is_clipped());
3350
3351 gfx::Rect empty;
3352 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3353 EXPECT_TRUE(root->render_surface()->is_clipped());
3354
3355 // Visible content rect calculation will check if the target surface is
3356 // clipped or not. An empty clip rect does not indicate the render surface
3357 // is unclipped.
danakj64767d902015-06-19 00:10:433358 EXPECT_EQ(empty, child1->visible_layer_rect());
3359 EXPECT_EQ(empty, child2->visible_layer_rect());
3360 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023361}
3362
3363TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233364 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
jaydasikabf1875a2016-06-28 03:39:593365 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173366 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063367
3368 root->SetBounds(gfx::Size(100, 100));
3369 child->SetPosition(gfx::PointF(5.f, 5.f));
3370 child->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173371 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283372
[email protected]630ddad2013-08-16 03:01:323373 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473374 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323375 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473376
jaydasika10d43fc2016-08-18 04:06:043377 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173378 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473379
danakj64767d902015-06-19 00:10:433380 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473381 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323382
[email protected]08bdf1b2014-04-16 23:23:293383 // Case 2: a matrix with flattened z, uninvertible and not visible according
3384 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323385 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263386 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323387 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3388
jaydasika10d43fc2016-08-18 04:06:043389 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173390 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323391
danakj64767d902015-06-19 00:10:433392 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293393 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323394
[email protected]08bdf1b2014-04-16 23:23:293395 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323396 uninvertible_matrix.MakeIdentity();
3397 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263398 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323399 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3400
jaydasika10d43fc2016-08-18 04:06:043401 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173402 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323403
danakj64767d902015-06-19 00:10:433404 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293405 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473406}
3407
[email protected]989386c2013-07-18 21:37:233408TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563409 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
jaydasikabf1875a2016-06-28 03:39:593410 LayerImpl* root = root_layer_for_testing();
ajumaae0dc2d2015-08-05 21:55:563411 LayerImpl* child = AddChildToRoot<LayerImpl>();
3412 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaae0dc2d2015-08-05 21:55:563413
ajumaae0dc2d2015-08-05 21:55:563414 gfx::Transform perspective;
3415 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3416
3417 gfx::Transform rotation;
3418 rotation.RotateAboutYAxis(45.0);
3419
danakje4fa7b72016-07-25 22:00:063420 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043421 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063422 child->SetPosition(gfx::PointF(10.f, 10.f));
3423 child->SetBounds(gfx::Size(100, 100));
3424 child->SetDrawsContent(true);
3425 child->Set3dSortingContextId(1);
3426 child->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:043427 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063428 grand_child->SetBounds(gfx::Size(100, 100));
3429 grand_child->SetDrawsContent(true);
3430 grand_child->Set3dSortingContextId(1);
3431 grand_child->test_properties()->should_flatten_transform = false;
ajumaae0dc2d2015-08-05 21:55:563432 ExecuteCalculateDrawProperties(root);
3433
3434 // Though all layers have invertible transforms, matrix multiplication using
3435 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053436 EXPECT_FALSE(root->layer_tree_impl()
3437 ->property_trees()
3438 ->transform_tree.Node(grand_child->transform_tree_index())
trchendba8b1502016-07-08 09:47:013439 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563440
sunxd71aea3e2016-04-01 23:48:053441 // CalcDrawProps skips a subtree when a layer's screen space transform is
3442 // uninvertible
3443 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563444}
3445
jaydasika69c77aa2016-07-14 22:48:483446TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) {
3447 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika69c77aa2016-07-14 22:48:483448 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323449 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3450 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223451 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483452
3453 std::unique_ptr<LayerImpl> root =
3454 LayerImpl::Create(host_impl.active_tree(), 1);
3455 std::unique_ptr<LayerImpl> child =
3456 LayerImpl::Create(host_impl.active_tree(), 2);
3457 std::unique_ptr<TextureLayerImpl> surface =
3458 TextureLayerImpl::Create(host_impl.active_tree(), 3);
3459 std::unique_ptr<TextureLayerImpl> surface_child =
3460 TextureLayerImpl::Create(host_impl.active_tree(), 4);
3461 std::unique_ptr<TextureLayerImpl> surface_sibling =
3462 TextureLayerImpl::Create(host_impl.active_tree(), 5);
3463 std::unique_ptr<TextureLayerImpl> surface_child_mask =
3464 TextureLayerImpl::Create(host_impl.active_tree(), 6);
3465
3466 surface->SetDrawsContent(true);
3467 surface_child->SetDrawsContent(true);
3468 surface_sibling->SetDrawsContent(true);
3469 surface_child_mask->SetDrawsContent(true);
3470 surface->SetContentsOpaque(true);
3471 surface_child->SetContentsOpaque(true);
3472 surface_sibling->SetContentsOpaque(true);
3473 surface_child_mask->SetContentsOpaque(true);
3474
jaydasika69c77aa2016-07-14 22:48:483475 gfx::Transform translate;
3476 translate.Translate(20.f, 20.f);
3477
danakje4fa7b72016-07-25 22:00:063478 root->SetBounds(gfx::Size(1000, 1000));
3479 child->SetBounds(gfx::Size(300, 300));
jaydasika10d43fc2016-08-18 04:06:043480 surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:063481 surface->SetBounds(gfx::Size(300, 300));
3482 surface->test_properties()->force_render_surface = true;
3483 surface_child->SetBounds(gfx::Size(300, 300));
3484 surface_child->test_properties()->force_render_surface = true;
3485 surface_sibling->SetBounds(gfx::Size(200, 200));
jaydasika69c77aa2016-07-14 22:48:483486
3487 LayerImpl* surface_ptr = surface.get();
3488 LayerImpl* surface_child_ptr = surface_child.get();
3489 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3490
3491 host_impl.SetViewportSize(root->bounds());
3492
3493 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3494 surface->test_properties()->AddChild(std::move(surface_child));
3495 child->test_properties()->AddChild(std::move(surface));
3496 child->test_properties()->AddChild(std::move(surface_sibling));
3497 root->test_properties()->AddChild(std::move(child));
3498 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3499 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323500 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika69c77aa2016-07-14 22:48:483501 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3502 bool update_lcd_text = false;
3503 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3504
3505 EXPECT_TRANSFORMATION_MATRIX_EQ(
3506 surface_ptr->render_surface()->draw_transform(), translate);
3507 // surface_sibling draws into the root render surface and occludes
3508 // surface_child's contents.
3509 Occlusion actual_occlusion =
3510 surface_child_ptr->render_surface()->occlusion_in_content_space();
3511 Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()),
3512 SimpleEnclosedRegion(gfx::Rect(200, 200)));
3513 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3514
3515 // Mask layer should have the same occlusion.
3516 actual_occlusion =
3517 surface_child_mask_ptr->draw_properties().occlusion_in_content_space;
3518 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3519}
3520
jaydasika2a1718b2016-10-26 22:58:023521TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) {
3522 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika2a1718b2016-10-26 22:58:023523 TestTaskGraphRunner task_graph_runner;
3524 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3525 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223526 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika2a1718b2016-10-26 22:58:023527
3528 std::unique_ptr<LayerImpl> root =
3529 LayerImpl::Create(host_impl.active_tree(), 1);
3530 std::unique_ptr<TextureLayerImpl> child =
3531 TextureLayerImpl::Create(host_impl.active_tree(), 2);
3532
3533 LayerImpl* child_ptr = child.get();
3534
3535 root->SetBounds(gfx::Size(100, 100));
3536 child->SetBounds(gfx::Size(100, 100));
3537 child->SetDrawsContent(true);
3538 gfx::Transform fractional_translate;
3539 fractional_translate.Translate(10.5f, 20.3f);
3540 child->test_properties()->transform = fractional_translate;
3541
3542 host_impl.SetViewportSize(root->bounds());
3543
3544 root->test_properties()->AddChild(std::move(child));
3545 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3546 host_impl.SetVisible(true);
3547 host_impl.InitializeRenderer(compositor_frame_sink.get());
3548 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3549 bool update_lcd_text = false;
3550 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3551
3552 EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate);
3553 fractional_translate.RoundTranslationComponents();
3554 EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(),
3555 fractional_translate);
3556 gfx::RectF layer_bounds_in_screen_space =
3557 MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(),
3558 gfx::RectF(gfx::SizeF(child_ptr->bounds())));
3559 EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f));
3560}
3561
ajumaae0dc2d2015-08-05 21:55:563562TEST_F(LayerTreeHostCommonTest,
3563 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163564 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563565 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323566 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3567 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223568 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483569
danakj60bc3bc2016-04-09 00:24:483570 std::unique_ptr<LayerImpl> root =
3571 LayerImpl::Create(host_impl.active_tree(), 1);
3572 std::unique_ptr<LayerImpl> child =
3573 LayerImpl::Create(host_impl.active_tree(), 2);
3574 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563575 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483576 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563577 LayerImpl::Create(host_impl.active_tree(), 4);
ajumaae0dc2d2015-08-05 21:55:563578
ajumaae0dc2d2015-08-05 21:55:563579 gfx::Transform perspective;
3580 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3581
3582 gfx::Transform rotation;
3583 rotation.RotateAboutYAxis(45.0);
3584
danakje4fa7b72016-07-25 22:00:063585 root->SetBounds(gfx::Size(1000, 1000));
jaydasika10d43fc2016-08-18 04:06:043586 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063587 child->SetPosition(gfx::PointF(10.f, 10.f));
3588 child->SetBounds(gfx::Size(300, 300));
3589 child->test_properties()->should_flatten_transform = false;
3590 child->Set3dSortingContextId(1);
jaydasika10d43fc2016-08-18 04:06:043591 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063592 grand_child->SetBounds(gfx::Size(200, 200));
3593 grand_child->test_properties()->should_flatten_transform = false;
3594 grand_child->Set3dSortingContextId(1);
3595 occluding_child->SetBounds(gfx::Size(200, 200));
3596 occluding_child->test_properties()->should_flatten_transform = false;
3597
3598 child->SetDrawsContent(true);
3599 grand_child->SetDrawsContent(true);
3600 occluding_child->SetDrawsContent(true);
3601 occluding_child->SetContentsOpaque(true);
ajumaae0dc2d2015-08-05 21:55:563602
3603 host_impl.SetViewportSize(root->bounds());
3604
jaydasika89f7b5a2016-06-22 02:08:393605 child->test_properties()->AddChild(std::move(grand_child));
3606 root->test_properties()->AddChild(std::move(child));
3607 root->test_properties()->AddChild(std::move(occluding_child));
jaydasikabf1875a2016-06-28 03:39:593608 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
sievers71c62dd52015-10-07 01:44:393609 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323610 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika4340ea02016-06-06 19:44:263611 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563612 bool update_lcd_text = false;
3613 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3614
jaydasikafc66cfb2016-06-10 04:34:223615 LayerImpl* grand_child_ptr = host_impl.active_tree()
jaydasikabf1875a2016-06-28 03:39:593616 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:223617 ->test_properties()
3618 ->children[0]
3619 ->test_properties()
3620 ->children[0];
ajumaae0dc2d2015-08-05 21:55:563621
3622 // Though all layers have invertible transforms, matrix multiplication using
3623 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053624 EXPECT_FALSE(
3625 host_impl.active_tree()
3626 ->property_trees()
3627 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
trchendba8b1502016-07-08 09:47:013628 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563629
sunxd71aea3e2016-04-01 23:48:053630 // Since |grand_child| has an uninvertible screen space transform, it is
3631 // skipped so
3632 // that we are not computing its occlusion_in_content_space.
3633 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563634 EXPECT_EQ(
3635 layer_bounds,
3636 grand_child_ptr->draw_properties()
3637 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3638}
3639
3640TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233641 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593642 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173643 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3644 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173645 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173646 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283647
danakje4fa7b72016-07-25 22:00:063648 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323649 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063650 render_surface->SetBounds(gfx::Size(3, 4));
3651 render_surface->test_properties()->force_render_surface = true;
3652 child1->SetPosition(gfx::PointF(5.f, 5.f));
3653 child1->SetBounds(gfx::Size(50, 50));
3654 child1->SetDrawsContent(true);
3655 child2->SetPosition(gfx::PointF(75.f, 75.f));
3656 child2->SetBounds(gfx::Size(50, 50));
3657 child2->SetDrawsContent(true);
3658 child3->SetPosition(gfx::PointF(125.f, 125.f));
3659 child3->SetBounds(gfx::Size(50, 50));
3660 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173661 ExecuteCalculateDrawProperties(root);
3662
3663 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323664
danakj5e6ff6d2015-09-05 04:43:443665 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323666 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323667
3668 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433669 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173670 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323671
3672 // A clipped surface grows its DrawableContentRect to include all drawable
3673 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443674 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173675 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323676
3677 // All layers that draw content into the surface have their visible content
3678 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433679 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3680 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3681 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323682
3683 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323684 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3685 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3686 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323687}
3688
[email protected]989386c2013-07-18 21:37:233689TEST_F(LayerTreeHostCommonTest,
3690 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323691 // Check that clipping does not propagate down surfaces.
jaydasikabf1875a2016-06-28 03:39:593692 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173693 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3694 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3695 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173696 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173697 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283698
danakje4fa7b72016-07-25 22:00:063699 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323700 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063701 render_surface1->SetBounds(gfx::Size(3, 4));
3702 render_surface1->test_properties()->force_render_surface = true;
3703 render_surface2->SetBounds(gfx::Size(7, 13));
3704 render_surface2->test_properties()->force_render_surface = true;
3705 child1->SetPosition(gfx::PointF(5.f, 5.f));
3706 child1->SetBounds(gfx::Size(50, 50));
3707 child1->SetDrawsContent(true);
3708 child2->SetPosition(gfx::PointF(75.f, 75.f));
3709 child2->SetBounds(gfx::Size(50, 50));
3710 child2->SetDrawsContent(true);
3711 child3->SetPosition(gfx::PointF(125.f, 125.f));
3712 child3->SetBounds(gfx::Size(50, 50));
3713 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173714 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323715
3716 ASSERT_TRUE(render_surface1->render_surface());
3717 ASSERT_TRUE(render_surface2->render_surface());
3718
danakj5e6ff6d2015-09-05 04:43:443719 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323720 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323721
3722 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433723 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3724 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3725 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323726
3727 // A clipped surface grows its DrawableContentRect to include all drawable
3728 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443729 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323730 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323731
3732 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3733 // is only implicitly clipped by render_surface1's content rect. So,
3734 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443735 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323736 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323737
jaydasika94bebdd2016-09-16 22:11:183738 // All layers that draw content into render_surface2 think they are unclipped
3739 // by the surface. So, only the viewport clip applies.
danakj64767d902015-06-19 00:10:433740 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183741 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3742 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323743
3744 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323745 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3746 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3747 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323748}
3749
[email protected]989386c2013-07-18 21:37:233750TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463751 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593752 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463753 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3754 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3755 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3756 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
jaydasika27d0f2e2015-10-16 23:52:463757
danakje4fa7b72016-07-25 22:00:063758 root->SetBounds(gfx::Size(100, 100));
3759 render_surface1->SetBounds(gfx::Size(100, 100));
3760 render_surface1->test_properties()->force_render_surface = true;
3761 child1->SetBounds(gfx::Size(500, 500));
3762 child1->SetDrawsContent(true);
3763 child2->SetBounds(gfx::Size(700, 700));
3764 child2->SetDrawsContent(true);
3765 render_surface2->SetBounds(gfx::Size(1000, 1000));
3766 render_surface2->test_properties()->force_render_surface = true;
3767 render_surface2->SetDrawsContent(true);
jaydasika27d0f2e2015-10-16 23:52:463768
3769 child1->SetMasksToBounds(true);
3770 child2->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463771 ExecuteCalculateDrawProperties(root);
jaydasika526eae0a2016-09-02 01:47:593772 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463773 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3774}
3775
3776TEST_F(LayerTreeHostCommonTest,
3777 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593778 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463779 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3780 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3781 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3782 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3783
danakje4fa7b72016-07-25 22:00:063784 root->SetBounds(gfx::Size(100, 100));
3785
3786 clip_parent->SetBounds(gfx::Size(50, 50));
3787 clip_parent->SetMasksToBounds(true);
3788 clip_parent->test_properties()->clip_children =
3789 base::MakeUnique<std::set<LayerImpl*>>();
3790 clip_parent->test_properties()->clip_children->insert(clip_child);
3791
3792 render_surface1->SetBounds(gfx::Size(20, 20));
3793 render_surface1->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463794 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063795 render_surface1->test_properties()->force_render_surface = true;
3796
3797 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika27d0f2e2015-10-16 23:52:463798 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563799 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika27d0f2e2015-10-16 23:52:463800
danakje4fa7b72016-07-25 22:00:063801 render_surface2->SetBounds(gfx::Size(60, 60));
3802 render_surface2->SetDrawsContent(true);
3803 render_surface2->test_properties()->force_render_surface = true;
jaydasika27d0f2e2015-10-16 23:52:463804
3805 ExecuteCalculateDrawProperties(root);
3806 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3807 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3808 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3809}
3810
jaydasika1f5312d2015-10-21 21:34:323811TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
jaydasikabf1875a2016-06-28 03:39:593812 LayerImpl* root = root_layer_for_testing();
jaydasika1f5312d2015-10-21 21:34:323813 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3814 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3815 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3816 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3817
danakje4fa7b72016-07-25 22:00:063818 root->SetBounds(gfx::Size(100, 100));
3819
3820 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
3821 clip_parent->SetBounds(gfx::Size(50, 50));
3822 clip_parent->test_properties()->clip_children =
3823 base::MakeUnique<std::set<LayerImpl*>>();
3824 clip_parent->test_properties()->clip_children->insert(clip_child);
3825
3826 render_surface1->SetBounds(gfx::Size(20, 20));
jaydasika1f5312d2015-10-21 21:34:323827 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063828 render_surface1->test_properties()->force_render_surface = true;
3829
3830 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika1f5312d2015-10-21 21:34:323831 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563832 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika1f5312d2015-10-21 21:34:323833
danakje4fa7b72016-07-25 22:00:063834 render_surface2->SetBounds(gfx::Size(60, 60));
3835 render_surface2->SetDrawsContent(true);
3836 render_surface2->test_properties()->force_render_surface = true;
3837
jaydasika1f5312d2015-10-21 21:34:323838 clip_parent->SetMasksToBounds(true);
3839 render_surface1->SetMasksToBounds(true);
3840
3841 ExecuteCalculateDrawProperties(root);
3842 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3843}
3844
jaydasika77a4a072015-10-20 21:47:273845TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3846 // Test that only drawn layers contribute to render surface content rect.
jaydasikabf1875a2016-06-28 03:39:593847 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:273848 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3849 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3850
danakje4fa7b72016-07-25 22:00:063851 root->SetBounds(gfx::Size(200, 200));
3852 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:273853 surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063854 surface->test_properties()->force_render_surface = true;
3855 test_layer->SetBounds(gfx::Size(150, 150));
jaydasika77a4a072015-10-20 21:47:273856
3857 ExecuteCalculateDrawProperties(root);
3858 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3859
3860 test_layer->SetDrawsContent(true);
3861 ExecuteCalculateDrawProperties(root);
3862 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3863}
3864
jaydasika27d0f2e2015-10-16 23:52:463865TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3866 // Tests visible rects computation when we have unclipped_surface->
3867 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3868 // of surface_with_unclipped_descendants doesn't propagate to the
3869 // clipped_surface below it.
jaydasikabf1875a2016-06-28 03:39:593870 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463871 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3872 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3873 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3874 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3875 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3876
danakje4fa7b72016-07-25 22:00:063877 root->SetBounds(gfx::Size(100, 100));
jaydasika27d0f2e2015-10-16 23:52:463878
danakje4fa7b72016-07-25 22:00:063879 unclipped_surface->SetBounds(gfx::Size(30, 30));
3880 unclipped_surface->SetDrawsContent(true);
3881 unclipped_surface->test_properties()->force_render_surface = true;
3882
3883 clip_parent->SetBounds(gfx::Size(50, 50));
3884 clip_parent->test_properties()->clip_children =
3885 base::MakeUnique<std::set<LayerImpl*>>();
3886 clip_parent->test_properties()->clip_children->insert(clip_child);
3887
3888 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
3889 unclipped_desc_surface->SetDrawsContent(true);
3890 unclipped_desc_surface->test_properties()->force_render_surface = true;
3891
3892 clip_child->SetBounds(gfx::Size(60, 60));
3893 clip_child->test_properties()->clip_parent = clip_parent;
3894
3895 clipped_surface->SetBounds(gfx::Size(60, 60));
3896 clipped_surface->SetDrawsContent(true);
3897 clipped_surface->test_properties()->force_render_surface = true;
3898
jaydasika27d0f2e2015-10-16 23:52:463899 clip_parent->SetMasksToBounds(true);
3900
3901 ExecuteCalculateDrawProperties(root);
3902 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3903 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3904 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3905}
3906
3907TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3908 // Tests visible rects computation when we have unclipped_surface->
3909 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3910 // of root propagate to the clipped_surface.
jaydasikabf1875a2016-06-28 03:39:593911 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463912 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3913 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3914 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3915 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3916 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3917
danakje4fa7b72016-07-25 22:00:063918 root->SetBounds(gfx::Size(10, 10));
jaydasika27d0f2e2015-10-16 23:52:463919
danakje4fa7b72016-07-25 22:00:063920 unclipped_surface->SetBounds(gfx::Size(50, 50));
3921 unclipped_surface->SetDrawsContent(true);
3922 unclipped_surface->test_properties()->force_render_surface = true;
3923
3924 clip_parent->SetBounds(gfx::Size(50, 50));
3925 clip_parent->test_properties()->clip_children =
3926 base::MakeUnique<std::set<LayerImpl*>>();
3927 clip_parent->test_properties()->clip_children->insert(clip_child);
3928
3929 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
3930 unclipped_desc_surface->SetDrawsContent(true);
3931 unclipped_desc_surface->test_properties()->force_render_surface = true;
3932
3933 clip_child->SetBounds(gfx::Size(100, 100));
3934 clip_child->test_properties()->clip_parent = clip_parent;
3935
3936 clipped_surface->SetBounds(gfx::Size(50, 50));
3937 clipped_surface->SetDrawsContent(true);
3938 clipped_surface->test_properties()->force_render_surface = true;
3939
jaydasika27d0f2e2015-10-16 23:52:463940 clip_parent->SetMasksToBounds(true);
3941 unclipped_desc_surface->SetMasksToBounds(true);
3942
3943 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:183944 EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593945 EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463946 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3947}
3948
3949TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233950 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323951 // Layers that have non-axis aligned bounds (due to transforms) have an
3952 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593953 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173954 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3955 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283956
[email protected]fb661802013-03-25 01:59:323957 gfx::Transform child_rotation;
3958 child_rotation.Rotate(45.0);
[email protected]fb661802013-03-25 01:59:323959
danakje4fa7b72016-07-25 22:00:063960 root->SetBounds(gfx::Size(100, 100));
3961 render_surface->SetBounds(gfx::Size(3, 4));
3962 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:043963 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:063964 child1->SetPosition(gfx::PointF(25.f, 25.f));
3965 child1->SetBounds(gfx::Size(50, 50));
3966 child1->SetDrawsContent(true);
3967 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173968 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323969
weiliangc0dece732015-07-27 19:06:173970 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323971
danakj5e6ff6d2015-09-05 04:43:443972 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323973 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323974
3975 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433976 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173977 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323978
3979 // The unclipped surface grows its DrawableContentRect to include all drawable
3980 // regions of the subtree.
3981 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3982 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263983 gfx::Rect(50 - diagonal_radius,
3984 50 - diagonal_radius,
3985 diagonal_radius * 2,
3986 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443987 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:173988 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323989
3990 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433991 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:323992 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323993}
3994
[email protected]989386c2013-07-18 21:37:233995TEST_F(LayerTreeHostCommonTest,
3996 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323997 // Layers that have non-axis aligned bounds (due to transforms) have an
3998 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593999 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174000 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4001 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:284002
[email protected]fb661802013-03-25 01:59:324003 gfx::Transform child_rotation;
4004 child_rotation.Rotate(45.0);
[email protected]a2566412014-06-05 03:14:204005
danakje4fa7b72016-07-25 22:00:064006 root->SetBounds(gfx::Size(50, 50));
[email protected]fb661802013-03-25 01:59:324007 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064008 render_surface->SetBounds(gfx::Size(3, 4));
4009 render_surface->test_properties()->force_render_surface = true;
4010 child1->SetPosition(gfx::PointF(25.f, 25.f));
4011 child1->SetBounds(gfx::Size(50, 50));
4012 child1->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:044013 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:064014 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:174015 ExecuteCalculateDrawProperties(root);
4016
4017 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324018
4019 // The clipped surface clamps the DrawableContentRect that encloses the
4020 // rotated layer.
4021 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264022 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4023 50 - diagonal_radius,
4024 diagonal_radius * 2,
4025 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444026 gfx::RectF expected_surface_drawable_content(
4027 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324028 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174029 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324030
4031 // On the clipped surface, only a quarter of the child1 is visible, but when
4032 // rotating it back to child1's content space, the actual enclosing rect ends
4033 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:334034 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324035
4036 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324037 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324038}
4039
[email protected]989386c2013-07-18 21:37:234040TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594041 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174042 FakePictureLayerImpl* render_surface1 =
4043 AddChildToRoot<FakePictureLayerImpl>();
weiliangc0dece732015-07-27 19:06:174044 FakePictureLayerImpl* render_surface2 =
4045 AddChild<FakePictureLayerImpl>(render_surface1);
weiliangc0dece732015-07-27 19:06:174046 FakePictureLayerImpl* child1 =
4047 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174048 FakePictureLayerImpl* child2 =
4049 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174050 FakePictureLayerImpl* child3 =
4051 AddChild<FakePictureLayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:284052
danakje4fa7b72016-07-25 22:00:064053 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324054 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064055 render_surface1->SetBounds(gfx::Size(3, 4));
4056 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
4057 render_surface1->SetDrawsContent(true);
4058 render_surface1->test_properties()->force_render_surface = true;
4059 render_surface2->SetBounds(gfx::Size(7, 13));
4060 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
4061 render_surface2->SetDrawsContent(true);
4062 render_surface2->test_properties()->force_render_surface = true;
4063 child1->SetBounds(gfx::Size(50, 50));
4064 child1->SetPosition(gfx::PointF(5.f, 5.f));
4065 child1->SetDrawsContent(true);
4066 child2->SetBounds(gfx::Size(50, 50));
4067 child2->SetPosition(gfx::PointF(75.f, 75.f));
4068 child2->SetDrawsContent(true);
4069 child3->SetBounds(gfx::Size(50, 50));
4070 child3->SetPosition(gfx::PointF(125.f, 125.f));
4071 child3->SetDrawsContent(true);
4072 float device_scale_factor = 2.f;
weiliangc0dece732015-07-27 19:06:174073 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324074
4075 ASSERT_TRUE(render_surface1->render_surface());
4076 ASSERT_TRUE(render_surface2->render_surface());
4077
4078 // drawable_content_rects for all layers and surfaces are scaled by
4079 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444080 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324081 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444082 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324083 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324084
4085 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4086 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444087 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324088 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324089
hush6b614212014-12-04 22:37:324090 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4091 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4092 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324093
4094 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434095 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324096
sohan.jyotie3bd6192014-10-13 07:13:594097 // All layer visible content rects are not expressed in content space of each
4098 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434099 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4100 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4101 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:184102 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect());
4103 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324104}
4105
[email protected]989386c2013-07-18 21:37:234106TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324107 // Verify the behavior of back-face culling when there are no preserve-3d
4108 // layers. Note that 3d transforms still apply in this case, but they are
4109 // "flattened" to each parent layer according to current W3C spec.
4110
danakje4fa7b72016-07-25 22:00:064111 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324112 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4113 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4114 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4115 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4116 LayerImpl* front_facing_child_of_front_facing_surface =
4117 AddChild<LayerImpl>(front_facing_surface);
4118 LayerImpl* back_facing_child_of_front_facing_surface =
4119 AddChild<LayerImpl>(front_facing_surface);
4120 LayerImpl* front_facing_child_of_back_facing_surface =
4121 AddChild<LayerImpl>(back_facing_surface);
4122 LayerImpl* back_facing_child_of_back_facing_surface =
4123 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284124
[email protected]fb661802013-03-25 01:59:324125 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324126 front_facing_child->test_properties()->double_sided = false;
4127 back_facing_child->test_properties()->double_sided = false;
4128 front_facing_surface->test_properties()->double_sided = false;
4129 back_facing_surface->test_properties()->double_sided = false;
4130 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4131 false;
4132 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4133 false;
4134 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4135 false;
4136 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4137 false;
4138
4139 // Everything draws content.
4140 front_facing_child->SetDrawsContent(true);
4141 back_facing_child->SetDrawsContent(true);
4142 front_facing_surface->SetDrawsContent(true);
4143 back_facing_surface->SetDrawsContent(true);
4144 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4145 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4146 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4147 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324148
4149 gfx::Transform backface_matrix;
4150 backface_matrix.Translate(50.0, 50.0);
4151 backface_matrix.RotateAboutYAxis(180.0);
4152 backface_matrix.Translate(-50.0, -50.0);
4153
danakje4fa7b72016-07-25 22:00:064154 root->SetBounds(gfx::Size(100, 100));
4155 front_facing_child->SetBounds(gfx::Size(100, 100));
4156 back_facing_child->SetBounds(gfx::Size(100, 100));
4157 front_facing_surface->SetBounds(gfx::Size(100, 100));
4158 back_facing_surface->SetBounds(gfx::Size(100, 100));
4159 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4160 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4161 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4162 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324163
danakje4fa7b72016-07-25 22:00:064164 front_facing_surface->test_properties()->force_render_surface = true;
4165 back_facing_surface->test_properties()->force_render_surface = true;
[email protected]fb661802013-03-25 01:59:324166
jaydasika10d43fc2016-08-18 04:06:044167 back_facing_child->test_properties()->transform = backface_matrix;
4168 back_facing_surface->test_properties()->transform = backface_matrix;
4169 back_facing_child_of_front_facing_surface->test_properties()->transform =
4170 backface_matrix;
4171 back_facing_child_of_back_facing_surface->test_properties()->transform =
4172 backface_matrix;
danakje4fa7b72016-07-25 22:00:064173
4174 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
4175 // spec, these layers should blindly use their own local transforms to
4176 // determine back-face culling.
jaydasika6ed869662016-09-21 14:29:594177 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324178
4179 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094180 EXPECT_FALSE(front_facing_child->has_render_surface());
4181 EXPECT_FALSE(back_facing_child->has_render_surface());
4182 EXPECT_TRUE(front_facing_surface->has_render_surface());
4183 EXPECT_TRUE(back_facing_surface->has_render_surface());
4184 EXPECT_FALSE(
4185 front_facing_child_of_front_facing_surface->has_render_surface());
4186 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4187 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4188 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324189
ajuma4711f4b12016-05-16 18:48:324190 EXPECT_EQ(4u, update_layer_list_impl()->size());
4191 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4192 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4193 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534194 front_facing_child_of_front_facing_surface->id()));
ajuma4711f4b12016-05-16 18:48:324195 EXPECT_TRUE(UpdateLayerListImplContains(
4196 front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324197}
4198
[email protected]989386c2013-07-18 21:37:234199TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324200 // Verify the behavior of back-face culling when preserves-3d transform style
4201 // is used.
4202
danakje4fa7b72016-07-25 22:00:064203 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:264204 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4205 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4206 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4207 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4208 LayerImpl* front_facing_child_of_front_facing_surface =
4209 AddChild<LayerImpl>(front_facing_surface);
4210 LayerImpl* back_facing_child_of_front_facing_surface =
4211 AddChild<LayerImpl>(front_facing_surface);
4212 LayerImpl* front_facing_child_of_back_facing_surface =
4213 AddChild<LayerImpl>(back_facing_surface);
4214 LayerImpl* back_facing_child_of_back_facing_surface =
4215 AddChild<LayerImpl>(back_facing_surface);
4216 // Opacity will not force creation of render surfaces in this case because of
4217 // the preserve-3d transform style. Instead, an example of when a surface
wangxianzhu932d7f12016-09-30 05:47:004218 // would be created with preserve-3d is when there is a mask layer.
4219 LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface);
4220 LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284221
[email protected]fb661802013-03-25 01:59:324222 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364223 front_facing_child->test_properties()->double_sided = false;
4224 back_facing_child->test_properties()->double_sided = false;
4225 front_facing_surface->test_properties()->double_sided = false;
4226 back_facing_surface->test_properties()->double_sided = false;
4227 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4228 false;
4229 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4230 false;
4231 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4232 false;
4233 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4234 false;
[email protected]fb661802013-03-25 01:59:324235
weiliangcc154ce22015-12-09 03:39:264236 // Everything draws content.
4237 front_facing_child->SetDrawsContent(true);
4238 back_facing_child->SetDrawsContent(true);
4239 front_facing_surface->SetDrawsContent(true);
4240 back_facing_surface->SetDrawsContent(true);
4241 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4242 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4243 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4244 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
wangxianzhu932d7f12016-09-30 05:47:004245 dummy_mask_layer1->SetDrawsContent(true);
4246 dummy_mask_layer2->SetDrawsContent(true);
weiliangcc154ce22015-12-09 03:39:264247
[email protected]fb661802013-03-25 01:59:324248 gfx::Transform backface_matrix;
4249 backface_matrix.Translate(50.0, 50.0);
4250 backface_matrix.RotateAboutYAxis(180.0);
4251 backface_matrix.Translate(-50.0, -50.0);
4252
danakje4fa7b72016-07-25 22:00:064253 root->SetBounds(gfx::Size(100, 100));
4254 front_facing_child->SetBounds(gfx::Size(100, 100));
4255 back_facing_child->SetBounds(gfx::Size(100, 100));
4256 front_facing_surface->SetBounds(gfx::Size(100, 100));
4257 back_facing_surface->SetBounds(gfx::Size(100, 100));
4258 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4259 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4260 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4261 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4262
jaydasika10d43fc2016-08-18 04:06:044263 back_facing_child->test_properties()->transform = backface_matrix;
4264 back_facing_surface->test_properties()->transform = backface_matrix;
4265 back_facing_child_of_front_facing_surface->test_properties()->transform =
4266 backface_matrix;
4267 back_facing_child_of_back_facing_surface->test_properties()->transform =
4268 backface_matrix;
danakje4fa7b72016-07-25 22:00:064269
[email protected]fb661802013-03-25 01:59:324270 // Each surface creates its own new 3d rendering context (as defined by W3C
4271 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4272 // rendering context should use the transform with respect to that context.
4273 // This 3d rendering context occurs when (a) parent's transform style is flat
4274 // and (b) the layer's transform style is preserve-3d.
danakje4fa7b72016-07-25 22:00:064275 front_facing_surface->test_properties()->should_flatten_transform = false;
4276 front_facing_surface->Set3dSortingContextId(1);
4277 back_facing_surface->test_properties()->should_flatten_transform = false;
4278 back_facing_surface->Set3dSortingContextId(1);
4279 front_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4280 back_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4281 front_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
4282 back_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
[email protected]fb661802013-03-25 01:59:324283
jaydasika6ed869662016-09-21 14:29:594284 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324285
awoloszyne83f28c2014-12-22 15:40:004286 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094287 EXPECT_FALSE(front_facing_child->has_render_surface());
4288 EXPECT_FALSE(back_facing_child->has_render_surface());
4289 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094290 // We expect that a has_render_surface was created but not used.
4291 EXPECT_TRUE(back_facing_surface->has_render_surface());
4292 EXPECT_FALSE(
4293 front_facing_child_of_front_facing_surface->has_render_surface());
4294 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4295 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4296 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324297
weiliangcc154ce22015-12-09 03:39:264298 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324299
weiliangcc154ce22015-12-09 03:39:264300 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4301 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4302 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534303 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324304}
4305
[email protected]989386c2013-07-18 21:37:234306TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324307 // Verify that layers are appropriately culled when their back face is showing
4308 // and they are not double sided, while animations are going on.
4309 //
ajuma4711f4b12016-05-16 18:48:324310 // Even layers that are animating get culled if their back face is showing and
4311 // they are not double sided.
danakje4fa7b72016-07-25 22:00:064312 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324313 LayerImpl* child = AddChildToRoot<LayerImpl>();
4314 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4315 LayerImpl* child_of_animating_surface =
4316 AddChild<LayerImpl>(animating_surface);
4317 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4318 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284319
[email protected]fb661802013-03-25 01:59:324320 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324321 child->test_properties()->double_sided = false;
4322 child2->test_properties()->double_sided = false;
4323 animating_surface->test_properties()->double_sided = false;
4324 child_of_animating_surface->test_properties()->double_sided = false;
4325 animating_child->test_properties()->double_sided = false;
4326
4327 // Everything draws content.
4328 child->SetDrawsContent(true);
4329 child2->SetDrawsContent(true);
4330 animating_surface->SetDrawsContent(true);
4331 child_of_animating_surface->SetDrawsContent(true);
4332 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324333
4334 gfx::Transform backface_matrix;
4335 backface_matrix.Translate(50.0, 50.0);
4336 backface_matrix.RotateAboutYAxis(180.0);
4337 backface_matrix.Translate(-50.0, -50.0);
4338
vollickef2ae922016-06-29 17:54:274339 SetElementIdsForTesting();
4340
loyso9556c732016-03-11 07:54:584341 // Animate the transform on the render surface.
vollickef2ae922016-06-29 17:54:274342 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
4343 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584344 // This is just an animating layer, not a surface.
vollickef2ae922016-06-29 17:54:274345 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
4346 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324347
danakje4fa7b72016-07-25 22:00:064348 root->SetBounds(gfx::Size(100, 100));
4349 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044350 child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064351 animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044352 animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064353 animating_surface->test_properties()->force_render_surface = true;
4354 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044355 child_of_animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064356 animating_child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044357 animating_child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064358 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324359
jaydasika6ed869662016-09-21 14:29:594360 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324361
ennec1332992015-08-24 19:45:094362 EXPECT_FALSE(child->has_render_surface());
4363 EXPECT_TRUE(animating_surface->has_render_surface());
4364 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4365 EXPECT_FALSE(animating_child->has_render_surface());
4366 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324367
ajuma4711f4b12016-05-16 18:48:324368 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534369
ajuma4711f4b12016-05-16 18:48:324370 // The back facing layers are culled from the layer list, and have an empty
4371 // visible rect.
4372 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4373 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4374 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4375 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4376 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324377
ajuma4711f4b12016-05-16 18:48:324378 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324379}
4380
[email protected]989386c2013-07-18 21:37:234381TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324382 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4383 // Verify the behavior of back-face culling for a render surface that is
4384 // created when it flattens its subtree, and its parent has preserves-3d.
4385
danakje4fa7b72016-07-25 22:00:064386 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324387 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4388 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4389 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4390 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284391
[email protected]fb661802013-03-25 01:59:324392 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324393 front_facing_surface->test_properties()->double_sided = false;
4394 back_facing_surface->test_properties()->double_sided = false;
4395
4396 // Everything draws content.
4397 front_facing_surface->SetDrawsContent(true);
4398 back_facing_surface->SetDrawsContent(true);
4399 child1->SetDrawsContent(true);
4400 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324401
4402 gfx::Transform backface_matrix;
4403 backface_matrix.Translate(50.0, 50.0);
4404 backface_matrix.RotateAboutYAxis(180.0);
4405 backface_matrix.Translate(-50.0, -50.0);
4406
danakje4fa7b72016-07-25 22:00:064407 root->SetBounds(gfx::Size(100, 100));
4408 front_facing_surface->SetBounds(gfx::Size(100, 100));
4409 front_facing_surface->test_properties()->force_render_surface = true;
4410 back_facing_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044411 back_facing_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064412 back_facing_surface->test_properties()->force_render_surface = true;
4413 child1->SetBounds(gfx::Size(100, 100));
4414 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324415
[email protected]a9d4d4f2014-06-19 06:49:284416 front_facing_surface->Set3dSortingContextId(1);
4417 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574418
jaydasika6ed869662016-09-21 14:29:594419 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324420
awoloszyne83f28c2014-12-22 15:40:004421 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094422 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004423
4424 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094425 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094426 EXPECT_FALSE(child1->has_render_surface());
4427 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324428
ajuma4711f4b12016-05-16 18:48:324429 EXPECT_EQ(2u, update_layer_list_impl()->size());
4430 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4431 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324432}
4433
enne637715732015-07-07 02:05:264434TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324435 // Verify draw and screen space transforms of layers not in a surface.
danakje4fa7b72016-07-25 22:00:064436 LayerImpl* root = root_layer_for_testing();
4437 root->SetBounds(gfx::Size(100, 100));
4438 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144439
enne637715732015-07-07 02:05:264440 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064441 child->SetPosition(gfx::PointF(2.f, 2.f));
4442 child->SetBounds(gfx::Size(10, 10));
jaydasika8640f9f2015-11-10 01:34:364443 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144444
jaydasika8640f9f2015-11-10 01:34:364445 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064446 child2->SetPosition(gfx::PointF(2.f, 2.f));
4447 child2->SetBounds(gfx::Size(5, 5));
jaydasika8640f9f2015-11-10 01:34:364448 child2->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284449
[email protected]fb661802013-03-25 01:59:324450 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264451 gfx::Size viewport_size(100, 100);
danakje4fa7b72016-07-25 22:00:064452 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144453
danakj59931942016-07-26 22:11:294454 EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale());
4455 EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale());
4456 EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale());
[email protected]518ee582012-10-24 18:29:444457
enne637715732015-07-07 02:05:264458 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144459
danakje4fa7b72016-07-25 22:00:064460 // Verify root transforms
4461 gfx::Transform expected_root_transform;
4462 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4463 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4464 root->ScreenSpaceTransform());
4465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4466 root->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144467
danakje4fa7b72016-07-25 22:00:064468 // Verify results of transformed root rects
4469 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
[email protected]94f206c12012-08-25 00:09:144470
danakje4fa7b72016-07-25 22:00:064471 gfx::RectF root_draw_rect =
4472 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4473 gfx::RectF root_screen_space_rect =
4474 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
[email protected]94f206c12012-08-25 00:09:144475
danakje4fa7b72016-07-25 22:00:064476 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4477 expected_root_draw_rect.Scale(device_scale_factor);
4478 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4479 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144480
jaydasika8640f9f2015-11-10 01:34:364481 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324482 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594483 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4484 expected_child_transform.Translate(child->position().x(),
4485 child->position().y());
[email protected]fb661802013-03-25 01:59:324486 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444487 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324488 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104489 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324490 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444491 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324492 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104493 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144494
jaydasika8640f9f2015-11-10 01:34:364495 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324496 // match.
danakjddaec912015-09-25 19:38:404497 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144498
[email protected]fb661802013-03-25 01:59:324499 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444500 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144501 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104502 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144503
jaydasika8640f9f2015-11-10 01:34:364504 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444505 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364506 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104507 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454508
danakjddaec912015-09-25 19:38:404509 gfx::RectF expected_child_draw_rect(child->position(),
4510 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324511 expected_child_draw_rect.Scale(device_scale_factor);
4512 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4513 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364514 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4515 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144516}
4517
enne637715732015-07-07 02:05:264518TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324519 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324520 gfx::Transform perspective_matrix;
4521 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094522
[email protected]fb661802013-03-25 01:59:324523 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054524 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094525
jaydasikabf1875a2016-06-28 03:39:594526 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064527 root->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094528
4529 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064530 page_scale->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094531
4532 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
danakje4fa7b72016-07-25 22:00:064533 parent->SetBounds(gfx::Size(100, 100));
jaydasika8640f9f2015-11-10 01:34:364534 parent->SetDrawsContent(true);
[email protected]9781afa2013-07-17 23:15:324535
enne637715732015-07-07 02:05:264536 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064537 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4538 perspective_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044539 perspective_surface->test_properties()->transform =
4540 perspective_matrix * scale_small_matrix;
enne637715732015-07-07 02:05:264541 perspective_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064542 perspective_surface->test_properties()->force_render_surface = true;
[email protected]1b30e8e2012-12-21 02:59:094543
enne637715732015-07-07 02:05:264544 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064545 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4546 scale_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044547 scale_surface->test_properties()->transform = scale_small_matrix;
enne637715732015-07-07 02:05:264548 scale_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064549 scale_surface->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:284550
[email protected]fb661802013-03-25 01:59:324551 float device_scale_factor = 2.5f;
4552 float page_scale_factor = 3.f;
sunxdc5d4fb42016-05-27 04:40:094553 root->layer_tree_impl()->SetViewportLayersFromIds(
4554 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4555 Layer::INVALID_ID);
jaydasika4340ea02016-06-06 19:44:264556 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094557 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264558 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:284559 root, nullptr);
[email protected]1b30e8e2012-12-21 02:59:094560
danakj59931942016-07-26 22:11:294561 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4562 parent->GetIdealContentsScale());
4563 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4564 perspective_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594565 // Ideal scale is the max 2d scale component of the combined transform up to
4566 // the nearest render target. Here this includes the layer transform as well
4567 // as the device and page scale factors.
4568 gfx::Transform transform = scale_small_matrix;
4569 transform.Scale(device_scale_factor * page_scale_factor,
4570 device_scale_factor * page_scale_factor);
4571 gfx::Vector2dF scales =
4572 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4573 float max_2d_scale = std::max(scales.x(), scales.y());
danakj59931942016-07-26 22:11:294574 EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594575
4576 // The ideal scale will draw 1:1 with its render target space along
4577 // the larger-scale axis.
4578 gfx::Vector2dF target_space_transform_scales =
4579 MathUtil::ComputeTransform2dScaleComponents(
4580 scale_surface->draw_properties().target_space_transform, 0.f);
4581 EXPECT_FLOAT_EQ(max_2d_scale,
4582 std::max(target_space_transform_scales.x(),
4583 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094584
enne637715732015-07-07 02:05:264585 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094586
[email protected]fb661802013-03-25 01:59:324587 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594588 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4589 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324590 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444591 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094592
[email protected]fb661802013-03-25 01:59:324593 // The scale for the perspective surface is not known, so it is rendered 1:1
4594 // with the screen, and then scaled during drawing.
4595 gfx::Transform expected_perspective_surface_draw_transform;
4596 expected_perspective_surface_draw_transform.Translate(
4597 device_scale_factor * page_scale_factor *
4598 perspective_surface->position().x(),
4599 device_scale_factor * page_scale_factor *
4600 perspective_surface->position().y());
4601 expected_perspective_surface_draw_transform.PreconcatTransform(
4602 perspective_matrix);
4603 expected_perspective_surface_draw_transform.PreconcatTransform(
4604 scale_small_matrix);
4605 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594606 expected_perspective_surface_layer_draw_transform.Scale(
4607 device_scale_factor * page_scale_factor,
4608 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324609 EXPECT_TRANSFORMATION_MATRIX_EQ(
4610 expected_perspective_surface_draw_transform,
4611 perspective_surface->render_surface()->draw_transform());
4612 EXPECT_TRANSFORMATION_MATRIX_EQ(
4613 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444614 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094615}
4616
enne637715732015-07-07 02:05:264617TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294618 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264619 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294620 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4621
4622 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264623 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294624 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4625
jaydasikabf1875a2016-06-28 03:39:594626 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294627 root->SetBounds(gfx::Size(100, 100));
4628
enne637715732015-07-07 02:05:264629 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064630 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044631 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364632 parent->SetDrawsContent(true);
[email protected]35a99a12013-05-09 23:52:294633
enne637715732015-07-07 02:05:264634 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064635 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4636 child_scale->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044637 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364638 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284639
[email protected]fb661802013-03-25 01:59:324640 float device_scale_factor = 2.5f;
4641 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214642
[email protected]989386c2013-07-18 21:37:234643 {
enne637715732015-07-07 02:05:264644 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:284645 root, nullptr);
[email protected]11ec92972012-11-10 03:06:214646
sohan.jyotie3bd6192014-10-13 07:13:594647 // The ideal scale is able to go below 1.
4648 float expected_ideal_scale =
4649 device_scale_factor * page_scale_factor * initial_parent_scale;
4650 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294651 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale());
[email protected]11ec92972012-11-10 03:06:214652
sohan.jyotie3bd6192014-10-13 07:13:594653 expected_ideal_scale = device_scale_factor * page_scale_factor *
4654 initial_parent_scale * initial_child_scale;
4655 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294656 EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale());
[email protected]989386c2013-07-18 21:37:234657 }
[email protected]11ec92972012-11-10 03:06:214658}
4659
enne637715732015-07-07 02:05:264660TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324661 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264662 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324663 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264664
[email protected]fb661802013-03-25 01:59:324665 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264666 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324667 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264668
jaydasikabf1875a2016-06-28 03:39:594669 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294670 root->SetBounds(gfx::Size(100, 100));
4671
enne637715732015-07-07 02:05:264672 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064673 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044674 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364675 parent->SetDrawsContent(true);
[email protected]6a9cff92012-11-08 11:53:264676
enne637715732015-07-07 02:05:264677 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064678 child_scale->SetBounds(gfx::Size(10, 10));
4679 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
jaydasika10d43fc2016-08-18 04:06:044680 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364681 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284682
danakje4fa7b72016-07-25 22:00:064683 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264684
danakj59931942016-07-26 22:11:294685 EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale());
danakje4fa7b72016-07-25 22:00:064686 // Animating layers compute ideal scale in the same way as when
4687 // they are static.
danakj59931942016-07-26 22:11:294688 EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale,
4689 child_scale->GetIdealContentsScale());
[email protected]6a9cff92012-11-08 11:53:264690}
4691
[email protected]989386c2013-07-18 21:37:234692TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594693 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064694 parent->SetBounds(gfx::Size(30, 30));
enneea850232015-07-27 16:43:124695 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064696 parent->Set3dSortingContextId(1);
4697 parent->test_properties()->should_flatten_transform = false;
[email protected]94f206c12012-08-25 00:09:144698
enneea850232015-07-27 16:43:124699 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064700 child->SetBounds(gfx::Size(10, 10));
4701 child->SetPosition(gfx::PointF(2.f, 2.f));
enneea850232015-07-27 16:43:124702 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064703 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:144704
[email protected]fb661802013-03-25 01:59:324705 // This layer should end up in the same surface as child, with the same draw
4706 // and screen space transforms.
enneea850232015-07-27 16:43:124707 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:064708 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
enneea850232015-07-27 16:43:124709 duplicate_child_non_owner->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144710
[email protected]fb661802013-03-25 01:59:324711 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124712 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144713
[email protected]fb661802013-03-25 01:59:324714 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004715 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124716 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144717
[email protected]fb661802013-03-25 01:59:324718 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594719 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324720 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104721 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324722 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444723 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144724
[email protected]fb661802013-03-25 01:59:324725 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594726 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324727 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444728 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144729
[email protected]fb661802013-03-25 01:59:324730 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594731 expected_screen_space_transform.Scale(device_scale_factor,
4732 device_scale_factor);
4733 expected_screen_space_transform.Translate(child->position().x(),
4734 child->position().y());
[email protected]fb661802013-03-25 01:59:324735 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104736 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144737
[email protected]fb661802013-03-25 01:59:324738 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444739 child->DrawTransform();
trchendba8b1502016-07-08 09:47:014740 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform,
ajumad9432e32015-11-30 19:43:444741 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324742 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104743 child->ScreenSpaceTransform(),
4744 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324745 EXPECT_EQ(child->drawable_content_rect(),
4746 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144747 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144748
[email protected]fb661802013-03-25 01:59:324749 gfx::Transform expected_render_surface_draw_transform;
4750 expected_render_surface_draw_transform.Translate(
4751 device_scale_factor * child->position().x(),
4752 device_scale_factor * child->position().y());
4753 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4754 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144755
[email protected]fb661802013-03-25 01:59:324756 gfx::Transform expected_surface_draw_transform;
4757 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4758 device_scale_factor * 2.f);
4759 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4760 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144761
[email protected]fb661802013-03-25 01:59:324762 gfx::Transform expected_surface_screen_space_transform;
4763 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4764 device_scale_factor * 2.f);
4765 EXPECT_TRANSFORMATION_MATRIX_EQ(
4766 expected_surface_screen_space_transform,
4767 child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474768}
4769
[email protected]989386c2013-07-18 21:37:234770TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324771 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
jaydasikabf1875a2016-06-28 03:39:594772 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064773 parent->SetBounds(gfx::Size(33, 31));
enneea850232015-07-27 16:43:124774 parent->SetDrawsContent(true);
[email protected]904e9132012-11-01 00:12:474775
enneea850232015-07-27 16:43:124776 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064777 child->SetBounds(gfx::Size(13, 11));
enneea850232015-07-27 16:43:124778 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064779 child->test_properties()->force_render_surface = true;
[email protected]904e9132012-11-01 00:12:474780
[email protected]873639e2013-07-24 19:56:314781 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124782 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474783
[email protected]fb661802013-03-25 01:59:324784 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004785 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124786 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474787
danakjf78fb272016-07-26 19:06:154788 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324789 child->render_surface()->draw_transform());
danakjf78fb272016-07-26 19:06:154790 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324791 child->render_surface()->draw_transform());
4792 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:154793 gfx::Transform(), child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144794}
4795
jaydasikadb41a582016-03-28 20:48:214796TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314797 scoped_refptr<Layer> root = Layer::Create();
4798 scoped_refptr<Layer> child = Layer::Create();
4799 scoped_refptr<Layer> grand_child = Layer::Create();
4800 scoped_refptr<Layer> mask_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:144801
[email protected]fb661802013-03-25 01:59:324802 child->AddChild(grand_child.get());
4803 child->SetMaskLayer(mask_layer.get());
4804 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144805
ennea7b43c32015-06-18 20:01:334806 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284807
[email protected]fb661802013-03-25 01:59:324808 int nonexistent_id = -1;
xingliu95d9e6b62016-08-18 03:53:084809 LayerTree* layer_tree = host()->GetLayerTree();
4810 EXPECT_EQ(root.get(), layer_tree->LayerById(root->id()));
4811 EXPECT_EQ(child.get(), layer_tree->LayerById(child->id()));
4812 EXPECT_EQ(grand_child.get(), layer_tree->LayerById(grand_child->id()));
4813 EXPECT_EQ(mask_layer.get(), layer_tree->LayerById(mask_layer->id()));
xingliu95d9e6b62016-08-18 03:53:084814 EXPECT_FALSE(layer_tree->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144815}
4816
[email protected]989386c2013-07-18 21:37:234817TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
jaydasikabf1875a2016-06-28 03:39:594818 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324819 LayerImpl* child = AddChild<LayerImpl>(root);
4820 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]498ec6e0e2012-11-30 18:24:574821
danakje4fa7b72016-07-25 22:00:064822 root->SetBounds(gfx::Size(100, 100));
4823 child->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:184824 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:064825 grand_child->SetBounds(gfx::Size(10, 10));
4826 grand_child->SetDrawsContent(true);
ajuma4711f4b12016-05-16 18:48:324827 ExecuteCalculateDrawProperties(root);
ennec1332992015-08-24 19:45:094828 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:574829}
4830
[email protected]989386c2013-07-18 21:37:234831TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164832 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564833 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:014834 FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider,
pimanc44437a22016-10-29 00:09:224835 &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:164836 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:484837 std::unique_ptr<LayerImpl> root =
4838 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064839 root->SetBounds(gfx::Size(100, 100));
[email protected]f90fc412013-03-30 20:13:164840 root->SetDrawsContent(true);
4841
danakj60bc3bc2016-04-09 00:24:484842 std::unique_ptr<LayerImpl> child =
4843 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064844 child->SetBounds(gfx::Size(50, 50));
[email protected]f90fc412013-03-30 20:13:164845 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:184846 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:164847
jaydasika9cb21c772016-05-10 22:37:084848 const int child_id = child->id();
jaydasika89f7b5a2016-06-22 02:08:394849 root->test_properties()->AddChild(std::move(child));
jaydasika9cb21c772016-05-10 22:37:084850 root->SetHasRenderSurface(true);
4851 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594852 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
jaydasika4340ea02016-06-06 19:44:264853 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:274854
[email protected]f90fc412013-03-30 20:13:164855 // Add opacity animation.
loyso9556c732016-03-11 07:54:584856 scoped_refptr<AnimationTimeline> timeline =
4857 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4858 host_impl.animation_host()->AddAnimationTimeline(timeline);
vollickef2ae922016-06-29 17:54:274859 host_impl.pending_tree()->SetElementIdsForTesting();
loyso968163c92016-01-04 23:18:484860
vollickef2ae922016-06-29 17:54:274861 ElementId child_element_id =
4862 host_impl.pending_tree()->LayerById(child_id)->element_id();
4863
4864 AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0,
4865 0.0f, 1.0f, false);
[email protected]f90fc412013-03-30 20:13:164866
[email protected]c0ae06c12013-06-24 18:32:194867 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534868 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:384869 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534870 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574871 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:164872
4873 // We should have one render surface and two layers. The child
4874 // layer should be included even though it is transparent.
4875 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:054876 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:074877
4878 // If the root itself is hidden, the child should not be drawn even if it has
4879 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:184880 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054881 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:074882 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:074883 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:384884 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:074885 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574886 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:074887
jaydasika0c2fd472016-03-24 01:26:054888 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:064889 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:054890 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:074891 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014892 EXPECT_FALSE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404893
4894 // A layer should be drawn and it should contribute to drawn surface when
4895 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:184896 root_layer->test_properties()->opacity = 1.0f;
4897 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054898 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:404899 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:404900 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:384901 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:404902 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574903 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:404904
jaydasika0c2fd472016-03-24 01:26:054905 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
4906 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:404907 node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014908 EXPECT_TRUE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404909 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:064910
4911 // But if the opacity of the layer remains 0 after activation, it should not
4912 // be drawn.
4913 host_impl.ActivateSyncTree();
danakj0da42ca62016-07-01 19:42:334914 LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id());
jaydasika8185d302016-04-14 15:20:064915 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
4916
4917 EffectTree& active_effect_tree =
4918 host_impl.active_tree()->property_trees()->effect_tree;
4919 EXPECT_TRUE(active_effect_tree.needs_update());
4920
4921 ExecuteCalculateDrawProperties(active_root);
4922
4923 node = active_effect_tree.Node(active_child->effect_tree_index());
trchendba8b1502016-07-08 09:47:014924 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:064925 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
4926 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:164927}
4928
danakj3f76ace2014-11-18 16:56:004929using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:264930class LCDTextTest : public LayerTreeHostCommonTestBase,
4931 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:364932 public:
4933 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:224934 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
4935 host_impl_(LCDTextTestLayerTreeSettings(),
4936 &task_runner_provider_,
danakj59931942016-07-26 22:11:294937 &task_graph_runner_) {}
enneaf5bda32015-02-19 01:27:364938
loyso968163c92016-01-04 23:18:484939 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
4940
[email protected]fb661802013-03-25 01:59:324941 protected:
sunxd5a7a4032016-06-01 18:49:224942 LayerTreeSettings LCDTextTestLayerTreeSettings() {
danakj59931942016-07-26 22:11:294943 LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings();
sunxd5a7a4032016-06-01 18:49:224944
4945 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4946 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4947 settings.can_use_lcd_text = can_use_lcd_text_;
4948 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
4949 return settings;
4950 }
4951
dcheng93a52eb2014-12-23 02:14:234952 void SetUp() override {
loyso9556c732016-03-11 07:54:584953 timeline_ =
4954 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4955 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:484956
danakj60bc3bc2016-04-09 00:24:484957 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:364958 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:484959 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:364960 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:484961 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:364962 LayerImpl::Create(host_impl_.active_tree(), 3);
4963
4964 // Stash raw pointers to look at later.
4965 root_ = root_ptr.get();
4966 child_ = child_ptr.get();
4967 grand_child_ = grand_child_ptr.get();
4968
jaydasika89f7b5a2016-06-22 02:08:394969 child_->test_properties()->AddChild(std::move(grand_child_ptr));
4970 root_->test_properties()->AddChild(std::move(child_ptr));
jaydasikabf1875a2016-06-28 03:39:594971 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:594972
vollickef2ae922016-06-29 17:54:274973 host_impl_.active_tree()->SetElementIdsForTesting();
4974
fmalita51b5e202014-11-18 20:11:504975 root_->SetContentsOpaque(true);
4976 child_->SetContentsOpaque(true);
4977 grand_child_->SetContentsOpaque(true);
4978
jaydasika3f930c12015-06-30 15:18:254979 root_->SetDrawsContent(true);
4980 child_->SetDrawsContent(true);
4981 grand_child_->SetDrawsContent(true);
4982
danakje4fa7b72016-07-25 22:00:064983 root_->SetBounds(gfx::Size(1, 1));
4984 child_->SetBounds(gfx::Size(1, 1));
4985 grand_child_->SetBounds(gfx::Size(1, 1));
4986
4987 child_->test_properties()->force_render_surface =
4988 std::tr1::get<2>(GetParam());
[email protected]fb661802013-03-25 01:59:324989 }
[email protected]10aabcc32012-12-13 09:18:594990
[email protected]fb661802013-03-25 01:59:324991 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:004992 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:364993
khushalsagarb64b360d2015-10-21 19:25:164994 FakeImplTaskRunnerProvider task_runner_provider_;
reveman34b7a1522015-03-23 20:27:474995 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:364996 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:484997 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:364998
danakj59931942016-07-26 22:11:294999 LayerImpl* root_ = nullptr;
5000 LayerImpl* child_ = nullptr;
5001 LayerImpl* grand_child_ = nullptr;
[email protected]10aabcc32012-12-13 09:18:595002};
5003
[email protected]fb661802013-03-25 01:59:325004TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005005 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5006 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5007
[email protected]fb661802013-03-25 01:59:325008 // Case 1: Identity transform.
flackre310f292016-10-12 21:09:285009 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225010 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5011 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5012 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595013
[email protected]fb661802013-03-25 01:59:325014 // Case 2: Integral translation.
5015 gfx::Transform integral_translation;
5016 integral_translation.Translate(1.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045017 child_->test_properties()->transform = integral_translation;
jaydasika3f930c12015-06-30 15:18:255018 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackre310f292016-10-12 21:09:285019 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225020 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5021 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5022 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595023
[email protected]fb661802013-03-25 01:59:325024 // Case 3: Non-integral translation.
5025 gfx::Transform non_integral_translation;
5026 non_integral_translation.Translate(1.5, 2.5);
jaydasika10d43fc2016-08-18 04:06:045027 child_->test_properties()->transform = non_integral_translation;
jaydasika3f930c12015-06-30 15:18:255028 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackre310f292016-10-12 21:09:285029 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225030 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5031 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5032 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595033
[email protected]fb661802013-03-25 01:59:325034 // Case 4: Rotation.
5035 gfx::Transform rotation;
5036 rotation.Rotate(10.0);
jaydasika10d43fc2016-08-18 04:06:045037 child_->test_properties()->transform = rotation;
jaydasika3f930c12015-06-30 15:18:255038 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackre310f292016-10-12 21:09:285039 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225040 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5041 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5042 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595043
[email protected]fb661802013-03-25 01:59:325044 // Case 5: Scale.
5045 gfx::Transform scale;
5046 scale.Scale(2.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045047 child_->test_properties()->transform = scale;
jaydasika3f930c12015-06-30 15:18:255048 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackre310f292016-10-12 21:09:285049 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225050 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5051 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5052 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595053
[email protected]fb661802013-03-25 01:59:325054 // Case 6: Skew.
5055 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105056 skew.Skew(10.0, 0.0);
jaydasika10d43fc2016-08-18 04:06:045057 child_->test_properties()->transform = skew;
jaydasika3f930c12015-06-30 15:18:255058 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackre310f292016-10-12 21:09:285059 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225060 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5061 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5062 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595063
[email protected]fb661802013-03-25 01:59:325064 // Case 7: Translucent.
jaydasika10d43fc2016-08-18 04:06:045065 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255066 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185067 child_->test_properties()->opacity = 0.5f;
flackre310f292016-10-12 21:09:285068 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225069 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5070 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5071 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595072
[email protected]fb661802013-03-25 01:59:325073 // Case 8: Sanity check: restore transform and opacity.
jaydasika10d43fc2016-08-18 04:06:045074 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255075 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185076 child_->test_properties()->opacity = 1.f;
flackre310f292016-10-12 21:09:285077 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225078 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5079 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5080 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505081
5082 // Case 9: Non-opaque content.
5083 child_->SetContentsOpaque(false);
flackre310f292016-10-12 21:09:285084 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225085 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5086 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5087 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505088
5089 // Case 10: Sanity check: restore content opaqueness.
5090 child_->SetContentsOpaque(true);
flackre310f292016-10-12 21:09:285091 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225092 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5093 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5094 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595095}
5096
[email protected]fd9a3b6d2013-08-03 00:46:175097TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005098 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335099 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005100
[email protected]fb661802013-03-25 01:59:325101 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackre310f292016-10-12 21:09:285102 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225103 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5104 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5105 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595106
[email protected]fb661802013-03-25 01:59:325107 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:185108 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:255109 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
vollickef2ae922016-06-29 17:54:275110
5111 SetElementIdsForTesting();
5112
5113 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5114 10.0, 0.9f, 0.1f, false);
flackre310f292016-10-12 21:09:285115 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:335116 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:225117 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5118 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5119 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335120}
5121
5122TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5123 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5124 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5125
5126 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackre310f292016-10-12 21:09:285127 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225128 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5129 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5130 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
vollickef2ae922016-06-29 17:54:275131 SetElementIdsForTesting();
fmalitafcd926a2015-05-13 20:19:335132
5133 // Mark contents non-opaque within the first animation frame.
5134 child_->SetContentsOpaque(false);
vollickef2ae922016-06-29 17:54:275135 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5136 10.0, 0.9f, 0.1f, false);
flackre310f292016-10-12 21:09:285137 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:335138 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:225139 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5140 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5141 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595142}
5143
5144INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5145 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005146 testing::Combine(testing::Bool(),
5147 testing::Bool(),
5148 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595149
[email protected]989386c2013-07-18 21:37:235150TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165151 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565152 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225153 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195154 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195155
danakj60bc3bc2016-04-09 00:24:485156 std::unique_ptr<LayerImpl> root =
5157 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065158 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195159 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065160 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195161
danakj60bc3bc2016-04-09 00:24:485162 std::unique_ptr<LayerImpl> child =
5163 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065164 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195165 child->SetDrawsContent(true);
5166
danakj60bc3bc2016-04-09 00:24:485167 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195168 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065169 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195170 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355171 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195172
jaydasika89f7b5a2016-06-22 02:08:395173 child->test_properties()->AddChild(std::move(grand_child));
5174 root->test_properties()->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005175 root->SetHasRenderSurface(true);
jaydasikabf1875a2016-06-28 03:39:595176 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195177
5178 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535179 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385180 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535181 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575182 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195183
5184 // We should have one render surface and two layers. The grand child has
5185 // hidden itself.
5186 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055187 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5188 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5189 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195190}
5191
[email protected]989386c2013-07-18 21:37:235192TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165193 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565194 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225195 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195196 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195197
danakj60bc3bc2016-04-09 00:24:485198 std::unique_ptr<LayerImpl> root =
5199 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065200 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195201 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095202 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195203
danakj60bc3bc2016-04-09 00:24:485204 std::unique_ptr<LayerImpl> child =
5205 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065206 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195207 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355208 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195209
danakj60bc3bc2016-04-09 00:24:485210 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195211 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065212 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195213 grand_child->SetDrawsContent(true);
5214
jaydasika89f7b5a2016-06-22 02:08:395215 child->test_properties()->AddChild(std::move(grand_child));
5216 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:595217 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195218
5219 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535220 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385221 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535222 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575223 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195224
5225 // We should have one render surface and one layers. The child has
5226 // hidden itself and the grand child.
5227 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095228 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5229 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195230}
5231
danakj60bc3bc2016-04-09 00:24:485232void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455233
[email protected]989386c2013-07-18 21:37:235234TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165235 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565236 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225237 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455238 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455239
danakj60bc3bc2016-04-09 00:24:485240 std::unique_ptr<LayerImpl> root =
5241 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065242 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305243 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095244 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455245
danakj60bc3bc2016-04-09 00:24:485246 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305247 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065248 copy_grand_parent->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305249 copy_grand_parent->SetDrawsContent(true);
5250 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455251
danakj60bc3bc2016-04-09 00:24:485252 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305253 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065254 copy_parent->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305255 copy_parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065256 copy_parent->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305257 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455258
danakj60bc3bc2016-04-09 00:24:485259 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305260 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065261 copy_request->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305262 copy_request->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065263 copy_request->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305264 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455265
danakj60bc3bc2016-04-09 00:24:485266 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305267 LayerImpl::Create(host_impl.pending_tree(), 5);
danakje4fa7b72016-07-25 22:00:065268 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305269 copy_child->SetDrawsContent(true);
5270 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455271
danakj60bc3bc2016-04-09 00:24:485272 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405273 LayerImpl::Create(host_impl.pending_tree(), 6);
danakje4fa7b72016-07-25 22:00:065274 copy_grand_child->SetBounds(gfx::Size(20, 20));
5275 copy_grand_child->SetDrawsContent(true);
jaydasika86654512016-01-27 17:05:075276 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5277
danakj60bc3bc2016-04-09 00:24:485278 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075279 LayerImpl::Create(host_impl.pending_tree(), 7);
danakje4fa7b72016-07-25 22:00:065280 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305281 copy_grand_parent_sibling_before->SetDrawsContent(true);
5282 LayerImpl* copy_grand_parent_sibling_before_layer =
5283 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535284
danakj60bc3bc2016-04-09 00:24:485285 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075286 LayerImpl::Create(host_impl.pending_tree(), 8);
danakje4fa7b72016-07-25 22:00:065287 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305288 copy_grand_parent_sibling_after->SetDrawsContent(true);
5289 LayerImpl* copy_grand_parent_sibling_after_layer =
5290 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535291
jaydasika89f7b5a2016-06-22 02:08:395292 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
5293 copy_request->test_properties()->AddChild(std::move(copy_child));
5294 copy_parent->test_properties()->AddChild(std::move(copy_request));
5295 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
5296 root->test_properties()->AddChild(
5297 std::move(copy_grand_parent_sibling_before));
5298 root->test_properties()->AddChild(std::move(copy_grand_parent));
5299 root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasikabf1875a2016-06-28 03:39:595300 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285301
[email protected]30fe19ff2013-07-04 00:54:455302 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075303 // hidden subtree on copy_layer. Also hide the copy grand child and its
5304 // subtree.
jaydasika5121caa82016-05-05 15:43:355305 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5306 copy_grand_parent_sibling_before_layer->test_properties()
5307 ->hide_layer_and_subtree = true;
5308 copy_grand_parent_sibling_after_layer->test_properties()
5309 ->hide_layer_and_subtree = true;
5310 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305311
ajumae6f541b2016-05-31 16:50:505312 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305313 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455314
weiliangc51fb255d2015-07-24 15:32:305315 LayerImplList render_surface_layer_list;
5316 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385317 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535318 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575319 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455320
jaydasika2411692c2016-03-23 01:56:095321 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025322 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5323 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5324 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535325
jaydasika86654512016-01-27 17:05:075326 // We should have four render surfaces, one for the root, one for the grand
5327 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455328 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075329 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095330 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075331 EXPECT_EQ(copy_grand_parent_layer->id(),
5332 render_surface_layer_list.at(1)->id());
5333 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5334 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455335
jaydasika86654512016-01-27 17:05:075336 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095337 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5338 EXPECT_EQ(root_layer->id(),
5339 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075340 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095341 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455342
[email protected]7392c7b2014-02-07 08:28:285343 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455344 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305345 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455346 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065347 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455348
5349 // The copy_layer's render surface should have two contributing layers.
5350 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5351 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235352 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305353 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235354 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075355
5356 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5357 // but the copy_layer and copy_child should be drawn for the copy request.
5358 // copy grand child should not be drawn as its hidden even in the copy
5359 // request.
ajumae4af47062016-05-24 23:59:045360 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095361 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075362 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015363 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075364 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015365 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075366 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015367 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075368 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015369 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075370 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015371 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075372
5373 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5374 // actually hidden.
5375 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455376}
5377
[email protected]989386c2013-07-18 21:37:235378TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165379 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565380 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225381 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455382 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455383
danakj60bc3bc2016-04-09 00:24:485384 std::unique_ptr<LayerImpl> root =
5385 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065386 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305387 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455388
danakj60bc3bc2016-04-09 00:24:485389 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305390 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:305391 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455392 copy_parent->SetMasksToBounds(true);
5393
danakj60bc3bc2016-04-09 00:24:485394 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305395 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065396 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305397 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065398 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:455399
danakj60bc3bc2016-04-09 00:24:485400 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305401 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065402 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305403 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455404
ajumae6f541b2016-05-31 16:50:505405 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305406 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455407
jaydasika89f7b5a2016-06-22 02:08:395408 copy_layer->test_properties()->AddChild(std::move(copy_child));
5409 copy_parent->test_properties()->AddChild(std::move(copy_layer));
5410 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305411
5412 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055413 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595414 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305415 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385416 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535417 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575418 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455419
xjze19f76402015-11-06 21:48:445420 // We should have two render surface, as the others are clipped out.
5421 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055422 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455423
xjze19f76402015-11-06 21:48:445424 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455425 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055426 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5427 EXPECT_EQ(root_layer->id(),
5428 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455429}
5430
weiliangcde7e0c32016-06-15 15:02:415431TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595432 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065433 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415434 root->SetDrawsContent(true);
5435 root->SetMasksToBounds(true);
5436
5437 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065438 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415439 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065440 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415441
5442 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065443 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5444 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415445 copy_child->SetDrawsContent(true);
5446
5447 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065448 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415449 copy_clip->SetMasksToBounds(true);
5450
5451 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065452 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5453 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415454 copy_clipped_child->SetDrawsContent(true);
5455
5456 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065457 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5458 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415459 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065460 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415461
5462 copy_layer->test_properties()->copy_requests.push_back(
5463 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5464
weiliangce22ce842016-07-04 23:31:535465 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415466 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535467 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415468
5469 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5470 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5471 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5472 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5473
5474 // Case 2: When the non root copy request layer is clipped.
5475 copy_layer->SetBounds(gfx::Size(50, 50));
5476 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535477 copy_layer->test_properties()->copy_requests.push_back(
5478 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415479 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5480
weiliangce22ce842016-07-04 23:31:535481 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415482 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535483 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415484
5485 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5486 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5487 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5488 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515489
5490 // Case 3: When there is device scale factor.
5491 float device_scale_factor = 2.f;
5492 copy_layer->test_properties()->copy_requests.push_back(
5493 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5494
5495 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5496 ExecuteCalculateDrawProperties(root, device_scale_factor);
5497 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5498
5499 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5500 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5501 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5502 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415503}
5504
[email protected]420fdf6e2013-08-26 20:36:385505TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5506 // Ensure that a transform between the layer and its render surface is not a
5507 // problem. Constructs the following layer tree.
5508 //
5509 // root (a render surface)
5510 // + render_surface
5511 // + clip_parent (scaled)
5512 // + intervening_clipping_layer
5513 // + clip_child
5514 //
5515 // The render surface should be resized correctly and the clip child should
5516 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595517 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315518 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5519 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285520 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315521 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285522 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315523 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5524 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565525 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485526 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315527 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565528 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385529
5530 intervening->SetMasksToBounds(true);
5531 clip_parent->SetMasksToBounds(true);
5532
[email protected]420fdf6e2013-08-26 20:36:385533 gfx::Transform scale_transform;
5534 scale_transform.Scale(2, 2);
5535
danakjf78fb272016-07-26 19:06:155536 root->SetBounds(gfx::Size(50, 50));
5537 render_surface->SetBounds(gfx::Size(10, 10));
5538 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:045539 clip_parent->test_properties()->transform = scale_transform;
danakjf78fb272016-07-26 19:06:155540 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5541 clip_parent->SetBounds(gfx::Size(10, 10));
5542 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5543 intervening->SetBounds(gfx::Size(5, 5));
5544 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5545 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315546 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385547
5548 ASSERT_TRUE(root->render_surface());
5549 ASSERT_TRUE(render_surface->render_surface());
5550
5551 // Ensure that we've inherited our clip parent's clip and weren't affected
5552 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145553 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5554 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5555 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385556
5557 // Ensure that the render surface reports a content rect that has been grown
5558 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145559 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5560 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385561
5562 // The above check implies the two below, but they nicely demonstrate that
5563 // we've grown, despite the intervening layer's clip.
5564 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5565 render_surface->render_surface()->content_rect()));
5566 ASSERT_FALSE(intervening->clip_rect().Contains(
5567 render_surface->render_surface()->content_rect()));
5568}
5569
5570TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5571 // Ensure that intervening render surfaces are not a problem in the basic
5572 // case. In the following tree, both render surfaces should be resized to
5573 // accomodate for the clip child, despite an intervening clip.
5574 //
5575 // root (a render surface)
5576 // + clip_parent (masks to bounds)
5577 // + render_surface1 (sets opacity)
5578 // + intervening (masks to bounds)
5579 // + render_surface2 (also sets opacity)
5580 // + clip_child
5581 //
jaydasikabf1875a2016-06-28 03:39:595582 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235583 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5584 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5585 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5586 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5587 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365588 render_surface1->SetDrawsContent(true);
5589 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235590 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385591
jaydasika1c0a27d42016-04-28 01:54:565592 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385593
5594 intervening->SetMasksToBounds(true);
5595 clip_parent->SetMasksToBounds(true);
5596
[email protected]420fdf6e2013-08-26 20:36:385597 gfx::Transform translation_transform;
5598 translation_transform.Translate(2, 2);
5599
danakjf78fb272016-07-26 19:06:155600 root->SetBounds(gfx::Size(50, 50));
5601 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5602 clip_parent->SetBounds(gfx::Size(40, 40));
5603 render_surface1->SetBounds(gfx::Size(10, 10));
5604 render_surface1->test_properties()->force_render_surface = true;
5605 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5606 intervening->SetBounds(gfx::Size(5, 5));
5607 render_surface2->SetBounds(gfx::Size(10, 10));
5608 render_surface2->test_properties()->force_render_surface = true;
5609 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5610 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235611 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385612
5613 EXPECT_TRUE(root->render_surface());
5614 EXPECT_TRUE(render_surface1->render_surface());
5615 EXPECT_TRUE(render_surface2->render_surface());
5616
5617 // Since the render surfaces could have expanded, they should not clip (their
5618 // bounds would no longer be reliable). We should resort to layer clipping
5619 // in this case.
jaydasika6f972de2016-04-07 16:16:145620 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5621 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385622 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145623 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5624 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385625 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5626
5627 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145628 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385629 EXPECT_TRUE(render_surface1->is_clipped());
5630
5631 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145632 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385633 EXPECT_TRUE(render_surface2->is_clipped());
5634
5635 // The content rects of both render surfaces should both have expanded to
5636 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145637 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5638 render_surface1->render_surface()->content_rect());
5639 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5640 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385641
5642 // The clip child should have inherited the clip parent's clip (projected to
5643 // the right space, of course), and should have the correctly sized visible
5644 // content rect.
jaydasika6f972de2016-04-07 16:16:145645 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5646 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385647 EXPECT_TRUE(clip_child->is_clipped());
5648}
5649
5650TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5651 // Ensure that intervening render surfaces are not a problem, even if there
5652 // is a scroll involved. Note, we do _not_ have to consider any other sort
5653 // of transform.
5654 //
5655 // root (a render surface)
5656 // + clip_parent (masks to bounds)
5657 // + render_surface1 (sets opacity)
5658 // + intervening (masks to bounds AND scrolls)
5659 // + render_surface2 (also sets opacity)
5660 // + clip_child
5661 //
jaydasikabf1875a2016-06-28 03:39:595662 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235663 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5664 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5665 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5666 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5667 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365668 render_surface1->SetDrawsContent(true);
5669 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235670 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385671
jaydasika1c0a27d42016-04-28 01:54:565672 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385673
5674 intervening->SetMasksToBounds(true);
5675 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235676 intervening->SetScrollClipLayer(clip_parent->id());
5677 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385678
5679 gfx::Transform translation_transform;
5680 translation_transform.Translate(2, 2);
5681
danakjf78fb272016-07-26 19:06:155682 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:045683 clip_parent->test_properties()->transform = translation_transform;
danakjf78fb272016-07-26 19:06:155684 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5685 clip_parent->SetBounds(gfx::Size(40, 40));
5686 render_surface1->SetBounds(gfx::Size(10, 10));
5687 render_surface1->test_properties()->force_render_surface = true;
5688 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5689 intervening->SetBounds(gfx::Size(5, 5));
5690 render_surface2->SetBounds(gfx::Size(10, 10));
5691 render_surface2->test_properties()->force_render_surface = true;
5692 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5693 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235694 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385695
5696 EXPECT_TRUE(root->render_surface());
5697 EXPECT_TRUE(render_surface1->render_surface());
5698 EXPECT_TRUE(render_surface2->render_surface());
5699
5700 // Since the render surfaces could have expanded, they should not clip (their
5701 // bounds would no longer be reliable). We should resort to layer clipping
5702 // in this case.
jaydasika6f972de2016-04-07 16:16:145703 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5704 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385705 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145706 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5707 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385708 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5709
5710 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145711 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385712 EXPECT_TRUE(render_surface1->is_clipped());
5713
5714 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145715 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385716 EXPECT_TRUE(render_surface2->is_clipped());
5717
5718 // The content rects of both render surfaces should both have expanded to
5719 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145720 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5721 render_surface1->render_surface()->content_rect());
5722 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
5723 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385724
5725 // The clip child should have inherited the clip parent's clip (projected to
5726 // the right space, of course), and should have the correctly sized visible
5727 // content rect.
jaydasika6f972de2016-04-07 16:16:145728 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
5729 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385730 EXPECT_TRUE(clip_child->is_clipped());
5731}
5732
5733TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5734 // Ensures that descendants of the clip child inherit the correct clip.
5735 //
5736 // root (a render surface)
5737 // + clip_parent (masks to bounds)
5738 // + intervening (masks to bounds)
5739 // + clip_child
5740 // + child
5741 //
jaydasikabf1875a2016-06-28 03:39:595742 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175743 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5744 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5745 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5746 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365747 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175748 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385749
jaydasika1c0a27d42016-04-28 01:54:565750 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155751 clip_parent->test_properties()->clip_children =
5752 base::MakeUnique<std::set<LayerImpl*>>();
5753 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385754
danakjf78fb272016-07-26 19:06:155755 root->SetBounds(gfx::Size(50, 50));
5756 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385757 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155758 intervening->SetBounds(gfx::Size(5, 5));
5759 intervening->SetMasksToBounds(true);
5760 clip_child->SetBounds(gfx::Size(60, 60));
5761 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385762
enne2d0d8e62015-08-18 18:29:175763 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385764
5765 EXPECT_TRUE(root->render_surface());
5766
5767 // Neither the clip child nor its descendant should have inherited the clip
5768 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145769 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385770 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145771 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385772 EXPECT_TRUE(child->is_clipped());
5773}
5774
5775TEST_F(LayerTreeHostCommonTest,
5776 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5777 // Ensures that non-descendant clip children in the tree do not affect
5778 // render surfaces.
5779 //
5780 // root (a render surface)
5781 // + clip_parent (masks to bounds)
5782 // + render_surface1
5783 // + clip_child
5784 // + render_surface2
5785 // + non_clip_child
5786 //
5787 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595788 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505789 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5790 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5791 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
enneb441cdd2015-07-28 22:47:505792 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
5793 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385794
jaydasika1c0a27d42016-04-28 01:54:565795 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155796 clip_parent->test_properties()->clip_children =
5797 base::MakeUnique<std::set<LayerImpl*>>();
5798 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385799
5800 clip_parent->SetMasksToBounds(true);
5801 render_surface1->SetMasksToBounds(true);
5802
danakjf78fb272016-07-26 19:06:155803 render_surface1->SetDrawsContent(true);
5804 clip_child->SetDrawsContent(true);
5805 render_surface2->SetDrawsContent(true);
5806 non_clip_child->SetDrawsContent(true);
5807
5808 root->SetBounds(gfx::Size(15, 15));
5809 clip_parent->SetBounds(gfx::Size(10, 10));
5810 render_surface1->SetPosition(gfx::PointF(5, 5));
5811 render_surface1->SetBounds(gfx::Size(5, 5));
5812 render_surface1->test_properties()->force_render_surface = true;
5813 render_surface2->SetBounds(gfx::Size(5, 5));
5814 render_surface2->test_properties()->force_render_surface = true;
5815 clip_child->SetPosition(gfx::PointF(-1, 1));
5816 clip_child->SetBounds(gfx::Size(10, 10));
5817 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:385818
enneb441cdd2015-07-28 22:47:505819 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385820
5821 EXPECT_TRUE(root->render_surface());
5822 EXPECT_TRUE(render_surface1->render_surface());
5823 EXPECT_TRUE(render_surface2->render_surface());
5824
jaydasika6f972de2016-04-07 16:16:145825 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385826 EXPECT_TRUE(render_surface1->is_clipped());
5827
5828 // The render surface should not clip (it has unclipped descendants), instead
5829 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:145830 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5831 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385832 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5833
jaydasika0d98ba92015-11-17 05:17:285834 // That said, it should have grown to accomodate the unclipped descendant and
5835 // its own size.
jaydasika6f972de2016-04-07 16:16:145836 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
5837 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385838
5839 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:145840 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
5841 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385842 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:425843 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385844
5845 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:145846 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
5847 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385848
5849 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:215850 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
5851 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:385852}
5853
weiliangc9ced1592015-11-17 19:04:375854TEST_F(LayerTreeHostCommonTest,
5855 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5856 // Verifies that Render Surfaces are created at the edge of rendering context.
5857
jaydasikabf1875a2016-06-28 03:39:595858 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:265859 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
5860 LayerImpl* child2 = AddChild<LayerImpl>(child1);
5861 LayerImpl* child3 = AddChild<LayerImpl>(child2);
5862 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375863
weiliangc9ced1592015-11-17 19:04:375864 gfx::Size bounds(100, 100);
5865
danakjf78fb272016-07-26 19:06:155866 root->SetBounds(bounds);
5867 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265868 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155869 child1->Set3dSortingContextId(1);
5870 child1->test_properties()->should_flatten_transform = false;
5871 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265872 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375873 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155874 child3->SetBounds(bounds);
5875 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375876 child3->Set3dSortingContextId(1);
jaydasika6ed869662016-09-21 14:29:595877 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
weiliangc9ced1592015-11-17 19:04:375878
5879 // Verify which render surfaces were created.
5880 EXPECT_TRUE(root->has_render_surface());
5881 EXPECT_FALSE(child1->has_render_surface());
5882 EXPECT_TRUE(child2->has_render_surface());
5883 EXPECT_FALSE(child3->has_render_surface());
5884}
5885
[email protected]45948712013-09-27 02:46:485886TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:165887 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565888 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225889 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:265890
danakj60bc3bc2016-04-09 00:24:485891 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:485892 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:485893 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:485894 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:485895 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:485896 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:485897 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:485898 LayerImpl::Create(host_impl.active_tree(), 12345678);
5899
[email protected]45948712013-09-27 02:46:485900 gfx::Size bounds(100, 100);
danakjf78fb272016-07-26 19:06:155901
5902 root->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485903 root->SetDrawsContent(true);
5904
5905 // This layer structure normally forces render surface due to preserves3d
5906 // behavior.
danakjf78fb272016-07-26 19:06:155907 child1->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485908 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155909 child1->Set3dSortingContextId(1);
5910 child1->test_properties()->should_flatten_transform = false;
5911 child2->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485912 child2->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:285913 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155914 child3->SetBounds(bounds);
5915 child3->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:285916 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:575917
jaydasika89f7b5a2016-06-22 02:08:395918 child2->test_properties()->AddChild(std::move(child3));
5919 child1->test_properties()->AddChild(std::move(child2));
5920 root->test_properties()->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:055921 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595922 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
[email protected]45948712013-09-27 02:46:485923
5924 {
5925 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055926 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:485927 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385928 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:485929 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:575930 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:485931
5932 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:025933
5934 int count_represents_target_render_surface = 0;
5935 int count_represents_contributing_render_surface = 0;
5936 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:515937 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5938 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:025939 it != end; ++it) {
5940 if (it.represents_target_render_surface())
5941 count_represents_target_render_surface++;
5942 if (it.represents_contributing_render_surface())
5943 count_represents_contributing_render_surface++;
5944 if (it.represents_itself())
5945 count_represents_itself++;
5946 }
5947
5948 // Two render surfaces.
5949 EXPECT_EQ(2, count_represents_target_render_surface);
5950 // Second render surface contributes to root render surface.
5951 EXPECT_EQ(1, count_represents_contributing_render_surface);
5952 // All 4 layers represent itself.
5953 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:485954 }
5955
5956 {
5957 LayerImplList render_surface_layer_list;
5958 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385959 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:485960 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:575961 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:485962
5963 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:025964
5965 int count_represents_target_render_surface = 0;
5966 int count_represents_contributing_render_surface = 0;
5967 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:515968 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5969 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:025970 it != end; ++it) {
5971 if (it.represents_target_render_surface())
5972 count_represents_target_render_surface++;
5973 if (it.represents_contributing_render_surface())
5974 count_represents_contributing_render_surface++;
5975 if (it.represents_itself())
5976 count_represents_itself++;
5977 }
5978
5979 // Only root layer has a render surface.
5980 EXPECT_EQ(1, count_represents_target_render_surface);
5981 // No layer contributes a render surface to root render surface.
5982 EXPECT_EQ(0, count_represents_contributing_render_surface);
5983 // All 4 layers represent itself.
5984 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:485985 }
5986}
5987
[email protected]a9aa60a82013-08-29 04:28:265988TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:595989 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:335990 LayerImpl* back_facing = AddChild<LayerImpl>(root);
5991 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
5992 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
5993 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
5994 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:155995
jaydasikae00c8a42016-01-28 20:18:335996 child1->SetDrawsContent(true);
5997 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:265998
danakjf78fb272016-07-26 19:06:155999 root->SetBounds(gfx::Size(50, 50));
[email protected]a9d4d4f2014-06-19 06:49:286000 root->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:156001 root->test_properties()->should_flatten_transform = false;
6002 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikae00c8a42016-01-28 20:18:336003 back_facing->Set3dSortingContextId(1);
jaydasikaca2605e2016-04-23 02:52:526004 back_facing->test_properties()->should_flatten_transform = false;
danakjf78fb272016-07-26 19:06:156005 render_surface1->SetBounds(gfx::Size(30, 30));
6006 render_surface1->Set3dSortingContextId(1);
6007 render_surface1->test_properties()->should_flatten_transform = false;
6008 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366009 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156010 render_surface2->SetBounds(gfx::Size(30, 30));
6011 // Different context from the rest.
jaydasikae00c8a42016-01-28 20:18:336012 render_surface2->Set3dSortingContextId(2);
danakjf78fb272016-07-26 19:06:156013 render_surface2->test_properties()->should_flatten_transform = false;
6014 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366015 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156016 child1->SetBounds(gfx::Size(20, 20));
6017 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:266018
enne03b0e9a2015-06-19 00:08:026019 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266020
jaydasikae00c8a42016-01-28 20:18:336021 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
6022 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
6023 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6024 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026025 ->at(0)
6026 ->render_surface()
6027 ->layer_list()
6028 .size());
6029 EXPECT_EQ(1u, render_surface_layer_list_impl()
6030 ->at(1)
6031 ->render_surface()
6032 ->layer_list()
6033 .size());
[email protected]a9aa60a82013-08-29 04:28:266034
danakjf78fb272016-07-26 19:06:156035 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:266036 rotation_transform.RotateAboutXAxis(180.0);
6037
jaydasika10d43fc2016-08-18 04:06:046038 back_facing->test_properties()->transform = rotation_transform;
jaydasika5aa88b82015-11-10 01:48:036039 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266040
enne03b0e9a2015-06-19 00:08:026041 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266042
jaydasikae00c8a42016-01-28 20:18:336043 // render_surface1 is in the same 3d rendering context as back_facing and is
6044 // not double sided, so it should not be in RSLL. render_surface2 is also not
6045 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6046 // context.
6047 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6048 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026049 ->at(0)
6050 ->render_surface()
6051 ->layer_list()
6052 .size());
[email protected]a9aa60a82013-08-29 04:28:266053}
6054
ajumaaa0d3862015-11-09 22:24:466055TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:596056 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:466057 LayerImpl* child = AddChild<LayerImpl>(root);
6058 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:466059
danakjf78fb272016-07-26 19:06:156060 root->SetBounds(gfx::Size(50, 50));
6061 root->test_properties()->should_flatten_transform = false;
6062 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:366063 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156064 child->test_properties()->should_flatten_transform = false;
6065 grand_child->SetBounds(gfx::Size(20, 20));
6066 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:466067 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:156068 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:466069 ExecuteCalculateDrawProperties(root);
6070
6071 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6072 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6073 ->at(0)
6074 ->render_surface()
6075 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556076
6077 // As all layers have identity transform, we shouldn't check for backface
6078 // visibility.
6079 EXPECT_FALSE(root->should_check_backface_visibility());
6080 EXPECT_FALSE(child->should_check_backface_visibility());
6081 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6082 // As there are no 3d rendering contexts, all layers should use their local
6083 // transform for backface visibility.
6084 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6085 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6086 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6087
danakjf78fb272016-07-26 19:06:156088 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:466089 rotation_transform.RotateAboutXAxis(180.0);
6090
jaydasika10d43fc2016-08-18 04:06:046091 child->test_properties()->transform = rotation_transform;
jaydasika62bd3dd2016-02-04 18:52:556092 child->Set3dSortingContextId(1);
6093 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466094 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6095
6096 ExecuteCalculateDrawProperties(root);
6097 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6098 EXPECT_EQ(0u, render_surface_layer_list_impl()
6099 ->at(0)
6100 ->render_surface()
6101 ->layer_list()
6102 .size());
jaydasika62bd3dd2016-02-04 18:52:556103
6104 // We should check for backface visibilty of child as it has a rotation
6105 // transform. We should also check for grand_child as it uses the backface
6106 // visibility of its parent.
6107 EXPECT_FALSE(root->should_check_backface_visibility());
6108 EXPECT_TRUE(child->should_check_backface_visibility());
6109 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6110 // child uses its local transform for backface visibility as it is the root of
6111 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6112 // the root, but it derives its backface visibility from its parent which uses
6113 // its local transform.
6114 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6115 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6116 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6117
6118 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366119 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556120 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6121
6122 ExecuteCalculateDrawProperties(root);
6123 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6124 EXPECT_EQ(0u, render_surface_layer_list_impl()
6125 ->at(0)
6126 ->render_surface()
6127 ->layer_list()
6128 .size());
6129
6130 // We should check the backface visibility of child as it has a rotation
6131 // transform and for grand_child as it is in a 3d rendering context and not
6132 // the root of it.
6133 EXPECT_FALSE(root->should_check_backface_visibility());
6134 EXPECT_TRUE(child->should_check_backface_visibility());
6135 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6136 // grand_child is in an existing 3d rendering context, so it should not use
6137 // local transform for backface visibility.
6138 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6139 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6140 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466141}
6142
sunxd59dd7da2016-05-19 20:07:476143TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:596144 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:476145 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6146 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6147 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6148
sunxd59dd7da2016-05-19 20:07:476149 gfx::Transform rotate_about_y;
6150 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:476151
danakjf78fb272016-07-26 19:06:156152 root->SetBounds(gfx::Size(50, 50));
6153 root->Set3dSortingContextId(1);
6154 root->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:046155 back_facing->test_properties()->transform = rotate_about_y;
danakjf78fb272016-07-26 19:06:156156 back_facing->SetBounds(gfx::Size(50, 50));
6157 back_facing->Set3dSortingContextId(1);
6158 back_facing->test_properties()->should_flatten_transform = false;
6159 render_surface1->SetBounds(gfx::Size(30, 30));
6160 render_surface1->Set3dSortingContextId(1);
6161 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476162 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156163 render_surface1->test_properties()->force_render_surface = true;
6164 render_surface2->SetBounds(gfx::Size(30, 30));
6165 render_surface2->Set3dSortingContextId(1);
6166 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476167 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156168 render_surface2->test_properties()->force_render_surface = true;
sunxd59dd7da2016-05-19 20:07:476169 ExecuteCalculateDrawProperties(root);
6170
6171 const EffectTree& tree =
6172 root->layer_tree_impl()->property_trees()->effect_tree;
6173 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016174 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476175 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016176 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476177
jaydasika09e16132016-08-24 21:39:346178 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6179 gfx::Transform(), back_facing->transform_tree_index(),
6180 root->layer_tree_impl());
6181 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6182 rotate_about_y, render_surface2->transform_tree_index(),
6183 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476184 ExecuteCalculateDrawProperties(root);
6185 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016186 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476187 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016188 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476189
jaydasika09e16132016-08-24 21:39:346190 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6191 rotate_about_y, render_surface1->transform_tree_index(),
6192 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476193 ExecuteCalculateDrawProperties(root);
6194 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016195 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476196 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016197 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476198}
6199
[email protected]995708c52013-10-17 20:52:596200TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6201 // Checks that the simple case (being clipped by a scroll parent that would
6202 // have been processed before you anyhow) results in the right clips.
6203 //
6204 // + root
6205 // + scroll_parent_border
6206 // | + scroll_parent_clip
6207 // | + scroll_parent
6208 // + scroll_child
6209 //
jaydasikabf1875a2016-06-28 03:39:596210 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:486211 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6212 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6213 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6214 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596215
enne085b48a2015-08-18 17:54:486216 scroll_parent->SetDrawsContent(true);
6217 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596218 scroll_parent_clip->SetMasksToBounds(true);
6219
jaydasika1c0a27d42016-04-28 01:54:566220 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156221 scroll_parent->test_properties()->scroll_children =
6222 base::MakeUnique<std::set<LayerImpl*>>();
6223 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596224
danakjf78fb272016-07-26 19:06:156225 root->SetBounds(gfx::Size(50, 50));
6226 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6227 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6228 scroll_parent->SetBounds(gfx::Size(50, 50));
6229 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:486230 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596231
6232 EXPECT_TRUE(root->render_surface());
6233
jaydasika6f972de2016-04-07 16:16:146234 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596235 EXPECT_TRUE(scroll_child->is_clipped());
6236}
6237
jaydasika8ccff3d2016-01-20 19:51:306238TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6239 // Tests the computation of draw transform for the scroll child when its
6240 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:596241 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:306242 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6243 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6244 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6245 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6246
6247 scroll_parent->SetDrawsContent(true);
6248 scroll_child->SetDrawsContent(true);
6249
jaydasika1c0a27d42016-04-28 01:54:566250 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156251 scroll_parent->test_properties()->scroll_children =
6252 base::MakeUnique<std::set<LayerImpl*>>();
6253 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:306254
danakjf78fb272016-07-26 19:06:156255 root->SetBounds(gfx::Size(50, 50));
6256 scroll_child_target->SetBounds(gfx::Size(50, 50));
6257 scroll_child_target->test_properties()->force_render_surface = true;
6258 scroll_child->SetBounds(gfx::Size(50, 50));
6259 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
6260 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:006261 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156262 scroll_parent_target->test_properties()->force_render_surface = true;
6263 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:306264
jaydasika2489a442016-01-29 02:26:006265 float device_scale_factor = 1.5f;
6266 LayerImplList render_surface_layer_list_impl;
jaydasikab4df4032016-09-13 18:38:496267 gfx::Size device_viewport_size =
6268 gfx::Size(root->bounds().width() * device_scale_factor,
6269 root->bounds().height() * device_scale_factor);
jaydasika2489a442016-01-29 02:26:006270 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasikab4df4032016-09-13 18:38:496271 root, device_viewport_size, gfx::Transform(),
6272 &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006273 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576274 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006275
weiliangc1da3fb892016-03-14 20:23:526276 EXPECT_EQ(scroll_child->effect_tree_index(),
6277 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006278 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6279 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6280 gfx::Transform scale;
6281 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:026282 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306283}
6284
[email protected]08bdf1b2014-04-16 23:23:296285TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:596286 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:196287 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:196288 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:156289
6290 root->SetBounds(gfx::Size(50, 50));
6291 root->SetDrawsContent(true);
6292 root->Set3dSortingContextId(1);
6293 parent->SetBounds(gfx::Size(30, 30));
6294 parent->SetDrawsContent(true);
6295 parent->Set3dSortingContextId(1);
6296 parent->test_properties()->force_render_surface = true;
6297 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:196298 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156299 child->Set3dSortingContextId(1);
6300 child->test_properties()->force_render_surface = true;
enneca33fed2015-07-27 18:22:196301 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296302
enneca33fed2015-07-27 18:22:196303 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296304
6305 gfx::Transform singular_transform;
6306 singular_transform.Scale3d(
6307 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6308
jaydasika10d43fc2016-08-18 04:06:046309 child->test_properties()->transform = singular_transform;
[email protected]08bdf1b2014-04-16 23:23:296310
sunxd71aea3e2016-04-01 23:48:056311 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196312 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296313
enneca33fed2015-07-27 18:22:196314 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296315
6316 // Ensure that the entire subtree under a layer with singular transform does
6317 // not get rendered.
jaydasika10d43fc2016-08-18 04:06:046318 parent->test_properties()->transform = singular_transform;
6319 child->test_properties()->transform = gfx::Transform();
[email protected]08bdf1b2014-04-16 23:23:296320
sunxd71aea3e2016-04-01 23:48:056321 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196322 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296323
enneca33fed2015-07-27 18:22:196324 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296325}
6326
[email protected]995708c52013-10-17 20:52:596327TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6328 // Checks that clipping by a scroll parent that follows you in paint order
6329 // still results in correct clipping.
6330 //
6331 // + root
[email protected]995708c52013-10-17 20:52:596332 // + scroll_parent_border
6333 // + scroll_parent_clip
6334 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026335 // + scroll_child
[email protected]995708c52013-10-17 20:52:596336 //
jaydasikabf1875a2016-06-28 03:39:596337 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026338 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6339 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6340 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6341 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596342
enne03b0e9a2015-06-19 00:08:026343 scroll_parent->SetDrawsContent(true);
6344 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596345
danakjf78fb272016-07-26 19:06:156346 root->SetBounds(gfx::Size(50, 50));
6347 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6348 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:596349 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156350 scroll_parent->SetBounds(gfx::Size(50, 50));
6351 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596352
jaydasika1c0a27d42016-04-28 01:54:566353 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156354 scroll_parent->test_properties()->scroll_children =
6355 base::MakeUnique<std::set<LayerImpl*>>();
6356 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596357
enne03b0e9a2015-06-19 00:08:026358 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596359
6360 EXPECT_TRUE(root->render_surface());
6361
jaydasika6f972de2016-04-07 16:16:146362 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596363 EXPECT_TRUE(scroll_child->is_clipped());
6364}
6365
6366TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6367 // Checks that clipping by a scroll parent and scroll grandparent that follow
6368 // you in paint order still results in correct clipping.
6369 //
6370 // + root
6371 // + scroll_child
6372 // + scroll_parent_border
6373 // | + scroll_parent_clip
6374 // | + scroll_parent
6375 // + scroll_grandparent_border
6376 // + scroll_grandparent_clip
6377 // + scroll_grandparent
6378 //
jaydasikabf1875a2016-06-28 03:39:596379 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026380 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6381 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6382 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6383 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6384 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6385 LayerImpl* scroll_grandparent_clip =
6386 AddChild<LayerImpl>(scroll_grandparent_border);
6387 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596388
enne03b0e9a2015-06-19 00:08:026389 scroll_parent->SetDrawsContent(true);
6390 scroll_grandparent->SetDrawsContent(true);
6391 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596392
6393 scroll_parent_clip->SetMasksToBounds(true);
6394 scroll_grandparent_clip->SetMasksToBounds(true);
6395
jaydasika1c0a27d42016-04-28 01:54:566396 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156397 scroll_parent->test_properties()->scroll_children =
6398 base::MakeUnique<std::set<LayerImpl*>>();
6399 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386400
jaydasika1c0a27d42016-04-28 01:54:566401 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156402 scroll_grandparent->test_properties()->scroll_children =
6403 base::MakeUnique<std::set<LayerImpl*>>();
6404 scroll_grandparent->test_properties()->scroll_children->insert(
6405 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596406
danakjf78fb272016-07-26 19:06:156407 root->SetBounds(gfx::Size(50, 50));
6408 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6409 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6410 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6411 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6412 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6413 scroll_parent->SetBounds(gfx::Size(50, 50));
6414 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596415
enne03b0e9a2015-06-19 00:08:026416 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596417
6418 EXPECT_TRUE(root->render_surface());
6419
jaydasika6f972de2016-04-07 16:16:146420 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596421 EXPECT_TRUE(scroll_child->is_clipped());
6422
6423 // Despite the fact that we visited the above layers out of order to get the
6424 // correct clip, the layer lists should be unaffected.
6425 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026426 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6427 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6428 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596429}
6430
6431TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6432 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226433 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596434 // + root
6435 // + scroll_child
6436 // + scroll_parent_border
6437 // + scroll_parent_clip
6438 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026439 // + render_surface2
[email protected]995708c52013-10-17 20:52:596440 // + scroll_grandparent_border
6441 // + scroll_grandparent_clip
6442 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026443 // + render_surface1
[email protected]995708c52013-10-17 20:52:596444 //
jaydasikabf1875a2016-06-28 03:39:596445 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026446 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596447
enne03b0e9a2015-06-19 00:08:026448 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6449 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596450
enne03b0e9a2015-06-19 00:08:026451 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6452 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6453 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6454 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6455 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6456 LayerImpl* scroll_grandparent_clip =
6457 AddChild<LayerImpl>(scroll_grandparent_border);
6458 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6459 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596460
enne03b0e9a2015-06-19 00:08:026461 scroll_parent->SetDrawsContent(true);
6462 render_surface1->SetDrawsContent(true);
6463 scroll_grandparent->SetDrawsContent(true);
6464 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596465
6466 scroll_parent_clip->SetMasksToBounds(true);
6467 scroll_grandparent_clip->SetMasksToBounds(true);
6468
jaydasika1c0a27d42016-04-28 01:54:566469 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156470 scroll_parent->test_properties()->scroll_children =
6471 base::MakeUnique<std::set<LayerImpl*>>();
6472 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386473
jaydasika1c0a27d42016-04-28 01:54:566474 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156475 scroll_grandparent->test_properties()->scroll_children =
6476 base::MakeUnique<std::set<LayerImpl*>>();
6477 scroll_grandparent->test_properties()->scroll_children->insert(
6478 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596479
danakjf78fb272016-07-26 19:06:156480 root->SetBounds(gfx::Size(50, 50));
6481 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6482 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6483 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6484 render_surface1->SetBounds(gfx::Size(50, 50));
6485 render_surface1->test_properties()->force_render_surface = true;
6486 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6487 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6488 scroll_parent->SetBounds(gfx::Size(50, 50));
6489 render_surface2->SetBounds(gfx::Size(50, 50));
6490 render_surface2->test_properties()->force_render_surface = true;
6491 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596492
enne03b0e9a2015-06-19 00:08:026493 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596494
6495 EXPECT_TRUE(root->render_surface());
6496
jaydasika6f972de2016-04-07 16:16:146497 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596498 EXPECT_TRUE(scroll_child->is_clipped());
6499
6500 // Despite the fact that we had to process the layers out of order to get the
6501 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026502 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6503 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6504 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6505 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6506 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6507 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6508 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596509}
6510
ajuma0b10f942015-03-21 07:45:536511TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6512 // Ensures that when we have a render surface between a fixed position layer
6513 // and its container, we compute the fixed position layer's draw transform
6514 // with respect to that intervening render surface, not with respect to its
6515 // container's render target.
6516 //
6517 // + root
6518 // + render_surface
6519 // + fixed
ajuma737b2702015-05-06 01:18:376520 // + child
ajuma0b10f942015-03-21 07:45:536521 //
jaydasikabf1875a2016-06-28 03:39:596522 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516523 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6524 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6525 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536526
jaydasika6b5a32bf2016-04-22 21:56:366527 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526528 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536529
6530 LayerPositionConstraint constraint;
6531 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526532 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536533
danakjf78fb272016-07-26 19:06:156534 root->SetBounds(gfx::Size(50, 50));
6535 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6536 render_surface->SetBounds(gfx::Size(50, 50));
6537 render_surface->SetDrawsContent(true);
6538 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6539 fixed->SetBounds(gfx::Size(50, 50));
6540 fixed->SetDrawsContent(true);
6541 child->SetPosition(gfx::PointF(1.f, 2.f));
6542 child->SetBounds(gfx::Size(50, 50));
6543 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516544 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536545
jaydasikabaede2d92016-07-20 00:34:326546 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516547 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326548 EffectTree& effect_tree =
6549 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156550
ajuma737b2702015-05-06 01:18:376551 gfx::Transform expected_fixed_draw_transform;
6552 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026553 EXPECT_TRANSFORMATION_MATRIX_EQ(
6554 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326555 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536556
ajuma737b2702015-05-06 01:18:376557 gfx::Transform expected_fixed_screen_space_transform;
6558 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026559 EXPECT_TRANSFORMATION_MATRIX_EQ(
6560 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326561 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376562
6563 gfx::Transform expected_child_draw_transform;
6564 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026565 EXPECT_TRANSFORMATION_MATRIX_EQ(
6566 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326567 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376568
6569 gfx::Transform expected_child_screen_space_transform;
6570 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026571 EXPECT_TRANSFORMATION_MATRIX_EQ(
6572 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326573 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536574}
6575
[email protected]d81752b2013-10-25 08:32:236576TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6577 // This test verifies that a scrolling layer that gets snapped to
6578 // integer coordinates doesn't move a fixed position child.
6579 //
6580 // + root
6581 // + container
6582 // + scroller
6583 // + fixed
6584 //
khushalsagarb64b360d2015-10-21 19:25:166585 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:566586 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:226587 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236588 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486589 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426590 LayerImpl::Create(host_impl.active_tree(), 1);
6591 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486592 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236593 LayerImpl::Create(host_impl.active_tree(), 2);
6594 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486595 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236596 LayerImpl::Create(host_impl.active_tree(), 3);
6597 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486598 std::unique_ptr<LayerImpl> fixed =
6599 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236600 LayerImpl* fixed_layer = fixed.get();
6601
jaydasikaca2605e2016-04-23 02:52:526602 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236603
6604 LayerPositionConstraint constraint;
6605 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526606 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236607
[email protected]adeda572014-01-31 00:49:476608 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236609
[email protected]d81752b2013-10-25 08:32:236610 gfx::Transform container_transform;
6611 container_transform.Translate3d(10.0, 20.0, 0.0);
6612 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6613
danakjf78fb272016-07-26 19:06:156614 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046615 container->test_properties()->transform = container_transform;
danakjf78fb272016-07-26 19:06:156616 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286617 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156618 scroller->SetBounds(gfx::Size(30, 30));
jaydasika0d98ba92015-11-17 05:17:286619 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156620 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286621 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156622
jaydasika89f7b5a2016-06-22 02:08:396623 scroller->test_properties()->AddChild(std::move(fixed));
6624 container->test_properties()->AddChild(std::move(scroller));
6625 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486626 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6627 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236628
6629 // Rounded to integers already.
6630 {
6631 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426632 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236633
6634 LayerImplList render_surface_layer_list;
6635 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386636 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:426637 root->layer_tree_impl()
6638 ->property_trees()
6639 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576640 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236641
6642 EXPECT_TRANSFORMATION_MATRIX_EQ(
6643 container_layer->draw_properties().screen_space_transform,
6644 fixed_layer->draw_properties().screen_space_transform);
6645 EXPECT_VECTOR_EQ(
6646 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6647 container_offset);
6648 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6649 .screen_space_transform.To2dTranslation(),
6650 container_offset - scroll_delta);
6651 }
6652
6653 // Scroll delta requiring rounding.
6654 {
6655 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426656 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236657
6658 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6659
6660 LayerImplList render_surface_layer_list;
6661 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386662 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576663 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236664
6665 EXPECT_TRANSFORMATION_MATRIX_EQ(
6666 container_layer->draw_properties().screen_space_transform,
6667 fixed_layer->draw_properties().screen_space_transform);
6668 EXPECT_VECTOR_EQ(
6669 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6670 container_offset);
6671 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6672 .screen_space_transform.To2dTranslation(),
6673 container_offset - rounded_scroll_delta);
6674 }
[email protected]cf15ad7b2014-04-02 03:59:266675
6676 // Scale is applied earlier in the tree.
6677 {
sunxdb7e79432016-03-09 21:13:426678 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266679 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286680 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:046681 container_layer->test_properties()->transform = scaled_container_transform;
danakj74af409e2016-07-01 00:41:486682
jaydasika0d98ba92015-11-17 05:17:286683 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266684
6685 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426686 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266687
6688 LayerImplList render_surface_layer_list;
6689 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386690 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576691 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266692
6693 EXPECT_TRANSFORMATION_MATRIX_EQ(
6694 container_layer->draw_properties().screen_space_transform,
6695 fixed_layer->draw_properties().screen_space_transform);
6696 EXPECT_VECTOR_EQ(
6697 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6698 container_offset);
6699
jaydasika10d43fc2016-08-18 04:06:046700 container_layer->test_properties()->transform = container_transform;
[email protected]cf15ad7b2014-04-02 03:59:266701 }
[email protected]d81752b2013-10-25 08:32:236702}
6703
miletus2c78036b2015-01-29 20:52:376704TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506705 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6706 // This test verifies that a scrolling layer whose screen space transform is
6707 // animating doesn't get snapped to integer coordinates.
6708 //
6709 // + root
6710 // + animated layer
6711 // + surface
6712 // + container
6713 // + scroller
6714 //
jaydasikabf1875a2016-06-28 03:39:596715 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506716 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6717 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6718 LayerImpl* container = AddChild<LayerImpl>(surface);
6719 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506720
ajuma5e8e40d2015-07-31 01:50:506721 gfx::Transform start_scale;
6722 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156723
6724 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046725 animated_layer->test_properties()->transform = start_scale;
danakjf78fb272016-07-26 19:06:156726 animated_layer->SetBounds(gfx::Size(50, 50));
6727 surface->SetBounds(gfx::Size(50, 50));
6728 surface->test_properties()->force_render_surface = true;
6729 container->SetBounds(gfx::Size(50, 50));
6730 scroller->SetBounds(gfx::Size(100, 100));
6731 scroller->SetScrollClipLayer(container->id());
6732 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506733
6734 gfx::Transform end_scale;
6735 end_scale.Scale(2.f, 2.f);
6736 TransformOperations start_operations;
6737 start_operations.AppendMatrix(start_scale);
6738 TransformOperations end_operations;
6739 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276740 SetElementIdsForTesting();
6741
6742 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6743 timeline_impl(), 1.0,
6744 start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:506745 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426746 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506747
6748 ExecuteCalculateDrawProperties(root);
6749
6750 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6751 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446752 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506753}
6754
sunxd8a9a60982016-07-29 18:46:566755TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6756 // This test verifies that a scrolling child of a scrolling layer doesn't get
6757 // snapped to integer coordinates.
6758 //
6759 // + root
6760 // + container
6761 // + scroller
6762 // + scroll_child
6763 //
6764 scoped_refptr<Layer> root = Layer::Create();
6765 scoped_refptr<Layer> container = Layer::Create();
6766 scoped_refptr<Layer> scroller = Layer::Create();
6767 scoped_refptr<Layer> scroll_child = Layer::Create();
6768 root->AddChild(container);
6769 root->AddChild(scroll_child);
6770 container->AddChild(scroller);
6771 host()->SetRootLayer(root);
6772
6773 scroller->SetScrollClipLayerId(container->id());
6774 scroll_child->SetScrollParent(scroller.get());
6775
6776 gfx::Transform rotate;
6777 rotate.RotateAboutYAxis(30);
6778 root->SetBounds(gfx::Size(50, 50));
6779 container->SetBounds(gfx::Size(50, 50));
6780 scroller->SetBounds(gfx::Size(100, 100));
6781 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6782 scroll_child->SetBounds(gfx::Size(10, 10));
6783 scroll_child->SetTransform(rotate);
6784
6785 ExecuteCalculateDrawProperties(root.get());
6786
6787 host()->host_impl()->CreatePendingTree();
6788 host()->CommitAndCreatePendingTree();
6789 host()->host_impl()->ActivateSyncTree();
6790 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6791
6792 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6793 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6794 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
6795 gfx::Vector2dF scroll_delta(5.f, 9.f);
6796 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6797
6798 ExecuteCalculateDrawProperties(root_impl);
6799
6800 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6801 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6802 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6803
6804 gfx::Transform expected_scroll_child_screen_space_transform;
6805 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6806 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6807 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6808 scroll_child_impl->ScreenSpaceTransform());
6809}
6810
flackr2215b4e2016-09-21 20:16:016811TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
6812 scoped_refptr<Layer> root = Layer::Create();
6813 scoped_refptr<Layer> container = Layer::Create();
6814 scoped_refptr<Layer> scroller = Layer::Create();
6815 scoped_refptr<Layer> sticky_pos = Layer::Create();
6816 root->AddChild(container);
6817 container->AddChild(scroller);
6818 scroller->AddChild(sticky_pos);
6819 host()->SetRootLayer(root);
6820 scroller->SetScrollClipLayerId(container->id());
6821
6822 LayerStickyPositionConstraint sticky_position;
6823 sticky_position.is_sticky = true;
6824 sticky_position.is_anchored_top = true;
6825 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:426826 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
flackr2215b4e2016-09-21 20:16:016827 sticky_position.scroll_container_relative_sticky_box_rect =
6828 gfx::Rect(10, 20, 10, 10);
6829 sticky_position.scroll_container_relative_containing_block_rect =
6830 gfx::Rect(0, 0, 50, 50);
6831 sticky_pos->SetStickyPositionConstraint(sticky_position);
6832
6833 root->SetBounds(gfx::Size(100, 100));
6834 container->SetBounds(gfx::Size(100, 100));
6835 scroller->SetBounds(gfx::Size(1000, 1000));
6836 sticky_pos->SetBounds(gfx::Size(10, 10));
6837 sticky_pos->SetPosition(gfx::PointF(10, 20));
6838
6839 ExecuteCalculateDrawProperties(root.get());
6840 host()->host_impl()->CreatePendingTree();
6841 host()->CommitAndCreatePendingTree();
6842 host()->host_impl()->ActivateSyncTree();
6843 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6844
6845 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6846 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6847 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6848
6849 ExecuteCalculateDrawProperties(root_impl);
6850 EXPECT_VECTOR2DF_EQ(
6851 gfx::Vector2dF(10.f, 20.f),
6852 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6853
6854 // Scroll less than sticking point, sticky element should move with scroll as
6855 // we haven't gotten to the initial sticky item location yet.
6856 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6857 ExecuteCalculateDrawProperties(root_impl);
6858 EXPECT_VECTOR2DF_EQ(
6859 gfx::Vector2dF(5.f, 15.f),
6860 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6861
6862 // Scroll past the sticking point, the Y coordinate should now be clamped.
6863 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6864 ExecuteCalculateDrawProperties(root_impl);
6865 EXPECT_VECTOR2DF_EQ(
6866 gfx::Vector2dF(-5.f, 10.f),
6867 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6868 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6869 ExecuteCalculateDrawProperties(root_impl);
6870 EXPECT_VECTOR2DF_EQ(
6871 gfx::Vector2dF(-5.f, 10.f),
6872 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6873
6874 // Scroll past the end of the sticky container (note: this element does not
6875 // have its own layer as it does not need to be composited).
6876 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6877 ExecuteCalculateDrawProperties(root_impl);
6878 EXPECT_VECTOR2DF_EQ(
6879 gfx::Vector2dF(-5.f, -10.f),
6880 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6881}
6882
flackrdc5dfbe2016-10-24 21:43:386883TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) {
6884 scoped_refptr<Layer> root = Layer::Create();
6885 scoped_refptr<Layer> container = Layer::Create();
6886 scoped_refptr<Layer> scroller = Layer::Create();
6887 scoped_refptr<Layer> sticky_pos = Layer::Create();
6888 root->AddChild(container);
6889 container->AddChild(scroller);
6890 scroller->AddChild(sticky_pos);
6891 host()->SetRootLayer(root);
6892 scroller->SetScrollClipLayerId(container->id());
6893
6894 LayerStickyPositionConstraint sticky_position;
6895 sticky_position.is_sticky = true;
6896 sticky_position.is_anchored_bottom = true;
6897 sticky_position.bottom_offset = 10.0f;
6898 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200);
6899 sticky_position.scroll_container_relative_sticky_box_rect =
6900 gfx::Rect(0, 200, 10, 10);
6901 sticky_position.scroll_container_relative_containing_block_rect =
6902 gfx::Rect(0, 0, 100, 500);
6903 sticky_pos->SetStickyPositionConstraint(sticky_position);
6904
6905 root->SetBounds(gfx::Size(100, 100));
6906 container->SetBounds(gfx::Size(100, 100));
6907 scroller->SetBounds(gfx::Size(100, 1000));
6908 sticky_pos->SetBounds(gfx::Size(10, 10));
6909 sticky_pos->SetPosition(gfx::PointF(0, 200));
6910
6911 ExecuteCalculateDrawProperties(root.get());
6912 host()->host_impl()->CreatePendingTree();
6913 host()->CommitAndCreatePendingTree();
6914 host()->host_impl()->ActivateSyncTree();
6915 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6916
6917 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6918 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6919 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6920
6921 ExecuteCalculateDrawProperties(root_impl);
6922 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f));
6923 ExecuteCalculateDrawProperties(root_impl);
6924 EXPECT_VECTOR2DF_EQ(
6925 gfx::Vector2dF(0.f, 80.f),
6926 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6927}
6928
flackr2215b4e2016-09-21 20:16:016929TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
6930 scoped_refptr<Layer> root = Layer::Create();
6931 scoped_refptr<Layer> container = Layer::Create();
6932 scoped_refptr<Layer> scroller = Layer::Create();
6933 scoped_refptr<Layer> sticky_pos = Layer::Create();
6934 root->AddChild(container);
6935 container->AddChild(scroller);
6936 scroller->AddChild(sticky_pos);
6937 host()->SetRootLayer(root);
6938 scroller->SetScrollClipLayerId(container->id());
6939
6940 LayerStickyPositionConstraint sticky_position;
6941 sticky_position.is_sticky = true;
6942 sticky_position.is_anchored_bottom = true;
6943 sticky_position.bottom_offset = 10.0f;
flackr68e1c292016-10-11 16:34:426944 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150);
flackr2215b4e2016-09-21 20:16:016945 sticky_position.scroll_container_relative_sticky_box_rect =
6946 gfx::Rect(0, 150, 10, 10);
6947 sticky_position.scroll_container_relative_containing_block_rect =
6948 gfx::Rect(0, 100, 50, 50);
6949 sticky_pos->SetStickyPositionConstraint(sticky_position);
6950
6951 root->SetBounds(gfx::Size(100, 100));
6952 container->SetBounds(gfx::Size(100, 100));
6953 scroller->SetBounds(gfx::Size(1000, 1000));
6954 sticky_pos->SetBounds(gfx::Size(10, 10));
6955 sticky_pos->SetPosition(gfx::PointF(0, 150));
6956
6957 ExecuteCalculateDrawProperties(root.get());
6958 host()->host_impl()->CreatePendingTree();
6959 host()->CommitAndCreatePendingTree();
6960 host()->host_impl()->ActivateSyncTree();
6961 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6962
6963 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6964 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6965 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6966
6967 // Initially the sticky element is moved up to the top of the container.
6968 ExecuteCalculateDrawProperties(root_impl);
6969 EXPECT_VECTOR2DF_EQ(
6970 gfx::Vector2dF(0.f, 100.f),
6971 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6972 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6973 ExecuteCalculateDrawProperties(root_impl);
6974 EXPECT_VECTOR2DF_EQ(
6975 gfx::Vector2dF(0.f, 95.f),
6976 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6977
6978 // Once we get past the top of the container it moves to be aligned 10px
6979 // up from the the bottom of the scroller.
6980 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
6981 ExecuteCalculateDrawProperties(root_impl);
6982 EXPECT_VECTOR2DF_EQ(
6983 gfx::Vector2dF(0.f, 80.f),
6984 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6985 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
6986 ExecuteCalculateDrawProperties(root_impl);
6987 EXPECT_VECTOR2DF_EQ(
6988 gfx::Vector2dF(0.f, 80.f),
6989 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6990
6991 // Once we scroll past its initial location, it sticks there.
6992 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
6993 ExecuteCalculateDrawProperties(root_impl);
6994 EXPECT_VECTOR2DF_EQ(
6995 gfx::Vector2dF(0.f, 0.f),
6996 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6997}
6998
mdjones2ee41afd2016-10-27 16:50:206999TEST_F(LayerTreeHostCommonTest, StickyPositionBottomHideBrowserControls) {
flackre310f292016-10-12 21:09:287000 scoped_refptr<Layer> root = Layer::Create();
7001 scoped_refptr<Layer> scroller = Layer::Create();
7002 scoped_refptr<Layer> sticky_pos = Layer::Create();
7003 root->AddChild(scroller);
7004 scroller->AddChild(sticky_pos);
7005 host()->SetRootLayer(root);
7006 scroller->SetScrollClipLayerId(root->id());
7007 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller,
7008 nullptr);
7009
7010 LayerStickyPositionConstraint sticky_position;
7011 sticky_position.is_sticky = true;
7012 sticky_position.is_anchored_bottom = true;
7013 sticky_position.bottom_offset = 10.0f;
7014 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150);
7015 sticky_position.scroll_container_relative_sticky_box_rect =
7016 gfx::Rect(0, 150, 10, 10);
7017 sticky_position.scroll_container_relative_containing_block_rect =
7018 gfx::Rect(0, 0, 100, 1000);
7019 sticky_pos->SetStickyPositionConstraint(sticky_position);
7020
7021 root->SetBounds(gfx::Size(100, 100));
7022 scroller->SetBounds(gfx::Size(100, 1000));
7023 sticky_pos->SetBounds(gfx::Size(10, 10));
7024 sticky_pos->SetPosition(gfx::PointF(0, 150));
7025
7026 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7027 scroller.get());
7028 host()->CommitAndCreateLayerImplTree();
7029 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7030 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7031 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id());
7032
7033 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
7034 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7035
7036 // Initially the sticky element is moved to the bottom of the container.
7037 EXPECT_VECTOR2DF_EQ(
7038 gfx::Vector2dF(0.f, 80.f),
7039 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7040
7041 // When we show the toolbar we hide part of the scroll container, this should
7042 // move the sticky element up to remain at the bottom of the clipped
7043 // container.
7044 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f));
7045 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll);
7046 EXPECT_VECTOR2DF_EQ(
7047 gfx::Vector2dF(0.f, 70.f),
7048 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7049}
7050
flackr2215b4e2016-09-21 20:16:017051TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
7052 scoped_refptr<Layer> root = Layer::Create();
7053 scoped_refptr<Layer> container = Layer::Create();
7054 scoped_refptr<Layer> scroller = Layer::Create();
7055 scoped_refptr<Layer> sticky_pos = Layer::Create();
7056 root->AddChild(container);
7057 container->AddChild(scroller);
7058 scroller->AddChild(sticky_pos);
7059 host()->SetRootLayer(root);
7060 scroller->SetScrollClipLayerId(container->id());
7061
7062 LayerStickyPositionConstraint sticky_position;
7063 sticky_position.is_sticky = true;
7064 sticky_position.is_anchored_left = true;
7065 sticky_position.is_anchored_right = true;
7066 sticky_position.left_offset = 10.f;
7067 sticky_position.right_offset = 10.f;
flackr68e1c292016-10-11 16:34:427068 sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0);
flackr2215b4e2016-09-21 20:16:017069 sticky_position.scroll_container_relative_sticky_box_rect =
7070 gfx::Rect(145, 0, 10, 10);
7071 sticky_position.scroll_container_relative_containing_block_rect =
7072 gfx::Rect(100, 0, 100, 100);
7073 sticky_pos->SetStickyPositionConstraint(sticky_position);
7074
7075 root->SetBounds(gfx::Size(100, 100));
7076 container->SetBounds(gfx::Size(100, 100));
7077 scroller->SetBounds(gfx::Size(1000, 1000));
7078 sticky_pos->SetBounds(gfx::Size(10, 10));
7079 sticky_pos->SetPosition(gfx::PointF(145, 0));
7080
7081 ExecuteCalculateDrawProperties(root.get());
7082 host()->host_impl()->CreatePendingTree();
7083 host()->CommitAndCreatePendingTree();
7084 host()->host_impl()->ActivateSyncTree();
7085 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7086
7087 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7088 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7089 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7090
7091 // Initially the sticky element is moved the leftmost side of the container.
7092 ExecuteCalculateDrawProperties(root_impl);
7093 EXPECT_VECTOR2DF_EQ(
7094 gfx::Vector2dF(100.f, 0.f),
7095 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7096 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
7097 ExecuteCalculateDrawProperties(root_impl);
7098 EXPECT_VECTOR2DF_EQ(
7099 gfx::Vector2dF(95.f, 0.f),
7100 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7101
7102 // Once we get past the left side of the container it moves to be aligned 10px
7103 // up from the the right of the scroller.
7104 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
7105 ExecuteCalculateDrawProperties(root_impl);
7106 EXPECT_VECTOR2DF_EQ(
7107 gfx::Vector2dF(80.f, 0.f),
7108 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7109 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
7110 ExecuteCalculateDrawProperties(root_impl);
7111 EXPECT_VECTOR2DF_EQ(
7112 gfx::Vector2dF(80.f, 0.f),
7113 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7114
7115 // When we get to the sticky element's original position we stop sticking
7116 // to the right.
7117 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
7118 ExecuteCalculateDrawProperties(root_impl);
7119 EXPECT_VECTOR2DF_EQ(
7120 gfx::Vector2dF(50.f, 0.f),
7121 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7122 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
7123 ExecuteCalculateDrawProperties(root_impl);
7124 EXPECT_VECTOR2DF_EQ(
7125 gfx::Vector2dF(40.f, 0.f),
7126 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7127
7128 // The element starts sticking to the left once we scroll far enough.
7129 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
7130 ExecuteCalculateDrawProperties(root_impl);
7131 EXPECT_VECTOR2DF_EQ(
7132 gfx::Vector2dF(10.f, 0.f),
7133 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7134 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
7135 ExecuteCalculateDrawProperties(root_impl);
7136 EXPECT_VECTOR2DF_EQ(
7137 gfx::Vector2dF(10.f, 0.f),
7138 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7139
7140 // Finally it stops sticking when it hits the right side of the container.
7141 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
7142 ExecuteCalculateDrawProperties(root_impl);
7143 EXPECT_VECTOR2DF_EQ(
7144 gfx::Vector2dF(0.f, 0.f),
7145 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7146 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
7147 ExecuteCalculateDrawProperties(root_impl);
7148 EXPECT_VECTOR2DF_EQ(
7149 gfx::Vector2dF(-5.f, 0.f),
7150 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7151}
7152
7153// This test ensures that the compositor sticky position code correctly accounts
7154// for the element having been given a position from the main thread sticky
7155// position code.
7156TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
7157 scoped_refptr<Layer> root = Layer::Create();
7158 scoped_refptr<Layer> container = Layer::Create();
7159 scoped_refptr<Layer> scroller = Layer::Create();
7160 scoped_refptr<Layer> sticky_pos = Layer::Create();
7161 root->AddChild(container);
7162 container->AddChild(scroller);
7163 scroller->AddChild(sticky_pos);
7164 host()->SetRootLayer(root);
7165 scroller->SetScrollClipLayerId(container->id());
7166
7167 LayerStickyPositionConstraint sticky_position;
7168 sticky_position.is_sticky = true;
7169 sticky_position.is_anchored_top = true;
7170 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:427171 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
flackr2215b4e2016-09-21 20:16:017172 sticky_position.scroll_container_relative_sticky_box_rect =
7173 gfx::Rect(10, 20, 10, 10);
7174 sticky_position.scroll_container_relative_containing_block_rect =
7175 gfx::Rect(0, 0, 50, 50);
7176 sticky_pos->SetStickyPositionConstraint(sticky_position);
7177
7178 root->SetBounds(gfx::Size(100, 100));
7179 container->SetBounds(gfx::Size(100, 100));
7180 scroller->SetBounds(gfx::Size(1000, 1000));
7181 sticky_pos->SetBounds(gfx::Size(10, 10));
7182 sticky_pos->SetPosition(gfx::PointF(10, 20));
7183
7184 ExecuteCalculateDrawProperties(root.get());
7185 host()->host_impl()->CreatePendingTree();
7186 host()->CommitAndCreatePendingTree();
7187 host()->host_impl()->ActivateSyncTree();
7188 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7189
7190 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7191 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7192 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7193
7194 ExecuteCalculateDrawProperties(root_impl);
7195 EXPECT_VECTOR2DF_EQ(
7196 gfx::Vector2dF(10.f, 20.f),
7197 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7198
7199 // Scroll less than sticking point, sticky element should move with scroll as
7200 // we haven't gotten to the initial sticky item location yet.
7201 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7202 ExecuteCalculateDrawProperties(root_impl);
7203 EXPECT_VECTOR2DF_EQ(
7204 gfx::Vector2dF(5.f, 15.f),
7205 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7206
7207 // Scroll past the sticking point, the Y coordinate should now be clamped.
7208 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7209 ExecuteCalculateDrawProperties(root_impl);
7210 EXPECT_VECTOR2DF_EQ(
7211 gfx::Vector2dF(-5.f, 10.f),
7212 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7213
7214 // Now the main thread commits the new position of the sticky element.
7215 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
7216 sticky_pos->SetPosition(gfx::PointF(10, 25));
7217 ExecuteCalculateDrawProperties(root.get());
7218 host()->host_impl()->CreatePendingTree();
7219 host()->CommitAndCreatePendingTree();
7220 host()->host_impl()->ActivateSyncTree();
7221 layer_tree_impl = host()->host_impl()->active_tree();
7222 root_impl = layer_tree_impl->LayerById(root->id());
7223 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7224 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7225
7226 // The element should still be where it was before. We reset the delta to
7227 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
7228 // thread.
7229 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7230 ExecuteCalculateDrawProperties(root_impl);
7231 EXPECT_VECTOR2DF_EQ(
7232 gfx::Vector2dF(-5.f, 10.f),
7233 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7234
7235 // And if we scroll a little further it remains there.
7236 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7237 ExecuteCalculateDrawProperties(root_impl);
7238 EXPECT_VECTOR2DF_EQ(
7239 gfx::Vector2dF(-5.f, 10.f),
7240 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7241}
7242
flackr68e1c292016-10-11 16:34:427243// This tests the main thread updates with a composited sticky container. In
7244// this case the position received from main is relative to the container but
7245// the constraint rects are relative to the ancestor scroller.
7246TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) {
7247 scoped_refptr<Layer> root = Layer::Create();
7248 scoped_refptr<Layer> container = Layer::Create();
7249 scoped_refptr<Layer> scroller = Layer::Create();
7250 scoped_refptr<Layer> sticky_container = Layer::Create();
7251 scoped_refptr<Layer> sticky_pos = Layer::Create();
7252 root->AddChild(container);
7253 container->AddChild(scroller);
7254 scroller->AddChild(sticky_container);
7255 sticky_container->AddChild(sticky_pos);
7256 host()->SetRootLayer(root);
7257 scroller->SetScrollClipLayerId(container->id());
7258
7259 LayerStickyPositionConstraint sticky_position;
7260 sticky_position.is_sticky = true;
7261 sticky_position.is_anchored_top = true;
7262 sticky_position.top_offset = 10.0f;
7263 // The sticky position layer is only offset by (0, 10) from its parent
7264 // layer, this position is used to determine the offset applied by the main
7265 // thread.
7266 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10);
7267 sticky_position.scroll_container_relative_sticky_box_rect =
7268 gfx::Rect(20, 30, 10, 10);
7269 sticky_position.scroll_container_relative_containing_block_rect =
7270 gfx::Rect(20, 20, 30, 30);
7271 sticky_pos->SetStickyPositionConstraint(sticky_position);
7272
7273 root->SetBounds(gfx::Size(100, 100));
7274 container->SetBounds(gfx::Size(100, 100));
7275 scroller->SetBounds(gfx::Size(1000, 1000));
7276 sticky_container->SetPosition(gfx::PointF(20, 20));
7277 sticky_container->SetBounds(gfx::Size(30, 30));
7278 sticky_pos->SetBounds(gfx::Size(10, 10));
7279 sticky_pos->SetPosition(gfx::PointF(0, 10));
7280
7281 ExecuteCalculateDrawProperties(root.get());
7282 host()->host_impl()->CreatePendingTree();
7283 host()->CommitAndCreatePendingTree();
7284 host()->host_impl()->ActivateSyncTree();
7285 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7286
7287 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7288 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7289 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7290
7291 ExecuteCalculateDrawProperties(root_impl);
7292 EXPECT_VECTOR2DF_EQ(
7293 gfx::Vector2dF(20.f, 30.f),
7294 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7295
7296 // Scroll less than sticking point, sticky element should move with scroll as
7297 // we haven't gotten to the initial sticky item location yet.
7298 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7299 ExecuteCalculateDrawProperties(root_impl);
7300 EXPECT_VECTOR2DF_EQ(
7301 gfx::Vector2dF(20.f, 25.f),
7302 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7303
7304 // Scroll past the sticking point, the Y coordinate should now be clamped.
7305 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7306 ExecuteCalculateDrawProperties(root_impl);
7307 EXPECT_VECTOR2DF_EQ(
7308 gfx::Vector2dF(20.f, 10.f),
7309 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7310
7311 // Now the main thread commits the new position of the sticky element.
7312 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25));
7313 sticky_pos->SetPosition(gfx::PointF(0, 15));
7314 ExecuteCalculateDrawProperties(root.get());
7315 host()->host_impl()->CreatePendingTree();
7316 host()->CommitAndCreatePendingTree();
7317 host()->host_impl()->ActivateSyncTree();
7318 layer_tree_impl = host()->host_impl()->active_tree();
7319 root_impl = layer_tree_impl->LayerById(root->id());
7320 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7321 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7322
7323 // The element should still be where it was before. We reset the delta to
7324 // (0, 0) because we have synced a scroll offset of (0, 25) from the main
7325 // thread.
7326 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7327 ExecuteCalculateDrawProperties(root_impl);
7328 EXPECT_VECTOR2DF_EQ(
7329 gfx::Vector2dF(20.f, 10.f),
7330 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7331
7332 // And if we scroll a little further it remains there.
7333 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7334 ExecuteCalculateDrawProperties(root_impl);
7335 EXPECT_VECTOR2DF_EQ(
7336 gfx::Vector2dF(20.f, 10.f),
7337 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7338
7339 // And hits the bottom of the container.
7340 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7341 ExecuteCalculateDrawProperties(root_impl);
7342 EXPECT_VECTOR2DF_EQ(
7343 gfx::Vector2dF(20.f, 5.f),
7344 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7345}
7346
flackr2215b4e2016-09-21 20:16:017347// A transform on a sticky element should not affect its sticky position.
7348TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7349 scoped_refptr<Layer> root = Layer::Create();
7350 scoped_refptr<Layer> container = Layer::Create();
7351 scoped_refptr<Layer> scroller = Layer::Create();
7352 scoped_refptr<Layer> sticky_pos = Layer::Create();
7353 root->AddChild(container);
7354 container->AddChild(scroller);
7355 scroller->AddChild(sticky_pos);
7356 host()->SetRootLayer(root);
7357 scroller->SetScrollClipLayerId(container->id());
7358 gfx::Transform t;
7359 t.Scale(2, 2);
7360 sticky_pos->SetTransform(t);
7361
7362 LayerStickyPositionConstraint sticky_position;
7363 sticky_position.is_sticky = true;
7364 sticky_position.is_anchored_top = true;
7365 sticky_position.top_offset = 0.0f;
flackr68e1c292016-10-11 16:34:427366 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20);
flackr2215b4e2016-09-21 20:16:017367 sticky_position.scroll_container_relative_sticky_box_rect =
7368 gfx::Rect(0, 20, 10, 10);
7369 sticky_position.scroll_container_relative_containing_block_rect =
7370 gfx::Rect(0, 0, 50, 50);
7371 sticky_pos->SetStickyPositionConstraint(sticky_position);
7372
7373 root->SetBounds(gfx::Size(100, 100));
7374 container->SetBounds(gfx::Size(100, 100));
7375 scroller->SetBounds(gfx::Size(1000, 1000));
7376 sticky_pos->SetBounds(gfx::Size(10, 10));
7377 sticky_pos->SetPosition(gfx::PointF(0, 20));
7378
7379 ExecuteCalculateDrawProperties(root.get());
7380 host()->host_impl()->CreatePendingTree();
7381 host()->CommitAndCreatePendingTree();
7382 host()->host_impl()->ActivateSyncTree();
7383 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7384
7385 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7386 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7387 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7388
7389 ExecuteCalculateDrawProperties(root_impl);
7390 EXPECT_VECTOR2DF_EQ(
7391 gfx::Vector2dF(0.f, 20.f),
7392 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7393
7394 // Scroll less than sticking point, sticky element should move with scroll as
7395 // we haven't gotten to the initial sticky item location yet.
7396 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7397 ExecuteCalculateDrawProperties(root_impl);
7398 EXPECT_VECTOR2DF_EQ(
7399 gfx::Vector2dF(0.f, 5.f),
7400 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7401
7402 // Scroll past the sticking point, the box is positioned at the scroller
7403 // edge.
7404 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7405 ExecuteCalculateDrawProperties(root_impl);
7406 EXPECT_VECTOR2DF_EQ(
7407 gfx::Vector2dF(0.f, 0.f),
7408 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7409 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7410 ExecuteCalculateDrawProperties(root_impl);
7411 EXPECT_VECTOR2DF_EQ(
7412 gfx::Vector2dF(0.f, 0.f),
7413 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7414
7415 // Scroll past the end of the sticky container.
7416 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7417 ExecuteCalculateDrawProperties(root_impl);
7418 EXPECT_VECTOR2DF_EQ(
7419 gfx::Vector2dF(0.f, -10.f),
7420 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7421}
7422
7423// Tests that a transform does not affect the sticking points. The sticky
7424// element will however move relative to the viewport due to its transform.
7425TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7426 scoped_refptr<Layer> root = Layer::Create();
7427 scoped_refptr<Layer> container = Layer::Create();
7428 scoped_refptr<Layer> scroller = Layer::Create();
7429 scoped_refptr<Layer> sticky_container = Layer::Create();
7430 scoped_refptr<Layer> sticky_pos = Layer::Create();
7431 root->AddChild(container);
7432 container->AddChild(scroller);
7433 scroller->AddChild(sticky_container);
7434 sticky_container->AddChild(sticky_pos);
7435 host()->SetRootLayer(root);
7436 scroller->SetScrollClipLayerId(container->id());
7437 gfx::Transform t;
7438 t.Scale(2, 2);
7439 sticky_container->SetTransform(t);
7440
7441 LayerStickyPositionConstraint sticky_position;
7442 sticky_position.is_sticky = true;
7443 sticky_position.is_anchored_top = true;
7444 sticky_position.top_offset = 0.0f;
flackr68e1c292016-10-11 16:34:427445 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20);
flackr2215b4e2016-09-21 20:16:017446 sticky_position.scroll_container_relative_sticky_box_rect =
7447 gfx::Rect(0, 20, 10, 10);
7448 sticky_position.scroll_container_relative_containing_block_rect =
7449 gfx::Rect(0, 0, 50, 50);
7450 sticky_pos->SetStickyPositionConstraint(sticky_position);
7451
7452 root->SetBounds(gfx::Size(100, 100));
7453 container->SetBounds(gfx::Size(100, 100));
7454 scroller->SetBounds(gfx::Size(1000, 1000));
7455 sticky_container->SetBounds(gfx::Size(50, 50));
7456 sticky_pos->SetBounds(gfx::Size(10, 10));
7457 sticky_pos->SetPosition(gfx::PointF(0, 20));
7458
7459 ExecuteCalculateDrawProperties(root.get());
7460 host()->host_impl()->CreatePendingTree();
7461 host()->CommitAndCreatePendingTree();
7462 host()->host_impl()->ActivateSyncTree();
7463 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7464
7465 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7466 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7467 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7468
7469 ExecuteCalculateDrawProperties(root_impl);
7470 EXPECT_VECTOR2DF_EQ(
7471 gfx::Vector2dF(0.f, 40.f),
7472 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7473
7474 // Scroll less than sticking point, sticky element should move with scroll as
7475 // we haven't gotten to the initial sticky item location yet.
7476 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7477 ExecuteCalculateDrawProperties(root_impl);
7478 EXPECT_VECTOR2DF_EQ(
7479 gfx::Vector2dF(0.f, 25.f),
7480 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7481
7482 // Scroll past the sticking point, the box is positioned at the scroller
7483 // edge but is also scaled by its container so it begins to move down.
7484 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7485 ExecuteCalculateDrawProperties(root_impl);
7486 EXPECT_VECTOR2DF_EQ(
7487 gfx::Vector2dF(0.f, 25.f),
7488 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7489 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7490 ExecuteCalculateDrawProperties(root_impl);
7491 EXPECT_VECTOR2DF_EQ(
7492 gfx::Vector2dF(0.f, 30.f),
7493 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7494
7495 // Scroll past the end of the sticky container.
7496 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7497 ExecuteCalculateDrawProperties(root_impl);
7498 EXPECT_VECTOR2DF_EQ(
7499 gfx::Vector2dF(0.f, 30.f),
7500 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7501}
7502
jaydasikaaf1582f2016-08-10 18:39:387503TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7504 scoped_refptr<Layer> root = Layer::Create();
7505 scoped_refptr<Layer> container = Layer::Create();
7506 scoped_refptr<Layer> scroller = Layer::Create();
7507 scoped_refptr<Layer> fixed_pos = Layer::Create();
7508
7509 scroller->SetIsContainerForFixedPositionLayers(true);
7510 root->AddChild(container);
7511 container->AddChild(scroller);
7512 scroller->AddChild(fixed_pos);
7513 host()->SetRootLayer(root);
7514
7515 LayerPositionConstraint fixed_position;
7516 fixed_position.set_is_fixed_position(true);
7517 scroller->SetScrollClipLayerId(container->id());
7518 fixed_pos->SetPositionConstraint(fixed_position);
7519
7520 root->SetBounds(gfx::Size(50, 50));
7521 container->SetBounds(gfx::Size(50, 50));
7522 scroller->SetBounds(gfx::Size(50, 50));
7523 fixed_pos->SetBounds(gfx::Size(50, 50));
7524
7525 gfx::Transform rotate;
7526 rotate.RotateAboutXAxis(20);
7527 container->SetTransform(rotate);
7528
7529 ExecuteCalculateDrawProperties(root.get());
khushalsagar86928f92016-08-17 21:49:057530 TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree;
jaydasikaaf1582f2016-08-10 18:39:387531 gfx::Transform transform;
7532 tree.ComputeTranslation(fixed_pos->transform_tree_index(),
7533 container->transform_tree_index(), &transform);
7534 EXPECT_TRUE(transform.IsIdentity());
7535}
7536
sunxd8a9a60982016-07-29 18:46:567537TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
7538 // This test verifies that a fixed pos child of a scrolling layer doesn't get
7539 // snapped to integer coordinates.
7540 //
7541 // + root
7542 // + container
7543 // + scroller
7544 // + fixed_pos
7545 //
7546 scoped_refptr<Layer> root = Layer::Create();
7547 scoped_refptr<Layer> container = Layer::Create();
7548 scoped_refptr<Layer> scroller = Layer::Create();
7549 scoped_refptr<Layer> fixed_pos = Layer::Create();
7550
7551 scroller->SetIsContainerForFixedPositionLayers(true);
7552
7553 root->AddChild(container);
7554 container->AddChild(scroller);
7555 scroller->AddChild(fixed_pos);
7556 host()->SetRootLayer(root);
7557
7558 LayerPositionConstraint fixed_position;
7559 fixed_position.set_is_fixed_position(true);
7560 scroller->SetScrollClipLayerId(container->id());
7561 fixed_pos->SetPositionConstraint(fixed_position);
7562
7563 root->SetBounds(gfx::Size(50, 50));
7564 container->SetBounds(gfx::Size(50, 50));
7565 scroller->SetBounds(gfx::Size(100, 100));
7566 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7567 fixed_pos->SetBounds(gfx::Size(10, 10));
7568
7569 ExecuteCalculateDrawProperties(root.get());
7570
7571 host()->host_impl()->CreatePendingTree();
7572 host()->CommitAndCreatePendingTree();
7573 host()->host_impl()->ActivateSyncTree();
7574 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7575
7576 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7577 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7578 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
7579 gfx::Vector2dF scroll_delta(5.f, 9.f);
7580 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7581
7582 ExecuteCalculateDrawProperties(root_impl);
7583
7584 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7585 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7586 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7587
7588 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
7589 10.3f);
7590 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
7591 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
7592}
7593
[email protected]1c3626e2014-04-09 17:49:227594class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7595 public:
danakj60bc3bc2016-04-09 00:24:487596 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227597 LayerTreeImpl* tree_impl,
7598 int id) {
danakj60bc3bc2016-04-09 00:24:487599 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227600 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7601 }
7602
dcheng716bedf2014-10-21 09:51:087603 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227604
[email protected]1c3626e2014-04-09 17:49:227605 private:
7606 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7607 int id)
[email protected]a57cb8b12014-06-13 18:15:377608 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227609 SetDrawsContent(true);
7610 }
[email protected]1c3626e2014-04-09 17:49:227611};
7612
7613TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167614 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567615 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017616 LayerTreeSettings settings = host()->GetSettings();
ajumab4a846f22015-08-24 19:13:447617 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167618 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227619 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:487620 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227621 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487622 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227623 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487624 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227625 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487626 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227627 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7628
7629 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7630 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7631 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097632 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227633
danakjf78fb272016-07-26 19:06:157634 grand_parent->SetBounds(gfx::Size(1, 2));
7635 parent->SetBounds(gfx::Size(1, 2));
7636 child->SetBounds(gfx::Size(1, 2));
7637 grand_child->SetBounds(gfx::Size(1, 2));
7638
jaydasika89f7b5a2016-06-22 02:08:397639 child->test_properties()->AddChild(std::move(grand_child));
7640 parent->test_properties()->AddChild(std::move(child));
7641 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597642 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:057643
jaydasika2411692c2016-03-23 01:56:097644 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227645
7646 // No layers have animations.
sunxdf468675e2016-06-30 23:56:187647 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7648 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7649 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7650 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227651
sunxdf468675e2016-06-30 23:56:187652 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7653 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7654 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7655 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037656
[email protected]1c3626e2014-04-09 17:49:227657 TransformOperations translation;
7658 translation.AppendTranslate(1.f, 2.f, 3.f);
7659
loyso968163c92016-01-04 23:18:487660 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587661 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7662 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487663
vollickef2ae922016-06-29 17:54:277664 host_impl.active_tree()->SetElementIdsForTesting();
loysodb006882016-09-14 00:31:517665
7666 scoped_refptr<AnimationPlayer> grand_parent_player =
7667 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7668 timeline->AttachPlayer(grand_parent_player);
7669 grand_parent_player->AttachElement(grand_parent_raw->element_id());
7670
7671 scoped_refptr<AnimationPlayer> parent_player =
7672 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7673 timeline->AttachPlayer(parent_player);
7674 parent_player->AttachElement(parent_raw->element_id());
7675
7676 scoped_refptr<AnimationPlayer> child_player =
7677 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7678 timeline->AttachPlayer(child_player);
7679 child_player->AttachElement(child_raw->element_id());
7680
7681 scoped_refptr<AnimationPlayer> grand_child_player =
7682 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7683 timeline->AttachPlayer(grand_child_player);
7684 grand_child_player->AttachElement(grand_child_raw->element_id());
7685
7686 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7687 translation);
[email protected]1c3626e2014-04-09 17:49:227688
7689 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187690 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7691 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7692 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7693 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227694
sunxdf468675e2016-06-30 23:56:187695 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7696 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7697 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7698 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037699
[email protected]1c3626e2014-04-09 17:49:227700 TransformOperations scale;
7701 scale.AppendScale(5.f, 4.f, 3.f);
7702
loysodb006882016-09-14 00:31:517703 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7704 scale);
ajumacaaa9b32015-08-04 15:55:297705 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097706 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227707
7708 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:187709 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7710 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7711 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
7712 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227713
sunxdf468675e2016-06-30 23:56:187714 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7715 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7716 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
7717 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037718
loysodb006882016-09-14 00:31:517719 AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0,
7720 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097721 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7722 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227723
7724 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187725 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7726 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:227727 // We don't support combining animated scales from two nodes; 0.f means
7728 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:187729 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7730 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227731
sunxdf468675e2016-06-30 23:56:187732 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7733 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
7734 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7735 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037736
loysodb006882016-09-14 00:31:517737 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7738 scale);
ajumacaaa9b32015-08-04 15:55:297739 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097740 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227741
7742 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187743 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7744 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7745 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7746 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227747
sunxdf468675e2016-06-30 23:56:187748 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7749 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7750 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7751 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037752
loysodb006882016-09-14 00:31:517753 grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7754 parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7755 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
[email protected]1c3626e2014-04-09 17:49:227756
7757 TransformOperations perspective;
7758 perspective.AppendPerspective(10.f);
7759
loysodb006882016-09-14 00:31:517760 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7761 perspective);
ajumab4a846f22015-08-24 19:13:447762 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097763 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227764
7765 // |child| has a scale-affecting animation but computing the maximum of this
7766 // animation is not supported.
sunxdf468675e2016-06-30 23:56:187767 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7768 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7769 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7770 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227771
sunxdf468675e2016-06-30 23:56:187772 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7773 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7774 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7775 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037776
loysobb507792016-10-04 05:31:027777 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7778
[email protected]1c3626e2014-04-09 17:49:227779 gfx::Transform scale_matrix;
7780 scale_matrix.Scale(1.f, 2.f);
jaydasika10d43fc2016-08-18 04:06:047781 grand_parent_raw->test_properties()->transform = scale_matrix;
7782 parent_raw->test_properties()->transform = scale_matrix;
jaydasika2411692c2016-03-23 01:56:097783 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487784
loysodb006882016-09-14 00:31:517785 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7786 scale);
jaydasika2411692c2016-03-23 01:56:097787 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227788
7789 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7790 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:187791 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7792 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7793 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
7794 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227795
sunxdf468675e2016-06-30 23:56:187796 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7797 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7798 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
7799 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037800
[email protected]1c3626e2014-04-09 17:49:227801 gfx::Transform perspective_matrix;
7802 perspective_matrix.ApplyPerspectiveDepth(2.f);
jaydasika10d43fc2016-08-18 04:06:047803 child_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097804 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7805 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227806
7807 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187808 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7809 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7810 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7811 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227812
sunxdf468675e2016-06-30 23:56:187813 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7814 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7815 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7816 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037817
jaydasika10d43fc2016-08-18 04:06:047818 parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097819 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7820 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227821
7822 // |parent| and |child| have transforms that are neither translations nor
7823 // scales.
sunxdf468675e2016-06-30 23:56:187824 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7825 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7826 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7827 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227828
sunxdf468675e2016-06-30 23:56:187829 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7830 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7831 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7832 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037833
jaydasika10d43fc2016-08-18 04:06:047834 parent_raw->test_properties()->transform = gfx::Transform();
7835 child_raw->test_properties()->transform = gfx::Transform();
7836 grand_parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097837 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227838
jaydasika2411692c2016-03-23 01:56:097839 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227840
7841 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187842 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7843 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7844 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7845 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037846
sunxdf468675e2016-06-30 23:56:187847 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7848 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7849 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7850 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227851}
7852
danakj59931942016-07-26 22:11:297853static void GatherDrawnLayers(const LayerImplList* rsll,
[email protected]390bb1ff2014-05-09 17:14:407854 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517855 for (LayerIterator it = LayerIterator::Begin(rsll),
7856 end = LayerIterator::End(rsll);
7857 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407858 LayerImpl* layer = *it;
7859 if (it.represents_itself())
7860 drawn_layers->insert(layer);
7861
7862 if (!it.represents_contributing_render_surface())
7863 continue;
7864
ajuma1d4026a32016-06-14 13:18:507865 if (layer->render_surface()->MaskLayer())
7866 drawn_layers->insert(layer->render_surface()->MaskLayer());
[email protected]390bb1ff2014-05-09 17:14:407867 }
7868}
7869
7870TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167871 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567872 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:227873 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407874
danakj60bc3bc2016-04-09 00:24:487875 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407876 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487877 std::unique_ptr<LayerImpl> parent =
7878 LayerImpl::Create(host_impl.active_tree(), 3);
7879 std::unique_ptr<LayerImpl> child =
7880 LayerImpl::Create(host_impl.active_tree(), 5);
7881 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407882 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487883 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407884 LayerImpl::Create(host_impl.active_tree(), 9);
7885
7886 LayerImpl* grand_parent_raw = grand_parent.get();
7887 LayerImpl* parent_raw = parent.get();
7888 LayerImpl* child_raw = child.get();
7889 LayerImpl* grand_child1_raw = grand_child1.get();
7890 LayerImpl* grand_child2_raw = grand_child2.get();
7891
danakjf78fb272016-07-26 19:06:157892 grand_parent->SetBounds(gfx::Size(1, 2));
7893 parent->SetBounds(gfx::Size(1, 2));
7894 child->SetBounds(gfx::Size(1, 2));
7895 grand_child1->SetBounds(gfx::Size(1, 2));
7896 grand_child2->SetBounds(gfx::Size(1, 2));
7897
jaydasika89f7b5a2016-06-22 02:08:397898 child->test_properties()->AddChild(std::move(grand_child1));
7899 child->test_properties()->AddChild(std::move(grand_child2));
7900 parent->test_properties()->AddChild(std::move(child));
7901 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597902 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407903
[email protected]390bb1ff2014-05-09 17:14:407904 // Start with nothing being drawn.
7905 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407906
ajuma0adb5902016-04-28 16:32:387907 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7908 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7909 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7910 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7911 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407912
7913 std::set<LayerImpl*> expected;
7914 std::set<LayerImpl*> actual;
7915 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7916 EXPECT_EQ(expected, actual);
7917
7918 // If we force render surface, but none of the layers are in the layer list,
7919 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007920 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127921 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407922
7923 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407924
ajuma0adb5902016-04-28 16:32:387925 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7926 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7927 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7928 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7929 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407930
7931 expected.clear();
7932 actual.clear();
7933 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7934 EXPECT_EQ(expected, actual);
7935
7936 // However, if we say that this layer also draws content, it will appear in
7937 // RSLL.
7938 grand_child1_raw->SetDrawsContent(true);
7939
7940 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407941
ajuma0adb5902016-04-28 16:32:387942 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7943 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7944 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7945 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7946 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407947
7948 expected.clear();
7949 expected.insert(grand_child1_raw);
7950
7951 actual.clear();
7952 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7953 EXPECT_EQ(expected, actual);
7954
7955 // Now child is forced to have a render surface, and one if its children draws
7956 // content.
7957 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007958 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127959 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007960 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407961 grand_child2_raw->SetDrawsContent(true);
7962
7963 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407964
ajuma0adb5902016-04-28 16:32:387965 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7966 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7967 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7968 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7969 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407970
7971 expected.clear();
7972 expected.insert(grand_child2_raw);
7973
7974 actual.clear();
7975 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7976 EXPECT_EQ(expected, actual);
7977
7978 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:507979 child_raw->test_properties()->SetMaskLayer(
7980 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047981 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407982
7983 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407984
ajuma0adb5902016-04-28 16:32:387985 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7986 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7987 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507988 EXPECT_TRUE(child_raw->test_properties()
7989 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387990 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7991 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407992
7993 expected.clear();
7994 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507995 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407996
7997 expected.clear();
7998 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507999 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408000
8001 actual.clear();
8002 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8003 EXPECT_EQ(expected, actual);
8004
[email protected]390bb1ff2014-05-09 17:14:408005 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408006
ajuma0adb5902016-04-28 16:32:388007 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8008 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8009 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508010 EXPECT_TRUE(child_raw->test_properties()
8011 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388012 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8013 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408014
8015 expected.clear();
8016 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508017 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408018
8019 actual.clear();
8020 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8021 EXPECT_EQ(expected, actual);
8022
ajuma1d4026a32016-06-14 13:18:508023 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408024
8025 // With nothing drawing, we should have no layers.
8026 grand_child2_raw->SetDrawsContent(false);
8027
8028 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408029
ajuma0adb5902016-04-28 16:32:388030 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8031 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8032 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508033 EXPECT_FALSE(child_raw->test_properties()
8034 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388035 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8036 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408037
8038 expected.clear();
8039 actual.clear();
8040 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8041 EXPECT_EQ(expected, actual);
8042
8043 // Child itself draws means that we should have the child and the mask in the
8044 // list.
8045 child_raw->SetDrawsContent(true);
8046
8047 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408048
ajuma0adb5902016-04-28 16:32:388049 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8050 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8051 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508052 EXPECT_TRUE(child_raw->test_properties()
8053 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388054 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8055 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408056
8057 expected.clear();
8058 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:508059 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408060 actual.clear();
8061 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8062 EXPECT_EQ(expected, actual);
8063
ajuma1d4026a32016-06-14 13:18:508064 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:048065 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408066
8067 // Now everyone's a member!
8068 grand_parent_raw->SetDrawsContent(true);
8069 parent_raw->SetDrawsContent(true);
8070 child_raw->SetDrawsContent(true);
8071 grand_child1_raw->SetDrawsContent(true);
8072 grand_child2_raw->SetDrawsContent(true);
8073
8074 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408075
ajuma0adb5902016-04-28 16:32:388076 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8077 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
8078 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
8079 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8080 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408081
8082 expected.clear();
8083 expected.insert(grand_parent_raw);
8084 expected.insert(parent_raw);
8085 expected.insert(child_raw);
8086 expected.insert(grand_child1_raw);
8087 expected.insert(grand_child2_raw);
8088
8089 actual.clear();
8090 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8091 EXPECT_EQ(expected, actual);
8092}
[email protected]18e69652014-06-13 12:50:588093
8094TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:168095 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568096 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018097 LayerTreeSettings settings = host()->GetSettings();
enne637715732015-07-07 02:05:268098 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:168099 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228100 &task_graph_runner);
[email protected]18e69652014-06-13 12:50:588101
danakj60bc3bc2016-04-09 00:24:488102 std::unique_ptr<LayerImpl> root =
8103 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:588104 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:488105 std::unique_ptr<LayerImpl> child1 =
8106 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:588107 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:488108 std::unique_ptr<LayerImpl> child2 =
8109 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:588110 LayerImpl* child2_layer = child2.get();
8111
danakjf78fb272016-07-26 19:06:158112 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:588113 scale_transform_child1.Scale(2, 3);
8114 scale_transform_child2.Scale(4, 5);
8115
danakjf78fb272016-07-26 19:06:158116 root->SetBounds(gfx::Size(1, 1));
8117 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048118 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158119 child1_layer->SetBounds(gfx::Size(1, 1));
8120 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:588121
ajuma1d4026a32016-06-14 13:18:508122 child1_layer->test_properties()->SetMaskLayer(
8123 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:588124
danakjf78fb272016-07-26 19:06:158125 root->test_properties()->AddChild(std::move(child1));
8126 root->test_properties()->AddChild(std::move(child2));
8127 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8128 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:588129
8130 ExecuteCalculateDrawProperties(root_layer);
8131
8132 TransformOperations scale;
8133 scale.AppendScale(5.f, 8.f, 3.f);
8134
loyso9556c732016-03-11 07:54:588135 scoped_refptr<AnimationTimeline> timeline =
8136 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8137 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:488138
jaydasika10d43fc2016-08-18 04:06:048139 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158140 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:288141 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278142 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8143 1.0, TransformOperations(), scale);
8144
jaydasika2411692c2016-03-23 01:56:098145 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:588146 ExecuteCalculateDrawProperties(root_layer);
8147
enne637715732015-07-07 02:05:268148 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
8149 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:508150 EXPECT_FLOAT_EQ(
8151 3.f,
8152 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268153 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588154
sunxdf468675e2016-06-30 23:56:188155 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8156 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8157 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:588158
[email protected]18e69652014-06-13 12:50:588159 // Changing page-scale would affect ideal_contents_scale and
8160 // maximum_animation_contents_scale.
8161
8162 float page_scale_factor = 3.f;
8163 float device_scale_factor = 1.0f;
8164 std::vector<LayerImpl*> render_surface_layer_list;
8165 gfx::Size device_viewport_size =
8166 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8167 root_layer->bounds().height() * device_scale_factor);
8168 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388169 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:588170
8171 inputs.page_scale_factor = page_scale_factor;
8172 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:118173 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:578174 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:588175
enne637715732015-07-07 02:05:268176 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
8177 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588178 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268179 9.f,
ajuma1d4026a32016-06-14 13:18:508180 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268181 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588182
sunxdf468675e2016-06-30 23:56:188183 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8184 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8185 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:588186
[email protected]18e69652014-06-13 12:50:588187 // Changing device-scale would affect ideal_contents_scale and
8188 // maximum_animation_contents_scale.
8189
8190 device_scale_factor = 4.0f;
8191 inputs.device_scale_factor = device_scale_factor;
8192 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:098193 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:578194 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:588195
enne637715732015-07-07 02:05:268196 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
8197 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588198 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268199 36.f,
ajuma1d4026a32016-06-14 13:18:508200 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268201 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588202
sunxdf468675e2016-06-30 23:56:188203 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8204 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8205 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
8206}
8207
8208TEST_F(LayerTreeHostCommonTest, AnimationScales) {
8209 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188210 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018211 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188212 settings.layer_transforms_should_scale_layer_contents = true;
8213 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228214 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188215
8216 std::unique_ptr<LayerImpl> root =
8217 LayerImpl::Create(host_impl.active_tree(), 1);
8218 LayerImpl* root_layer = root.get();
8219 std::unique_ptr<LayerImpl> child1 =
8220 LayerImpl::Create(host_impl.active_tree(), 2);
8221 LayerImpl* child1_layer = child1.get();
8222 std::unique_ptr<LayerImpl> child2 =
8223 LayerImpl::Create(host_impl.active_tree(), 3);
8224 LayerImpl* child2_layer = child2.get();
8225
8226 root->test_properties()->AddChild(std::move(child1));
8227 child1_layer->test_properties()->AddChild(std::move(child2));
8228 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8229
8230 host_impl.active_tree()->SetElementIdsForTesting();
8231
danakjf78fb272016-07-26 19:06:158232 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:188233 scale_transform_child1.Scale(2, 3);
8234 scale_transform_child2.Scale(4, 5);
8235
danakjf78fb272016-07-26 19:06:158236 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048237 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158238 child1_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048239 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158240 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:188241
8242 TransformOperations scale;
8243 scale.AppendScale(5.f, 8.f, 3.f);
8244
8245 scoped_refptr<AnimationTimeline> timeline =
8246 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8247 host_impl.animation_host()->AddAnimationTimeline(timeline);
8248
8249 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8250 1.0, TransformOperations(), scale);
8251
sunxdf468675e2016-06-30 23:56:188252 // Correctly computes animation scale when rebuilding property trees.
8253 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8254 ExecuteCalculateDrawProperties(root_layer);
8255
8256 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8257 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8258 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
8259
8260 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8261 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
8262 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
8263
8264 // Correctly updates animation scale when layer property changes.
jaydasika10d43fc2016-08-18 04:06:048265 child1_layer->test_properties()->transform = gfx::Transform();
jaydasika09e16132016-08-24 21:39:348266 root_layer->layer_tree_impl()
8267 ->property_trees()
8268 ->transform_tree.OnTransformAnimated(gfx::Transform(),
8269 child1_layer->transform_tree_index(),
8270 root_layer->layer_tree_impl());
sunxdf468675e2016-06-30 23:56:188271 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
8272 ExecuteCalculateDrawProperties(root_layer);
8273 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
8274 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
8275
8276 // Do not update animation scale if already updated.
8277 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
8278 child2_layer->transform_tree_index(), 100.f, 100.f);
8279 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
8280 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
8281}
8282
8283TEST_F(LayerTreeHostCommonTest,
8284 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
8285 // Returns empty scale if layer_transforms_should_scale_layer_contents is
8286 // false.
8287 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188288 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018289 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188290 settings.layer_transforms_should_scale_layer_contents = false;
8291 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228292 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188293
8294 std::unique_ptr<LayerImpl> root =
8295 LayerImpl::Create(host_impl.active_tree(), 1);
8296 LayerImpl* root_layer = root.get();
8297 std::unique_ptr<LayerImpl> child =
8298 LayerImpl::Create(host_impl.active_tree(), 2);
8299 LayerImpl* child_layer = child.get();
8300
8301 root->test_properties()->AddChild(std::move(child));
8302 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8303
8304 host_impl.active_tree()->SetElementIdsForTesting();
8305
danakjf78fb272016-07-26 19:06:158306 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:188307 scale_transform_child.Scale(4, 5);
8308
danakjf78fb272016-07-26 19:06:158309 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048310 child_layer->test_properties()->transform = scale_transform_child;
danakjf78fb272016-07-26 19:06:158311 child_layer->SetBounds(gfx::Size(1, 1));
8312
sunxdf468675e2016-06-30 23:56:188313 TransformOperations scale;
8314 scale.AppendScale(5.f, 8.f, 3.f);
8315
8316 scoped_refptr<AnimationTimeline> timeline =
8317 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8318 host_impl.animation_host()->AddAnimationTimeline(timeline);
8319
8320 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
8321 1.0, TransformOperations(), scale);
8322
sunxdf468675e2016-06-30 23:56:188323 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8324 ExecuteCalculateDrawProperties(root_layer);
8325
8326 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8327 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
8328
8329 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8330 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:588331}
8332
danakjf6069db2014-09-13 00:46:478333TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598334 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148335 LayerImpl* clip = AddChild<LayerImpl>(root);
8336 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:478337
danakjf78fb272016-07-26 19:06:158338 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:148339 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158340 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:478341 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158342 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:148343 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158344 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:478345
8346 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:148347 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:148348 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakjf78fb272016-07-26 19:06:158349 root, device_viewport_size, gfx::Transform(),
ajuma0adb5902016-04-28 16:32:388350 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:478351 inputs.device_scale_factor = 2.f;
8352 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:298353 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:578354 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478355
8356 // Layers in the root render surface have their visible content rect clipped
8357 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148358 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478359
8360 // Layers drawing to a child render surface should still have their visible
8361 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148362 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478363}
8364
timav599f4359d2014-12-05 00:12:228365TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168366 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568367 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228368 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
timav599f4359d2014-12-05 00:12:228369
8370 // Set two layers: the root layer clips it's child,
8371 // the child draws its content.
8372
8373 gfx::Size root_size = gfx::Size(300, 500);
8374
8375 // Sublayer should be bigger than the root enlarged by bounds_delta.
8376 gfx::Size sublayer_size = gfx::Size(300, 1000);
8377
mdjones2ee41afd2016-10-27 16:50:208378 // Device viewport accomidated the root and the browser controls.
timav599f4359d2014-12-05 00:12:228379 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:228380
miletus8bd08a622015-06-16 18:44:528381 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:598382 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:228383 LayerImpl::Create(host_impl.active_tree(), 1));
8384
jaydasikabf1875a2016-06-28 03:39:598385 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:158386 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:228387 root->SetMasksToBounds(true);
8388
jaydasika89f7b5a2016-06-22 02:08:398389 root->test_properties()->AddChild(
8390 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:228391
jaydasikafc66cfb2016-06-10 04:34:228392 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:158393 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:228394 sublayer->SetDrawsContent(true);
8395
danakj74af409e2016-07-01 00:41:488396 host_impl.active_tree()->BuildPropertyTreesForTesting();
8397
timav599f4359d2014-12-05 00:12:228398 LayerImplList layer_impl_list;
8399 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388400 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:228401
sunxdb365de02016-04-28 20:32:578402 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438403 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228404
8405 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578406 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228407
8408 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8409 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438410 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228411}
8412
ajumadd2802e72015-06-30 20:28:298413TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318414 scoped_refptr<Layer> root = Layer::Create();
8415 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8416 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8417 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8418 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298419
8420 root->AddChild(inner_viewport_container_layer);
8421 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8422 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8423 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8424
8425 inner_viewport_scroll_layer->SetScrollClipLayerId(
8426 inner_viewport_container_layer->id());
8427 outer_viewport_scroll_layer->SetScrollClipLayerId(
8428 outer_viewport_container_layer->id());
8429
8430 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8431 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8432
8433 host()->SetRootLayer(root);
khushalsagar86928f92016-08-17 21:49:058434 host()->GetLayerTree()->RegisterViewportLayers(
8435 nullptr, root, inner_viewport_scroll_layer, outer_viewport_scroll_layer);
ajumadd2802e72015-06-30 20:28:298436
loyso0940d412016-03-14 01:30:318437 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8438 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298439
8440 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8441 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8442
8443 LayerPositionConstraint fixed_to_right;
8444 fixed_to_right.set_is_fixed_position(true);
8445 fixed_to_right.set_is_fixed_to_right_edge(true);
8446
8447 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8448 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8449
jaydasika6ed869662016-09-21 14:29:598450 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298451
8452 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8453 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8454 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8455
8456 LayerPositionConstraint fixed_to_left;
8457 fixed_to_left.set_is_fixed_position(true);
8458 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8459
jaydasika6ed869662016-09-21 14:29:598460 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298461 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8462 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8463
8464 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8465
jaydasika6ed869662016-09-21 14:29:598466 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298467 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8468 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8469}
8470
vollick7d83b452015-02-24 20:18:068471TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
sunxd713aedbd2016-08-10 22:22:148472 host_impl()->CreatePendingTree();
8473 std::unique_ptr<LayerImpl> pending_root =
8474 LayerImpl::Create(host_impl()->pending_tree(), 1);
8475 LayerImpl* root = pending_root.get();
8476 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root));
8477 std::unique_ptr<LayerImpl> animated_ptr =
8478 LayerImpl::Create(host_impl()->pending_tree(), 2);
8479 LayerImpl* animated = animated_ptr.get();
8480 root->test_properties()->AddChild(std::move(animated_ptr));
vollick7d83b452015-02-24 20:18:068481
sunxd713aedbd2016-08-10 22:22:148482 animated->SetDrawsContent(true);
8483 host_impl()->pending_tree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278484
danakjf78fb272016-07-26 19:06:158485 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:068486 root->SetMasksToBounds(true);
sunxd713aedbd2016-08-10 22:22:148487 root->test_properties()->force_render_surface = true;
8488 animated->test_properties()->opacity = 0.f;
danakjf78fb272016-07-26 19:06:158489 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:068490
sunxd713aedbd2016-08-10 22:22:148491 AddOpacityTransitionToElementWithPlayer(
8492 animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false);
8493 animated->test_properties()->opacity_can_animate = true;
8494 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598495 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
vollick7d83b452015-02-24 20:18:068496
sunxd713aedbd2016-08-10 22:22:148497 EXPECT_FALSE(animated->visible_layer_rect().IsEmpty());
vollick7d83b452015-02-24 20:18:068498}
8499
ajumaa92fdc12015-03-31 22:47:418500TEST_F(LayerTreeHostCommonTest,
8501 VisibleContentRectForAnimatedLayerWithSingularTransform) {
sunxd713aedbd2016-08-10 22:22:148502 LayerImpl* root = root_layer_for_testing();
8503 LayerImpl* clip = AddChild<LayerImpl>(root);
8504 LayerImpl* animated = AddChild<LayerImpl>(clip);
8505 LayerImpl* surface = AddChild<LayerImpl>(animated);
8506 LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface);
ajumaa92fdc12015-03-31 22:47:418507
sunxd713aedbd2016-08-10 22:22:148508 SetElementIdsForTesting();
ajumaa92fdc12015-03-31 22:47:418509
sunxd713aedbd2016-08-10 22:22:148510 animated->SetDrawsContent(true);
8511 surface->SetDrawsContent(true);
8512 descendant_of_animation->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278513
ajumaa92fdc12015-03-31 22:47:418514 gfx::Transform uninvertible_matrix;
8515 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8516
danakjf78fb272016-07-26 19:06:158517 root->SetBounds(gfx::Size(100, 100));
8518 clip->SetBounds(gfx::Size(10, 10));
8519 clip->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:048520 animated->test_properties()->transform = uninvertible_matrix;
danakjf78fb272016-07-26 19:06:158521 animated->SetBounds(gfx::Size(120, 120));
8522 surface->SetBounds(gfx::Size(100, 100));
sunxd713aedbd2016-08-10 22:22:148523 surface->test_properties()->force_render_surface = true;
danakjf78fb272016-07-26 19:06:158524 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:418525
8526 TransformOperations start_transform_operations;
8527 start_transform_operations.AppendMatrix(uninvertible_matrix);
8528 TransformOperations end_transform_operations;
8529
sunxd713aedbd2016-08-10 22:22:148530 AddAnimatedTransformToElementWithPlayer(
8531 animated->element_id(), timeline_impl(), 10.0, start_transform_operations,
8532 end_transform_operations);
jaydasika6ed869662016-09-21 14:29:598533 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
ajumaa92fdc12015-03-31 22:47:418534
8535 // The animated layer has a singular transform and maps to a non-empty rect in
8536 // clipped target space, so is treated as fully visible.
sunxd713aedbd2016-08-10 22:22:148537 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418538
8539 // The singular transform on |animated| is flattened when inherited by
8540 // |surface|, and this happens to make it invertible.
sunxd713aedbd2016-08-10 22:22:148541 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect());
8542 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418543
8544 gfx::Transform zero_matrix;
8545 zero_matrix.Scale3d(0.f, 0.f, 0.f);
jaydasika09e16132016-08-24 21:39:348546 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
8547 zero_matrix, animated->transform_tree_index(), root->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:598548 // While computing visible rects by combining clips in screen space, we set
8549 // the entire layer as visible if the screen space transform is singular. This
8550 // is not always true when we combine clips in target space because if the
8551 // intersection of combined_clip in taret space with layer_rect projected to
8552 // target space is empty, we set it to an empty rect.
8553 bool skip_verify_visible_rect_calculations = true;
8554 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
8555 root, skip_verify_visible_rect_calculations);
ajumaa92fdc12015-03-31 22:47:418556
8557 // The animated layer maps to the empty rect in clipped target space, so is
8558 // treated as having an empty visible rect.
sunxd713aedbd2016-08-10 22:22:148559 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418560
jaydasika6ed869662016-09-21 14:29:598561 // The animated layer will be treated as fully visible when we combine clips
8562 // in screen space.
8563 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
8564 root->layer_tree_impl()->property_trees(), animated);
8565 EXPECT_EQ(gfx::Rect(120, 120), visible_rect);
8566
ajumaa92fdc12015-03-31 22:47:418567 // This time, flattening does not make |animated|'s transform invertible. This
8568 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348569 // |surface| and layers that draw into it as having empty visible rect.
sunxd713aedbd2016-08-10 22:22:148570 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect());
8571 EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418572}
8573
ajuma20384bf2016-07-22 13:26:158574// Verify that having animated opacity but current opacity 1 still creates
8575// a render surface.
8576TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
8577 LayerImpl* root = root_layer_for_testing();
8578 LayerImpl* child = AddChild<LayerImpl>(root);
8579 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:158580
danakjf78fb272016-07-26 19:06:158581 root->SetBounds(gfx::Size(50, 50));
8582 child->SetBounds(gfx::Size(50, 50));
8583 child->SetDrawsContent(true);
8584 grandchild->SetBounds(gfx::Size(50, 50));
8585 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:158586
8587 SetElementIdsForTesting();
8588 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
8589 10.0, 1.f, 0.2f, false);
8590 ExecuteCalculateDrawProperties(root);
8591
8592 EXPECT_EQ(1.f, child->Opacity());
8593 EXPECT_TRUE(root->has_render_surface());
8594 EXPECT_TRUE(child->has_render_surface());
8595 EXPECT_FALSE(grandchild->has_render_surface());
8596}
8597
enne92f2f6d92015-02-25 23:13:318598// Verify that having an animated filter (but no current filter, as these
8599// are mutually exclusive) correctly creates a render surface.
8600TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598601 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328602 LayerImpl* child = AddChild<LayerImpl>(root);
8603 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318604
danakjf78fb272016-07-26 19:06:158605 root->SetBounds(gfx::Size(50, 50));
8606 child->SetBounds(gfx::Size(50, 50));
8607 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:318608
vollickef2ae922016-06-29 17:54:278609 SetElementIdsForTesting();
8610 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
8611 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:328612 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318613
ennec1332992015-08-24 19:45:098614 EXPECT_TRUE(root->has_render_surface());
8615 EXPECT_TRUE(child->has_render_surface());
8616 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318617
ajumacb2b74432016-07-21 19:11:158618 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8619 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:318620
8621 EXPECT_FALSE(root->FilterIsAnimating());
8622 EXPECT_TRUE(child->FilterIsAnimating());
8623 EXPECT_FALSE(grandchild->FilterIsAnimating());
8624}
8625
ajuma315a4782015-07-24 21:16:348626// Verify that having a filter animation with a delayed start time creates a
8627// render surface.
8628TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598629 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328630 LayerImpl* child = AddChild<LayerImpl>(root);
8631 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348632
danakjf78fb272016-07-26 19:06:158633 root->SetBounds(gfx::Size(50, 50));
8634 child->SetBounds(gfx::Size(50, 50));
8635 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:348636
vollickef2ae922016-06-29 17:54:278637 SetElementIdsForTesting();
8638
danakj60bc3bc2016-04-09 00:24:488639 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348640 KeyframedFilterAnimationCurve::Create());
8641 FilterOperations start_filters;
8642 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8643 FilterOperations end_filters;
8644 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8645 curve->AddKeyframe(
8646 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8647 curve->AddKeyframe(FilterKeyframe::Create(
8648 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488649 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308650 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558651 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348652 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348653
vollickef2ae922016-06-29 17:54:278654 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
8655 std::move(animation));
ajuma4711f4b12016-05-16 18:48:328656 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348657
ennec1332992015-08-24 19:45:098658 EXPECT_TRUE(root->has_render_surface());
8659 EXPECT_TRUE(child->has_render_surface());
8660 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348661
ajumacb2b74432016-07-21 19:11:158662 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8663 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:348664
8665 EXPECT_FALSE(root->FilterIsAnimating());
8666 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8667 EXPECT_FALSE(child->FilterIsAnimating());
8668 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8669 EXPECT_FALSE(grandchild->FilterIsAnimating());
8670 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8671}
8672
vollick0120eb22015-03-02 03:07:348673// Ensures that the property tree code accounts for offsets between fixed
8674// position layers and their respective containers.
8675TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:598676 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148677 LayerImpl* child = AddChild<LayerImpl>(root);
8678 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348679
danakjf78fb272016-07-26 19:06:158680 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:348681 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528682 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158683 child->SetPosition(gfx::PointF(1000, 1000));
8684 child->SetBounds(gfx::Size(50, 50));
8685 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8686 grandchild->SetBounds(gfx::Size(50, 50));
8687 grandchild->SetDrawsContent(true);
8688
vollick0120eb22015-03-02 03:07:348689 LayerPositionConstraint constraint;
8690 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528691 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:348692
jaydasika6f972de2016-04-07 16:16:148693 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348694
jaydasika6f972de2016-04-07 16:16:148695 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348696}
8697
ajuma0178b522015-07-02 21:08:418698// Ensures that the property tree code accounts for offsets between fixed
8699// position containers and their transform tree parents, when a fixed position
8700// layer's container is its layer tree parent, but this parent doesn't have its
8701// own transform tree node.
8702TEST_F(LayerTreeHostCommonTest,
8703 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:598704 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148705 LayerImpl* child = AddChild<LayerImpl>(root);
8706 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418707
danakjf78fb272016-07-26 19:06:158708 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:418709 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158710 root->test_properties()->is_container_for_fixed_position_layers = true;
8711 child->SetPosition(gfx::PointF(1000, 1000));
8712 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:528713 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158714 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8715 grandchild->SetBounds(gfx::Size(50, 50));
8716 grandchild->SetDrawsContent(true);
8717
ajuma0178b522015-07-02 21:08:418718 LayerPositionConstraint constraint;
8719 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528720 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:418721
jaydasika6f972de2016-04-07 16:16:148722 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418723
jaydasika6f972de2016-04-07 16:16:148724 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418725}
8726
vollick8c824742015-03-20 22:21:088727TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:598728 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148729 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8730 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088731 gfx::Transform translate_z;
8732 translate_z.Translate3d(0, 0, 10);
8733
danakjf78fb272016-07-26 19:06:158734 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:528735 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088736
danakjf78fb272016-07-26 19:06:158737 frame_clip->SetPosition(gfx::PointF(500, 100));
8738 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:088739 frame_clip->SetMasksToBounds(true);
8740
danakjf78fb272016-07-26 19:06:158741 fixed->SetBounds(gfx::Size(1000, 1000));
8742 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088743
8744 LayerPositionConstraint constraint;
8745 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528746 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:088747
jaydasika6f972de2016-04-07 16:16:148748 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088749
8750 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148751 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088752}
8753
vollick06ca3e832015-03-31 19:37:128754TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:598755 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148756 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8757 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8758 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8759
danakjf78fb272016-07-26 19:06:158760 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:148761 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158762 root->test_properties()->is_container_for_fixed_position_layers = true;
8763 frame_clip->SetPosition(gfx::PointF(500, 100));
8764 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148765 frame_clip->SetMasksToBounds(true);
8766 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158767 scroller->SetBounds(gfx::Size(1000, 1000));
jaydasika6f972de2016-04-07 16:16:148768 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8769 scroller->SetScrollClipLayer(frame_clip->id());
8770 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158771 fixed->SetPosition(gfx::PointF(100, 100));
8772 fixed->SetBounds(gfx::Size(50, 50));
8773 fixed->SetMasksToBounds(true);
8774 fixed->SetDrawsContent(true);
8775 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:128776
8777 LayerPositionConstraint constraint;
8778 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528779 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128780
jaydasika6f972de2016-04-07 16:16:148781 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128782
8783 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148784 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128785}
8786
vollick5057e1e2015-04-17 19:12:328787TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:328788 gfx::Transform translate;
8789 gfx::Transform rotate;
8790
8791 translate.Translate(10, 10);
8792 rotate.Rotate(45);
8793
loyso0940d412016-03-14 01:30:318794 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:158795 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:328796 root->SetIsContainerForFixedPositionLayers(true);
8797
ennea7b43c32015-06-18 20:01:338798 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328799
jaydasika6ed869662016-09-21 14:29:598800 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ennea7b43c32015-06-18 20:01:338801 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328802
8803 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338804 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328805
8806 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338807 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328808}
8809
ajumab0e0c1c2015-04-23 00:29:238810TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:598811 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148812 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238813
ajumab0e0c1c2015-04-23 00:29:238814 gfx::Transform scale_matrix;
8815 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:238816
danakjf78fb272016-07-26 19:06:158817 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148818 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048819 child->test_properties()->transform = scale_matrix;
danakjf78fb272016-07-26 19:06:158820 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148821 child->SetDrawsContent(true);
8822
8823 ExecuteCalculateDrawProperties(root);
8824 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238825
jaydasika38be7a822016-04-21 16:07:068826 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238827
jaydasika6f972de2016-04-07 16:16:148828 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8829 ExecuteCalculateDrawProperties(root);
8830 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238831}
8832
ajumaf09db8962015-04-24 21:55:348833TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:598834 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148835 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8836 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348837
ajumaf09db8962015-04-24 21:55:348838 gfx::Transform scale;
8839 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:158840
8841 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:048842 scroll_child->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:158843 scroll_child->SetBounds(gfx::Size(40, 40));
8844 scroll_child->SetDrawsContent(true);
8845 scroll_parent->SetBounds(gfx::Size(30, 30));
8846 scroll_parent->SetDrawsContent(true);
8847
8848 scroll_child->test_properties()->scroll_parent = scroll_parent;
8849 scroll_parent->test_properties()->scroll_children =
8850 base::MakeUnique<std::set<LayerImpl*>>();
8851 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:348852
jaydasika6f972de2016-04-07 16:16:148853 ExecuteCalculateDrawProperties(root);
8854 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348855
8856 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148857 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8858 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8859 ExecuteCalculateDrawProperties(root);
8860 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348861}
8862
danakj60bc3bc2016-04-09 00:24:488863static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128864
sunxded58688e2016-01-11 21:01:028865TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8866 // If the layer has a node in effect_tree, the return value of
8867 // num_copy_requests_in_target_subtree() must be equal to the actual number
8868 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8869 // to be the value of its nearest ancestor that owns an effect node and
8870 // greater than or equal to the actual number of copy requests in the
8871 // sub-layer_tree.
8872
loyso0940d412016-03-14 01:30:318873 scoped_refptr<Layer> root = Layer::Create();
8874 scoped_refptr<Layer> child1 = Layer::Create();
8875 scoped_refptr<Layer> child2 = Layer::Create();
8876 scoped_refptr<Layer> grandchild = Layer::Create();
8877 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028878
8879 root->AddChild(child1);
8880 root->AddChild(child2);
8881 child1->AddChild(grandchild);
8882 grandchild->AddChild(greatgrandchild);
8883 host()->SetRootLayer(root);
8884
8885 child1->RequestCopyOfOutput(
8886 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8887 greatgrandchild->RequestCopyOfOutput(
8888 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8889 child2->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598890 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:028891
8892 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8893 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8894 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8895 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8896 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8897}
8898
vollick2175fae82015-04-27 21:18:128899TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:318900 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328901 FakeContentLayerClient client;
8902 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128903 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318904 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128905 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318906 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258907 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318908 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:158909
8910 root->SetBounds(gfx::Size(100, 100));
8911 child->SetBounds(gfx::Size(10, 10));
8912 grandchild->SetBounds(gfx::Size(10, 10));
8913 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128914
8915 root->AddChild(child);
8916 child->AddChild(grandchild);
8917 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:338918 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:088919 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278920
vollick2175fae82015-04-27 21:18:128921 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598922 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148923 const LayerList* update_list = GetUpdateLayerList();
8924 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128925
8926 // Now we will reset the visible rect from property trees for the grandchild,
8927 // and we will configure |child| in several ways that should force the subtree
8928 // to be skipped. The visible content rect for |grandchild| should, therefore,
8929 // remain empty.
vollick2175fae82015-04-27 21:18:128930 gfx::Transform singular;
8931 singular.matrix().set(0, 0, 0);
8932
8933 child->SetTransform(singular);
jaydasika6ed869662016-09-21 14:29:598934 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148935 update_list = GetUpdateLayerList();
8936 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
danakjf78fb272016-07-26 19:06:158937 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128938
8939 child->SetHideLayerAndSubtree(true);
jaydasika6ed869662016-09-21 14:29:598940 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148941 update_list = GetUpdateLayerList();
8942 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128943 child->SetHideLayerAndSubtree(false);
8944
ajuma315a4782015-07-24 21:16:348945 gfx::Transform zero_z_scale;
8946 zero_z_scale.Scale3d(1, 1, 0);
8947 child->SetTransform(zero_z_scale);
8948
8949 // Add a transform animation with a start delay. Now, even though |child| has
8950 // a singular transform, the subtree should still get processed.
8951 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488952 std::unique_ptr<Animation> animation = Animation::Create(
8953 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308954 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558955 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348956 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278957 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
8958 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598959 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148960 update_list = GetUpdateLayerList();
8961 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348962
vollickef2ae922016-06-29 17:54:278963 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
8964 animation_id);
danakjf78fb272016-07-26 19:06:158965 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128966 child->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598967 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148968 update_list = GetUpdateLayerList();
8969 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128970
8971 // Now, even though child has zero opacity, we will configure |grandchild| and
8972 // |greatgrandchild| in several ways that should force the subtree to be
8973 // processed anyhow.
jaydasika86654512016-01-27 17:05:078974 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128975 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
jaydasika6ed869662016-09-21 14:29:598976 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148977 update_list = GetUpdateLayerList();
8978 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348979
8980 // Add an opacity animation with a start delay.
8981 animation_id = 1;
8982 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488983 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308984 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558985 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348986 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278987 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
8988 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598989 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148990 update_list = GetUpdateLayerList();
8991 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128992}
8993
sunxd71aea3e2016-04-01 23:48:058994TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168995 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568996 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228997 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
vollick2175fae82015-04-27 21:18:128998
danakj60bc3bc2016-04-09 00:24:488999 std::unique_ptr<LayerImpl> root =
9000 LayerImpl::Create(host_impl.active_tree(), 1);
9001 std::unique_ptr<LayerImpl> child =
9002 LayerImpl::Create(host_impl.active_tree(), 2);
9003 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:129004 LayerImpl::Create(host_impl.active_tree(), 3);
9005
danakj60bc3bc2016-04-09 00:24:489006 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:259007 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:129008
danakjf78fb272016-07-26 19:06:159009 root->SetBounds(gfx::Size(100, 100));
9010 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129011 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159012 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129013 grandchild->SetDrawsContent(true);
9014 greatgrandchild->SetDrawsContent(true);
9015
jaydasika2411692c2016-03-23 01:56:099016 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:129017 LayerImpl* child_ptr = child.get();
9018 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:129019
jaydasika89f7b5a2016-06-22 02:08:399020 child->test_properties()->AddChild(std::move(grandchild));
9021 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:599022 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:129023
vollickef2ae922016-06-29 17:54:279024 host_impl.active_tree()->SetElementIdsForTesting();
9025
vollick2175fae82015-04-27 21:18:129026 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599027 // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059028 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129029
9030 // Now we will reset the visible rect from property trees for the grandchild,
9031 // and we will configure |child| in several ways that should force the subtree
9032 // to be skipped. The visible content rect for |grandchild| should, therefore,
9033 // remain empty.
weiliangcc97575c2016-03-03 18:34:279034 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:059035
vollick2175fae82015-04-27 21:18:129036 gfx::Transform singular;
9037 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:059038 // This line is used to make the results of skipping and not skipping layers
9039 // different.
9040 singular.matrix().set(0, 1, 1);
9041
9042 gfx::Transform rotate;
9043 rotate.Rotate(90);
9044
9045 gfx::Transform rotate_back_and_translate;
9046 rotate_back_and_translate.RotateAboutYAxis(180);
9047 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:129048
jaydasika10d43fc2016-08-18 04:06:049049 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059050 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599051 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279052 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049053 child_ptr->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129054
jaydasika5121caa82016-05-05 15:43:359055 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika6ed869662016-09-21 14:29:599056 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279057 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359058 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129059
jaydasikab5bc1a22016-08-24 02:59:059060 child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated(
9061 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:599062 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279063 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:189064 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:129065
jaydasika10d43fc2016-08-18 04:06:049066 root_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059067 // Force transform tree to have a node for child, so that ancestor's
9068 // invertible transform can be tested.
jaydasika10d43fc2016-08-18 04:06:049069 child_ptr->test_properties()->transform = rotate;
sunxd71aea3e2016-04-01 23:48:059070 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599071 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059072 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049073 root_ptr->test_properties()->transform = gfx::Transform();
9074 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:059075
jaydasikaab317e02016-06-01 00:53:189076 root_ptr->test_properties()->opacity = 0.f;
9077 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:059078 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599079 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059080 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:189081 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:059082
jaydasikaab317e02016-06-01 00:53:189083 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:129084 // Now, even though child has zero opacity, we will configure |grandchild| and
9085 // |greatgrandchild| in several ways that should force the subtree to be
9086 // processed anyhow.
ajumae6f541b2016-05-31 16:50:509087 grandchild_ptr->test_properties()->copy_requests.push_back(
9088 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:099089 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599090 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279091 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:509092
9093 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:189094 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:059095
9096 // A double sided render surface with backface visible should not be skipped
9097 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9098 child_ptr->SetHasRenderSurface(true);
jaydasika6b5a32bf2016-04-22 21:56:369099 child_ptr->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049100 child_ptr->test_properties()->transform = rotate_back_and_translate;
sunxd71aea3e2016-04-01 23:48:059101 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599102 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059103 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049104 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:059105
danakj60bc3bc2016-04-09 00:24:489106 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059107 KeyframedTransformAnimationCurve::Create());
9108 TransformOperations start;
9109 start.AppendTranslate(1.f, 2.f, 3.f);
9110 gfx::Transform transform;
9111 transform.Scale3d(1.0, 2.0, 3.0);
9112 TransformOperations operation;
9113 operation.AppendMatrix(transform);
9114 curve->AddKeyframe(
9115 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9116 curve->AddKeyframe(TransformKeyframe::Create(
9117 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:489118 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:059119 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9120 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:589121 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279122 root_ptr->element_id(), player.get());
loysobb507792016-10-04 05:31:029123 player->AddAnimation(std::move(transform_animation));
sunxd71aea3e2016-04-01 23:48:059124 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9125 child_ptr->SetScrollClipLayer(root_ptr->id());
jaydasika10d43fc2016-08-18 04:06:049126 root_ptr->test_properties()->transform = singular;
9127 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059128 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599129 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:279130 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:059131
loysofb69174e2016-04-27 00:58:589132 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279133 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:059134}
9135
jaydasikaf187b06b2016-04-11 23:30:279136TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:599137 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:279138 LayerImpl* child = AddChild<LayerImpl>(root);
9139 LayerImpl* grand_child = AddChild<LayerImpl>(child);
9140
vollickef2ae922016-06-29 17:54:279141 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:279142
9143 gfx::Transform singular;
9144 singular.matrix().set(0, 0, 0);
9145 singular.matrix().set(0, 1, 1);
9146
danakjf78fb272016-07-26 19:06:159147 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:049148 child->test_properties()->transform = singular;
danakjf78fb272016-07-26 19:06:159149 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:279150 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159151 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:279152 grand_child->SetDrawsContent(true);
9153
danakj25c52c32016-04-12 21:51:089154 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:279155 KeyframedTransformAnimationCurve::Create());
9156 TransformOperations start;
9157 start.AppendTranslate(1.f, 2.f, 3.f);
9158 gfx::Transform transform;
9159 transform.Scale3d(1.0, 2.0, 3.0);
9160 TransformOperations operation;
9161 operation.AppendMatrix(transform);
9162 curve->AddKeyframe(
9163 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9164 curve->AddKeyframe(TransformKeyframe::Create(
9165 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:089166 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:279167 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9168 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:589169 host_impl()->active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279170 grand_child->element_id(), player.get());
loysobb507792016-10-04 05:31:029171 player->AddAnimation(std::move(transform_animation));
jaydasikaf187b06b2016-04-11 23:30:279172
9173 ExecuteCalculateDrawProperties(root);
9174 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
9175 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
9176
loysofb69174e2016-04-27 00:58:589177 host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279178 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:279179}
9180
sunxd71aea3e2016-04-01 23:48:059181TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
9182 FakeImplTaskRunnerProvider task_runner_provider;
sunxd71aea3e2016-04-01 23:48:059183 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:229184 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
sunxd71aea3e2016-04-01 23:48:059185
sunxd71aea3e2016-04-01 23:48:059186 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:489187 std::unique_ptr<LayerImpl> root =
9188 LayerImpl::Create(host_impl.pending_tree(), 1);
9189 std::unique_ptr<LayerImpl> child =
9190 LayerImpl::Create(host_impl.pending_tree(), 2);
9191 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:059192 LayerImpl::Create(host_impl.pending_tree(), 3);
9193
danakj60bc3bc2016-04-09 00:24:489194 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:059195 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
9196
danakjf78fb272016-07-26 19:06:159197 root->SetBounds(gfx::Size(100, 100));
9198 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:059199 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159200 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:059201 grandchild->SetDrawsContent(true);
9202 greatgrandchild->SetDrawsContent(true);
9203
sunxd71aea3e2016-04-01 23:48:059204 LayerImpl* root_ptr = root.get();
9205 LayerImpl* grandchild_ptr = grandchild.get();
9206
jaydasika89f7b5a2016-06-22 02:08:399207 child->test_properties()->AddChild(std::move(grandchild));
9208 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:059209
jaydasikabf1875a2016-06-28 03:39:599210 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:279211 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:059212
9213 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599214 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059215 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9216
danakj60bc3bc2016-04-09 00:24:489217 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059218 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:499219 std::unique_ptr<TimingFunction> func =
9220 CubicBezierTimingFunction::CreatePreset(
9221 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:059222 curve->AddKeyframe(
9223 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9224 curve->AddKeyframe(
9225 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489226 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059227 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9228 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:589229 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279230 root_ptr->element_id(), player.get());
loysobb507792016-10-04 05:31:029231 player->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189232 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059233 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9234 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599235 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059236 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9237
loysofb69174e2016-04-27 00:58:589238 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279239 root_ptr->element_id(), player.get());
vollick2175fae82015-04-27 21:18:129240}
9241
9242TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:599243 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149244 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129245
danakjf78fb272016-07-26 19:06:159246 root->SetBounds(gfx::Size(100, 100));
9247 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149248 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129249
jaydasika6f972de2016-04-07 16:16:149250 ExecuteCalculateDrawProperties(root);
9251 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279252 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129253
jaydasika5121caa82016-05-05 15:43:359254 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149255 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9256 ExecuteCalculateDrawProperties(root);
9257 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359258 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129259
9260 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149261 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9262 ExecuteCalculateDrawProperties(root);
9263 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129264 child->SetBounds(gfx::Size(10, 10));
9265
9266 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369267 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129268 rotate.RotateAboutXAxis(180.f);
jaydasika10d43fc2016-08-18 04:06:049269 child->test_properties()->transform = rotate;
jaydasika6f972de2016-04-07 16:16:149270 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9271 ExecuteCalculateDrawProperties(root);
9272 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369273 child->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049274 child->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129275
jaydasikaab317e02016-06-01 00:53:189276 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149277 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9278 ExecuteCalculateDrawProperties(root);
9279 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129280}
9281
jaydasika3d10aa62015-05-06 17:50:449282TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9283 // Ensure that the treewalk in LayerTreeHostCommom::
9284 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319285 scoped_refptr<Layer> root = Layer::Create();
9286 scoped_refptr<Layer> parent = Layer::Create();
9287 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449288
danakjf78fb272016-07-26 19:06:159289 root->SetBounds(gfx::Size(100, 100));
9290 parent->SetBounds(gfx::Size(100, 100));
9291 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:449292 child->SetClipParent(root.get());
9293
danakjf78fb272016-07-26 19:06:159294 root->AddChild(parent);
9295 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:339296 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449297
jaydasika3d10aa62015-05-06 17:50:449298 child->RequestCopyOfOutput(
9299 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029300
jaydasika6ed869662016-09-21 14:29:599301 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029302 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9303
9304 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika6ed869662016-09-21 14:29:599305 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029306 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449307}
9308
vollick692444f2015-05-20 15:39:149309TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:159310 scoped_refptr<Layer> root = Layer::Create();
9311 root->SetBounds(gfx::Size(800, 800));
9312
vollick692444f2015-05-20 15:39:149313 gfx::Transform translate_z;
9314 translate_z.Translate3d(0, 0, 10);
9315
loyso0940d412016-03-14 01:30:319316 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:159317 child->SetTransform(translate_z);
9318 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:149319
9320 root->AddChild(child);
9321
ennea7b43c32015-06-18 20:01:339322 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149323
jaydasika6ed869662016-09-21 14:29:599324 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149325 EXPECT_NE(-1, child->transform_tree_index());
9326
9327 child->RemoveFromParent();
9328
jaydasika6ed869662016-09-21 14:29:599329 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149330 EXPECT_EQ(-1, child->transform_tree_index());
9331}
9332
jaydasika67d7989e2015-08-06 21:55:349333TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9334 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:599335 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349336 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9337 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9338 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9339 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9340
jaydasika67d7989e2015-08-06 21:55:349341 // This transform should be a significant one so that a transform node is
9342 // formed for it.
9343 gfx::Transform transform1;
9344 transform1.RotateAboutYAxis(45);
9345 transform1.RotateAboutXAxis(30);
9346 // This transform should be a 3d transform as we want the render surface
9347 // to flatten the transform
9348 gfx::Transform transform2;
9349 transform2.Translate3d(10, 10, 10);
9350
danakjf78fb272016-07-26 19:06:159351 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049352 significant_transform->test_properties()->transform = transform1;
danakjf78fb272016-07-26 19:06:159353 significant_transform->SetBounds(gfx::Size(30, 30));
9354 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349355 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159356 layer_clips_subtree->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049357 render_surface->test_properties()->transform = transform2;
danakjf78fb272016-07-26 19:06:159358 render_surface->SetBounds(gfx::Size(30, 30));
9359 render_surface->test_properties()->force_render_surface = true;
9360 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349361 test_layer->SetDrawsContent(true);
9362
jaydasika5237db02016-09-20 01:34:309363 float device_scale_factor = 1.f;
9364 float page_scale_factor = 1.f;
9365 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:289366 LayerImpl* inner_viewport_scroll_layer = nullptr;
jaydasika5237db02016-09-20 01:34:309367 // Visible rects computed by combining clips in target space and root space
9368 // don't match because of rotation transforms. So, we skip
9369 // verify_visible_rect_calculations.
9370 bool skip_verify_visible_rect_calculations = true;
9371 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:289372 page_scale_layer, inner_viewport_scroll_layer,
jaydasika5237db02016-09-20 01:34:309373 skip_verify_visible_rect_calculations);
jaydasika67d7989e2015-08-06 21:55:349374
ajumae4af47062016-05-24 23:59:049375 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:349376 root->layer_tree_impl()->property_trees()->transform_tree;
9377 TransformNode* transform_node =
9378 transform_tree.Node(significant_transform->transform_tree_index());
9379 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9380
weiliangcc154ce22015-12-09 03:39:269381 EXPECT_TRUE(root->has_render_surface());
9382 EXPECT_FALSE(significant_transform->has_render_surface());
9383 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9384 EXPECT_TRUE(render_surface->has_render_surface());
9385 EXPECT_FALSE(test_layer->has_render_surface());
9386
ajumae4af47062016-05-24 23:59:049387 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:349388 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma259f1e72016-10-24 16:25:389389 EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE);
weiliangcd15784432016-06-07 17:57:339390 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect());
jaydasika5237db02016-09-20 01:34:309391
9392 // Also test the visible rects computed by combining clips in root space.
9393 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
9394 root->layer_tree_impl()->property_trees(), test_layer);
9395 EXPECT_EQ(gfx::Rect(30, 20), visible_rect);
jaydasika67d7989e2015-08-06 21:55:349396}
9397
9398TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9399 // Ensure that when parent clip node's transform is an ancestor of current
9400 // clip node's target, clip is 'projected' from parent space to current
9401 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:599402 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349403 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9404 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9405 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9406
jaydasika67d7989e2015-08-06 21:55:349407 gfx::Transform transform;
9408 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:159409
9410 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049411 clip_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159412 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349413 clip_layer->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049414 target_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159415 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349416 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159417 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349418 test_layer->SetDrawsContent(true);
9419
jaydasika67d7989e2015-08-06 21:55:349420 ExecuteCalculateDrawProperties(root);
9421
weiliangcc97575c2016-03-03 18:34:279422 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349423}
9424
jaydasika7d5c1ed2015-08-14 14:27:029425TEST_F(LayerTreeHostCommonTest,
9426 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9427 // Ensure clip rect is calculated correctly when render surface has unclipped
9428 // descendants.
jaydasikabf1875a2016-06-28 03:39:599429 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:029430 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9431 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9432 LayerImpl* render_surface =
9433 AddChild<LayerImpl>(between_clip_parent_and_child);
9434 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9435
weiliangcbb2e8642016-03-04 00:24:429436 gfx::Transform translate;
9437 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029438
danakjf78fb272016-07-26 19:06:159439 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049440 clip_parent->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159441 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:429442 clip_parent->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049443 between_clip_parent_and_child->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159444 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
9445 render_surface->SetBounds(gfx::Size(30, 30));
9446 render_surface->test_properties()->force_render_surface = true;
9447 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:029448 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159449
jaydasika1c0a27d42016-04-28 01:54:569450 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159451 clip_parent->test_properties()->clip_children =
9452 base::MakeUnique<std::set<LayerImpl*>>();
9453 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:029454
9455 ExecuteCalculateDrawProperties(root);
9456
weiliangcbb2e8642016-03-04 00:24:429457 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259458 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569459 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9460 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029461}
9462
jaydasika571dd2cf2015-09-25 20:55:429463TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089464 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9465 // Ensure that the visible layer rect of a descendant of a surface with
9466 // unclipped descendants is computed correctly, when the surface doesn't apply
9467 // a clip.
jaydasikabf1875a2016-06-28 03:39:599468 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:089469 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9470 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9471 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9472 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9473
danakjf78fb272016-07-26 19:06:159474 root->SetBounds(gfx::Size(30, 10));
9475 clip_parent->SetBounds(gfx::Size(30, 30));
9476 render_surface->SetBounds(gfx::Size(10, 15));
9477 render_surface->test_properties()->force_render_surface = true;
9478 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:089479 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159480 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:089481 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159482
jaydasika1c0a27d42016-04-28 01:54:569483 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159484 clip_parent->test_properties()->clip_children =
9485 base::MakeUnique<std::set<LayerImpl*>>();
9486 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:089487
9488 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:189489 EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect());
ajuma01734dd02015-10-07 01:22:089490}
9491
9492TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429493 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:599494 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429495 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9496 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9497 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9498 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9499 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9500
danakjf78fb272016-07-26 19:06:159501 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429502 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159503 clip_parent->SetBounds(gfx::Size(30, 30));
9504 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429505 render_surface->SetMasksToBounds(true);
9506 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159507 render_surface->test_properties()->force_render_surface = true;
9508 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429509 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159510 clip_child->SetBounds(gfx::Size(50, 50));
9511 clip_child->SetDrawsContent(true);
9512 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429513 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429514
danakjf78fb272016-07-26 19:06:159515 clip_child->test_properties()->clip_parent = clip_parent;
9516 clip_parent->test_properties()->clip_children =
9517 base::MakeUnique<std::set<LayerImpl*>>();
9518 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:429519
9520 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569521 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9522 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429523 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9524 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9525}
9526
ajumae2b7a5c2015-09-30 21:41:429527TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:599528 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:429529 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9530 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9531 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9532
danakjf78fb272016-07-26 19:06:159533 root->SetBounds(gfx::Size(50, 50));
9534 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429535 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159536 render_surface->SetBounds(gfx::Size(30, 30));
9537 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:429538 render_surface->SetMasksToBounds(true);
9539 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159540 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429541 clip_child->SetDrawsContent(true);
9542
jaydasika1c0a27d42016-04-28 01:54:569543 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159544 clip_parent->test_properties()->clip_children =
9545 base::MakeUnique<std::set<LayerImpl*>>();
9546 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:429547
9548 ExecuteCalculateDrawProperties(root);
9549
9550 // The clip child should inherit its clip parent's clipping state, not its
9551 // tree parent's clipping state.
9552 EXPECT_FALSE(clip_parent->is_clipped());
9553 EXPECT_TRUE(render_surface->is_clipped());
9554 EXPECT_FALSE(clip_child->is_clipped());
9555}
9556
jaydasika77a4a072015-10-20 21:47:279557TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9558 // Tests the value of render surface content rect when we have multiple types
9559 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9560 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:599561 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279562 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9563 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9564 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9565 LayerImpl* unclipped_desc_surface2 =
9566 AddChild<LayerImpl>(unclipped_desc_surface);
9567 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9568 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9569
danakjf78fb272016-07-26 19:06:159570 root->SetBounds(gfx::Size(80, 80));
9571 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:279572 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159573 unclipped_surface->SetDrawsContent(true);
9574 unclipped_surface->test_properties()->force_render_surface = true;
9575 clip_parent->SetBounds(gfx::Size(50, 50));
9576 clip_parent->SetMasksToBounds(true);
9577 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279578 unclipped_desc_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159579 unclipped_desc_surface->SetDrawsContent(true);
9580 unclipped_desc_surface->test_properties()->force_render_surface = true;
9581 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
9582 unclipped_desc_surface2->SetDrawsContent(true);
9583 unclipped_desc_surface2->test_properties()->force_render_surface = true;
9584 clip_child->SetBounds(gfx::Size(100, 100));
9585 clipped_surface->SetBounds(gfx::Size(70, 70));
9586 clipped_surface->SetDrawsContent(true);
9587 clipped_surface->test_properties()->force_render_surface = true;
9588
9589 clip_child->test_properties()->clip_parent = clip_parent;
9590 clip_parent->test_properties()->clip_children =
9591 base::MakeUnique<std::set<LayerImpl*>>();
9592 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279593
9594 ExecuteCalculateDrawProperties(root);
9595 EXPECT_EQ(gfx::Rect(50, 50),
9596 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:569597 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:279598 unclipped_desc_surface->render_surface()->content_rect());
9599 EXPECT_EQ(gfx::Rect(50, 50),
9600 unclipped_desc_surface2->render_surface()->content_rect());
9601 EXPECT_EQ(gfx::Rect(50, 50),
9602 clipped_surface->render_surface()->content_rect());
9603}
9604
9605TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9606 // Tests the value of render surface content rect when we have a layer that
9607 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:599608 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279609 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9610 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9611 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9612 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9613 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9614
jaydasika77a4a072015-10-20 21:47:279615 gfx::Transform translate;
9616 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:159617
jaydasika778cb272016-08-15 19:00:549618 gfx::Transform rotate;
9619 rotate.RotateAboutXAxis(10);
9620
danakjf78fb272016-07-26 19:06:159621 root->SetBounds(gfx::Size(100, 100));
9622 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279623 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159624 surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049625 surface->test_properties()->transform = rotate;
danakjf78fb272016-07-26 19:06:159626 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:279627 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159628 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:049629 unclipped_desc_surface->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159630 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9631 unclipped_desc_surface->SetDrawsContent(true);
9632 unclipped_desc_surface->test_properties()->force_render_surface = true;
9633 clip_child->SetBounds(gfx::Size(100, 100));
9634 clip_child->SetDrawsContent(true);
9635
9636 clip_child->test_properties()->clip_parent = clip_parent;
9637 clip_parent->test_properties()->clip_children =
9638 base::MakeUnique<std::set<LayerImpl*>>();
9639 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279640
9641 ExecuteCalculateDrawProperties(root);
9642
9643 EXPECT_EQ(gfx::Rect(10, 10),
9644 unclipped_desc_surface->render_surface()->content_rect());
9645}
9646
jaydasika2c8c2872015-10-21 23:28:219647TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:599648 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:219649 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9650 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9651 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9652 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9653 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9654
jaydasika2c8c2872015-10-21 23:28:219655
jaydasika2c8c2872015-10-21 23:28:219656 gfx::Transform scale;
9657 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:159658
9659 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:049660 surface->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159661 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:219662 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159663 surface->test_properties()->force_render_surface = true;
9664 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:219665 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159666 clip_parent->SetBounds(gfx::Size(50, 50));
9667 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9668 unclipped_desc_surface->SetDrawsContent(true);
9669 unclipped_desc_surface->test_properties()->force_render_surface = true;
9670 clip_child->SetBounds(gfx::Size(100, 100));
9671 clip_child->SetDrawsContent(true);
9672
9673 clip_child->test_properties()->clip_parent = clip_parent;
9674 clip_parent->test_properties()->clip_children =
9675 base::MakeUnique<std::set<LayerImpl*>>();
9676 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:219677
9678 ExecuteCalculateDrawProperties(root);
9679
9680 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9681}
9682
jaydasika60f85862015-10-01 20:36:149683TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:599684 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:149685 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9686 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9687
jaydasika86654512016-01-27 17:05:079688 gfx::Transform translation;
9689 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:149690
danakjf78fb272016-07-26 19:06:159691 root->SetBounds(gfx::Size(30, 30));
9692 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:149693 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159694 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049695 test_layer->test_properties()->transform = translation;
danakjf78fb272016-07-26 19:06:159696 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:149697 test_layer->SetDrawsContent(true);
dtapuskaee0b6982016-01-29 15:14:489698 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
danakjf78fb272016-07-26 19:06:159699 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:149700
9701 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:029702 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
9703 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149704}
9705
jaydasikae4910fa22015-10-09 00:52:099706TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:599707 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:099708 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9709 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9710 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9711
danakjf78fb272016-07-26 19:06:159712 root->SetBounds(gfx::Size(30, 30));
9713 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:099714 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159715 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099716 render_surface->SetMasksToBounds(true);
9717 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159718 render_surface->test_properties()->force_render_surface = true;
9719 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099720 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:099721
danakjf78fb272016-07-26 19:06:159722 clip_child->test_properties()->clip_parent = clip_parent;
9723 clip_parent->test_properties()->clip_children =
9724 base::MakeUnique<std::set<LayerImpl*>>();
9725 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:099726
9727 ExecuteCalculateDrawProperties(root);
jaydasikab4df4032016-09-13 18:38:499728 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
jaydasikae4910fa22015-10-09 00:52:099729}
9730
jaydasika571dd2cf2015-09-25 20:55:429731TEST_F(LayerTreeHostCommonTest,
9732 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:599733 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429734 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9735 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:159736
9737 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429738 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369739 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159740 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429741 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369742 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159743 render_surface->test_properties()->force_render_surface = true;
9744 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429745 test_layer->SetMasksToBounds(true);
9746 test_layer->SetDrawsContent(true);
9747 ExecuteCalculateDrawProperties(root);
9748
9749 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9750 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9751 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9752}
9753
jaydasikab5504ca2015-12-18 23:41:559754TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9755 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:599756 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:559757 LayerImpl* hidden = AddChild<LayerImpl>(root);
9758 LayerImpl* test = AddChild<LayerImpl>(hidden);
9759
danakjf78fb272016-07-26 19:06:159760 root->SetBounds(gfx::Size(30, 30));
9761 hidden->SetBounds(gfx::Size(30, 30));
9762 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:359763 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:159764 test->SetBounds(gfx::Size(30, 30));
9765 test->test_properties()->force_render_surface = true;
9766
jaydasikab5504ca2015-12-18 23:41:559767 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079768 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559769
jaydasika5121caa82016-05-05 15:43:359770 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559771 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9772 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079773 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559774}
9775
jaydasikac0137282015-10-01 15:50:309776TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:599777 LayerImpl* root = root_layer_for_testing();
jaydasikac0137282015-10-01 15:50:309778 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9779 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9780 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9781
danakjf78fb272016-07-26 19:06:159782 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309783 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159784 render_surface1->SetPosition(gfx::PointF(10, 10));
9785 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309786 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159787 render_surface1->test_properties()->force_render_surface = true;
9788 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309789 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159790 render_surface2->test_properties()->force_render_surface = true;
9791 clip_child->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309792
danakjf78fb272016-07-26 19:06:159793 clip_child->test_properties()->clip_parent = root;
9794 root->test_properties()->clip_children =
9795 base::MakeUnique<std::set<LayerImpl*>>();
9796 root->test_properties()->clip_children->insert(clip_child);
9797
jaydasikac0137282015-10-01 15:50:309798 ExecuteCalculateDrawProperties(root);
9799
9800 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379801 // A clip node is created for every render surface and for layers that have
9802 // local clip. So, here it should be craeted for every layer.
9803 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309804}
9805
ajumadb6216f2c2016-06-07 21:44:059806TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
9807 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599808 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:099809 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509810 child->test_properties()->SetMaskLayer(
9811 LayerImpl::Create(root->layer_tree_impl(), 100));
9812 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:099813
jaydasika224bca02015-12-18 02:37:099814 gfx::Transform transform;
9815 transform.Translate(10, 10);
9816
danakjf78fb272016-07-26 19:06:159817 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:099818 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:049819 child->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159820 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:099821 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:159822 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:099823 ExecuteCalculateDrawProperties(root);
9824
ajumadb6216f2c2016-06-07 21:44:059825 // The render surface created for the mask has no contributing content, so the
9826 // mask isn't a drawn RSLL member. This means it has an empty visible rect,
9827 // but its screen space transform can still be computed correctly on-demand.
ajuma1d4026a32016-06-14 13:18:509828 EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member());
9829 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
9830 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059831
9832 // Make the child's render surface have contributing content.
9833 child->SetDrawsContent(true);
9834 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9835 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509836 EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member());
9837 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
9838 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059839
jaydasika224bca02015-12-18 02:37:099840 transform.Translate(10, 10);
jaydasika10d43fc2016-08-18 04:06:049841 child->test_properties()->transform = transform;
jaydasika224bca02015-12-18 02:37:099842 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9843 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509844 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
9845 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:059846}
9847
jaydasikaf62311f2016-04-20 14:38:459848TEST_F(LayerTreeHostCommonTest,
9849 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:599850 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:459851 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9852 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9853 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9854 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:459855
9856 gfx::Transform scale;
9857 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:159858
9859 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049860 render_surface1->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159861 render_surface1->SetBounds(gfx::Size(30, 30));
9862 render_surface1->test_properties()->force_render_surface = true;
9863 between_targets->SetBounds(gfx::Size(30, 30));
9864 render_surface2->SetBounds(gfx::Size(30, 30));
9865 render_surface2->test_properties()->force_render_surface = true;
9866 test_layer->SetBounds(gfx::Size(30, 30));
9867 test_layer->SetDrawsContent(true);
9868
jaydasikab433552b2016-10-26 18:49:449869 // We want layer between the two targets to create a clip node and effect
jaydasikaf62311f2016-04-20 14:38:459870 // node but it shouldn't create a render surface.
9871 between_targets->SetMasksToBounds(true);
jaydasikab433552b2016-10-26 18:49:449872 between_targets->test_properties()->opacity = 0.5f;
jaydasikaf62311f2016-04-20 14:38:459873
9874 ExecuteCalculateDrawProperties(root);
9875
jaydasikab433552b2016-10-26 18:49:449876 EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree;
9877 EffectNode* node = tree.Node(render_surface1->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439878 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459879
jaydasikab433552b2016-10-26 18:49:449880 node = tree.Node(between_targets->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439881 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:459882
jaydasikab433552b2016-10-26 18:49:449883 node = tree.Node(render_surface2->effect_tree_index());
jaydasika6be761602016-07-18 20:11:439884 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459885
9886 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9887}
9888
jaydasika3c5633d2016-08-25 00:39:229889TEST_F(LayerTreeHostCommonTest, NoisyTransform) {
9890 LayerImpl* root = root_layer_for_testing();
9891 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9892 LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface);
9893 LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface);
9894 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip);
9895
9896 scroll_child->test_properties()->scroll_parent = scroll_parent;
9897 scroll_parent->test_properties()->scroll_children =
9898 base::MakeUnique<std::set<LayerImpl*>>();
9899 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
9900 scroll_parent->SetScrollClipLayer(scroll_clip->id());
9901
9902 scroll_parent->SetDrawsContent(true);
9903 scroll_child->SetDrawsContent(true);
9904 render_surface->test_properties()->force_render_surface = true;
9905
9906 // A noisy transform that's invertible.
9907 gfx::Transform transform;
9908 transform.matrix().setDouble(0, 0, 6.12323e-17);
9909 transform.matrix().setDouble(0, 2, 1);
9910 transform.matrix().setDouble(2, 2, 6.12323e-17);
9911 transform.matrix().setDouble(2, 0, -1);
9912
9913 scroll_child->test_properties()->transform = transform;
9914 render_surface->test_properties()->transform = transform;
9915
9916 root->SetBounds(gfx::Size(30, 30));
9917 scroll_child->SetBounds(gfx::Size(30, 30));
9918 scroll_parent->SetBounds(gfx::Size(30, 30));
9919 ExecuteCalculateDrawProperties(root);
9920
9921 gfx::Transform expected;
9922 expected.matrix().setDouble(0, 0, 3.749395e-33);
9923 expected.matrix().setDouble(0, 2, 6.12323e-17);
9924 expected.matrix().setDouble(2, 0, -1);
9925 expected.matrix().setDouble(2, 2, 6.12323e-17);
9926 EXPECT_TRANSFORMATION_MATRIX_EQ(expected,
9927 scroll_child->ScreenSpaceTransform());
9928}
9929
jaydasika5160e672015-10-15 15:25:149930TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:599931 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:149932 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059933 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149934
sunxd71aea3e2016-04-01 23:48:059935 child->SetDrawsContent(true);
9936 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149937
9938 gfx::Transform large_transform;
9939 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9940 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9941 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9942 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9943
danakjf78fb272016-07-26 19:06:159944 root->SetBounds(gfx::Size(30, 30));
9945 render_surface1->SetBounds(gfx::Size(30, 30));
9946 render_surface1->test_properties()->force_render_surface = true;
9947
sunxd71aea3e2016-04-01 23:48:059948 // TODO(sunxd): we make child have no render surface, because if the
9949 // child has one, the large transform applied to child will result in NaNs in
9950 // the draw_transform of the render_surface, thus make draw property updates
9951 // skip the child layer. We need further investigation into this to know
9952 // what exactly happens here.
jaydasika10d43fc2016-08-18 04:06:049953 child->test_properties()->transform = large_transform;
danakjf78fb272016-07-26 19:06:159954 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:149955
9956 ExecuteCalculateDrawProperties(root);
9957
jaydasika5160e672015-10-15 15:25:149958 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:059959 render_surface1->render_surface()->DrawableContentRect());
9960
9961 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9962 std::isnan(child->DrawTransform().matrix().get(0, 0));
9963 EXPECT_TRUE(is_inf_or_nan);
9964
9965 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9966 std::isnan(child->DrawTransform().matrix().get(1, 1));
9967 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149968
danakj59931942016-07-26 22:11:299969 // The root layer should be in the RenderSurfaceLayerListImpl.
9970 const auto* rsll = render_surface_layer_list_impl();
9971 EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end());
jaydasika5160e672015-10-15 15:25:149972}
9973
jaydasika8d6efe2e2016-05-17 15:37:219974TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:219975 scoped_refptr<Layer> root = Layer::Create();
9976 scoped_refptr<LayerWithForcedDrawsContent> child =
9977 make_scoped_refptr(new LayerWithForcedDrawsContent());
9978 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:219979 host()->SetRootLayer(root);
9980
danakjf78fb272016-07-26 19:06:159981 root->SetBounds(gfx::Size(100, 100));
9982 child->SetBounds(gfx::Size(20, 20));
jaydasika6ed869662016-09-21 14:29:599983 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219984
9985 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9986 // property trees as a new effect node will be created.
9987 child->SetOpacity(0.5f);
9988 PropertyTrees* property_trees = host()->property_trees();
9989 EXPECT_TRUE(property_trees->needs_rebuild);
9990
jaydasika6ed869662016-09-21 14:29:599991 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219992 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9993 property_trees->effect_id_to_index_map.end());
9994
9995 // child already has an effect node. Changing its opacity shouldn't trigger
9996 // a property trees rebuild.
9997 child->SetOpacity(0.8f);
9998 property_trees = host()->property_trees();
9999 EXPECT_FALSE(property_trees->needs_rebuild);
10000
jaydasika6ed869662016-09-21 14:29:5910001 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110002 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
10003 property_trees->effect_id_to_index_map.end());
10004
10005 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
10006 // property trees as the effect node may no longer be needed.
10007 child->SetOpacity(1.f);
10008 property_trees = host()->property_trees();
10009 EXPECT_TRUE(property_trees->needs_rebuild);
10010
jaydasika6ed869662016-09-21 14:29:5910011 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110012 EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()),
10013 property_trees->effect_id_to_index_map.end());
10014}
10015
jaydasika9cb21c772016-05-10 22:37:0810016TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:0810017 scoped_refptr<Layer> root = Layer::Create();
10018 scoped_refptr<LayerWithForcedDrawsContent> animated =
10019 make_scoped_refptr(new LayerWithForcedDrawsContent());
10020 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:0810021 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:0810022 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:2710023
danakjf78fb272016-07-26 19:06:1510024 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:0810025 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:1510026 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:0810027 animated->SetOpacity(0.f);
10028
10029 scoped_refptr<AnimationPlayer> player =
10030 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
10031 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:2710032
10033 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:0810034
10035 int animation_id = 0;
10036 std::unique_ptr<Animation> animation = Animation::Create(
10037 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
10038 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:5510039 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:0810040 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
10041 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:2710042 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
10043 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:0810044
jaydasika6ed869662016-09-21 14:29:5910045 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika9cb21c772016-05-10 22:37:0810046
khushalsagar86928f92016-08-17 21:49:0510047 EffectTree& tree = root->GetLayerTree()->property_trees()->effect_tree;
jaydasika9cb21c772016-05-10 22:37:0810048 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110049 EXPECT_FALSE(node->is_currently_animating_opacity);
10050 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810051
10052 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:5810053 host()->AnimateLayers(
jaydasika9cb21c772016-05-10 22:37:0810054 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
10055 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110056 EXPECT_TRUE(node->is_currently_animating_opacity);
10057 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810058
10059 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
10060 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110061 EXPECT_FALSE(node->is_currently_animating_opacity);
10062 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810063}
10064
jaydasika6c3404e92016-05-19 02:40:3610065TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:3610066 scoped_refptr<Layer> root = Layer::Create();
10067 scoped_refptr<LayerWithForcedDrawsContent> animated =
10068 make_scoped_refptr(new LayerWithForcedDrawsContent());
10069 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:3610070 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:0810071 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:2710072
danakjf78fb272016-07-26 19:06:1510073 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:3610074 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:1510075 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:3610076
10077 scoped_refptr<AnimationPlayer> player =
10078 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
10079 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:2710080 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:3610081
10082 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
10083 KeyframedTransformAnimationCurve::Create());
10084 TransformOperations start;
10085 start.AppendTranslate(1.f, 2.f, 3.f);
10086 gfx::Transform transform;
10087 transform.Scale3d(1.0, 2.0, 3.0);
10088 TransformOperations operation;
10089 operation.AppendMatrix(transform);
10090 curve->AddKeyframe(
10091 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
10092 curve->AddKeyframe(TransformKeyframe::Create(
10093 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
10094 std::unique_ptr<Animation> animation(
10095 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
10096 animation->set_fill_mode(Animation::FillMode::NONE);
10097 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
10098 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:2710099 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
10100 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:3610101
jaydasika6ed869662016-09-21 14:29:5910102 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika6c3404e92016-05-19 02:40:3610103
khushalsagar86928f92016-08-17 21:49:0510104 TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree;
jaydasika6c3404e92016-05-19 02:40:3610105 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110106 EXPECT_FALSE(node->is_currently_animating);
10107 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610108
10109 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:5810110 host()->AnimateLayers(
jaydasika6c3404e92016-05-19 02:40:3610111 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
10112 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110113 EXPECT_TRUE(node->is_currently_animating);
10114 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610115
10116 player->AbortAnimations(TargetProperty::TRANSFORM,
10117 false /*needs_completion*/);
10118 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110119 EXPECT_FALSE(node->is_currently_animating);
10120 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610121}
10122
khushalsagar37694212016-01-15 20:46:4810123TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
10124 LayerTreeHostCommon::ScrollUpdateInfo scroll;
10125 scroll.layer_id = 2;
10126 scroll.scroll_delta = gfx::Vector2d(5, 10);
10127
10128 proto::ScrollUpdateInfo proto;
10129 scroll.ToProtobuf(&proto);
10130 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
10131 new_scroll.FromProtobuf(proto);
10132
10133 EXPECT_EQ(scroll, new_scroll);
10134}
10135
10136TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
10137 ScrollAndScaleSet scroll_and_scale_set;
10138
10139 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
10140 scroll1.layer_id = 1;
10141 scroll1.scroll_delta = gfx::Vector2d(5, 10);
10142 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
10143 scroll2.layer_id = 2;
10144 scroll2.scroll_delta = gfx::Vector2d(1, 5);
10145 scroll_and_scale_set.scrolls.push_back(scroll1);
10146 scroll_and_scale_set.scrolls.push_back(scroll2);
10147
10148 scroll_and_scale_set.page_scale_delta = 0.3f;
10149 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
10150 scroll_and_scale_set.top_controls_delta = 0.9f;
10151
10152 proto::ScrollAndScaleSet proto;
10153 scroll_and_scale_set.ToProtobuf(&proto);
10154 ScrollAndScaleSet new_scroll_and_scale_set;
10155 new_scroll_and_scale_set.FromProtobuf(proto);
10156
10157 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
10158}
10159
sunxdea1df782016-01-28 00:12:3310160TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
10161 // Test the behavior of scroll tree builder
10162 // Topology:
sunxdcfccd1b32016-02-11 00:54:2010163 // +root1(1)[inner_viewport_container_layer]
10164 // +-page_scale_layer
10165 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
10166 // scrollable, inner_viewport_scroll_layer]
10167 // +------child6(6)[kScrollbarScrolling]
10168 // +--------grand_child10(10)[kScrollbarScrolling]
10169 // +----parent3(3)
10170 // +------child7(7)[scrollable]
10171 // +------child8(8)[scroll_parent=7]
10172 // +--------grand_child11(11)[scrollable]
10173 // +----parent4(4)
10174 // +------child9(9)
10175 // +--------grand_child12(12)
10176 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:3310177 //
10178 // Expected scroll tree topology:
10179 // +property_tree_root---owner:-1
10180 // +--root---owner:1, id:1
10181 // +----node---owner:2, id:2
10182 // +------node---owner:6, id:3
10183 // +----node---owner:7, id:4
10184 // +------node---owner:11, id:5
10185 // +----node---owner:5, id:6
10186 //
10187 // Extra check:
10188 // scroll_tree_index() of:
10189 // grand_child10:3
10190 // parent3:1
10191 // child8:4
10192 // parent4:1
10193 // child9:1
10194 // grand_child12:1
loyso0940d412016-03-14 01:30:3110195 scoped_refptr<Layer> root1 = Layer::Create();
10196 scoped_refptr<Layer> page_scale_layer = Layer::Create();
10197 scoped_refptr<Layer> parent2 = Layer::Create();
10198 scoped_refptr<Layer> parent3 = Layer::Create();
10199 scoped_refptr<Layer> parent4 = Layer::Create();
10200 scoped_refptr<Layer> parent5 = Layer::Create();
10201 scoped_refptr<Layer> child6 = Layer::Create();
10202 scoped_refptr<Layer> child7 = Layer::Create();
10203 scoped_refptr<Layer> child8 = Layer::Create();
10204 scoped_refptr<Layer> child9 = Layer::Create();
10205 scoped_refptr<Layer> grand_child10 = Layer::Create();
10206 scoped_refptr<Layer> grand_child11 = Layer::Create();
10207 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:3310208
sunxdcfccd1b32016-02-11 00:54:2010209 root1->AddChild(page_scale_layer);
10210 page_scale_layer->AddChild(parent2);
10211 page_scale_layer->AddChild(parent3);
10212 page_scale_layer->AddChild(parent4);
10213 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310214 parent2->AddChild(child6);
10215 parent3->AddChild(child7);
10216 parent3->AddChild(child8);
10217 parent4->AddChild(child9);
10218 child6->AddChild(grand_child10);
10219 child8->AddChild(grand_child11);
10220 child9->AddChild(grand_child12);
10221 host()->SetRootLayer(root1);
10222
10223 parent2->AddMainThreadScrollingReasons(
10224 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:4810225 parent2->AddMainThreadScrollingReasons(
10226 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310227 parent2->SetScrollClipLayerId(root1->id());
10228 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810229 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310230 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810231 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310232
sunxdcfccd1b32016-02-11 00:54:2010233 child7->SetScrollClipLayerId(parent3->id());
10234
sunxdea1df782016-01-28 00:12:3310235 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:2010236 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:3310237
10238 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010239 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310240
khushalsagar86928f92016-08-17 21:49:0510241 host()->GetLayerTree()->RegisterViewportLayers(nullptr, page_scale_layer,
10242 parent2, nullptr);
jaydasika6ed869662016-09-21 14:29:5910243 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get());
sunxdea1df782016-01-28 00:12:3310244
10245 const int kInvalidPropertyTreeNodeId = -1;
10246 const int kRootPropertyTreeNodeId = 0;
10247
10248 // Property tree root
ajumae4af47062016-05-24 23:59:0410249 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010250 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010251 property_trees.is_main_thread = true;
10252 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410253 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310254 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10255 property_tree_root->id = kRootPropertyTreeNodeId;
10256 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
10257 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
trchendba8b1502016-07-08 09:47:0110258 property_tree_root->scrollable = false;
10259 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810260 MainThreadScrollingReason::kNotScrollingOnMain;
trchendba8b1502016-07-08 09:47:0110261 property_tree_root->contains_non_fast_scrollable_region = false;
10262 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310263
10264 // The node owned by root1
10265 ScrollNode scroll_root1;
10266 scroll_root1.id = 1;
10267 scroll_root1.owner_id = root1->id();
trchendba8b1502016-07-08 09:47:0110268 scroll_root1.user_scrollable_horizontal = true;
10269 scroll_root1.user_scrollable_vertical = true;
10270 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310271 expected_scroll_tree.Insert(scroll_root1, 0);
10272
10273 // The node owned by parent2
10274 ScrollNode scroll_parent2;
10275 scroll_parent2.id = 2;
10276 scroll_parent2.owner_id = parent2->id();
trchendba8b1502016-07-08 09:47:0110277 scroll_parent2.scrollable = true;
10278 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810279 parent2->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110280 scroll_parent2.scroll_clip_layer_bounds = root1->bounds();
10281 scroll_parent2.bounds = parent2->bounds();
10282 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
10283 scroll_parent2.is_inner_viewport_scroll_layer = true;
10284 scroll_parent2.user_scrollable_horizontal = true;
10285 scroll_parent2.user_scrollable_vertical = true;
10286 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310287 expected_scroll_tree.Insert(scroll_parent2, 1);
10288
10289 // The node owned by child6
10290 ScrollNode scroll_child6;
10291 scroll_child6.id = 3;
10292 scroll_child6.owner_id = child6->id();
trchendba8b1502016-07-08 09:47:0110293 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810294 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110295 scroll_child6.should_flatten = true;
10296 scroll_child6.user_scrollable_horizontal = true;
10297 scroll_child6.user_scrollable_vertical = true;
10298 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310299 expected_scroll_tree.Insert(scroll_child6, 2);
10300
10301 // The node owned by child7, child7 also owns a transform node
10302 ScrollNode scroll_child7;
10303 scroll_child7.id = 4;
10304 scroll_child7.owner_id = child7->id();
trchendba8b1502016-07-08 09:47:0110305 scroll_child7.scrollable = true;
10306 scroll_child7.scroll_clip_layer_bounds = parent3->bounds();
10307 scroll_child7.bounds = child7->bounds();
10308 scroll_child7.user_scrollable_horizontal = true;
10309 scroll_child7.user_scrollable_vertical = true;
10310 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310311 expected_scroll_tree.Insert(scroll_child7, 1);
10312
10313 // The node owned by grand_child11, grand_child11 also owns a transform node
10314 ScrollNode scroll_grand_child11;
10315 scroll_grand_child11.id = 5;
10316 scroll_grand_child11.owner_id = grand_child11->id();
trchendba8b1502016-07-08 09:47:0110317 scroll_grand_child11.scrollable = true;
10318 scroll_grand_child11.user_scrollable_horizontal = true;
10319 scroll_grand_child11.user_scrollable_vertical = true;
10320 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310321 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10322
10323 // The node owned by parent5
10324 ScrollNode scroll_parent5;
10325 scroll_parent5.id = 8;
10326 scroll_parent5.owner_id = parent5->id();
trchendba8b1502016-07-08 09:47:0110327 scroll_parent5.contains_non_fast_scrollable_region = true;
10328 scroll_parent5.bounds = gfx::Size(10, 10);
10329 scroll_parent5.should_flatten = true;
10330 scroll_parent5.user_scrollable_horizontal = true;
10331 scroll_parent5.user_scrollable_vertical = true;
10332 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310333 expected_scroll_tree.Insert(scroll_parent5, 1);
10334
sunxdc044b11a2016-03-16 16:23:2010335 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10336 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10337 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10338 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310339 expected_scroll_tree.set_needs_update(false);
10340
10341 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10342
10343 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010344 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310345 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10346 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10347 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10348 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10349 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10350 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10351}
10352
[email protected]ba565742012-11-10 09:29:4810353} // namespace
10354} // namespace cc