blob: 1b1e75a9d75dee31e0eac3425e28afb081f65a83 [file] [log] [blame]
ajumae2b7a5c2015-09-30 21:41:421// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_common.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj6496cba2014-10-16 01:31:089#include <algorithm>
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]995708c52013-10-17 20:52:5911#include <set>
vmpstra370ef52015-11-18 10:41:2812#include <vector>
[email protected]995708c52013-10-17 20:52:5913
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
loyso968163c92016-01-04 23:18:4815#include "cc/animation/animation_host.h"
16#include "cc/animation/animation_id_provider.h"
sunxd71aea3e2016-04-01 23:48:0517#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3418#include "cc/animation/keyframed_animation_curve.h"
[email protected]1c3626e2014-04-09 17:49:2219#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5220#include "cc/base/math_util.h"
sunxd29f17bf2016-02-03 02:47:4821#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/content_layer_client.h"
[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() {
65 verify_transform_tree_calculations = true;
jaydasika853306a2016-07-29 19:28:3466 verify_clip_tree_calculations = true;
danakj59931942016-07-26 22:11:2967 }
68};
69
70class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest {
71 public:
72 LayerTreeHostCommonTestBase()
73 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {}
74 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings)
75 : LayerTestCommon::LayerImplTest(settings) {}
76
77 static void SetScrollOffsetDelta(LayerImpl* layer_impl,
78 const gfx::Vector2dF& delta) {
79 if (layer_impl->layer_tree_impl()
80 ->property_trees()
81 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(),
82 delta))
vollickc9696912016-09-16 16:02:4783 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id());
danakj59931942016-07-26 22:11:2984 }
85
86 static float GetMaximumAnimationScale(LayerImpl* layer_impl) {
87 return layer_impl->layer_tree_impl()
88 ->property_trees()
89 ->GetAnimationScales(layer_impl->transform_tree_index(),
90 layer_impl->layer_tree_impl())
91 .maximum_animation_scale;
92 }
93
94 static float GetStartingAnimationScale(LayerImpl* layer_impl) {
95 return layer_impl->layer_tree_impl()
96 ->property_trees()
97 ->GetAnimationScales(layer_impl->transform_tree_index(),
98 layer_impl->layer_tree_impl())
99 .starting_animation_scale;
100 }
101
102 void ExecuteCalculateDrawProperties(Layer* root_layer,
103 float device_scale_factor,
104 float page_scale_factor,
105 Layer* page_scale_layer) {
106 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;
121 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
122 }
123
jaydasika5237db02016-09-20 01:34:30124 void ExecuteCalculateDrawProperties(
125 LayerImpl* root_layer,
126 float device_scale_factor,
127 float page_scale_factor,
128 LayerImpl* page_scale_layer,
129 bool skip_verify_visible_rect_calculations = false) {
danakj59931942016-07-26 22:11:29130 if (device_scale_factor !=
131 root_layer->layer_tree_impl()->device_scale_factor())
132 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
133
134 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
135
136 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
137
138 gfx::Size device_viewport_size =
139 gfx::Size(root_layer->bounds().width() * device_scale_factor,
140 root_layer->bounds().height() * device_scale_factor);
141
142 render_surface_layer_list_impl_.reset(new LayerImplList);
143
144 // We are probably not testing what is intended if the root_layer bounds are
145 // empty.
146 DCHECK(!root_layer->bounds().IsEmpty());
147 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
148 root_layer, device_viewport_size,
149 render_surface_layer_list_impl_.get());
150 inputs.device_scale_factor = device_scale_factor;
151 inputs.page_scale_factor = page_scale_factor;
152 inputs.page_scale_layer = page_scale_layer;
153 inputs.can_adjust_raster_scales = true;
jaydasika5237db02016-09-20 01:34:30154 if (skip_verify_visible_rect_calculations)
155 inputs.verify_visible_rect_calculations = false;
danakj59931942016-07-26 22:11:29156
157 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
158 }
159
160 template <class LayerType>
161 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
162 LayerType* page_scale_application_layer = nullptr;
163 ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f,
164 page_scale_application_layer);
165 }
166
167 template <class LayerType>
168 void ExecuteCalculateDrawProperties(LayerType* root_layer,
169 float device_scale_factor) {
170 LayerType* page_scale_application_layer = nullptr;
171 ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f,
172 page_scale_application_layer);
173 }
174
sunxd713aedbd2016-08-10 22:22:14175 const LayerList* GetUpdateLayerList() { return &update_layer_list_; }
176
jaydasika6ed869662016-09-21 14:29:59177 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) {
khushalsagar86928f92016-08-17 21:49:05178 DCHECK(root_layer->GetLayerTree());
danakj59931942016-07-26 22:11:29179 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer);
180
181 bool can_render_to_separate_surface = true;
182
183 const Layer* page_scale_layer =
khushalsagar86928f92016-08-17 21:49:05184 root_layer->GetLayerTree()->page_scale_layer();
danakj59931942016-07-26 22:11:29185 Layer* inner_viewport_scroll_layer =
khushalsagar86928f92016-08-17 21:49:05186 root_layer->GetLayerTree()->inner_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29187 Layer* outer_viewport_scroll_layer =
khushalsagar86928f92016-08-17 21:49:05188 root_layer->GetLayerTree()->outer_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29189 const Layer* overscroll_elasticity_layer =
khushalsagar86928f92016-08-17 21:49:05190 root_layer->GetLayerTree()->overscroll_elasticity_layer();
danakj59931942016-07-26 22:11:29191 gfx::Vector2dF elastic_overscroll =
khushalsagar86928f92016-08-17 21:49:05192 root_layer->GetLayerTree()->elastic_overscroll();
danakj59931942016-07-26 22:11:29193 float page_scale_factor = 1.f;
194 float device_scale_factor = 1.f;
195 gfx::Size device_viewport_size =
196 gfx::Size(root_layer->bounds().width() * device_scale_factor,
197 root_layer->bounds().height() * device_scale_factor);
198 PropertyTrees* property_trees =
khushalsagar86928f92016-08-17 21:49:05199 root_layer->GetLayerTree()->property_trees();
danakj59931942016-07-26 22:11:29200 update_layer_list_.clear();
201 PropertyTreeBuilder::BuildPropertyTrees(
202 root_layer, page_scale_layer, inner_viewport_scroll_layer,
203 outer_viewport_scroll_layer, overscroll_elasticity_layer,
204 elastic_overscroll, page_scale_factor, device_scale_factor,
205 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees);
206 draw_property_utils::UpdatePropertyTrees(property_trees,
207 can_render_to_separate_surface);
208 draw_property_utils::FindLayersThatNeedUpdates(
xingliu95d9e6b62016-08-18 03:53:08209 root_layer->GetLayerTree(), property_trees->transform_tree,
danakj59931942016-07-26 22:11:29210 property_trees->effect_tree, &update_layer_list_);
danakj59931942016-07-26 22:11:29211 }
212
jaydasika6ed869662016-09-21 14:29:59213 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
214 LayerImpl* root_layer,
215 bool skip_verify_visible_rect_calculations = false) {
danakj59931942016-07-26 22:11:29216 DCHECK(root_layer->layer_tree_impl());
217 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer);
218
219 bool can_render_to_separate_surface = true;
220
221 LayerImpl* page_scale_layer = nullptr;
222 LayerImpl* inner_viewport_scroll_layer =
223 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
224 LayerImpl* outer_viewport_scroll_layer =
225 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
226 LayerImpl* overscroll_elasticity_layer =
227 root_layer->layer_tree_impl()->OverscrollElasticityLayer();
228 gfx::Vector2dF elastic_overscroll =
229 root_layer->layer_tree_impl()->elastic_overscroll()->Current(
230 root_layer->layer_tree_impl()->IsActiveTree());
231 float page_scale_factor = 1.f;
232 float device_scale_factor = 1.f;
233 gfx::Size device_viewport_size =
234 gfx::Size(root_layer->bounds().width() * device_scale_factor,
235 root_layer->bounds().height() * device_scale_factor);
236 update_layer_list_impl_.reset(new LayerImplList);
237 root_layer->layer_tree_impl()->BuildLayerListForTesting();
jaydasika6ed869662016-09-21 14:29:59238 PropertyTrees* property_trees =
239 root_layer->layer_tree_impl()->property_trees();
danakj59931942016-07-26 22:11:29240 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects(
241 root_layer, page_scale_layer, inner_viewport_scroll_layer,
242 outer_viewport_scroll_layer, overscroll_elasticity_layer,
243 elastic_overscroll, page_scale_factor, device_scale_factor,
244 gfx::Rect(device_viewport_size), gfx::Transform(),
jaydasika6ed869662016-09-21 14:29:59245 can_render_to_separate_surface, property_trees,
danakj59931942016-07-26 22:11:29246 update_layer_list_impl_.get());
jaydasika6ed869662016-09-21 14:29:59247 draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_,
248 property_trees);
249 if (!skip_verify_visible_rect_calculations)
250 draw_property_utils::VerifyVisibleRectsCalculations(
251 *update_layer_list_impl_, property_trees);
danakj59931942016-07-26 22:11:29252 }
253
254 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(
255 LayerImpl* root_layer) {
256 gfx::Size device_viewport_size =
257 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height());
258 render_surface_layer_list_impl_.reset(new LayerImplList);
259
260 DCHECK(!root_layer->bounds().IsEmpty());
261 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
262 root_layer, device_viewport_size,
263 render_surface_layer_list_impl_.get());
264 inputs.can_adjust_raster_scales = true;
265 inputs.can_render_to_separate_surface = false;
266
267 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
268 }
269
270 bool UpdateLayerListImplContains(int id) const {
271 for (auto* layer : *update_layer_list_impl_) {
272 if (layer->id() == id)
273 return true;
274 }
275 return false;
276 }
277
278 bool UpdateLayerListContains(int id) const {
279 for (const auto& layer : update_layer_list_) {
280 if (layer->id() == id)
281 return true;
282 }
283 return false;
284 }
285
286 const LayerImplList* render_surface_layer_list_impl() const {
287 return render_surface_layer_list_impl_.get();
288 }
289 const LayerImplList* update_layer_list_impl() const {
290 return update_layer_list_impl_.get();
291 }
292 const LayerList& update_layer_list() const { return update_layer_list_; }
293
sunxd713aedbd2016-08-10 22:22:14294 bool VerifyLayerInList(scoped_refptr<Layer> layer,
295 const LayerList* layer_list) {
296 return std::find(layer_list->begin(), layer_list->end(), layer) !=
297 layer_list->end();
298 }
299
danakj59931942016-07-26 22:11:29300 private:
301 std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_;
302 LayerList update_layer_list_;
303 std::unique_ptr<LayerImplList> update_layer_list_impl_;
304};
305
306class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
307 public testing::Test {};
308
[email protected]96baf3e2012-10-22 23:09:55309class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32310 public:
loyso0940d412016-03-14 01:30:31311 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14312
danakj59931942016-07-26 22:11:29313 bool DrawsContent() const override { return true; }
[email protected]d58499a2012-10-09 22:27:47314
[email protected]fb661802013-03-25 01:59:32315 private:
dcheng716bedf2014-10-21 09:51:08316 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:14317};
318
danakj59931942016-07-26 22:11:29319class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings {
enne637715732015-07-07 02:05:26320 public:
321 LayerTreeSettingsScaleContent() {
322 layer_transforms_should_scale_layer_contents = true;
323 }
324};
325
danakj59931942016-07-26 22:11:29326class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase,
327 public testing::Test {
enne637715732015-07-07 02:05:26328 public:
329 LayerTreeHostCommonScalingTest()
danakj59931942016-07-26 22:11:29330 : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {}
enne637715732015-07-07 02:05:26331};
332
weiliangc6da32862016-04-20 16:40:11333class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
334 public:
335 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
336
337 LayerImpl* TestVisibleRectAndDrawableContentRect(
338 const gfx::Rect& target_rect,
339 const gfx::Transform& layer_transform,
340 const gfx::Rect& layer_rect) {
jaydasikabf1875a2016-06-28 03:39:59341 LayerImpl* root = root_layer_for_testing();
weiliangc6da32862016-04-20 16:40:11342 LayerImpl* target = AddChild<LayerImpl>(root);
343 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
344
345 root->SetDrawsContent(true);
346 target->SetDrawsContent(true);
347 target->SetMasksToBounds(true);
348 drawing_layer->SetDrawsContent(true);
349
danakje4fa7b72016-07-25 22:00:06350 root->SetBounds(gfx::Size(500, 500));
351 root->test_properties()->force_render_surface = true;
352 target->SetPosition(gfx::PointF(target_rect.origin()));
353 target->SetBounds(target_rect.size());
354 target->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:04355 drawing_layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06356 drawing_layer->SetPosition(gfx::PointF(layer_rect.origin()));
357 drawing_layer->SetBounds(layer_rect.size());
358 drawing_layer->test_properties()->should_flatten_transform = false;
weiliangc6da32862016-04-20 16:40:11359
360 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
361 ExecuteCalculateDrawProperties(root);
362
363 return drawing_layer;
364 }
365};
366
[email protected]989386c2013-07-18 21:37:23367TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32368 // Sanity check: For layers positioned at zero, with zero size,
369 // and with identity transforms, then the draw transform,
370 // screen space transform, and the hierarchy passed on to children
371 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14372
jaydasikabf1875a2016-06-28 03:39:59373 LayerImpl* parent = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51374 LayerImpl* child = AddChild<LayerImpl>(parent);
375 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28376
danakje4fa7b72016-07-25 22:00:06377 parent->SetBounds(gfx::Size(100, 100));
[email protected]94f206c12012-08-25 00:09:14378
sunxdfd920f3f2016-04-05 16:17:51379 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14380
danakjf78fb272016-07-26 19:06:15381 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
382 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51383 child->ScreenSpaceTransform());
danakjf78fb272016-07-26 19:06:15384 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51385 grand_child->DrawTransform());
danakjf78fb272016-07-26 19:06:15386 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51387 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14388}
389
jaydasika322436372015-12-16 23:42:38390TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
391 // Tests that effect tree node gets a valid transform id when a layer
392 // has opacity but doesn't create a render surface.
jaydasikabf1875a2016-06-28 03:39:59393 LayerImpl* parent = root_layer_for_testing();
jaydasika322436372015-12-16 23:42:38394 LayerImpl* child = AddChild<LayerImpl>(parent);
395 child->SetDrawsContent(true);
396
danakje4fa7b72016-07-25 22:00:06397 parent->SetBounds(gfx::Size(100, 100));
398 child->SetPosition(gfx::PointF(10, 10));
399 child->SetBounds(gfx::Size(100, 100));
jaydasikaab317e02016-06-01 00:53:18400 child->test_properties()->opacity = 0.f;
jaydasika322436372015-12-16 23:42:38401 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04402 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38403 parent->layer_tree_impl()->property_trees()->effect_tree;
404 EffectNode* node = effect_tree.Node(child->effect_tree_index());
405 const int transform_tree_size = parent->layer_tree_impl()
406 ->property_trees()
407 ->transform_tree.next_available_id();
trchendba8b1502016-07-08 09:47:01408 EXPECT_LT(node->transform_id, transform_tree_size);
jaydasika322436372015-12-16 23:42:38409}
410
[email protected]989386c2013-07-18 21:37:23411TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
jaydasikabf1875a2016-06-28 03:39:59412 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51413 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14414
jaydasikabaede2d92016-07-20 00:34:32415 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51416 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32417 EffectTree& effect_tree =
418 host_impl()->active_tree()->property_trees()->effect_tree;
enne826452722015-08-18 22:22:31419
danakje4fa7b72016-07-25 22:00:06420 root->SetBounds(gfx::Size(1, 2));
421
422 // Case 1: Setting the bounds of the layer should not affect either the draw
[email protected]fb661802013-03-25 01:59:32423 // transform or the screenspace transform.
danakje4fa7b72016-07-25 22:00:06424 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51425 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31426 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15427 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32428 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31429 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15430 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32431 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14432
danakje4fa7b72016-07-25 22:00:06433 // Case 2: The anchor point by itself (without a layer transform) should have
[email protected]fb661802013-03-25 01:59:32434 // no effect on the transforms.
danakje4fa7b72016-07-25 22:00:06435 layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
436 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51437 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
438 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31439 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15440 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32441 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31442 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15443 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32444 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14445
danakje4fa7b72016-07-25 22:00:06446 // Case 3: A change in actual position affects both the draw transform and
[email protected]fb661802013-03-25 01:59:32447 // screen space transform.
448 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05449 position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06450 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51451 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
452 ExecuteCalculateDrawProperties(root);
453 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32454 position_transform,
455 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31456 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27457 position_transform,
jaydasikabaede2d92016-07-20 00:34:32458 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14459
danakje4fa7b72016-07-25 22:00:06460 // Case 4: In the correct sequence of transforms, the layer transform should
461 // pre-multiply the translation-to-center. This is easily tested by using a
[email protected]fb661802013-03-25 01:59:32462 // scale transform, because scale and translation are not commutative.
463 gfx::Transform layer_transform;
464 layer_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:04465 layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06466 layer->test_properties()->transform_origin = gfx::Point3F();
467 layer->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51468 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
469 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31470 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32471 layer_transform,
472 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31473 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32474 layer_transform,
475 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14476
danakje4fa7b72016-07-25 22:00:06477 // Case 5: The layer transform should occur with respect to the anchor point.
[email protected]fb661802013-03-25 01:59:32478 gfx::Transform translation_to_anchor;
479 translation_to_anchor.Translate(5.0, 0.0);
480 gfx::Transform expected_result =
481 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06482 layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f);
sunxdfd920f3f2016-04-05 16:17:51483 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
484 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31485 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32486 expected_result,
487 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31488 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32489 expected_result,
490 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14491
danakje4fa7b72016-07-25 22:00:06492 // Case 6: Verify that position pre-multiplies the layer transform. The
[email protected]fb661802013-03-25 01:59:32493 // current implementation of CalculateDrawProperties does this implicitly, but
494 // it is still worth testing to detect accidental regressions.
495 expected_result = position_transform * translation_to_anchor *
496 layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06497 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51498 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
499 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31500 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32501 expected_result,
502 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31503 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32504 expected_result,
505 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14506}
507
[email protected]989386c2013-07-18 21:37:23508TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13509 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32510 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01511 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32512 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
513 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16514 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32515 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20516
khushalsagarb64b360d2015-10-21 19:25:16517 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45518 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56519 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16520 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56521 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20522
danakj60bc3bc2016-04-09 00:24:48523 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32524 LayerImpl::Create(host_impl.active_tree(), 1));
525 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28526 sublayer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:06527 sublayer->SetBounds(gfx::Size(500, 500));
[email protected]657b24c2013-03-06 09:01:20528
danakj60bc3bc2016-04-09 00:24:48529 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32530 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47531 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
danakje4fa7b72016-07-25 22:00:06532 scroll_layer->SetBounds(gfx::Size(10, 20));
danakj60bc3bc2016-04-09 00:24:48533 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
[email protected]adeda572014-01-31 00:49:47534 LayerImpl::Create(host_impl.active_tree(), 4));
535 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
536
537 scroll_layer->SetScrollClipLayer(clip_layer->id());
538 clip_layer->SetBounds(
539 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
540 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
541 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42542 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32543 gfx::Transform impl_transform;
jaydasika89f7b5a2016-06-22 02:08:39544 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47545 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
jaydasika89f7b5a2016-06-22 02:08:39546 clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42547 scroll_layer_raw_ptr->layer_tree_impl()
548 ->property_trees()
549 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
550 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20551
danakj60bc3bc2016-04-09 00:24:48552 std::unique_ptr<LayerImpl> root(
553 LayerImpl::Create(host_impl.active_tree(), 3));
danakje4fa7b72016-07-25 22:00:06554 root->SetBounds(gfx::Size(3, 4));
jaydasika89f7b5a2016-06-22 02:08:39555 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00556 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09557 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59558 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
[email protected]657b24c2013-03-06 09:01:20559
jaydasikaa534a472016-03-31 01:12:16560 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasikaf419bf72016-06-15 10:21:21561 scroll_layer->test_properties()->parent);
danakjf78fb272016-07-26 19:06:15562 gfx::Transform expected_transform;
[email protected]fb661802013-03-25 01:59:32563 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33564 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16565 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33566 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16567 page_scale * kDeviceScale));
568 expected_transform.Scale(page_scale * kDeviceScale,
569 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32570 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44571 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32572 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10573 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20574
[email protected]fb661802013-03-25 01:59:32575 gfx::Transform arbitrary_translate;
576 const float kTranslateX = 10.6f;
577 const float kTranslateY = 20.6f;
578 arbitrary_translate.Translate(kTranslateX, kTranslateY);
jaydasika10d43fc2016-08-18 04:06:04579 scroll_layer->test_properties()->transform = arbitrary_translate;
jaydasika2411692c2016-03-23 01:56:09580 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16581 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasikaf419bf72016-06-15 10:21:21582 scroll_layer->test_properties()->parent);
[email protected]fb661802013-03-25 01:59:32583 expected_transform.MakeIdentity();
584 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16585 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
586 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33587 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16588 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
589 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33590 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16591 expected_transform.Scale(page_scale * kDeviceScale,
592 page_scale * kDeviceScale);
593 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
594 sublayer->DrawTransform());
595
596 // Test that page scale is updated even when we don't rebuild property trees.
597 page_scale = 1.888f;
598 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
jaydasikaf419bf72016-06-15 10:21:21599 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(),
600 Layer::INVALID_ID, Layer::INVALID_ID);
jaydasikaa534a472016-03-31 01:12:16601 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
602 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
603 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasikaf419bf72016-06-15 10:21:21604 scroll_layer->test_properties()->parent);
jaydasikaa534a472016-03-31 01:12:16605
606 expected_transform.MakeIdentity();
607 expected_transform.Translate(
608 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
609 sub_layer_screen_position.x() * page_scale *
610 kDeviceScale),
611 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
612 sub_layer_screen_position.y() * page_scale *
613 kDeviceScale));
614 expected_transform.Scale(page_scale * kDeviceScale,
615 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32616 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44617 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20618}
619
[email protected]989386c2013-07-18 21:37:23620TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
jaydasikabf1875a2016-06-28 03:39:59621 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51622 LayerImpl* parent = AddChild<LayerImpl>(root);
623 LayerImpl* child = AddChild<LayerImpl>(parent);
624 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28625
[email protected]fb661802013-03-25 01:59:32626 // One-time setup of root layer
danakje4fa7b72016-07-25 22:00:06627 root->SetBounds(gfx::Size(1, 2));
enne826452722015-08-18 22:22:31628
jaydasikabaede2d92016-07-20 00:34:32629 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51630 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32631 EffectTree& effect_tree =
632 host_impl()->active_tree()->property_trees()->effect_tree;
[email protected]ecc12622012-10-30 20:45:42633
[email protected]fb661802013-03-25 01:59:32634 // Case 1: parent's anchor point should not affect child or grand_child.
danakje4fa7b72016-07-25 22:00:06635 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
636 parent->SetBounds(gfx::Size(10, 12));
637 child->SetBounds(gfx::Size(16, 18));
638 grand_child->SetBounds(gfx::Size(76, 78));
sunxdfd920f3f2016-04-05 16:17:51639 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31640
641 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15642 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32643 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31644 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15645 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32646 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
647 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15648 gfx::Transform(), draw_property_utils::DrawTransform(
649 grand_child, transform_tree, effect_tree));
jaydasikabaede2d92016-07-20 00:34:32650 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15651 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32652 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14653
[email protected]fb661802013-03-25 01:59:32654 // Case 2: parent's position affects child and grand_child.
655 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05656 parent_position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06657 parent->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51658 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
659 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31660 EXPECT_TRANSFORMATION_MATRIX_EQ(
661 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32662 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31663 EXPECT_TRANSFORMATION_MATRIX_EQ(
664 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32665 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
666 EXPECT_TRANSFORMATION_MATRIX_EQ(
667 parent_position_transform, draw_property_utils::DrawTransform(
668 grand_child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31669 EXPECT_TRANSFORMATION_MATRIX_EQ(
670 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32671 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14672
[email protected]fb661802013-03-25 01:59:32673 // Case 3: parent's local transform affects child and grandchild
674 gfx::Transform parent_layer_transform;
675 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
676 gfx::Transform parent_translation_to_anchor;
677 parent_translation_to_anchor.Translate(2.5, 3.0);
678 gfx::Transform parent_composite_transform =
679 parent_translation_to_anchor * parent_layer_transform *
680 Inverse(parent_translation_to_anchor);
jaydasika10d43fc2016-08-18 04:06:04681 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06682 parent->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51683 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
684 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31685 EXPECT_TRANSFORMATION_MATRIX_EQ(
686 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32687 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31688 EXPECT_TRANSFORMATION_MATRIX_EQ(
689 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32690 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
enne826452722015-08-18 22:22:31691 EXPECT_TRANSFORMATION_MATRIX_EQ(
692 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32693 draw_property_utils::DrawTransform(grand_child, transform_tree,
694 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(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14698}
699
[email protected]989386c2013-07-18 21:37:23700TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:59701 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28702 LayerImpl* parent = AddChildToRoot<LayerImpl>();
703 LayerImpl* child = AddChild<LayerImpl>(parent);
704 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]94f206c12012-08-25 00:09:14705
[email protected]fb661802013-03-25 01:59:32706 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05707 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32708 gfx::Transform parent_translation_to_anchor;
709 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44710
[email protected]fb661802013-03-25 01:59:32711 gfx::Transform parent_composite_transform =
712 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39713 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32714 gfx::Vector2dF parent_composite_scale =
715 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
716 1.f);
717 gfx::Transform surface_sublayer_transform;
718 surface_sublayer_transform.Scale(parent_composite_scale.x(),
719 parent_composite_scale.y());
720 gfx::Transform surface_sublayer_composite_transform =
721 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14722
danakje4fa7b72016-07-25 22:00:06723 root->SetBounds(gfx::Size(1, 2));
jaydasika10d43fc2016-08-18 04:06:04724 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06725 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
726 parent->SetBounds(gfx::Size(100, 120));
727 child->SetBounds(gfx::Size(16, 18));
728 child->test_properties()->force_render_surface = true;
729 grand_child->SetBounds(gfx::Size(8, 10));
730 grand_child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28731 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14732
[email protected]fb661802013-03-25 01:59:32733 // Render surface should have been created now.
734 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25735 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14736
[email protected]fb661802013-03-25 01:59:32737 // The child layer's draw transform should refer to its new render surface.
738 // The screen-space transform, however, should still refer to the root.
739 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44740 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32741 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10742 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14743
[email protected]fb661802013-03-25 01:59:32744 // Because the grand_child is the only drawable content, the child's render
745 // surface will tighten its bounds to the grand_child. The scale at which the
746 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25747 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
748 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14749
[email protected]fb661802013-03-25 01:59:32750 // The screen space is the same as the target since the child surface draws
751 // into the root.
752 EXPECT_TRANSFORMATION_MATRIX_EQ(
753 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25754 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14755}
756
ajuma51d73f72015-10-19 19:43:58757TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:59758 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:58759 LayerImpl* parent = AddChildToRoot<LayerImpl>();
760 LayerImpl* child = AddChild<LayerImpl>(parent);
761 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma51d73f72015-10-19 19:43:58762
763 gfx::Transform parent_transform;
764 parent_transform.Translate(10.0, 10.0);
765
766 gfx::Transform child_transform;
767 child_transform.Rotate(45.0);
768
danakje4fa7b72016-07-25 22:00:06769 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:04770 parent->test_properties()->transform = parent_transform;
danakje4fa7b72016-07-25 22:00:06771 parent->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:04772 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:06773 child->SetBounds(gfx::Size(10, 10));
774 child->test_properties()->force_render_surface = true;
775 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
776 grand_child->SetBounds(gfx::Size(20, 20));
777 grand_child->SetDrawsContent(true);
ajuma51d73f72015-10-19 19:43:58778
779 gfx::Transform expected_grand_child_screen_space_transform;
780 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
781 expected_grand_child_screen_space_transform.Rotate(45.0);
782 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
783
784 // First compute draw properties with separate surfaces enabled.
785 ExecuteCalculateDrawProperties(root);
786
787 // The grand child's draw transform should be its offset wrt the child.
788 gfx::Transform expected_grand_child_draw_transform;
789 expected_grand_child_draw_transform.Translate(2.0, 2.0);
790 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44791 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58792 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10793 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58794
795 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
796
797 // With separate surfaces disabled, the grand child's draw transform should be
798 // the same as its screen space transform.
799 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44800 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58801 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10802 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58803}
804
[email protected]989386c2013-07-18 21:37:23805TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32806 // This test creates a more complex tree and verifies it all at once. This
807 // covers the following cases:
808 // - layers that are described w.r.t. a render surface: should have draw
809 // transforms described w.r.t. that surface
810 // - A render surface described w.r.t. an ancestor render surface: should
811 // have a draw transform described w.r.t. that ancestor surface
[email protected]fb661802013-03-25 01:59:32812 // - Sanity check on recursion: verify transforms of layers described w.r.t.
813 // a render surface that is described w.r.t. an ancestor render surface.
814 // - verifying that each layer has a reference to the correct render surface
815 // and render target values.
816
jaydasikabf1875a2016-06-28 03:39:59817 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28818 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36819 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28820 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36821 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28822 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36823 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28824 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36825 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28826 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36827 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28828 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36829 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28830 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36831 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28832 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
833 grand_child_of_rs1->SetDrawsContent(true);
834 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
835 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32836
[email protected]fb661802013-03-25 01:59:32837 // In combination with descendant draws content, opacity != 1 forces the layer
838 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18839 render_surface1->test_properties()->opacity = 0.5f;
840 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32841
[email protected]fb661802013-03-25 01:59:32842 // All layers in the tree are initialized with an anchor at .25 and a size of
wangxianzhu932d7f12016-09-30 05:47:00843 // (10,10). Matrix "A" is the composite layer transform used in all layers.
[email protected]fb661802013-03-25 01:59:32844 gfx::Transform translation_to_anchor;
845 translation_to_anchor.Translate(2.5, 0.0);
846 gfx::Transform layer_transform;
847 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32848
849 gfx::Transform A =
850 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32851
852 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39853 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32854 gfx::Transform surface1_sublayer_transform;
855 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
856 surface1_parent_transform_scale.y());
857
858 // SS1 = transform given to the subtree of render_surface1
859 gfx::Transform SS1 = surface1_sublayer_transform;
860 // S1 = transform to move from render_surface1 pixels to the layer space of
861 // the owning layer
862 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
863
864 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39865 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32866 gfx::Transform surface2_sublayer_transform;
867 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
868 surface2_parent_transform_scale.y());
869
870 // SS2 = transform given to the subtree of render_surface2
871 gfx::Transform SS2 = surface2_sublayer_transform;
872 // S2 = transform to move from render_surface2 pixels to the layer space of
873 // the owning layer
874 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
875
danakje4fa7b72016-07-25 22:00:06876 root->SetBounds(gfx::Size(1, 2));
877 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04878 parent->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06879 parent->SetBounds(gfx::Size(10, 10));
880 render_surface1->test_properties()->transform_origin =
881 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04882 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06883 render_surface1->SetBounds(gfx::Size(10, 10));
884 render_surface1->test_properties()->force_render_surface = true;
885 render_surface2->test_properties()->transform_origin =
886 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04887 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06888 render_surface2->SetBounds(gfx::Size(10, 10));
889 render_surface2->test_properties()->force_render_surface = true;
890 child_of_root->test_properties()->transform_origin =
891 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04892 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06893 child_of_root->SetBounds(gfx::Size(10, 10));
894 child_of_rs1->test_properties()->transform_origin =
895 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04896 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06897 child_of_rs1->SetBounds(gfx::Size(10, 10));
898 child_of_rs2->test_properties()->transform_origin =
899 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04900 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06901 child_of_rs2->SetBounds(gfx::Size(10, 10));
902 grand_child_of_root->test_properties()->transform_origin =
903 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04904 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06905 grand_child_of_root->SetBounds(gfx::Size(10, 10));
906 grand_child_of_rs1->test_properties()->transform_origin =
907 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04908 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06909 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
910 grand_child_of_rs2->test_properties()->transform_origin =
911 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04912 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06913 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:32914
enne25dea3f2015-07-27 16:44:28915 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32916
917 // Only layers that are associated with render surfaces should have an actual
918 // RenderSurface() value.
919 ASSERT_TRUE(root->render_surface());
920 ASSERT_FALSE(child_of_root->render_surface());
921 ASSERT_FALSE(grand_child_of_root->render_surface());
922
923 ASSERT_TRUE(render_surface1->render_surface());
924 ASSERT_FALSE(child_of_rs1->render_surface());
925 ASSERT_FALSE(grand_child_of_rs1->render_surface());
926
927 ASSERT_TRUE(render_surface2->render_surface());
928 ASSERT_FALSE(child_of_rs2->render_surface());
929 ASSERT_FALSE(grand_child_of_rs2->render_surface());
930
931 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25932 EXPECT_EQ(root->render_surface(), parent->render_target());
933 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
934 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32935
weiliangc189c1a12016-04-11 16:16:25936 EXPECT_EQ(render_surface1->render_surface(),
937 render_surface1->render_target());
938 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
939 EXPECT_EQ(render_surface1->render_surface(),
940 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32941
weiliangc189c1a12016-04-11 16:16:25942 EXPECT_EQ(render_surface2->render_surface(),
943 render_surface2->render_target());
944 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
945 EXPECT_EQ(render_surface2->render_surface(),
946 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32947
948 // Verify layer draw transforms note that draw transforms are described with
949 // respect to the nearest ancestor render surface but screen space transforms
950 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44951 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
952 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39953 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44954 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32955
ajumad9432e32015-11-30 19:43:44956 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
957 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39958 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44959 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32960
ajumad9432e32015-11-30 19:43:44961 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
962 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39963 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44964 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32965
966 // Verify layer screen-space transforms
967 //
ajumab6aa1c62015-12-01 21:01:10968 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
969 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
970 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
971 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32972
[email protected]baf64d062014-02-16 22:10:39973 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10974 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39975 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10976 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39977 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10978 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32979
[email protected]baf64d062014-02-16 22:10:39980 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10981 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39982 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10983 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39984 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10985 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32986
987 // Verify render surface transforms.
988 //
989 // Draw transform of render surface 1 is described with respect to root.
990 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39991 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32992 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39993 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32994 // Draw transform of render surface 2 is described with respect to render
995 // surface 1.
996 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39997 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32998 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39999 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321000 render_surface2->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321001
1002 // Sanity check. If these fail there is probably a bug in the test itself. It
1003 // is expected that we correctly set up transforms so that the y-component of
1004 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:101005 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:261006 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101007 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321008 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101009 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321010
[email protected]803f6b52013-09-12 00:51:261011 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101012 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
1013 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321014 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101015 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321016
[email protected]803f6b52013-09-12 00:51:261017 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:101018 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
1019 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321020 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101021 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321022}
1023
[email protected]989386c2013-07-18 21:37:231024TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321025 // For layers that flatten their subtree, there should be an orthographic
1026 // projection (for x and y values) in the middle of the transform sequence.
1027 // Note that the way the code is currently implemented, it is not expected to
1028 // use a canonical orthographic projection.
1029
jaydasikabf1875a2016-06-28 03:39:591030 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:281031 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:361032 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:281033 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1034 grand_child->SetDrawsContent(true);
1035 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1036 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321037
1038 gfx::Transform rotation_about_y_axis;
1039 rotation_about_y_axis.RotateAboutYAxis(30.0);
1040
danakje4fa7b72016-07-25 22:00:061041 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041042 child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061043 child->SetBounds(gfx::Size(10, 10));
1044 child->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041045 grand_child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061046 grand_child->SetBounds(gfx::Size(10, 10));
1047 great_grand_child->SetBounds(gfx::Size(10, 10));
[email protected]d600df7d2013-08-03 02:34:281048
[email protected]fb661802013-03-25 01:59:321049 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521050 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
1051 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
1052 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
1053 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:321054
1055 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1056 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1057 gfx::Transform expected_grand_child_draw_transform =
1058 rotation_about_y_axis; // draws onto child's render surface
1059 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1060 flattened_rotation_about_y.FlattenTo2d();
1061 gfx::Transform expected_grand_child_screen_space_transform =
1062 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081063 gfx::Transform expected_great_grand_child_draw_transform =
1064 flattened_rotation_about_y;
1065 gfx::Transform expected_great_grand_child_screen_space_transform =
1066 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321067
enne25dea3f2015-07-27 16:44:281068 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321069
1070 // The child's draw transform should have been taken by its surface.
1071 ASSERT_TRUE(child->render_surface());
1072 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1073 child->render_surface()->draw_transform());
1074 EXPECT_TRANSFORMATION_MATRIX_EQ(
1075 expected_child_screen_space_transform,
1076 child->render_surface()->screen_space_transform());
danakje4fa7b72016-07-25 22:00:061077 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321078 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101079 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441081 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321082 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101083 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081084 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441085 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081086 EXPECT_TRANSFORMATION_MATRIX_EQ(
1087 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101088 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321089}
1090
ajumadbd92cb2015-07-16 13:47:061091TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasikabf1875a2016-06-28 03:39:591092 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:141093 LayerImpl* child = AddChild<LayerImpl>(root);
1094 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061095
1096 gfx::Transform child_transform;
1097 child_transform.Translate(50.0, 50.0);
1098 child_transform.RotateAboutZAxis(30.0);
1099
1100 gfx::Transform grand_child_transform;
1101 grand_child_transform.RotateAboutYAxis(90.0);
1102
danakje4fa7b72016-07-25 22:00:061103 root->SetBounds(gfx::Size(200, 200));
jaydasika10d43fc2016-08-18 04:06:041104 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:061105 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:041106 grand_child->test_properties()->transform = grand_child_transform;
danakje4fa7b72016-07-25 22:00:061107 grand_child->SetBounds(gfx::Size(100, 100));
jaydasikaca2605e2016-04-23 02:52:521108 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141109 grand_child->SetDrawsContent(true);
jaydasika6ed869662016-09-21 14:29:591110 float device_scale_factor = 1.f;
1111 float page_scale_factor = 1.f;
1112 LayerImpl* page_scale_layer = nullptr;
1113 // Visible rects computed by combining clips in target space and root space
1114 // don't match because of rotation transforms. So, we skip
1115 // verify_visible_rect_calculations.
1116 bool skip_verify_visible_rect_calculations = true;
1117 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
1118 page_scale_layer,
1119 skip_verify_visible_rect_calculations);
ajumadbd92cb2015-07-16 13:47:061120
1121 // Mapping grand_child's bounds to target space produces a non-empty rect
1122 // that is fully contained within the target's bounds, so grand_child should
1123 // be considered fully visible.
1124 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141125 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061126}
1127
[email protected]989386c2013-07-18 21:37:231128TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321129 // A layer that is empty in one axis, but not the other, was accidentally
1130 // skipping a necessary translation. Without that translation, the coordinate
1131 // space of the layer's draw transform is incorrect.
1132 //
1133 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1134 // but if that layer becomes a render surface, then its draw transform is
1135 // implicitly inherited by the rest of the subtree, which then is positioned
1136 // incorrectly as a result.
1137
jaydasikabf1875a2016-06-28 03:39:591138 LayerImpl* root = root_layer_for_testing();
ennec1332992015-08-24 19:45:091139 LayerImpl* child = AddChild<LayerImpl>(root);
1140 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1141 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321142
danakje4fa7b72016-07-25 22:00:061143 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:321144 // The child height is zero, but has non-zero width that should be accounted
1145 // for while computing draw transforms.
danakje4fa7b72016-07-25 22:00:061146 child->SetBounds(gfx::Size(10, 0));
1147 child->test_properties()->force_render_surface = true;
1148 grand_child->SetBounds(gfx::Size(10, 10));
ennec1332992015-08-24 19:45:091149 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321150
ennec1332992015-08-24 19:45:091151 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321152 // This is the real test, the rest are sanity checks.
danakje4fa7b72016-07-25 22:00:061153 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:321154 child->render_surface()->draw_transform());
danakje4fa7b72016-07-25 22:00:061155 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1156 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441157 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321158}
1159
jaydasika9bbee9b2016-01-13 00:36:481160TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
jaydasikabf1875a2016-06-28 03:39:591161 LayerImpl* root = root_layer_for_testing();
jaydasika9bbee9b2016-01-13 00:36:481162 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1163 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1164 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1165
jaydasika9bbee9b2016-01-13 00:36:481166 gfx::Transform translate;
1167 translate.Translate3d(5, 5, 5);
danakje4fa7b72016-07-25 22:00:061168
1169 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041170 render_surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061171 render_surface->SetBounds(gfx::Size(100, 100));
1172 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041173 child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061174 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041175 grand_child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061176 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika9bbee9b2016-01-13 00:36:481177 grand_child->SetDrawsContent(true);
1178
1179 // render_surface will have a sublayer scale because of device scale factor.
1180 float device_scale_factor = 2.0f;
1181 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481182 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381183 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481184 inputs.device_scale_factor = device_scale_factor;
1185 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571186 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481187
1188 // Between grand_child and render_surface, we translate by (10, 10) and scale
1189 // by a factor of 2.
1190 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1191 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1192 expected_translation);
1193}
1194
[email protected]989386c2013-07-18 21:37:231195TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321196 // Transformations applied at the root of the tree should be forwarded
1197 // to child layers instead of applied to the root RenderSurface.
jaydasikabf1875a2016-06-28 03:39:591198 LayerImpl* root = root_layer_for_testing();
enned3f61fb02015-08-18 22:54:391199 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061200
1201 root->SetDrawsContent(true);
1202 root->SetBounds(gfx::Size(20, 20));
enned3f61fb02015-08-18 22:54:391203 child->SetDrawsContent(true);
enned3f61fb02015-08-18 22:54:391204 child->SetScrollClipLayer(root->id());
danakje4fa7b72016-07-25 22:00:061205 child->SetBounds(gfx::Size(20, 20));
[email protected]f224cc92013-06-06 23:23:321206
[email protected]f224cc92013-06-06 23:23:321207 gfx::Transform translate;
1208 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231209 {
enned3f61fb02015-08-18 22:54:391210 LayerImplList render_surface_layer_list_impl;
1211 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381212 root, root->bounds(), translate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321213 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571214 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021215 EXPECT_TRANSFORMATION_MATRIX_EQ(
1216 translate, root->draw_properties().target_space_transform);
1217 EXPECT_TRANSFORMATION_MATRIX_EQ(
1218 translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151219 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021220 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231221 }
[email protected]f224cc92013-06-06 23:23:321222
1223 gfx::Transform scale;
1224 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231225 {
enned3f61fb02015-08-18 22:54:391226 LayerImplList render_surface_layer_list_impl;
1227 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381228 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321229 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571230 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021231 EXPECT_TRANSFORMATION_MATRIX_EQ(
1232 scale, root->draw_properties().target_space_transform);
1233 EXPECT_TRANSFORMATION_MATRIX_EQ(
1234 scale, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151235 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021236 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231237 }
[email protected]f224cc92013-06-06 23:23:321238
1239 gfx::Transform rotate;
1240 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231241 {
enned3f61fb02015-08-18 22:54:391242 LayerImplList render_surface_layer_list_impl;
1243 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381244 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321245 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571246 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021247 EXPECT_TRANSFORMATION_MATRIX_EQ(
1248 rotate, root->draw_properties().target_space_transform);
1249 EXPECT_TRANSFORMATION_MATRIX_EQ(
1250 rotate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151251 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021252 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231253 }
[email protected]f224cc92013-06-06 23:23:321254
1255 gfx::Transform composite;
1256 composite.ConcatTransform(translate);
1257 composite.ConcatTransform(scale);
1258 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231259 {
enned3f61fb02015-08-18 22:54:391260 LayerImplList render_surface_layer_list_impl;
1261 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381262 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321263 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571264 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021265 EXPECT_TRANSFORMATION_MATRIX_EQ(
1266 composite, root->draw_properties().target_space_transform);
1267 EXPECT_TRANSFORMATION_MATRIX_EQ(
1268 composite, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151269 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021270 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231271 }
[email protected]f224cc92013-06-06 23:23:321272
[email protected]9781afa2013-07-17 23:15:321273 // Verify it composes correctly with device scale.
1274 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231275
1276 {
enned3f61fb02015-08-18 22:54:391277 LayerImplList render_surface_layer_list_impl;
1278 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381279 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531280 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321281 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571282 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231283 gfx::Transform device_scaled_translate = translate;
1284 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
weiliangcc3517722016-06-28 22:52:021285 EXPECT_TRANSFORMATION_MATRIX_EQ(
1286 device_scaled_translate,
1287 root->draw_properties().target_space_transform);
1288 EXPECT_TRANSFORMATION_MATRIX_EQ(
1289 device_scaled_translate,
1290 child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151291 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021292 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231293 }
[email protected]9781afa2013-07-17 23:15:321294
1295 // Verify it composes correctly with page scale.
1296 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231297
1298 {
enned3f61fb02015-08-18 22:54:391299 LayerImplList render_surface_layer_list_impl;
1300 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381301 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531302 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391303 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321304 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571305 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231306 gfx::Transform page_scaled_translate = translate;
1307 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
weiliangcc3517722016-06-28 22:52:021308 EXPECT_TRANSFORMATION_MATRIX_EQ(
1309 page_scaled_translate, root->draw_properties().target_space_transform);
1310 EXPECT_TRANSFORMATION_MATRIX_EQ(
1311 page_scaled_translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151312 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021313 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231314 }
[email protected]9781afa2013-07-17 23:15:321315
[email protected]f224cc92013-06-06 23:23:321316 // Verify that it composes correctly with transforms directly on root layer.
jaydasika10d43fc2016-08-18 04:06:041317 root->test_properties()->transform = composite;
[email protected]989386c2013-07-18 21:37:231318
1319 {
enned3f61fb02015-08-18 22:54:391320 LayerImplList render_surface_layer_list_impl;
1321 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381322 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391323 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571324 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231325 gfx::Transform compositeSquared = composite;
1326 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261327 EXPECT_TRANSFORMATION_MATRIX_EQ(
1328 compositeSquared, root->draw_properties().target_space_transform);
1329 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391330 compositeSquared, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151331 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021332 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231333 }
[email protected]f224cc92013-06-06 23:23:321334}
1335
[email protected]989386c2013-07-18 21:37:231336TEST_F(LayerTreeHostCommonTest,
1337 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
danakje4fa7b72016-07-25 22:00:061338 LayerImpl* root = root_layer_for_testing();
enneea850232015-07-27 16:43:121339 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1340 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
danakje4fa7b72016-07-25 22:00:061341
1342 root->SetBounds(gfx::Size(10, 10));
1343 root->SetMasksToBounds(true);
1344 render_surface1->SetBounds(gfx::Size(10, 10));
1345 render_surface1->test_properties()->force_render_surface = true;
enneea850232015-07-27 16:43:121346 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061347 child->SetPosition(gfx::PointF(30.f, 30.f));
1348 child->SetBounds(gfx::Size(10, 10));
1349 ExecuteCalculateDrawProperties(root);
[email protected]d600df7d2013-08-03 02:34:281350
danakje4fa7b72016-07-25 22:00:061351 // The child layer's content is entirely outside the root's clip rect, so
[email protected]fb661802013-03-25 01:59:321352 // the intermediate render surface should not be listed here, even if it was
1353 // forced to be created. Render surfaces without children or visible content
1354 // are unexpected at draw time (e.g. we might try to create a content texture
1355 // of size 0).
danakje4fa7b72016-07-25 22:00:061356 ASSERT_TRUE(root->render_surface());
enneea850232015-07-27 16:43:121357 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321358}
1359
[email protected]989386c2013-07-18 21:37:231360TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
danakje4fa7b72016-07-25 22:00:061361 LayerImpl* root = root_layer_for_testing();
1362 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
enne03b0e9a2015-06-19 00:08:021363 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
[email protected]d600df7d2013-08-03 02:34:281364
danakje4fa7b72016-07-25 22:00:061365 render_surface1->SetBounds(gfx::Size(10, 10));
1366 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181367 render_surface1->test_properties()->opacity = 0.f;
danakje4fa7b72016-07-25 22:00:061368 child->SetBounds(gfx::Size(10, 10));
1369 child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321370
enne03b0e9a2015-06-19 00:08:021371 LayerImplList render_surface_layer_list;
1372 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061373 root, root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531374 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571375 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321376
1377 // Since the layer is transparent, render_surface1->render_surface() should
1378 // not have gotten added anywhere. Also, the drawable content rect should not
1379 // have been extended by the children.
danakje4fa7b72016-07-25 22:00:061380 ASSERT_TRUE(root->render_surface());
1381 EXPECT_EQ(0U, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:321382 EXPECT_EQ(1U, render_surface_layer_list.size());
danakje4fa7b72016-07-25 22:00:061383 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
1384 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321385}
1386
hendrikwc266f7b2015-08-21 23:41:341387TEST_F(LayerTreeHostCommonTest,
1388 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
danakje4fa7b72016-07-25 22:00:061389 LayerImpl* root = root_layer_for_testing();
1390 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
hendrikwc266f7b2015-08-21 23:41:341391 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
hendrikwc266f7b2015-08-21 23:41:341392
danakje4fa7b72016-07-25 22:00:061393 root->SetBounds(gfx::Size(10, 10));
1394 render_surface1->SetBounds(gfx::Size(10, 10));
1395 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181396 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071397 render_surface1->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341398 FilterOperations filters;
1399 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
ajuma50bce7e2016-06-24 20:56:041400 render_surface1->test_properties()->background_filters = filters;
danakje4fa7b72016-07-25 22:00:061401 child->SetBounds(gfx::Size(10, 10));
1402 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341403
jaydasika369c24b2016-04-06 23:44:161404 {
1405 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161406 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061407 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161408 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571409 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161410 EXPECT_EQ(2U, render_surface_layer_list.size());
1411 }
hendrikwc266f7b2015-08-21 23:41:341412 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161413 // shouldn't be skipped and should be drawn.
danakje4fa7b72016-07-25 22:00:061414 ASSERT_TRUE(root->render_surface());
1415 EXPECT_EQ(1U, root->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361416 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
danakje4fa7b72016-07-25 22:00:061417 root->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161418 EffectTree& effect_tree =
danakje4fa7b72016-07-25 22:00:061419 root->layer_tree_impl()->property_trees()->effect_tree;
jaydasika369c24b2016-04-06 23:44:161420 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011421 EXPECT_TRUE(node->is_drawn);
jaydasika369c24b2016-04-06 23:44:161422
danakje4fa7b72016-07-25 22:00:061423 // When root is transparent, the layer should not be drawn.
jaydasika898b2f12016-08-20 04:22:091424 effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(),
1425 root->layer_tree_impl());
1426 effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(),
1427 root->layer_tree_impl());
jaydasika8185d302016-04-14 15:20:061428 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161429 {
1430 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161431 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061432 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161433 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571434 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161435 }
1436
1437 node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011438 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:061439 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341440}
1441
senorblanco38858c52016-01-20 23:15:001442TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
jaydasikabf1875a2016-06-28 03:39:591443 LayerImpl* root = root_layer_for_testing();
senorblanco38858c52016-01-20 23:15:001444 LayerImpl* parent = AddChild<LayerImpl>(root);
1445 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1446 LayerImpl* child2 = AddChild<LayerImpl>(parent);
senorblanco38858c52016-01-20 23:15:001447
senorblanco38858c52016-01-20 23:15:001448 gfx::Transform scale_matrix;
1449 scale_matrix.Scale(2.0f, 2.0f);
danakje4fa7b72016-07-25 22:00:061450
1451 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041452 parent->test_properties()->transform = scale_matrix;
senorblanco38858c52016-01-20 23:15:001453 FilterOperations filters;
1454 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
ajumacb2b74432016-07-21 19:11:151455 parent->test_properties()->filters = filters;
danakje4fa7b72016-07-25 22:00:061456 parent->test_properties()->force_render_surface = true;
1457 child1->SetBounds(gfx::Size(25, 25));
1458 child1->SetDrawsContent(true);
1459 child1->test_properties()->force_render_surface = true;
1460 child2->SetPosition(gfx::PointF(25, 25));
1461 child2->SetBounds(gfx::Size(25, 25));
1462 child2->SetDrawsContent(true);
1463 child2->test_properties()->force_render_surface = true;
senorblanco38858c52016-01-20 23:15:001464
1465 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001466 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381467 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001468 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571469 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001470
1471 ASSERT_TRUE(parent->render_surface());
1472 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1473 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman1c44d5b52016-06-06 21:19:301474
1475 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1476 // blur (-30,-30 110x110), and then scaled by the scale matrix
1477 // (-60,-60 220x220).
1478 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
senorblanco38858c52016-01-20 23:15:001479 parent->render_surface()->DrawableContentRect());
1480}
1481
jbroman1c44d5b52016-06-06 21:19:301482TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
jaydasikabf1875a2016-06-28 03:39:591483 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301484 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061485
1486 root->SetBounds(gfx::Size(100, 100));
1487 child->SetBounds(gfx::Size(25, 25));
jbroman1c44d5b52016-06-06 21:19:301488 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061489 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301490 FilterOperations filters;
1491 filters.Append(FilterOperation::CreateReferenceFilter(
1492 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151493 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301494 ExecuteCalculateDrawProperties(root);
1495
1496 // The render surface's size should be unaffected by the offset image filter;
1497 // it need only have a drawable content rect large enough to contain the
1498 // contents (at the new offset).
1499 ASSERT_TRUE(child->render_surface());
1500 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1501 child->render_surface()->DrawableContentRect());
1502}
1503
1504TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1505 const float device_scale_factor = 2.0f;
1506
jaydasikabf1875a2016-06-28 03:39:591507 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301508 LayerImpl* child = AddChild<LayerImpl>(root);
jbroman1c44d5b52016-06-06 21:19:301509
danakje4fa7b72016-07-25 22:00:061510 root->SetBounds(gfx::Size(100, 100));
1511 child->SetBounds(gfx::Size(25, 25));
1512 child->SetDrawsContent(true);
1513 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301514
1515 FilterOperations filters;
1516 filters.Append(FilterOperation::CreateReferenceFilter(
1517 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151518 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301519
1520 ExecuteCalculateDrawProperties(root, device_scale_factor);
1521
1522 // The render surface's size should be unaffected by the offset image filter;
1523 // it need only have a drawable content rect large enough to contain the
1524 // contents (at the new offset). All coordinates should be scaled by 2,
1525 // corresponding to the device scale factor.
1526 ASSERT_TRUE(child->render_surface());
1527 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1528 child->render_surface()->DrawableContentRect());
1529}
1530
rosca948d29d2014-11-09 10:25:131531TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
danakje4fa7b72016-07-25 22:00:061532 LayerImpl* root = root_layer_for_testing();
1533 LayerImpl* child = AddChild<LayerImpl>(root);
1534
1535 root->SetBounds(gfx::Size(10, 10));
1536 child->SetBounds(gfx::Size(10, 10));
enned5f4ddd2015-08-18 16:50:061537 child->SetDrawsContent(true);
ajuma4c14b252016-07-26 20:10:591538 child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode;
jaydasikaab317e02016-06-01 00:53:181539 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061540 child->test_properties()->force_render_surface = true;
1541 ExecuteCalculateDrawProperties(root);
rosca948d29d2014-11-09 10:25:131542
1543 // Since the child layer has a blend mode other than normal, it should get
1544 // its own render surface. Also, layer's draw_properties should contain the
1545 // default blend mode, since the render surface becomes responsible for
1546 // applying the blend mode.
1547 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291548 EXPECT_EQ(1.0f, child->draw_opacity());
1549 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261550 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131551}
1552
jaydasikafbdb86e2016-01-21 18:57:511553TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
jaydasikabf1875a2016-06-28 03:39:591554 LayerImpl* root = root_layer_for_testing();
jaydasikafbdb86e2016-01-21 18:57:511555 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1556 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1557 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1558
danakje4fa7b72016-07-25 22:00:061559 root->SetBounds(gfx::Size(10, 10));
1560 surface1->SetBounds(gfx::Size(10, 10));
jaydasikafbdb86e2016-01-21 18:57:511561 surface1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181562 surface1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061563 surface1->test_properties()->force_render_surface = true;
1564 not_surface->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:181565 not_surface->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061566 surface2->SetBounds(gfx::Size(10, 10));
1567 surface2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181568 surface2->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061569 surface2->test_properties()->force_render_surface = true;
jaydasikafbdb86e2016-01-21 18:57:511570 ExecuteCalculateDrawProperties(root);
1571
1572 ASSERT_TRUE(surface1->render_surface());
1573 ASSERT_FALSE(not_surface->render_surface());
1574 ASSERT_TRUE(surface2->render_surface());
1575 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1576 // surface2's draw opacity should include the opacity of not-surface and
1577 // itself, but not the opacity of surface1.
1578 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1579}
1580
ajuma51d73f72015-10-19 19:43:581581TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1582 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1583 // the product of all ancestor layer opacties and the layer's own opacity.
1584 // (Rendering will still be incorrect in situations where we really do need
1585 // surfaces to apply opacity, such as when we have overlapping layers with an
1586 // ancestor whose opacity is <1.)
jaydasikabf1875a2016-06-28 03:39:591587 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581588 LayerImpl* parent = AddChild<LayerImpl>(root);
1589 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1590 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1591 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1592 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1593 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1594
danakje4fa7b72016-07-25 22:00:061595 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581596 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061597 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581598 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061599 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581600 child1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181601 child1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061602 child1->test_properties()->force_render_surface = true;
1603 child2->SetBounds(gfx::Size(100, 100));
1604 child2->SetDrawsContent(true);
1605 grand_child->SetBounds(gfx::Size(100, 100));
1606 grand_child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181607 grand_child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061608 grand_child->test_properties()->force_render_surface = true;
1609 leaf_node1->SetBounds(gfx::Size(100, 100));
1610 leaf_node1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181611 leaf_node1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061612 leaf_node2->SetBounds(gfx::Size(100, 100));
1613 leaf_node2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181614 leaf_node2->test_properties()->opacity = 0.5f;
ajuma51d73f72015-10-19 19:43:581615
1616 // With surfaces enabled, each layer's draw opacity is the product of layer
1617 // opacities on the path from the layer to its render target, not including
1618 // the opacity of the layer that owns the target surface (since that opacity
1619 // is applied by the surface).
1620 ExecuteCalculateDrawProperties(root);
1621 EXPECT_EQ(1.f, root->draw_opacity());
1622 EXPECT_EQ(1.f, parent->draw_opacity());
1623 EXPECT_EQ(1.f, child1->draw_opacity());
1624 EXPECT_EQ(1.f, child2->draw_opacity());
1625 EXPECT_EQ(1.f, grand_child->draw_opacity());
1626 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1627 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1628
1629 // With surfaces disabled, each layer's draw opacity is the product of layer
1630 // opacities on the path from the layer to the root.
1631 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1632 EXPECT_EQ(1.f, root->draw_opacity());
1633 EXPECT_EQ(1.f, parent->draw_opacity());
1634 EXPECT_EQ(0.5f, child1->draw_opacity());
1635 EXPECT_EQ(1.f, child2->draw_opacity());
1636 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1637 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1638 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1639}
1640
[email protected]989386c2013-07-18 21:37:231641TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
danakje4fa7b72016-07-25 22:00:061642 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:261643 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1644 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261645
danakje4fa7b72016-07-25 22:00:061646 root->SetBounds(gfx::Size(10, 10));
1647 render_surface1->SetBounds(gfx::Size(10, 10));
jaydasika6b5a32bf2016-04-22 21:56:361648 render_surface1->test_properties()->force_render_surface = true;
danakje4fa7b72016-07-25 22:00:061649 child->SetBounds(gfx::Size(10, 10));
1650 child->SetDrawsContent(true);
weiliangceffae0462015-12-08 23:17:261651
[email protected]989386c2013-07-18 21:37:231652 {
jaydasika6ed869662016-09-21 14:29:591653 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:321654
[email protected]989386c2013-07-18 21:37:231655 // The root layer always creates a render surface
danakje4fa7b72016-07-25 22:00:061656 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091657 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231658 }
[email protected]fb661802013-03-25 01:59:321659
[email protected]989386c2013-07-18 21:37:231660 {
jaydasika6b5a32bf2016-04-22 21:56:361661 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261662 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:591663 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
danakje4fa7b72016-07-25 22:00:061664 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091665 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231666 }
[email protected]fb661802013-03-25 01:59:321667}
1668
ajuma246190a2015-03-11 20:56:031669TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1670 // Render surfaces act as a flattening point for their subtree, so should
1671 // always flatten the target-to-screen space transform seen by descendants.
jaydasikabf1875a2016-06-28 03:39:591672 LayerImpl* root = root_layer_for_testing();
enne1a79c5542015-08-18 19:43:571673 LayerImpl* parent = AddChild<LayerImpl>(root);
1674 LayerImpl* child = AddChild<LayerImpl>(parent);
1675 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1676
ajuma246190a2015-03-11 20:56:031677 gfx::Transform rotation_about_y_axis;
1678 rotation_about_y_axis.RotateAboutYAxis(30.0);
ajuma246190a2015-03-11 20:56:031679
danakje4fa7b72016-07-25 22:00:061680 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041681 parent->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061682 parent->SetBounds(gfx::Size(10, 10));
1683 parent->test_properties()->force_render_surface = true;
1684 child->SetBounds(gfx::Size(10, 10));
1685 child->SetDrawsContent(true);
1686 grand_child->SetBounds(gfx::Size(10, 10));
1687 grand_child->SetDrawsContent(true);
jaydasikaca2605e2016-04-23 02:52:521688 grand_child->test_properties()->should_flatten_transform = false;
enne1a79c5542015-08-18 19:43:571689 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031690
1691 EXPECT_TRUE(parent->render_surface());
1692 EXPECT_FALSE(child->render_surface());
1693 EXPECT_FALSE(grand_child->render_surface());
1694
danakje4fa7b72016-07-25 22:00:061695 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1696 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441697 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031698
1699 // The screen-space transform inherited by |child| and |grand_child| should
1700 // have been flattened at their render target. In particular, the fact that
1701 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
danakje4fa7b72016-07-25 22:00:061702 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1703 flattened_rotation_about_y.FlattenTo2d();
ajuma246190a2015-03-11 20:56:031704 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101705 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031706 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101707 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031708}
1709
[email protected]989386c2013-07-18 21:37:231710TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321711 // The entire subtree of layers that are outside the clip rect should be
1712 // culled away, and should not affect the render_surface_layer_list.
1713 //
1714 // The test tree is set up as follows:
1715 // - all layers except the leaf_nodes are forced to be a new render surface
1716 // that have something to draw.
1717 // - parent is a large container layer.
danakje4fa7b72016-07-25 22:00:061718 // - child has MasksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321719 // - grand_child is positioned outside of the child's bounds
1720 // - great_grand_child is also kept outside child's bounds.
1721 //
1722 // In this configuration, grand_child and great_grand_child are completely
1723 // outside the clip rect, and they should never get scheduled on the list of
1724 // render surfaces.
[email protected]fb661802013-03-25 01:59:321725
danakje4fa7b72016-07-25 22:00:061726 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571727 LayerImpl* child = AddChildToRoot<LayerImpl>();
1728 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1729 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281730
danakje4fa7b72016-07-25 22:00:061731 // leaf_node1 ensures that root and child are kept on the
[email protected]fb661802013-03-25 01:59:321732 // render_surface_layer_list, even though grand_child and great_grand_child
1733 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571734 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
weiliangcfb3d5eaa2015-07-28 23:54:571735 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
[email protected]fb661802013-03-25 01:59:321736
danakje4fa7b72016-07-25 22:00:061737 root->SetBounds(gfx::Size(500, 500));
1738 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321739 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061740 child->test_properties()->force_render_surface = true;
1741 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1742 grand_child->SetBounds(gfx::Size(10, 10));
1743 great_grand_child->SetBounds(gfx::Size(10, 10));
1744 leaf_node1->SetBounds(gfx::Size(500, 500));
1745 leaf_node1->SetDrawsContent(true);
1746 leaf_node1->SetBounds(gfx::Size(20, 20));
1747 leaf_node2->SetDrawsContent(true);
1748 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321749
weiliangcfb3d5eaa2015-07-28 23:54:571750 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061751 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
weiliangcfb3d5eaa2015-07-28 23:54:571752 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321753}
1754
[email protected]989386c2013-07-18 21:37:231755TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321756 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571757 // of the surface.
[email protected]fb661802013-03-25 01:59:321758
1759 // The test tree is set up as follows:
danakje4fa7b72016-07-25 22:00:061760 // - root is a container layer that masksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321761 // - child is a render surface, which has a clip rect set to the bounds of
danakje4fa7b72016-07-25 22:00:061762 // the root.
[email protected]fb661802013-03-25 01:59:321763 // - grand_child is a render surface, and the only visible content in child.
danakje4fa7b72016-07-25 22:00:061764 // It is positioned outside of the clip rect from root.
[email protected]fb661802013-03-25 01:59:321765
1766 // In this configuration, grand_child should be outside the clipped
1767 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571768 // render_surface_layer_list.
1769
danakje4fa7b72016-07-25 22:00:061770 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571771 LayerImpl* child = AddChildToRoot<LayerImpl>();
1772 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1773 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
[email protected]fb661802013-03-25 01:59:321774
danakje4fa7b72016-07-25 22:00:061775 root->SetMasksToBounds(true);
1776 root->SetBounds(gfx::Size(100, 100));
1777 child->SetBounds(gfx::Size(20, 20));
1778 child->test_properties()->force_render_surface = true;
1779 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1780 grand_child->SetBounds(gfx::Size(10, 10));
1781 grand_child->test_properties()->force_render_surface = true;
1782 leaf_node->SetBounds(gfx::Size(10, 10));
1783 leaf_node->SetDrawsContent(true);
1784 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321785
weiliangcfb3d5eaa2015-07-28 23:54:571786 // We should cull child and grand_child from the
1787 // render_surface_layer_list.
1788 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061789 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321790}
1791
ajumae2b7a5c2015-09-30 21:41:421792TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1793 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321794 // - the layer clips its subtree, e.g. masks to bounds,
1795 // - the layer is clipped by an ancestor that contributes to the same
1796 // render target,
1797 // - a surface is clipped by an ancestor that contributes to the same
1798 // render target.
1799 //
1800 // In particular, for a layer that owns a render surface:
1801 // - the render surface inherits any clip from ancestors, and does NOT
1802 // pass that clipped status to the layer itself.
1803 // - but if the layer itself masks to bounds, it is considered clipped
1804 // and propagates the clip to the subtree.
1805
jaydasikabf1875a2016-06-28 03:39:591806 LayerImpl* root = root_layer_for_testing();
enne76bf8982015-08-18 17:55:331807 LayerImpl* parent = AddChild<LayerImpl>(root);
1808 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1809 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1810 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1811 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
enne76bf8982015-08-18 17:55:331812 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
enne76bf8982015-08-18 17:55:331813
danakje4fa7b72016-07-25 22:00:061814 root->SetBounds(gfx::Size(100, 100));
1815 parent->SetBounds(gfx::Size(100, 100));
1816 parent->SetDrawsContent(true);
1817 child1->SetBounds(gfx::Size(100, 100));
1818 child1->SetDrawsContent(true);
1819 child2->SetBounds(gfx::Size(100, 100));
1820 child2->SetDrawsContent(true);
1821 child2->test_properties()->force_render_surface = true;
1822 grand_child->SetBounds(gfx::Size(100, 100));
1823 grand_child->SetDrawsContent(true);
1824 leaf_node1->SetBounds(gfx::Size(100, 100));
1825 leaf_node1->SetDrawsContent(true);
1826 leaf_node2->SetBounds(gfx::Size(100, 100));
1827 leaf_node2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331828
1829 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521830 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331831
weiliangce3f09a612016-03-16 17:02:521832 ASSERT_TRUE(root->render_surface());
1833 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331834
weiliangce3f09a612016-03-16 17:02:521835 EXPECT_FALSE(root->is_clipped());
1836 EXPECT_TRUE(root->render_surface()->is_clipped());
1837 EXPECT_FALSE(parent->is_clipped());
1838 EXPECT_FALSE(child1->is_clipped());
1839 EXPECT_FALSE(child2->is_clipped());
1840 EXPECT_FALSE(child2->render_surface()->is_clipped());
1841 EXPECT_FALSE(grand_child->is_clipped());
1842 EXPECT_FALSE(leaf_node1->is_clipped());
1843 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331844
danakje4fa7b72016-07-25 22:00:061845 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
enne76bf8982015-08-18 17:55:331846 // surface are clipped. But layers that contribute to child2's surface are
1847 // not clipped explicitly because child2's surface already accounts for
1848 // that clip.
weiliangce3f09a612016-03-16 17:02:521849 parent->SetMasksToBounds(true);
1850 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331851
weiliangce3f09a612016-03-16 17:02:521852 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331853
weiliangce3f09a612016-03-16 17:02:521854 ASSERT_TRUE(root->render_surface());
1855 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331856
weiliangce3f09a612016-03-16 17:02:521857 EXPECT_FALSE(root->is_clipped());
1858 EXPECT_TRUE(root->render_surface()->is_clipped());
1859 EXPECT_TRUE(parent->is_clipped());
1860 EXPECT_TRUE(child1->is_clipped());
1861 EXPECT_FALSE(child2->is_clipped());
1862 EXPECT_TRUE(child2->render_surface()->is_clipped());
1863 EXPECT_TRUE(grand_child->is_clipped());
1864 EXPECT_TRUE(leaf_node1->is_clipped());
1865 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331866
weiliangce3f09a612016-03-16 17:02:521867 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331868
danakje4fa7b72016-07-25 22:00:061869 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
enne76bf8982015-08-18 17:55:331870 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521871 child2->SetMasksToBounds(true);
1872 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331873
weiliangce3f09a612016-03-16 17:02:521874 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331875
weiliangce3f09a612016-03-16 17:02:521876 ASSERT_TRUE(root->render_surface());
1877 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331878
weiliangce3f09a612016-03-16 17:02:521879 EXPECT_FALSE(root->is_clipped());
1880 EXPECT_TRUE(root->render_surface()->is_clipped());
1881 EXPECT_FALSE(parent->is_clipped());
1882 EXPECT_FALSE(child1->is_clipped());
1883 EXPECT_TRUE(child2->is_clipped());
1884 EXPECT_FALSE(child2->render_surface()->is_clipped());
1885 EXPECT_FALSE(grand_child->is_clipped());
1886 EXPECT_FALSE(leaf_node1->is_clipped());
1887 EXPECT_TRUE(leaf_node2->is_clipped());
1888}
1889
1890TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1891 // Tests that when as long as layer is clipped, it's clip rect is set to
1892 // correct value.
jaydasikabf1875a2016-06-28 03:39:591893 LayerImpl* root = root_layer_for_testing();
weiliangce3f09a612016-03-16 17:02:521894 LayerImpl* parent = AddChild<LayerImpl>(root);
1895 LayerImpl* child = AddChild<LayerImpl>(parent);
1896
danakje4fa7b72016-07-25 22:00:061897 root->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521898 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061899 parent->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521900 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061901 child->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521902 child->SetDrawsContent(true);
weiliangce3f09a612016-03-16 17:02:521903 child->SetMasksToBounds(true);
1904
1905 ExecuteCalculateDrawProperties(root);
1906
1907 EXPECT_FALSE(root->is_clipped());
1908 EXPECT_FALSE(parent->is_clipped());
1909 EXPECT_TRUE(child->is_clipped());
1910 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1911
1912 parent->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061913 child->SetPosition(gfx::PointF(100.f, 100.f));
weiliangce3f09a612016-03-16 17:02:521914 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1915
1916 ExecuteCalculateDrawProperties(root);
1917
1918 EXPECT_FALSE(root->is_clipped());
1919 EXPECT_TRUE(parent->is_clipped());
1920 EXPECT_TRUE(child->is_clipped());
1921 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321922}
1923
ajuma51d73f72015-10-19 19:43:581924TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1925 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1926 // when a layer or its ancestor has a clip; in particular, if a layer
1927 // is_clipped, so is its entire subtree (since there are no render surfaces
1928 // that can reset is_clipped).
jaydasikabf1875a2016-06-28 03:39:591929 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581930 LayerImpl* parent = AddChild<LayerImpl>(root);
1931 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1932 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1933 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1934 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1935 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1936
danakje4fa7b72016-07-25 22:00:061937 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581938 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061939 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581940 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061941 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581942 child1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061943 child1->test_properties()->force_render_surface = true;
1944 child2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581945 child2->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061946 grand_child->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581947 grand_child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061948 grand_child->test_properties()->force_render_surface = true;
1949 leaf_node1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581950 leaf_node1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061951 leaf_node2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581952 leaf_node2->SetDrawsContent(true);
1953
ajuma51d73f72015-10-19 19:43:581954 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1955 // or without surfaces.
1956 ExecuteCalculateDrawProperties(root);
1957 EXPECT_FALSE(root->is_clipped());
1958 EXPECT_FALSE(parent->is_clipped());
1959 EXPECT_FALSE(child1->is_clipped());
1960 EXPECT_FALSE(child2->is_clipped());
1961 EXPECT_FALSE(grand_child->is_clipped());
1962 EXPECT_FALSE(leaf_node1->is_clipped());
1963 EXPECT_FALSE(leaf_node2->is_clipped());
1964
1965 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1966 EXPECT_FALSE(root->is_clipped());
1967 EXPECT_FALSE(parent->is_clipped());
1968 EXPECT_FALSE(child1->is_clipped());
1969 EXPECT_FALSE(child2->is_clipped());
1970 EXPECT_FALSE(grand_child->is_clipped());
1971 EXPECT_FALSE(leaf_node1->is_clipped());
1972 EXPECT_FALSE(leaf_node2->is_clipped());
1973
1974 // Case 2: The root is clipped. With surfaces, this only persists until the
1975 // next render surface. Without surfaces, the entire tree is clipped.
1976 root->SetMasksToBounds(true);
1977 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1978 ExecuteCalculateDrawProperties(root);
1979 EXPECT_TRUE(root->is_clipped());
1980 EXPECT_TRUE(parent->is_clipped());
1981 EXPECT_FALSE(child1->is_clipped());
1982 EXPECT_TRUE(child2->is_clipped());
1983 EXPECT_FALSE(grand_child->is_clipped());
1984 EXPECT_FALSE(leaf_node1->is_clipped());
1985 EXPECT_TRUE(leaf_node2->is_clipped());
1986
1987 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1988 EXPECT_TRUE(root->is_clipped());
1989 EXPECT_TRUE(parent->is_clipped());
1990 EXPECT_TRUE(child1->is_clipped());
1991 EXPECT_TRUE(child2->is_clipped());
1992 EXPECT_TRUE(grand_child->is_clipped());
1993 EXPECT_TRUE(leaf_node1->is_clipped());
1994 EXPECT_TRUE(leaf_node2->is_clipped());
1995
1996 root->SetMasksToBounds(false);
1997
1998 // Case 3: The parent is clipped. Again, with surfaces, this only persists
1999 // until the next render surface. Without surfaces, parent's entire subtree is
2000 // clipped.
2001 parent->SetMasksToBounds(true);
2002 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2003 ExecuteCalculateDrawProperties(root);
2004 EXPECT_FALSE(root->is_clipped());
2005 EXPECT_TRUE(parent->is_clipped());
2006 EXPECT_FALSE(child1->is_clipped());
2007 EXPECT_TRUE(child2->is_clipped());
2008 EXPECT_FALSE(grand_child->is_clipped());
2009 EXPECT_FALSE(leaf_node1->is_clipped());
2010 EXPECT_TRUE(leaf_node2->is_clipped());
2011
2012 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2013 EXPECT_FALSE(root->is_clipped());
2014 EXPECT_TRUE(parent->is_clipped());
2015 EXPECT_TRUE(child1->is_clipped());
2016 EXPECT_TRUE(child2->is_clipped());
2017 EXPECT_TRUE(grand_child->is_clipped());
2018 EXPECT_TRUE(leaf_node1->is_clipped());
2019 EXPECT_TRUE(leaf_node2->is_clipped());
2020
2021 parent->SetMasksToBounds(false);
2022
2023 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2024 // has no non-surface children. Without surfaces, child1's entire subtree is
2025 // clipped.
2026 child1->SetMasksToBounds(true);
2027 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2028 ExecuteCalculateDrawProperties(root);
2029 EXPECT_FALSE(root->is_clipped());
2030 EXPECT_FALSE(parent->is_clipped());
2031 EXPECT_TRUE(child1->is_clipped());
2032 EXPECT_FALSE(child2->is_clipped());
2033 EXPECT_FALSE(grand_child->is_clipped());
2034 EXPECT_FALSE(leaf_node1->is_clipped());
2035 EXPECT_FALSE(leaf_node2->is_clipped());
2036
2037 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2038 EXPECT_FALSE(root->is_clipped());
2039 EXPECT_FALSE(parent->is_clipped());
2040 EXPECT_TRUE(child1->is_clipped());
2041 EXPECT_FALSE(child2->is_clipped());
2042 EXPECT_TRUE(grand_child->is_clipped());
2043 EXPECT_TRUE(leaf_node1->is_clipped());
2044 EXPECT_FALSE(leaf_node2->is_clipped());
2045
2046 child1->SetMasksToBounds(false);
2047
2048 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2049 // surfaces is the same.
2050 leaf_node1->SetMasksToBounds(true);
2051 leaf_node2->SetMasksToBounds(true);
2052 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2053 ExecuteCalculateDrawProperties(root);
2054 EXPECT_FALSE(root->is_clipped());
2055 EXPECT_FALSE(parent->is_clipped());
2056 EXPECT_FALSE(child1->is_clipped());
2057 EXPECT_FALSE(child2->is_clipped());
2058 EXPECT_FALSE(grand_child->is_clipped());
2059 EXPECT_TRUE(leaf_node1->is_clipped());
2060 EXPECT_TRUE(leaf_node2->is_clipped());
2061
2062 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2063 EXPECT_FALSE(root->is_clipped());
2064 EXPECT_FALSE(parent->is_clipped());
2065 EXPECT_FALSE(child1->is_clipped());
2066 EXPECT_FALSE(child2->is_clipped());
2067 EXPECT_FALSE(grand_child->is_clipped());
2068 EXPECT_TRUE(leaf_node1->is_clipped());
2069 EXPECT_TRUE(leaf_node2->is_clipped());
2070}
2071
[email protected]fd9a3b6d2013-08-03 00:46:172072TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322073 // Verify that layers get the appropriate DrawableContentRect when their
danakje4fa7b72016-07-25 22:00:062074 // parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322075 //
2076 // grand_child1 - completely inside the region; DrawableContentRect should
2077 // be the layer rect expressed in target space.
danakje4fa7b72016-07-25 22:00:062078 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
[email protected]fb661802013-03-25 01:59:322079 // will be the intersection of layer bounds and the mask region.
danakje4fa7b72016-07-25 22:00:062080 // grand_child3 - partially clipped and MasksToBounds; the
[email protected]fb661802013-03-25 01:59:322081 // DrawableContentRect will still be the intersection of layer bounds and
2082 // the mask region.
2083 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2084 // be empty.
[email protected]fb661802013-03-25 01:59:322085
jaydasikabf1875a2016-06-28 03:39:592086 LayerImpl* parent = root_layer_for_testing();
enne07405c772015-08-18 17:56:452087 LayerImpl* child = AddChild<LayerImpl>(parent);
2088 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2089 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2090 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2091 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322092
danakje4fa7b72016-07-25 22:00:062093 parent->SetBounds(gfx::Size(500, 500));
[email protected]fb661802013-03-25 01:59:322094 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062095 child->SetBounds(gfx::Size(20, 20));
2096 child->test_properties()->force_render_surface = true;
2097 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2098 grand_child1->SetBounds(gfx::Size(10, 10));
2099 grand_child1->SetDrawsContent(true);
2100 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2101 grand_child2->SetBounds(gfx::Size(10, 10));
2102 grand_child2->SetDrawsContent(true);
2103 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
[email protected]fb661802013-03-25 01:59:322104 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062105 grand_child3->SetBounds(gfx::Size(10, 10));
2106 grand_child3->SetDrawsContent(true);
2107 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2108 grand_child4->SetBounds(gfx::Size(10, 10));
2109 grand_child4->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452110 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322111
hush6b614212014-12-04 22:37:322112 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2113 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2114 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322115 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2116}
2117
[email protected]989386c2013-07-18 21:37:232118TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322119 // Verify that render surfaces (and their layers) get the appropriate
danakje4fa7b72016-07-25 22:00:062120 // clip rects when their parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322121 //
2122 // Layers that own render surfaces (at least for now) do not inherit any
2123 // clipping; instead the surface will enforce the clip for the entire subtree.
2124 // They may still have a clip rect of their own layer bounds, however, if
danakje4fa7b72016-07-25 22:00:062125 // MasksToBounds was true.
jaydasikabf1875a2016-06-28 03:39:592126 LayerImpl* parent = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:572127 LayerImpl* child = AddChildToRoot<LayerImpl>();
2128 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2129 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2130 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2131 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:062132 // The leaf nodes ensure that these grand_children become render surfaces for
[email protected]fb661802013-03-25 01:59:322133 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572134 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
weiliangcfb3d5eaa2015-07-28 23:54:572135 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
weiliangcfb3d5eaa2015-07-28 23:54:572136 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
weiliangcfb3d5eaa2015-07-28 23:54:572137 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
[email protected]fb661802013-03-25 01:59:322138
danakje4fa7b72016-07-25 22:00:062139 parent->SetBounds(gfx::Size(500, 500));
2140 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:322141 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062142 child->test_properties()->force_render_surface = true;
2143 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2144 grand_child1->SetBounds(gfx::Size(10, 10));
2145 grand_child1->test_properties()->force_render_surface = true;
2146 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2147 grand_child2->SetBounds(gfx::Size(10, 10));
2148 grand_child2->test_properties()->force_render_surface = true;
2149 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
2150 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322151 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062152 grand_child3->test_properties()->force_render_surface = true;
2153 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2154 grand_child4->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322155 grand_child4->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062156 grand_child4->test_properties()->force_render_surface = true;
2157 leaf_node1->SetBounds(gfx::Size(10, 10));
2158 leaf_node1->SetDrawsContent(true);
2159 leaf_node2->SetBounds(gfx::Size(10, 10));
2160 leaf_node2->SetDrawsContent(true);
2161 leaf_node3->SetBounds(gfx::Size(10, 10));
2162 leaf_node3->SetDrawsContent(true);
2163 leaf_node4->SetBounds(gfx::Size(10, 10));
2164 leaf_node4->SetDrawsContent(true);
weiliangcfb3d5eaa2015-07-28 23:54:572165 ExecuteCalculateDrawProperties(parent);
2166
[email protected]fb661802013-03-25 01:59:322167 ASSERT_TRUE(grand_child1->render_surface());
2168 ASSERT_TRUE(grand_child2->render_surface());
2169 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322170
2171 // Surfaces are clipped by their parent, but un-affected by the owning layer's
danakje4fa7b72016-07-25 22:00:062172 // MasksToBounds.
hush6b614212014-12-04 22:37:322173 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2174 grand_child1->render_surface()->clip_rect());
2175 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2176 grand_child2->render_surface()->clip_rect());
2177 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2178 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322179}
2180
ajuma51d73f72015-10-19 19:43:582181TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2182 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2183 // intersection of all ancestor clips in screen space; in particular, if a
2184 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2185 // subtree (since there are no render surfaces that can reset the clip_rect).
jaydasikabf1875a2016-06-28 03:39:592186 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582187 LayerImpl* parent = AddChild<LayerImpl>(root);
2188 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2189 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2190 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2191 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2192 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2193
danakje4fa7b72016-07-25 22:00:062194 root->SetBounds(gfx::Size(100, 100));
2195 parent->SetPosition(gfx::PointF(2.f, 2.f));
2196 parent->SetBounds(gfx::Size(400, 400));
2197 child1->SetPosition(gfx::PointF(4.f, 4.f));
2198 child1->SetBounds(gfx::Size(800, 800));
2199 child2->SetPosition(gfx::PointF(3.f, 3.f));
2200 child2->SetBounds(gfx::Size(800, 800));
2201 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2202 grand_child->SetBounds(gfx::Size(1500, 1500));
2203 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
2204 leaf_node1->SetBounds(gfx::Size(2000, 2000));
2205 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
2206 leaf_node2->SetBounds(gfx::Size(2000, 2000));
2207
ajuma51d73f72015-10-19 19:43:582208 root->SetDrawsContent(true);
2209 parent->SetDrawsContent(true);
2210 child1->SetDrawsContent(true);
2211 child2->SetDrawsContent(true);
2212 grand_child->SetDrawsContent(true);
2213 leaf_node1->SetDrawsContent(true);
2214 leaf_node2->SetDrawsContent(true);
2215
danakje4fa7b72016-07-25 22:00:062216 root->test_properties()->force_render_surface = true;
2217 child1->test_properties()->force_render_surface = true;
2218 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582219
2220 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2221 // bounds in target space. The only thing that changes when surfaces are
2222 // disabled is that target space is always screen space.
2223 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262224 EXPECT_TRUE(root->has_render_surface());
2225 EXPECT_FALSE(parent->has_render_surface());
2226 EXPECT_TRUE(child1->has_render_surface());
2227 EXPECT_FALSE(child2->has_render_surface());
2228 EXPECT_TRUE(grand_child->has_render_surface());
2229 EXPECT_FALSE(leaf_node1->has_render_surface());
2230 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422231 EXPECT_FALSE(root->is_clipped());
2232 EXPECT_FALSE(parent->is_clipped());
2233 EXPECT_FALSE(child1->is_clipped());
2234 EXPECT_FALSE(child2->is_clipped());
2235 EXPECT_FALSE(grand_child->is_clipped());
2236 EXPECT_FALSE(leaf_node1->is_clipped());
2237 EXPECT_FALSE(leaf_node2->is_clipped());
2238 EXPECT_TRUE(root->render_surface()->is_clipped());
2239 EXPECT_FALSE(child1->render_surface()->is_clipped());
2240 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2241 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582242
2243 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422244 EXPECT_FALSE(root->is_clipped());
2245 EXPECT_FALSE(parent->is_clipped());
2246 EXPECT_FALSE(child1->is_clipped());
2247 EXPECT_FALSE(child2->is_clipped());
2248 EXPECT_FALSE(grand_child->is_clipped());
2249 EXPECT_FALSE(leaf_node1->is_clipped());
2250 EXPECT_FALSE(leaf_node2->is_clipped());
2251 EXPECT_TRUE(root->render_surface()->is_clipped());
2252 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582253
2254 // Case 2: The root is clipped. In this case, layers that draw into the root
2255 // render surface are clipped by the root's bounds.
2256 root->SetMasksToBounds(true);
2257 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362258 root->test_properties()->force_render_surface = true;
2259 child1->test_properties()->force_render_surface = true;
2260 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582261 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262262 EXPECT_TRUE(root->has_render_surface());
2263 EXPECT_FALSE(parent->has_render_surface());
2264 EXPECT_TRUE(child1->has_render_surface());
2265 EXPECT_FALSE(child2->has_render_surface());
2266 EXPECT_TRUE(grand_child->has_render_surface());
2267 EXPECT_FALSE(leaf_node1->has_render_surface());
2268 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422269 EXPECT_TRUE(root->is_clipped());
2270 EXPECT_TRUE(parent->is_clipped());
2271 EXPECT_FALSE(child1->is_clipped());
2272 EXPECT_TRUE(child1->render_surface()->is_clipped());
2273 EXPECT_TRUE(child2->is_clipped());
2274 EXPECT_FALSE(grand_child->is_clipped());
2275 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2276 EXPECT_FALSE(leaf_node1->is_clipped());
2277 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582278 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2279 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422280 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582281 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582282 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2283
2284 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422285 EXPECT_TRUE(root->is_clipped());
2286 EXPECT_TRUE(parent->is_clipped());
2287 EXPECT_TRUE(child1->is_clipped());
2288 EXPECT_TRUE(child2->is_clipped());
2289 EXPECT_TRUE(grand_child->is_clipped());
2290 EXPECT_TRUE(leaf_node1->is_clipped());
2291 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582292 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2293 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2294 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2295 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2296 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2297 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2298 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2299
2300 root->SetMasksToBounds(false);
2301
2302 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2303 // parent clip rect only contributes to the subtree rooted at child2, since
2304 // the subtree rooted at child1 renders into a separate surface. Similarly,
2305 // child1's clip rect doesn't contribute to its descendants, since its only
2306 // child is a render surface. However, without surfaces, these clip rects
2307 // contribute to all descendants.
2308 parent->SetMasksToBounds(true);
2309 child1->SetMasksToBounds(true);
2310 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362311 root->test_properties()->force_render_surface = true;
2312 child1->test_properties()->force_render_surface = true;
2313 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582314 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262315 EXPECT_TRUE(root->has_render_surface());
2316 EXPECT_FALSE(parent->has_render_surface());
2317 EXPECT_TRUE(child1->has_render_surface());
2318 EXPECT_FALSE(child2->has_render_surface());
2319 EXPECT_TRUE(grand_child->has_render_surface());
2320 EXPECT_FALSE(leaf_node1->has_render_surface());
2321 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422322 EXPECT_FALSE(root->is_clipped());
2323 EXPECT_TRUE(root->render_surface()->is_clipped());
2324 EXPECT_TRUE(parent->is_clipped());
2325 EXPECT_TRUE(child1->is_clipped());
2326 EXPECT_TRUE(child2->is_clipped());
2327 EXPECT_FALSE(grand_child->is_clipped());
2328 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2329 EXPECT_FALSE(leaf_node1->is_clipped());
2330 EXPECT_TRUE(leaf_node2->is_clipped());
2331 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582332 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2333 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2334 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422335 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582336 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2337
2338 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422339 EXPECT_FALSE(root->is_clipped());
2340 EXPECT_TRUE(root->render_surface()->is_clipped());
2341 EXPECT_TRUE(parent->is_clipped());
2342 EXPECT_TRUE(child1->is_clipped());
2343 EXPECT_TRUE(child2->is_clipped());
2344 EXPECT_TRUE(grand_child->is_clipped());
2345 EXPECT_TRUE(leaf_node1->is_clipped());
2346 EXPECT_TRUE(leaf_node2->is_clipped());
2347 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582348 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2349 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2350 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2351 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2352 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2353 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2354}
2355
jaydasika8d0064f2016-06-02 23:34:542356TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
jaydasikabf1875a2016-06-28 03:39:592357 LayerImpl* root = root_layer_for_testing();
jaydasika8d0064f2016-06-02 23:34:542358 LayerImpl* parent = AddChild<LayerImpl>(root);
2359 LayerImpl* child = AddChild<LayerImpl>(parent);
2360 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2361 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2362
danakje4fa7b72016-07-25 22:00:062363 root->SetBounds(gfx::Size(100, 100));
2364 parent->SetPosition(gfx::PointF(2.f, 2.f));
2365 parent->SetBounds(gfx::Size(400, 400));
2366 parent->SetMasksToBounds(true);
2367 child->SetPosition(gfx::PointF(4.f, 4.f));
2368 child->SetBounds(gfx::Size(800, 800));
2369 child->SetMasksToBounds(true);
2370 child->test_properties()->force_render_surface = true;
2371 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2372 grand_child->SetBounds(gfx::Size(1500, 1500));
2373 grand_child->test_properties()->force_render_surface = true;
2374 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2375 leaf_node->SetBounds(gfx::Size(2000, 2000));
2376
jaydasika8d0064f2016-06-02 23:34:542377 root->SetDrawsContent(true);
2378 parent->SetDrawsContent(true);
2379 child->SetDrawsContent(true);
2380 grand_child->SetDrawsContent(true);
2381 leaf_node->SetDrawsContent(true);
2382
jaydasika8d0064f2016-06-02 23:34:542383 host_impl()->set_resourceless_software_draw_for_testing();
2384 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2385 gfx::PointF test_point(90.f, 90.f);
2386 LayerImpl* result_layer =
2387 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2388 ASSERT_TRUE(result_layer);
2389 EXPECT_EQ(leaf_node, result_layer);
2390}
2391
ajuma51d73f72015-10-19 19:43:582392TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2393 // Tests that draw properties are computed correctly when we disable and then
2394 // re-enable separate surfaces.
jaydasikabf1875a2016-06-28 03:39:592395 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582396 LayerImpl* parent = AddChild<LayerImpl>(root);
2397 LayerImpl* child = AddChild<LayerImpl>(parent);
2398 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2399 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2400
danakje4fa7b72016-07-25 22:00:062401 root->SetBounds(gfx::Size(100, 100));
2402 parent->SetPosition(gfx::PointF(2.f, 2.f));
2403 parent->SetBounds(gfx::Size(400, 400));
2404 parent->SetMasksToBounds(true);
2405 child->SetPosition(gfx::PointF(4.f, 4.f));
2406 child->SetBounds(gfx::Size(800, 800));
2407 child->SetMasksToBounds(true);
2408 child->test_properties()->force_render_surface = true;
2409 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2410 grand_child->SetBounds(gfx::Size(1500, 1500));
2411 grand_child->test_properties()->force_render_surface = true;
2412 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2413 leaf_node->SetBounds(gfx::Size(2000, 2000));
2414
ajuma51d73f72015-10-19 19:43:582415 root->SetDrawsContent(true);
2416 parent->SetDrawsContent(true);
2417 child->SetDrawsContent(true);
2418 grand_child->SetDrawsContent(true);
2419 leaf_node->SetDrawsContent(true);
2420
ajuma51d73f72015-10-19 19:43:582421 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2422 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2423
2424 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2425 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2426
2427 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422428 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252429 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582430 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022431 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2432 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582433
2434 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422435 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582436 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2437 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022438 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces,
2439 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582440
2441 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422442 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252443 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582444 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022445 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2446 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582447}
2448
[email protected]989386c2013-07-18 21:37:232449TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
danakje4fa7b72016-07-25 22:00:062450 LayerImpl* root = root_layer_for_testing();
enneab0fee42015-07-07 17:36:422451 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2452 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2453 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2454 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2455 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2456 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2457 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2458 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322459
danakje4fa7b72016-07-25 22:00:062460 root->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362461 render_surface1->SetDrawsContent(true);
2462 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422463 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362464 render_surface2->SetDrawsContent(true);
2465 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422466 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362467 child_of_root->SetDrawsContent(true);
2468 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322469
2470 gfx::Transform layer_transform;
2471 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322472
jaydasika10d43fc2016-08-18 04:06:042473 root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062474 root->SetPosition(gfx::PointF(2.5f, 0.f));
2475 root->SetBounds(gfx::Size(10, 10));
2476 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042477 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062478 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2479 render_surface1->SetBounds(gfx::Size(10, 10));
2480 render_surface1->test_properties()->transform_origin =
2481 gfx::Point3F(0.25f, 0.f, 0.f);
2482 render_surface1->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042483 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062484 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2485 render_surface2->SetBounds(gfx::Size(10, 10));
2486 render_surface2->test_properties()->transform_origin =
2487 gfx::Point3F(0.25f, 0.f, 0.f);
2488 render_surface2->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042489 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062490 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2491 child_of_root->SetBounds(gfx::Size(10, 10));
2492 child_of_root->test_properties()->transform_origin =
2493 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042494 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062495 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2496 child_of_rs1->SetBounds(gfx::Size(10, 10));
2497 child_of_rs1->test_properties()->transform_origin =
2498 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042499 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062500 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2501 child_of_rs2->SetBounds(gfx::Size(10, 10));
2502 child_of_rs2->test_properties()->transform_origin =
2503 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042504 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062505 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2506 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2507 grand_child_of_root->test_properties()->transform_origin =
2508 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042509 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062510 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2511 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2512 grand_child_of_rs1->test_properties()->transform_origin =
2513 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042514 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062515 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2516 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2517 grand_child_of_rs2->test_properties()->transform_origin =
2518 gfx::Point3F(0.25f, 0.f, 0.f);
[email protected]fb661802013-03-25 01:59:322519
danakje4fa7b72016-07-25 22:00:062520 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:272521 SetElementIdsForTesting();
jaydasika9cb21c772016-05-10 22:37:082522
loyso9556c732016-03-11 07:54:582523 // Put an animated opacity on the render surface.
vollickef2ae922016-06-29 17:54:272524 AddOpacityTransitionToElementWithPlayer(
2525 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322526
loyso9556c732016-03-11 07:54:582527 // Also put an animated opacity on a layer without descendants.
vollickef2ae922016-06-29 17:54:272528 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2529 timeline_impl(), 10.0, 1.f, 0.f,
2530 false);
[email protected]fb661802013-03-25 01:59:322531
loyso9556c732016-03-11 07:54:582532 // Put a transform animation on the render surface.
vollickef2ae922016-06-29 17:54:272533 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2534 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322535
loyso9556c732016-03-11 07:54:582536 // Also put transform animations on grand_child_of_root, and
2537 // grand_child_of_rs2
vollickef2ae922016-06-29 17:54:272538 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2539 timeline_impl(), 10.0, 30, 0);
2540 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2541 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322542
danakje4fa7b72016-07-25 22:00:062543 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2544 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322545
2546 // Only layers that are associated with render surfaces should have an actual
2547 // RenderSurface() value.
danakje4fa7b72016-07-25 22:00:062548 ASSERT_TRUE(root->render_surface());
[email protected]fb661802013-03-25 01:59:322549 ASSERT_FALSE(child_of_root->render_surface());
2550 ASSERT_FALSE(grand_child_of_root->render_surface());
2551
2552 ASSERT_TRUE(render_surface1->render_surface());
2553 ASSERT_FALSE(child_of_rs1->render_surface());
2554 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2555
2556 ASSERT_TRUE(render_surface2->render_surface());
2557 ASSERT_FALSE(child_of_rs2->render_surface());
2558 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2559
2560 // Verify all render target accessors
danakje4fa7b72016-07-25 22:00:062561 EXPECT_EQ(root->render_surface(), root->render_target());
2562 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
2563 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322564
weiliangc189c1a12016-04-11 16:16:252565 EXPECT_EQ(render_surface1->render_surface(),
2566 render_surface1->render_target());
2567 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2568 EXPECT_EQ(render_surface1->render_surface(),
2569 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322570
weiliangc189c1a12016-04-11 16:16:252571 EXPECT_EQ(render_surface2->render_surface(),
2572 render_surface2->render_target());
2573 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2574 EXPECT_EQ(render_surface2->render_surface(),
2575 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322576
[email protected]fb661802013-03-25 01:59:322577 // Verify screen_space_transform_is_animating values
danakje4fa7b72016-07-25 22:00:062578 EXPECT_FALSE(root->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322579 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2580 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2581 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322582 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2583 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2584 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322585 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2586 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2587
2588 // Sanity check. If these fail there is probably a bug in the test itself.
2589 // It is expected that we correctly set up transforms so that the y-component
2590 // of the screen-space transform encodes the "depth" of the layer in the tree.
danakje4fa7b72016-07-25 22:00:062591 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262592 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102593 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322594 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102595 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322596
[email protected]803f6b52013-09-12 00:51:262597 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102598 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2599 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322600 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102601 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322602
[email protected]803f6b52013-09-12 00:51:262603 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102604 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2605 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322606 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102607 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322608}
2609
ajuma9384b9c22015-09-17 20:35:032610TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
danakje4fa7b72016-07-25 22:00:062611 LayerImpl* root = root_layer_for_testing();
ajuma9384b9c22015-09-17 20:35:032612 LayerImpl* child = AddChildToRoot<LayerImpl>();
2613 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2614
ajuma9384b9c22015-09-17 20:35:032615 gfx::Transform large_transform;
2616 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2617
danakje4fa7b72016-07-25 22:00:062618 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042619 child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062620 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042621 grand_child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062622 grand_child->SetBounds(gfx::Size(10, 10));
2623 grand_child->SetDrawsContent(true);
2624 ExecuteCalculateDrawProperties(root);
ajuma9384b9c22015-09-17 20:35:032625
2626 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2627}
2628
ajuma315a4782015-07-24 21:16:342629TEST_F(LayerTreeHostCommonTest,
2630 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
danakje4fa7b72016-07-25 22:00:062631 LayerImpl* root = root_layer_for_testing();
2632 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma315a4782015-07-24 21:16:342633 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2634 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2635
danakje4fa7b72016-07-25 22:00:062636 root->SetDrawsContent(true);
ajuma315a4782015-07-24 21:16:342637 child->SetDrawsContent(true);
2638 grand_child->SetDrawsContent(true);
2639 great_grand_child->SetDrawsContent(true);
2640
danakje4fa7b72016-07-25 22:00:062641 root->SetBounds(gfx::Size(10, 10));
2642 child->SetBounds(gfx::Size(10, 10));
2643 grand_child->SetBounds(gfx::Size(10, 10));
2644 great_grand_child->SetBounds(gfx::Size(10, 10));
ajuma315a4782015-07-24 21:16:342645
vollickef2ae922016-06-29 17:54:272646 SetElementIdsForTesting();
2647
ajuma315a4782015-07-24 21:16:342648 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482649 std::unique_ptr<Animation> animation = Animation::Create(
2650 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302651 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552652 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342653 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:272654 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2655 std::move(animation));
danakje4fa7b72016-07-25 22:00:062656 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:342657
danakje4fa7b72016-07-25 22:00:062658 EXPECT_FALSE(root->screen_space_transform_is_animating());
ajuma315a4782015-07-24 21:16:342659 EXPECT_FALSE(child->screen_space_transform_is_animating());
2660
2661 EXPECT_FALSE(grand_child->TransformIsAnimating());
2662 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2663 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2664 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2665}
2666
weiliangc6da32862016-04-20 16:40:112667TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2668 // Test visible layer rect and drawable content rect are calculated correctly
2669 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322670
[email protected]2c7c6702013-03-26 03:14:052671 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322672 gfx::Transform layer_to_surface_transform;
2673
2674 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232675 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112676 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2677 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2678 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2679 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2680 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2681 EXPECT_EQ(expected_drawable_content_rect,
2682 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322683
2684 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052685 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112686 expected_visible_layer_rect = gfx::Rect();
2687 expected_drawable_content_rect = gfx::Rect();
2688 drawing_layer = TestVisibleRectAndDrawableContentRect(
2689 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2690 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2691 EXPECT_EQ(expected_drawable_content_rect,
2692 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322693
2694 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052695 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112696 expected_visible_layer_rect = gfx::Rect(20, 20);
2697 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2698 drawing_layer = TestVisibleRectAndDrawableContentRect(
2699 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2700 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2701 EXPECT_EQ(expected_drawable_content_rect,
2702 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322703}
2704
weiliangc6da32862016-04-20 16:40:112705TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2706 // Test visible layer rect and drawable content rect are calculated correctly
2707 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322708
[email protected]2c7c6702013-03-26 03:14:052709 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2710 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322711 gfx::Transform layer_to_surface_transform;
2712
2713 // Case 1: Layer is contained within the surface.
2714 layer_to_surface_transform.MakeIdentity();
2715 layer_to_surface_transform.Translate(50.0, 50.0);
2716 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112717 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2718 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2719 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2720 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2721 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2722 EXPECT_EQ(expected_drawable_content_rect,
2723 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322724
2725 // Case 2: Layer is outside the surface rect.
2726 layer_to_surface_transform.MakeIdentity();
2727 layer_to_surface_transform.Translate(-50.0, 0.0);
2728 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112729 expected_visible_layer_rect = gfx::Rect();
2730 expected_drawable_content_rect = gfx::Rect();
2731 drawing_layer = TestVisibleRectAndDrawableContentRect(
2732 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2733 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2734 EXPECT_EQ(expected_drawable_content_rect,
2735 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322736
2737 // Case 3: The layer is rotated about its top-left corner. In surface space,
2738 // the layer is oriented diagonally, with the left half outside of the render
2739 // surface. In this case, the g should still be the entire layer
2740 // (remember the g is computed in layer space); both the top-left
2741 // and bottom-right corners of the layer are still visible.
2742 layer_to_surface_transform.MakeIdentity();
2743 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112744 expected_visible_layer_rect = gfx::Rect(30, 30);
2745 expected_drawable_content_rect = gfx::Rect(22, 43);
2746 drawing_layer = TestVisibleRectAndDrawableContentRect(
2747 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2748 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2749 EXPECT_EQ(expected_drawable_content_rect,
2750 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322751
2752 // Case 4: The layer is rotated about its top-left corner, and translated
2753 // upwards. In surface space, the layer is oriented diagonally, with only the
2754 // top corner of the surface overlapping the layer. In layer space, the render
2755 // surface overlaps the right side of the layer. The g should be
2756 // the layer's right half.
2757 layer_to_surface_transform.MakeIdentity();
2758 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2759 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112760 // Right half of layer bounds.
2761 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2762 expected_drawable_content_rect = gfx::Rect(22, 22);
2763 drawing_layer = TestVisibleRectAndDrawableContentRect(
2764 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2765 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2766 EXPECT_EQ(expected_drawable_content_rect,
2767 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322768}
2769
weiliangc6da32862016-04-20 16:40:112770TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2771 // Test visible layer rect and drawable content rect are calculated correctly
2772 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322773
[email protected]2c7c6702013-03-26 03:14:052774 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2775 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322776 gfx::Transform layer_to_surface_transform;
2777
2778 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2779 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112780 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322781 layer_to_surface_transform.MakeIdentity();
2782 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112783 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2784 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2785 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2786 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2787 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2788 EXPECT_EQ(expected_drawable_content_rect,
2789 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322790
2791 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2792 // degrees, but shifted to the side so only the right-half the layer would be
2793 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112794 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262795 SkMScalar half_width_of_rotated_layer =
2796 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322797 layer_to_surface_transform.MakeIdentity();
2798 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232799 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2800 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112801 // Tight half of the layer.
2802 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2803 expected_drawable_content_rect = gfx::Rect(36, 100);
2804 drawing_layer = TestVisibleRectAndDrawableContentRect(
2805 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2806 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2807 EXPECT_EQ(expected_drawable_content_rect,
2808 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322809}
2810
weiliangc6da32862016-04-20 16:40:112811TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2812 // Test visible layer rect and drawable content rect are calculated correctly
2813 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322814
[email protected]2c7c6702013-03-26 03:14:052815 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2816 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322817 gfx::Transform layer_to_surface_transform;
2818
2819 // Case 1: Even though the layer is twice as large as the surface, due to
2820 // perspective foreshortening, the layer will fit fully in the surface when
2821 // its translated more than the perspective amount.
2822 layer_to_surface_transform.MakeIdentity();
2823
2824 // The following sequence of transforms applies the perspective about the
2825 // center of the surface.
2826 layer_to_surface_transform.Translate(50.0, 50.0);
2827 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2828 layer_to_surface_transform.Translate(-50.0, -50.0);
2829
2830 // This translate places the layer in front of the surface's projection plane.
2831 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2832
weiliangc6da32862016-04-20 16:40:112833 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2834 // offset by layer position.
2835 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2836 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2837 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2838 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2839 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2840 EXPECT_EQ(expected_drawable_content_rect,
2841 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322842
2843 // Case 2: same projection as before, except that the layer is also translated
2844 // to the side, so that only the right half of the layer should be visible.
2845 //
2846 // Explanation of expected result: The perspective ratio is (z distance
2847 // between layer and camera origin) / (z distance between projection plane and
2848 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112849 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322850 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112851 // -25 == -100 in the layer's units.
2852 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2853 // Visible layer rect is moved by 100, and drawable content rect is in target
2854 // space and is moved by 25.
2855 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2856 expected_drawable_content_rect = gfx::Rect(13, 38);
2857 drawing_layer = TestVisibleRectAndDrawableContentRect(
2858 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2859 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2860 EXPECT_EQ(expected_drawable_content_rect,
2861 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322862}
2863
weiliangc6da32862016-04-20 16:40:112864TEST_F(LayerTreeHostCommonDrawRectsTest,
2865 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322866 // There is currently no explicit concept of an orthographic projection plane
2867 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2868 // are technically behind the surface in an orthographic world should not be
2869 // clipped when they are flattened to the surface.
2870
[email protected]2c7c6702013-03-26 03:14:052871 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2872 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322873 gfx::Transform layer_to_surface_transform;
2874
2875 // This sequence of transforms effectively rotates the layer about the y-axis
2876 // at the center of the layer.
2877 layer_to_surface_transform.MakeIdentity();
2878 layer_to_surface_transform.Translate(50.0, 0.0);
2879 layer_to_surface_transform.RotateAboutYAxis(45.0);
2880 layer_to_surface_transform.Translate(-50.0, 0.0);
2881
weiliangc6da32862016-04-20 16:40:112882 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2883 // space.
2884 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2885 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2886 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2887 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2888 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2889 EXPECT_EQ(expected_drawable_content_rect,
2890 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322891}
2892
weiliangc6da32862016-04-20 16:40:112893TEST_F(LayerTreeHostCommonDrawRectsTest,
2894 DrawRectsFor3dPerspectiveWhenClippedByW) {
2895 // Test visible layer rect and drawable content rect are calculated correctly
2896 // when projecting a surface onto a layer, but the layer is partially behind
2897 // the camera (not just behind the projection plane). In this case, the
2898 // cartesian coordinates may seem to be valid, but actually they are not. The
2899 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2900 // coordinates before converting to cartesian coordinates. The drawable
2901 // content rect would be entire surface rect because layer is rotated at the
2902 // camera position.
[email protected]fb661802013-03-25 01:59:322903
weiliangc6da32862016-04-20 16:40:112904 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2905 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322906 gfx::Transform layer_to_surface_transform;
2907
2908 // The layer is positioned so that the right half of the layer should be in
2909 // front of the camera, while the other half is behind the surface's
2910 // projection plane. The following sequence of transforms applies the
2911 // perspective and rotation about the center of the layer.
2912 layer_to_surface_transform.MakeIdentity();
2913 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112914 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2915 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2916 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322917
2918 // Sanity check that this transform does indeed cause w < 0 when applying the
2919 // transform, otherwise this code is not testing the intended scenario.
2920 bool clipped;
2921 MathUtil::MapQuad(layer_to_surface_transform,
2922 gfx::QuadF(gfx::RectF(layer_content_rect)),
2923 &clipped);
2924 ASSERT_TRUE(clipped);
2925
weiliangc6da32862016-04-20 16:40:112926 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2927 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2928 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2929 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2930 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2931 EXPECT_EQ(expected_drawable_content_rect,
2932 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322933}
2934
weiliangc6da32862016-04-20 16:40:112935TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322936 // To determine visible rect in layer space, there needs to be an
2937 // un-projection from surface space to layer space. When the original
2938 // transform was a perspective projection that was clipped, it returns a rect
2939 // that encloses the clipped bounds. Un-projecting this new rect may require
2940 // clipping again.
2941
2942 // This sequence of transforms causes one corner of the layer to protrude
2943 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:112944 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
2945 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322946 gfx::Transform layer_to_surface_transform;
2947 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:112948 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:322949 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2950 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2951 layer_to_surface_transform.RotateAboutYAxis(45.0);
2952 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:112953 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:322954
2955 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2956 // code is not testing the intended scenario.
2957 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442958 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2959 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322960 MathUtil::ProjectQuad(
2961 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2962 ASSERT_TRUE(clipped);
2963
2964 // Only the corner of the layer is not visible on the surface because of being
2965 // clipped. But, the net result of rounding visible region to an axis-aligned
2966 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:112967 gfx::Rect expected_visible_layer_rect = layer_content_rect;
2968 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2969 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2970 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2971 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2972 EXPECT_EQ(expected_drawable_content_rect,
2973 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322974}
2975
miletus9d3da522015-06-05 19:45:072976TEST_F(LayerTreeHostCommonTest,
2977 VisibleRectsForPositionedRootLayerClippedByViewport) {
jaydasikabf1875a2016-06-28 03:39:592978 LayerImpl* root = root_layer_for_testing();
miletus9d3da522015-06-05 19:45:072979
danakje4fa7b72016-07-25 22:00:062980 root->SetPosition(gfx::PointF(60, 70));
2981 root->SetBounds(gfx::Size(100, 100));
2982 root->SetDrawsContent(true);
enne6c281f6e2015-08-18 23:23:002983 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:072984
danakj5e6ff6d2015-09-05 04:43:442985 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:072986 root->render_surface()->DrawableContentRect());
2987 // In target space, not clipped.
2988 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2989 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:442990 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:072991}
2992
[email protected]989386c2013-07-18 21:37:232993TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
jaydasikabf1875a2016-06-28 03:39:592994 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:172995 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:172996 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:172997 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:062998
2999 root->SetBounds(gfx::Size(100, 100));
3000 child1_layer->SetBounds(gfx::Size(50, 50));
3001 child1_layer->SetDrawsContent(true);
3002 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
3003 child2_layer->SetBounds(gfx::Size(50, 50));
3004 child2_layer->SetDrawsContent(true);
3005 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
3006 child3_layer->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173007 child3_layer->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173008 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323009
danakj5e6ff6d2015-09-05 04:43:443010 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323011 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323012
danakj64767d902015-06-19 00:10:433013 // Layers that do not draw content should have empty visible_layer_rects.
3014 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323015
danakj64767d902015-06-19 00:10:433016 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173017 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3018 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3019 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323020
3021 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173022 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3023 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3024 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323025}
3026
[email protected]989386c2013-07-18 21:37:233027TEST_F(LayerTreeHostCommonTest,
3028 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
jaydasikabf1875a2016-06-28 03:39:593029 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173030 LayerImpl* child = AddChildToRoot<LayerImpl>();
3031 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173032 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173033 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:283034
danakje4fa7b72016-07-25 22:00:063035 root->SetBounds(gfx::Size(100, 100));
3036 child->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323037 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063038 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
3039 grand_child1->SetBounds(gfx::Size(50, 50));
3040 grand_child1->SetDrawsContent(true);
3041 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
3042 grand_child2->SetBounds(gfx::Size(50, 50));
3043 grand_child2->SetDrawsContent(true);
3044 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
3045 grand_child3->SetBounds(gfx::Size(50, 50));
3046 grand_child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173047 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323048
danakj5e6ff6d2015-09-05 04:43:443049 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323050 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323051
3052 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433053 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3054 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323055
3056 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433057 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3058 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3059 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323060
3061 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323062 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3063 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323064 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3065}
3066
ajuma27442dd2015-03-30 19:19:483067TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasikabf1875a2016-06-28 03:39:593068 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:143069 LayerImpl* child = AddChild<LayerImpl>(root);
3070 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483071
ajuma27442dd2015-03-30 19:19:483072 gfx::Transform child_scale_matrix;
3073 child_scale_matrix.Scale(0.25f, 0.25f);
3074 gfx::Transform grand_child_scale_matrix;
3075 grand_child_scale_matrix.Scale(0.246f, 0.246f);
ajuma27442dd2015-03-30 19:19:483076
danakje4fa7b72016-07-25 22:00:063077 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043078 child->test_properties()->transform = child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063079 child->SetBounds(gfx::Size(10, 10));
ajuma27442dd2015-03-30 19:19:483080 child->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:043081 grand_child->test_properties()->transform = grand_child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063082 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:143083 grand_child->SetDrawsContent(true);
3084 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483085
weiliangcd15784432016-06-07 17:57:333086 // The visible rect is expanded to integer coordinates.
3087 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483088}
3089
[email protected]989386c2013-07-18 21:37:233090TEST_F(LayerTreeHostCommonTest,
3091 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593092 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173093 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3094 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173095 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173096 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
danakje4fa7b72016-07-25 22:00:063097
3098 root->SetBounds(gfx::Size(100, 100));
3099 render_surface->SetBounds(gfx::Size(3, 4));
3100 render_surface->test_properties()->force_render_surface = true;
3101 child1->SetPosition(gfx::PointF(5.f, 5.f));
3102 child1->SetBounds(gfx::Size(50, 50));
3103 child1->SetDrawsContent(true);
3104 child2->SetPosition(gfx::PointF(75.f, 75.f));
3105 child2->SetBounds(gfx::Size(50, 50));
3106 child2->SetDrawsContent(true);
3107 child3->SetPosition(gfx::PointF(125.f, 125.f));
3108 child3->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173109 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173110 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323111
weiliangc0dece732015-07-27 19:06:173112 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323113
danakj5e6ff6d2015-09-05 04:43:443114 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323115 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323116
3117 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433118 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173119 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323120
3121 // An unclipped surface grows its DrawableContentRect to include all drawable
3122 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443123 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173124 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323125
3126 // All layers that draw content into the unclipped surface are also unclipped.
jaydasika94bebdd2016-09-16 22:11:183127 // Only the viewport clip should apply
danakj64767d902015-06-19 00:10:433128 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183129 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3130 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323131
hush6b614212014-12-04 22:37:323132 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3133 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3134 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323135}
3136
[email protected]989386c2013-07-18 21:37:233137TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583138 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:593139 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:583140 LayerImpl* parent = AddChild<LayerImpl>(root);
3141 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3142 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3143 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3144 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3145 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3146 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3147
danakje4fa7b72016-07-25 22:00:063148 root->SetBounds(gfx::Size(100, 100));
3149 parent->SetPosition(gfx::PointF(2.f, 2.f));
3150 parent->SetBounds(gfx::Size(400, 400));
3151 child1->SetPosition(gfx::PointF(4.f, 4.f));
3152 child1->SetBounds(gfx::Size(800, 800));
3153 child1->test_properties()->force_render_surface = true;
3154 child2->SetPosition(gfx::PointF(3.f, 3.f));
3155 child2->SetBounds(gfx::Size(800, 800));
3156 child2->test_properties()->force_render_surface = true;
3157 grand_child1->SetPosition(gfx::PointF(8.f, 8.f));
3158 grand_child1->SetBounds(gfx::Size(1500, 1500));
3159 grand_child2->SetPosition(gfx::PointF(7.f, 7.f));
3160 grand_child2->SetBounds(gfx::Size(1500, 1500));
3161 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
3162 leaf_node1->SetBounds(gfx::Size(2000, 2000));
3163 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
3164 leaf_node2->SetBounds(gfx::Size(2000, 2000));
3165
ajuma51d73f72015-10-19 19:43:583166 root->SetDrawsContent(true);
3167 parent->SetDrawsContent(true);
3168 child1->SetDrawsContent(true);
3169 child2->SetDrawsContent(true);
3170 grand_child1->SetDrawsContent(true);
3171 grand_child2->SetDrawsContent(true);
3172 leaf_node1->SetDrawsContent(true);
3173 leaf_node2->SetDrawsContent(true);
3174
jaydasika94bebdd2016-09-16 22:11:183175 // Case 1: No layers clip. Visible rects are clipped by the viewport.
ajuma51d73f72015-10-19 19:43:583176 // Each layer's drawable content rect is its bounds in target space; the only
3177 // thing that changes with surfaces disabled is that target space is always
3178 // screen space.
weiliangcc154ce22015-12-09 03:39:263179 root->SetHasRenderSurface(true);
3180 child1->SetHasRenderSurface(true);
3181 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583182 ExecuteCalculateDrawProperties(root);
3183 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3184 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183185 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3186 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3187 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3188 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3189 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3190 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583191
3192 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3193 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3194 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3195 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3196 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3197 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3198 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3199 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3200
3201 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3202 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3203 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3204 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3205 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3206 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3207 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3208 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3209 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3210
3211 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3212 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3213 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3214 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3215 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3216 grand_child1->drawable_content_rect());
3217 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3218 grand_child2->drawable_content_rect());
3219 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3220 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3221
3222 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3223 // all visible layer rects are clipped by the intersection of all ancestor
3224 // clips, whether or not surfaces are disabled. However, drawable content
3225 // rects are clipped only until the next render surface is reached, so
3226 // descendants of parent have their drawable content rects clipped only when
3227 // surfaces are disabled.
3228 parent->SetMasksToBounds(true);
3229 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3230 ExecuteCalculateDrawProperties(root);
3231 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3232 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3233 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3234 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3235 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3236 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3237 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3238 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3239
3240 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3241 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3242 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3243 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3244 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3245 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3246 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3247 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3248
3249 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3250 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3251 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3252 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3253 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3254 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3255 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3256 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3257 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3258
3259 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3260 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3261 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3262 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3263 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3264 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3265 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3266 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3267
3268 parent->SetMasksToBounds(false);
3269
3270 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
jaydasika526eae0a2016-09-02 01:47:593271 // layers have their visible rects clipped by them; Similarly, descendants of
3272 // these layers have their drawable content rects clipped by them.
ajuma51d73f72015-10-19 19:43:583273 child1->SetMasksToBounds(true);
3274 grand_child2->SetMasksToBounds(true);
3275 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3276 ExecuteCalculateDrawProperties(root);
3277 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3278 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593279 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183280 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593281 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3282 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3283 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3284 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583285
3286 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3287 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3288 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3289 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3290 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3291 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3292 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3293 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3294
3295 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3296 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3297 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3298 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3299 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3300 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3301 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3302 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3303 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3304
3305 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3306 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3307 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3308 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3309 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3310 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3311 grand_child2->drawable_content_rect());
3312 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3313 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3314}
3315
3316TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023317 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
jaydasikabf1875a2016-06-28 03:39:593318 LayerImpl* root = root_layer_for_testing();
enne6c281f6e2015-08-18 23:23:003319 LayerImpl* child1 = AddChild<LayerImpl>(root);
3320 LayerImpl* child2 = AddChild<LayerImpl>(root);
3321 LayerImpl* child3 = AddChild<LayerImpl>(root);
hush887bb542014-12-02 22:49:023322
danakje4fa7b72016-07-25 22:00:063323 root->SetBounds(gfx::Size(100, 100));
3324 child1->SetPosition(gfx::PointF(5.f, 5.f));
3325 child1->SetBounds(gfx::Size(50, 50));
3326 child1->SetDrawsContent(true);
3327 child2->SetPosition(gfx::PointF(75.f, 75.f));
3328 child2->SetBounds(gfx::Size(50, 50));
3329 child2->SetDrawsContent(true);
3330 child3->SetPosition(gfx::PointF(125.f, 125.f));
3331 child3->SetBounds(gfx::Size(50, 50));
3332 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023333
enne6c281f6e2015-08-18 23:23:003334 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023335 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003336 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383337 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023338
sunxdb365de02016-04-28 20:32:573339 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023340 ASSERT_TRUE(root->render_surface());
3341 EXPECT_FALSE(root->is_clipped());
3342
3343 gfx::Rect empty;
3344 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3345 EXPECT_TRUE(root->render_surface()->is_clipped());
3346
3347 // Visible content rect calculation will check if the target surface is
3348 // clipped or not. An empty clip rect does not indicate the render surface
3349 // is unclipped.
danakj64767d902015-06-19 00:10:433350 EXPECT_EQ(empty, child1->visible_layer_rect());
3351 EXPECT_EQ(empty, child2->visible_layer_rect());
3352 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023353}
3354
3355TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233356 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
jaydasikabf1875a2016-06-28 03:39:593357 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173358 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063359
3360 root->SetBounds(gfx::Size(100, 100));
3361 child->SetPosition(gfx::PointF(5.f, 5.f));
3362 child->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173363 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283364
[email protected]630ddad2013-08-16 03:01:323365 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473366 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323367 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473368
jaydasika10d43fc2016-08-18 04:06:043369 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173370 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473371
danakj64767d902015-06-19 00:10:433372 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473373 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323374
[email protected]08bdf1b2014-04-16 23:23:293375 // Case 2: a matrix with flattened z, uninvertible and not visible according
3376 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323377 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263378 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323379 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3380
jaydasika10d43fc2016-08-18 04:06:043381 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173382 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323383
danakj64767d902015-06-19 00:10:433384 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293385 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323386
[email protected]08bdf1b2014-04-16 23:23:293387 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323388 uninvertible_matrix.MakeIdentity();
3389 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263390 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323391 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3392
jaydasika10d43fc2016-08-18 04:06:043393 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173394 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323395
danakj64767d902015-06-19 00:10:433396 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293397 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473398}
3399
[email protected]989386c2013-07-18 21:37:233400TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563401 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
jaydasikabf1875a2016-06-28 03:39:593402 LayerImpl* root = root_layer_for_testing();
ajumaae0dc2d2015-08-05 21:55:563403 LayerImpl* child = AddChildToRoot<LayerImpl>();
3404 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaae0dc2d2015-08-05 21:55:563405
ajumaae0dc2d2015-08-05 21:55:563406 gfx::Transform perspective;
3407 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3408
3409 gfx::Transform rotation;
3410 rotation.RotateAboutYAxis(45.0);
3411
danakje4fa7b72016-07-25 22:00:063412 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043413 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063414 child->SetPosition(gfx::PointF(10.f, 10.f));
3415 child->SetBounds(gfx::Size(100, 100));
3416 child->SetDrawsContent(true);
3417 child->Set3dSortingContextId(1);
3418 child->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:043419 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063420 grand_child->SetBounds(gfx::Size(100, 100));
3421 grand_child->SetDrawsContent(true);
3422 grand_child->Set3dSortingContextId(1);
3423 grand_child->test_properties()->should_flatten_transform = false;
ajumaae0dc2d2015-08-05 21:55:563424 ExecuteCalculateDrawProperties(root);
3425
3426 // Though all layers have invertible transforms, matrix multiplication using
3427 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053428 EXPECT_FALSE(root->layer_tree_impl()
3429 ->property_trees()
3430 ->transform_tree.Node(grand_child->transform_tree_index())
trchendba8b1502016-07-08 09:47:013431 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563432
sunxd71aea3e2016-04-01 23:48:053433 // CalcDrawProps skips a subtree when a layer's screen space transform is
3434 // uninvertible
3435 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563436}
3437
jaydasika69c77aa2016-07-14 22:48:483438TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) {
3439 FakeImplTaskRunnerProvider task_runner_provider;
3440 TestSharedBitmapManager shared_bitmap_manager;
3441 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323442 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3443 FakeCompositorFrameSink::Create3d();
jaydasika69c77aa2016-07-14 22:48:483444 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
3445 &task_graph_runner);
3446
3447 std::unique_ptr<LayerImpl> root =
3448 LayerImpl::Create(host_impl.active_tree(), 1);
3449 std::unique_ptr<LayerImpl> child =
3450 LayerImpl::Create(host_impl.active_tree(), 2);
3451 std::unique_ptr<TextureLayerImpl> surface =
3452 TextureLayerImpl::Create(host_impl.active_tree(), 3);
3453 std::unique_ptr<TextureLayerImpl> surface_child =
3454 TextureLayerImpl::Create(host_impl.active_tree(), 4);
3455 std::unique_ptr<TextureLayerImpl> surface_sibling =
3456 TextureLayerImpl::Create(host_impl.active_tree(), 5);
3457 std::unique_ptr<TextureLayerImpl> surface_child_mask =
3458 TextureLayerImpl::Create(host_impl.active_tree(), 6);
3459
3460 surface->SetDrawsContent(true);
3461 surface_child->SetDrawsContent(true);
3462 surface_sibling->SetDrawsContent(true);
3463 surface_child_mask->SetDrawsContent(true);
3464 surface->SetContentsOpaque(true);
3465 surface_child->SetContentsOpaque(true);
3466 surface_sibling->SetContentsOpaque(true);
3467 surface_child_mask->SetContentsOpaque(true);
3468
jaydasika69c77aa2016-07-14 22:48:483469 gfx::Transform translate;
3470 translate.Translate(20.f, 20.f);
3471
danakje4fa7b72016-07-25 22:00:063472 root->SetBounds(gfx::Size(1000, 1000));
3473 child->SetBounds(gfx::Size(300, 300));
jaydasika10d43fc2016-08-18 04:06:043474 surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:063475 surface->SetBounds(gfx::Size(300, 300));
3476 surface->test_properties()->force_render_surface = true;
3477 surface_child->SetBounds(gfx::Size(300, 300));
3478 surface_child->test_properties()->force_render_surface = true;
3479 surface_sibling->SetBounds(gfx::Size(200, 200));
jaydasika69c77aa2016-07-14 22:48:483480
3481 LayerImpl* surface_ptr = surface.get();
3482 LayerImpl* surface_child_ptr = surface_child.get();
3483 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3484
3485 host_impl.SetViewportSize(root->bounds());
3486
3487 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3488 surface->test_properties()->AddChild(std::move(surface_child));
3489 child->test_properties()->AddChild(std::move(surface));
3490 child->test_properties()->AddChild(std::move(surface_sibling));
3491 root->test_properties()->AddChild(std::move(child));
3492 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3493 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323494 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika69c77aa2016-07-14 22:48:483495 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3496 bool update_lcd_text = false;
3497 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3498
3499 EXPECT_TRANSFORMATION_MATRIX_EQ(
3500 surface_ptr->render_surface()->draw_transform(), translate);
3501 // surface_sibling draws into the root render surface and occludes
3502 // surface_child's contents.
3503 Occlusion actual_occlusion =
3504 surface_child_ptr->render_surface()->occlusion_in_content_space();
3505 Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()),
3506 SimpleEnclosedRegion(gfx::Rect(200, 200)));
3507 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3508
3509 // Mask layer should have the same occlusion.
3510 actual_occlusion =
3511 surface_child_mask_ptr->draw_properties().occlusion_in_content_space;
3512 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3513}
3514
ajumaae0dc2d2015-08-05 21:55:563515TEST_F(LayerTreeHostCommonTest,
3516 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163517 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563518 TestSharedBitmapManager shared_bitmap_manager;
3519 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323520 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3521 FakeCompositorFrameSink::Create3d();
khushalsagarb64b360d2015-10-21 19:25:163522 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563523 &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483524
danakj60bc3bc2016-04-09 00:24:483525 std::unique_ptr<LayerImpl> root =
3526 LayerImpl::Create(host_impl.active_tree(), 1);
3527 std::unique_ptr<LayerImpl> child =
3528 LayerImpl::Create(host_impl.active_tree(), 2);
3529 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563530 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483531 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563532 LayerImpl::Create(host_impl.active_tree(), 4);
ajumaae0dc2d2015-08-05 21:55:563533
ajumaae0dc2d2015-08-05 21:55:563534 gfx::Transform perspective;
3535 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3536
3537 gfx::Transform rotation;
3538 rotation.RotateAboutYAxis(45.0);
3539
danakje4fa7b72016-07-25 22:00:063540 root->SetBounds(gfx::Size(1000, 1000));
jaydasika10d43fc2016-08-18 04:06:043541 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063542 child->SetPosition(gfx::PointF(10.f, 10.f));
3543 child->SetBounds(gfx::Size(300, 300));
3544 child->test_properties()->should_flatten_transform = false;
3545 child->Set3dSortingContextId(1);
jaydasika10d43fc2016-08-18 04:06:043546 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063547 grand_child->SetBounds(gfx::Size(200, 200));
3548 grand_child->test_properties()->should_flatten_transform = false;
3549 grand_child->Set3dSortingContextId(1);
3550 occluding_child->SetBounds(gfx::Size(200, 200));
3551 occluding_child->test_properties()->should_flatten_transform = false;
3552
3553 child->SetDrawsContent(true);
3554 grand_child->SetDrawsContent(true);
3555 occluding_child->SetDrawsContent(true);
3556 occluding_child->SetContentsOpaque(true);
ajumaae0dc2d2015-08-05 21:55:563557
3558 host_impl.SetViewportSize(root->bounds());
3559
jaydasika89f7b5a2016-06-22 02:08:393560 child->test_properties()->AddChild(std::move(grand_child));
3561 root->test_properties()->AddChild(std::move(child));
3562 root->test_properties()->AddChild(std::move(occluding_child));
jaydasikabf1875a2016-06-28 03:39:593563 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
sievers71c62dd52015-10-07 01:44:393564 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323565 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika4340ea02016-06-06 19:44:263566 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563567 bool update_lcd_text = false;
3568 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3569
jaydasikafc66cfb2016-06-10 04:34:223570 LayerImpl* grand_child_ptr = host_impl.active_tree()
jaydasikabf1875a2016-06-28 03:39:593571 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:223572 ->test_properties()
3573 ->children[0]
3574 ->test_properties()
3575 ->children[0];
ajumaae0dc2d2015-08-05 21:55:563576
3577 // Though all layers have invertible transforms, matrix multiplication using
3578 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053579 EXPECT_FALSE(
3580 host_impl.active_tree()
3581 ->property_trees()
3582 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
trchendba8b1502016-07-08 09:47:013583 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563584
sunxd71aea3e2016-04-01 23:48:053585 // Since |grand_child| has an uninvertible screen space transform, it is
3586 // skipped so
3587 // that we are not computing its occlusion_in_content_space.
3588 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563589 EXPECT_EQ(
3590 layer_bounds,
3591 grand_child_ptr->draw_properties()
3592 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3593}
3594
3595TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233596 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593597 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173598 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3599 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173600 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173601 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283602
danakje4fa7b72016-07-25 22:00:063603 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323604 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063605 render_surface->SetBounds(gfx::Size(3, 4));
3606 render_surface->test_properties()->force_render_surface = true;
3607 child1->SetPosition(gfx::PointF(5.f, 5.f));
3608 child1->SetBounds(gfx::Size(50, 50));
3609 child1->SetDrawsContent(true);
3610 child2->SetPosition(gfx::PointF(75.f, 75.f));
3611 child2->SetBounds(gfx::Size(50, 50));
3612 child2->SetDrawsContent(true);
3613 child3->SetPosition(gfx::PointF(125.f, 125.f));
3614 child3->SetBounds(gfx::Size(50, 50));
3615 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173616 ExecuteCalculateDrawProperties(root);
3617
3618 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323619
danakj5e6ff6d2015-09-05 04:43:443620 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323621 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323622
3623 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433624 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173625 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323626
3627 // A clipped surface grows its DrawableContentRect to include all drawable
3628 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443629 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173630 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323631
3632 // All layers that draw content into the surface have their visible content
3633 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433634 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3635 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3636 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323637
3638 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323639 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3640 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3641 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323642}
3643
[email protected]989386c2013-07-18 21:37:233644TEST_F(LayerTreeHostCommonTest,
3645 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323646 // Check that clipping does not propagate down surfaces.
jaydasikabf1875a2016-06-28 03:39:593647 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173648 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3649 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3650 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173651 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173652 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283653
danakje4fa7b72016-07-25 22:00:063654 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323655 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063656 render_surface1->SetBounds(gfx::Size(3, 4));
3657 render_surface1->test_properties()->force_render_surface = true;
3658 render_surface2->SetBounds(gfx::Size(7, 13));
3659 render_surface2->test_properties()->force_render_surface = true;
3660 child1->SetPosition(gfx::PointF(5.f, 5.f));
3661 child1->SetBounds(gfx::Size(50, 50));
3662 child1->SetDrawsContent(true);
3663 child2->SetPosition(gfx::PointF(75.f, 75.f));
3664 child2->SetBounds(gfx::Size(50, 50));
3665 child2->SetDrawsContent(true);
3666 child3->SetPosition(gfx::PointF(125.f, 125.f));
3667 child3->SetBounds(gfx::Size(50, 50));
3668 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173669 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323670
3671 ASSERT_TRUE(render_surface1->render_surface());
3672 ASSERT_TRUE(render_surface2->render_surface());
3673
danakj5e6ff6d2015-09-05 04:43:443674 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323675 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323676
3677 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433678 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3679 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3680 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323681
3682 // A clipped surface grows its DrawableContentRect to include all drawable
3683 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443684 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323685 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323686
3687 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3688 // is only implicitly clipped by render_surface1's content rect. So,
3689 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443690 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323691 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323692
jaydasika94bebdd2016-09-16 22:11:183693 // All layers that draw content into render_surface2 think they are unclipped
3694 // by the surface. So, only the viewport clip applies.
danakj64767d902015-06-19 00:10:433695 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183696 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3697 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323698
3699 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323700 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3701 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3702 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323703}
3704
[email protected]989386c2013-07-18 21:37:233705TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463706 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593707 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463708 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3709 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3710 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3711 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
jaydasika27d0f2e2015-10-16 23:52:463712
danakje4fa7b72016-07-25 22:00:063713 root->SetBounds(gfx::Size(100, 100));
3714 render_surface1->SetBounds(gfx::Size(100, 100));
3715 render_surface1->test_properties()->force_render_surface = true;
3716 child1->SetBounds(gfx::Size(500, 500));
3717 child1->SetDrawsContent(true);
3718 child2->SetBounds(gfx::Size(700, 700));
3719 child2->SetDrawsContent(true);
3720 render_surface2->SetBounds(gfx::Size(1000, 1000));
3721 render_surface2->test_properties()->force_render_surface = true;
3722 render_surface2->SetDrawsContent(true);
jaydasika27d0f2e2015-10-16 23:52:463723
3724 child1->SetMasksToBounds(true);
3725 child2->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463726 ExecuteCalculateDrawProperties(root);
jaydasika526eae0a2016-09-02 01:47:593727 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463728 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3729}
3730
3731TEST_F(LayerTreeHostCommonTest,
3732 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593733 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463734 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3735 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3736 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3737 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3738
danakje4fa7b72016-07-25 22:00:063739 root->SetBounds(gfx::Size(100, 100));
3740
3741 clip_parent->SetBounds(gfx::Size(50, 50));
3742 clip_parent->SetMasksToBounds(true);
3743 clip_parent->test_properties()->clip_children =
3744 base::MakeUnique<std::set<LayerImpl*>>();
3745 clip_parent->test_properties()->clip_children->insert(clip_child);
3746
3747 render_surface1->SetBounds(gfx::Size(20, 20));
3748 render_surface1->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463749 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063750 render_surface1->test_properties()->force_render_surface = true;
3751
3752 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika27d0f2e2015-10-16 23:52:463753 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563754 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika27d0f2e2015-10-16 23:52:463755
danakje4fa7b72016-07-25 22:00:063756 render_surface2->SetBounds(gfx::Size(60, 60));
3757 render_surface2->SetDrawsContent(true);
3758 render_surface2->test_properties()->force_render_surface = true;
jaydasika27d0f2e2015-10-16 23:52:463759
3760 ExecuteCalculateDrawProperties(root);
3761 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3762 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3763 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3764}
3765
jaydasika1f5312d2015-10-21 21:34:323766TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
jaydasikabf1875a2016-06-28 03:39:593767 LayerImpl* root = root_layer_for_testing();
jaydasika1f5312d2015-10-21 21:34:323768 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3769 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3770 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3771 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3772
danakje4fa7b72016-07-25 22:00:063773 root->SetBounds(gfx::Size(100, 100));
3774
3775 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
3776 clip_parent->SetBounds(gfx::Size(50, 50));
3777 clip_parent->test_properties()->clip_children =
3778 base::MakeUnique<std::set<LayerImpl*>>();
3779 clip_parent->test_properties()->clip_children->insert(clip_child);
3780
3781 render_surface1->SetBounds(gfx::Size(20, 20));
jaydasika1f5312d2015-10-21 21:34:323782 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063783 render_surface1->test_properties()->force_render_surface = true;
3784
3785 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika1f5312d2015-10-21 21:34:323786 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563787 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika1f5312d2015-10-21 21:34:323788
danakje4fa7b72016-07-25 22:00:063789 render_surface2->SetBounds(gfx::Size(60, 60));
3790 render_surface2->SetDrawsContent(true);
3791 render_surface2->test_properties()->force_render_surface = true;
3792
jaydasika1f5312d2015-10-21 21:34:323793 clip_parent->SetMasksToBounds(true);
3794 render_surface1->SetMasksToBounds(true);
3795
3796 ExecuteCalculateDrawProperties(root);
3797 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3798}
3799
jaydasika77a4a072015-10-20 21:47:273800TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3801 // Test that only drawn layers contribute to render surface content rect.
jaydasikabf1875a2016-06-28 03:39:593802 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:273803 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3804 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3805
danakje4fa7b72016-07-25 22:00:063806 root->SetBounds(gfx::Size(200, 200));
3807 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:273808 surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063809 surface->test_properties()->force_render_surface = true;
3810 test_layer->SetBounds(gfx::Size(150, 150));
jaydasika77a4a072015-10-20 21:47:273811
3812 ExecuteCalculateDrawProperties(root);
3813 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3814
3815 test_layer->SetDrawsContent(true);
3816 ExecuteCalculateDrawProperties(root);
3817 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3818}
3819
jaydasika27d0f2e2015-10-16 23:52:463820TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3821 // Tests visible rects computation when we have unclipped_surface->
3822 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3823 // of surface_with_unclipped_descendants doesn't propagate to the
3824 // clipped_surface below it.
jaydasikabf1875a2016-06-28 03:39:593825 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463826 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3827 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3828 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3829 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3830 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3831
danakje4fa7b72016-07-25 22:00:063832 root->SetBounds(gfx::Size(100, 100));
jaydasika27d0f2e2015-10-16 23:52:463833
danakje4fa7b72016-07-25 22:00:063834 unclipped_surface->SetBounds(gfx::Size(30, 30));
3835 unclipped_surface->SetDrawsContent(true);
3836 unclipped_surface->test_properties()->force_render_surface = true;
3837
3838 clip_parent->SetBounds(gfx::Size(50, 50));
3839 clip_parent->test_properties()->clip_children =
3840 base::MakeUnique<std::set<LayerImpl*>>();
3841 clip_parent->test_properties()->clip_children->insert(clip_child);
3842
3843 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
3844 unclipped_desc_surface->SetDrawsContent(true);
3845 unclipped_desc_surface->test_properties()->force_render_surface = true;
3846
3847 clip_child->SetBounds(gfx::Size(60, 60));
3848 clip_child->test_properties()->clip_parent = clip_parent;
3849
3850 clipped_surface->SetBounds(gfx::Size(60, 60));
3851 clipped_surface->SetDrawsContent(true);
3852 clipped_surface->test_properties()->force_render_surface = true;
3853
jaydasika27d0f2e2015-10-16 23:52:463854 clip_parent->SetMasksToBounds(true);
3855
3856 ExecuteCalculateDrawProperties(root);
3857 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3858 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3859 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3860}
3861
3862TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3863 // Tests visible rects computation when we have unclipped_surface->
3864 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3865 // of root propagate to the clipped_surface.
jaydasikabf1875a2016-06-28 03:39:593866 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463867 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3868 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3869 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3870 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3871 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3872
danakje4fa7b72016-07-25 22:00:063873 root->SetBounds(gfx::Size(10, 10));
jaydasika27d0f2e2015-10-16 23:52:463874
danakje4fa7b72016-07-25 22:00:063875 unclipped_surface->SetBounds(gfx::Size(50, 50));
3876 unclipped_surface->SetDrawsContent(true);
3877 unclipped_surface->test_properties()->force_render_surface = true;
3878
3879 clip_parent->SetBounds(gfx::Size(50, 50));
3880 clip_parent->test_properties()->clip_children =
3881 base::MakeUnique<std::set<LayerImpl*>>();
3882 clip_parent->test_properties()->clip_children->insert(clip_child);
3883
3884 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
3885 unclipped_desc_surface->SetDrawsContent(true);
3886 unclipped_desc_surface->test_properties()->force_render_surface = true;
3887
3888 clip_child->SetBounds(gfx::Size(100, 100));
3889 clip_child->test_properties()->clip_parent = clip_parent;
3890
3891 clipped_surface->SetBounds(gfx::Size(50, 50));
3892 clipped_surface->SetDrawsContent(true);
3893 clipped_surface->test_properties()->force_render_surface = true;
3894
jaydasika27d0f2e2015-10-16 23:52:463895 clip_parent->SetMasksToBounds(true);
3896 unclipped_desc_surface->SetMasksToBounds(true);
3897
3898 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:183899 EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593900 EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463901 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3902}
3903
3904TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233905 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323906 // Layers that have non-axis aligned bounds (due to transforms) have an
3907 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593908 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173909 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3910 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283911
[email protected]fb661802013-03-25 01:59:323912 gfx::Transform child_rotation;
3913 child_rotation.Rotate(45.0);
[email protected]fb661802013-03-25 01:59:323914
danakje4fa7b72016-07-25 22:00:063915 root->SetBounds(gfx::Size(100, 100));
3916 render_surface->SetBounds(gfx::Size(3, 4));
3917 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:043918 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:063919 child1->SetPosition(gfx::PointF(25.f, 25.f));
3920 child1->SetBounds(gfx::Size(50, 50));
3921 child1->SetDrawsContent(true);
3922 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173923 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323924
weiliangc0dece732015-07-27 19:06:173925 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323926
danakj5e6ff6d2015-09-05 04:43:443927 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323928 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323929
3930 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433931 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173932 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323933
3934 // The unclipped surface grows its DrawableContentRect to include all drawable
3935 // regions of the subtree.
3936 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3937 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263938 gfx::Rect(50 - diagonal_radius,
3939 50 - diagonal_radius,
3940 diagonal_radius * 2,
3941 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443942 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:173943 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323944
3945 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433946 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:323947 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323948}
3949
[email protected]989386c2013-07-18 21:37:233950TEST_F(LayerTreeHostCommonTest,
3951 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323952 // Layers that have non-axis aligned bounds (due to transforms) have an
3953 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593954 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173955 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3956 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283957
[email protected]fb661802013-03-25 01:59:323958 gfx::Transform child_rotation;
3959 child_rotation.Rotate(45.0);
[email protected]a2566412014-06-05 03:14:203960
danakje4fa7b72016-07-25 22:00:063961 root->SetBounds(gfx::Size(50, 50));
[email protected]fb661802013-03-25 01:59:323962 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063963 render_surface->SetBounds(gfx::Size(3, 4));
3964 render_surface->test_properties()->force_render_surface = true;
3965 child1->SetPosition(gfx::PointF(25.f, 25.f));
3966 child1->SetBounds(gfx::Size(50, 50));
3967 child1->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:043968 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:063969 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173970 ExecuteCalculateDrawProperties(root);
3971
3972 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323973
3974 // The clipped surface clamps the DrawableContentRect that encloses the
3975 // rotated layer.
3976 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263977 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3978 50 - diagonal_radius,
3979 diagonal_radius * 2,
3980 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443981 gfx::RectF expected_surface_drawable_content(
3982 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:323983 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:173984 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323985
3986 // On the clipped surface, only a quarter of the child1 is visible, but when
3987 // rotating it back to child1's content space, the actual enclosing rect ends
3988 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:333989 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323990
3991 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323992 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323993}
3994
[email protected]989386c2013-07-18 21:37:233995TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:593996 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173997 FakePictureLayerImpl* render_surface1 =
3998 AddChildToRoot<FakePictureLayerImpl>();
weiliangc0dece732015-07-27 19:06:173999 FakePictureLayerImpl* render_surface2 =
4000 AddChild<FakePictureLayerImpl>(render_surface1);
weiliangc0dece732015-07-27 19:06:174001 FakePictureLayerImpl* child1 =
4002 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174003 FakePictureLayerImpl* child2 =
4004 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174005 FakePictureLayerImpl* child3 =
4006 AddChild<FakePictureLayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:284007
danakje4fa7b72016-07-25 22:00:064008 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324009 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064010 render_surface1->SetBounds(gfx::Size(3, 4));
4011 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
4012 render_surface1->SetDrawsContent(true);
4013 render_surface1->test_properties()->force_render_surface = true;
4014 render_surface2->SetBounds(gfx::Size(7, 13));
4015 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
4016 render_surface2->SetDrawsContent(true);
4017 render_surface2->test_properties()->force_render_surface = true;
4018 child1->SetBounds(gfx::Size(50, 50));
4019 child1->SetPosition(gfx::PointF(5.f, 5.f));
4020 child1->SetDrawsContent(true);
4021 child2->SetBounds(gfx::Size(50, 50));
4022 child2->SetPosition(gfx::PointF(75.f, 75.f));
4023 child2->SetDrawsContent(true);
4024 child3->SetBounds(gfx::Size(50, 50));
4025 child3->SetPosition(gfx::PointF(125.f, 125.f));
4026 child3->SetDrawsContent(true);
4027 float device_scale_factor = 2.f;
weiliangc0dece732015-07-27 19:06:174028 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324029
4030 ASSERT_TRUE(render_surface1->render_surface());
4031 ASSERT_TRUE(render_surface2->render_surface());
4032
4033 // drawable_content_rects for all layers and surfaces are scaled by
4034 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444035 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324036 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444037 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324038 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324039
4040 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4041 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444042 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324043 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324044
hush6b614212014-12-04 22:37:324045 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4046 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4047 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324048
4049 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434050 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324051
sohan.jyotie3bd6192014-10-13 07:13:594052 // All layer visible content rects are not expressed in content space of each
4053 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434054 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4055 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4056 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:184057 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect());
4058 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324059}
4060
[email protected]989386c2013-07-18 21:37:234061TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324062 // Verify the behavior of back-face culling when there are no preserve-3d
4063 // layers. Note that 3d transforms still apply in this case, but they are
4064 // "flattened" to each parent layer according to current W3C spec.
4065
danakje4fa7b72016-07-25 22:00:064066 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324067 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4068 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4069 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4070 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4071 LayerImpl* front_facing_child_of_front_facing_surface =
4072 AddChild<LayerImpl>(front_facing_surface);
4073 LayerImpl* back_facing_child_of_front_facing_surface =
4074 AddChild<LayerImpl>(front_facing_surface);
4075 LayerImpl* front_facing_child_of_back_facing_surface =
4076 AddChild<LayerImpl>(back_facing_surface);
4077 LayerImpl* back_facing_child_of_back_facing_surface =
4078 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284079
[email protected]fb661802013-03-25 01:59:324080 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324081 front_facing_child->test_properties()->double_sided = false;
4082 back_facing_child->test_properties()->double_sided = false;
4083 front_facing_surface->test_properties()->double_sided = false;
4084 back_facing_surface->test_properties()->double_sided = false;
4085 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4086 false;
4087 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4088 false;
4089 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4090 false;
4091 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4092 false;
4093
4094 // Everything draws content.
4095 front_facing_child->SetDrawsContent(true);
4096 back_facing_child->SetDrawsContent(true);
4097 front_facing_surface->SetDrawsContent(true);
4098 back_facing_surface->SetDrawsContent(true);
4099 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4100 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4101 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4102 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324103
4104 gfx::Transform backface_matrix;
4105 backface_matrix.Translate(50.0, 50.0);
4106 backface_matrix.RotateAboutYAxis(180.0);
4107 backface_matrix.Translate(-50.0, -50.0);
4108
danakje4fa7b72016-07-25 22:00:064109 root->SetBounds(gfx::Size(100, 100));
4110 front_facing_child->SetBounds(gfx::Size(100, 100));
4111 back_facing_child->SetBounds(gfx::Size(100, 100));
4112 front_facing_surface->SetBounds(gfx::Size(100, 100));
4113 back_facing_surface->SetBounds(gfx::Size(100, 100));
4114 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4115 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4116 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4117 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324118
danakje4fa7b72016-07-25 22:00:064119 front_facing_surface->test_properties()->force_render_surface = true;
4120 back_facing_surface->test_properties()->force_render_surface = true;
[email protected]fb661802013-03-25 01:59:324121
jaydasika10d43fc2016-08-18 04:06:044122 back_facing_child->test_properties()->transform = backface_matrix;
4123 back_facing_surface->test_properties()->transform = backface_matrix;
4124 back_facing_child_of_front_facing_surface->test_properties()->transform =
4125 backface_matrix;
4126 back_facing_child_of_back_facing_surface->test_properties()->transform =
4127 backface_matrix;
danakje4fa7b72016-07-25 22:00:064128
4129 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
4130 // spec, these layers should blindly use their own local transforms to
4131 // determine back-face culling.
jaydasika6ed869662016-09-21 14:29:594132 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324133
4134 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094135 EXPECT_FALSE(front_facing_child->has_render_surface());
4136 EXPECT_FALSE(back_facing_child->has_render_surface());
4137 EXPECT_TRUE(front_facing_surface->has_render_surface());
4138 EXPECT_TRUE(back_facing_surface->has_render_surface());
4139 EXPECT_FALSE(
4140 front_facing_child_of_front_facing_surface->has_render_surface());
4141 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4142 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4143 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324144
ajuma4711f4b12016-05-16 18:48:324145 EXPECT_EQ(4u, update_layer_list_impl()->size());
4146 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4147 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4148 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534149 front_facing_child_of_front_facing_surface->id()));
ajuma4711f4b12016-05-16 18:48:324150 EXPECT_TRUE(UpdateLayerListImplContains(
4151 front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324152}
4153
[email protected]989386c2013-07-18 21:37:234154TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324155 // Verify the behavior of back-face culling when preserves-3d transform style
4156 // is used.
4157
danakje4fa7b72016-07-25 22:00:064158 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:264159 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4160 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4161 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4162 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4163 LayerImpl* front_facing_child_of_front_facing_surface =
4164 AddChild<LayerImpl>(front_facing_surface);
4165 LayerImpl* back_facing_child_of_front_facing_surface =
4166 AddChild<LayerImpl>(front_facing_surface);
4167 LayerImpl* front_facing_child_of_back_facing_surface =
4168 AddChild<LayerImpl>(back_facing_surface);
4169 LayerImpl* back_facing_child_of_back_facing_surface =
4170 AddChild<LayerImpl>(back_facing_surface);
4171 // Opacity will not force creation of render surfaces in this case because of
4172 // the preserve-3d transform style. Instead, an example of when a surface
wangxianzhu932d7f12016-09-30 05:47:004173 // would be created with preserve-3d is when there is a mask layer.
4174 LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface);
4175 LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284176
[email protected]fb661802013-03-25 01:59:324177 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364178 front_facing_child->test_properties()->double_sided = false;
4179 back_facing_child->test_properties()->double_sided = false;
4180 front_facing_surface->test_properties()->double_sided = false;
4181 back_facing_surface->test_properties()->double_sided = false;
4182 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4183 false;
4184 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4185 false;
4186 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4187 false;
4188 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4189 false;
[email protected]fb661802013-03-25 01:59:324190
weiliangcc154ce22015-12-09 03:39:264191 // Everything draws content.
4192 front_facing_child->SetDrawsContent(true);
4193 back_facing_child->SetDrawsContent(true);
4194 front_facing_surface->SetDrawsContent(true);
4195 back_facing_surface->SetDrawsContent(true);
4196 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4197 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4198 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4199 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
wangxianzhu932d7f12016-09-30 05:47:004200 dummy_mask_layer1->SetDrawsContent(true);
4201 dummy_mask_layer2->SetDrawsContent(true);
weiliangcc154ce22015-12-09 03:39:264202
[email protected]fb661802013-03-25 01:59:324203 gfx::Transform backface_matrix;
4204 backface_matrix.Translate(50.0, 50.0);
4205 backface_matrix.RotateAboutYAxis(180.0);
4206 backface_matrix.Translate(-50.0, -50.0);
4207
danakje4fa7b72016-07-25 22:00:064208 root->SetBounds(gfx::Size(100, 100));
4209 front_facing_child->SetBounds(gfx::Size(100, 100));
4210 back_facing_child->SetBounds(gfx::Size(100, 100));
4211 front_facing_surface->SetBounds(gfx::Size(100, 100));
4212 back_facing_surface->SetBounds(gfx::Size(100, 100));
4213 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4214 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4215 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4216 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4217
jaydasika10d43fc2016-08-18 04:06:044218 back_facing_child->test_properties()->transform = backface_matrix;
4219 back_facing_surface->test_properties()->transform = backface_matrix;
4220 back_facing_child_of_front_facing_surface->test_properties()->transform =
4221 backface_matrix;
4222 back_facing_child_of_back_facing_surface->test_properties()->transform =
4223 backface_matrix;
danakje4fa7b72016-07-25 22:00:064224
[email protected]fb661802013-03-25 01:59:324225 // Each surface creates its own new 3d rendering context (as defined by W3C
4226 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4227 // rendering context should use the transform with respect to that context.
4228 // This 3d rendering context occurs when (a) parent's transform style is flat
4229 // and (b) the layer's transform style is preserve-3d.
danakje4fa7b72016-07-25 22:00:064230 front_facing_surface->test_properties()->should_flatten_transform = false;
4231 front_facing_surface->Set3dSortingContextId(1);
4232 back_facing_surface->test_properties()->should_flatten_transform = false;
4233 back_facing_surface->Set3dSortingContextId(1);
4234 front_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4235 back_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4236 front_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
4237 back_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
[email protected]fb661802013-03-25 01:59:324238
jaydasika6ed869662016-09-21 14:29:594239 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324240
awoloszyne83f28c2014-12-22 15:40:004241 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094242 EXPECT_FALSE(front_facing_child->has_render_surface());
4243 EXPECT_FALSE(back_facing_child->has_render_surface());
4244 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094245 // We expect that a has_render_surface was created but not used.
4246 EXPECT_TRUE(back_facing_surface->has_render_surface());
4247 EXPECT_FALSE(
4248 front_facing_child_of_front_facing_surface->has_render_surface());
4249 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4250 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4251 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324252
weiliangcc154ce22015-12-09 03:39:264253 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324254
weiliangcc154ce22015-12-09 03:39:264255 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4256 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4257 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534258 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324259}
4260
[email protected]989386c2013-07-18 21:37:234261TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324262 // Verify that layers are appropriately culled when their back face is showing
4263 // and they are not double sided, while animations are going on.
4264 //
ajuma4711f4b12016-05-16 18:48:324265 // Even layers that are animating get culled if their back face is showing and
4266 // they are not double sided.
danakje4fa7b72016-07-25 22:00:064267 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324268 LayerImpl* child = AddChildToRoot<LayerImpl>();
4269 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4270 LayerImpl* child_of_animating_surface =
4271 AddChild<LayerImpl>(animating_surface);
4272 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4273 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284274
[email protected]fb661802013-03-25 01:59:324275 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324276 child->test_properties()->double_sided = false;
4277 child2->test_properties()->double_sided = false;
4278 animating_surface->test_properties()->double_sided = false;
4279 child_of_animating_surface->test_properties()->double_sided = false;
4280 animating_child->test_properties()->double_sided = false;
4281
4282 // Everything draws content.
4283 child->SetDrawsContent(true);
4284 child2->SetDrawsContent(true);
4285 animating_surface->SetDrawsContent(true);
4286 child_of_animating_surface->SetDrawsContent(true);
4287 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324288
4289 gfx::Transform backface_matrix;
4290 backface_matrix.Translate(50.0, 50.0);
4291 backface_matrix.RotateAboutYAxis(180.0);
4292 backface_matrix.Translate(-50.0, -50.0);
4293
vollickef2ae922016-06-29 17:54:274294 SetElementIdsForTesting();
4295
loyso9556c732016-03-11 07:54:584296 // Animate the transform on the render surface.
vollickef2ae922016-06-29 17:54:274297 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
4298 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584299 // This is just an animating layer, not a surface.
vollickef2ae922016-06-29 17:54:274300 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
4301 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324302
danakje4fa7b72016-07-25 22:00:064303 root->SetBounds(gfx::Size(100, 100));
4304 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044305 child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064306 animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044307 animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064308 animating_surface->test_properties()->force_render_surface = true;
4309 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044310 child_of_animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064311 animating_child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044312 animating_child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064313 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324314
jaydasika6ed869662016-09-21 14:29:594315 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324316
ennec1332992015-08-24 19:45:094317 EXPECT_FALSE(child->has_render_surface());
4318 EXPECT_TRUE(animating_surface->has_render_surface());
4319 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4320 EXPECT_FALSE(animating_child->has_render_surface());
4321 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324322
ajuma4711f4b12016-05-16 18:48:324323 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534324
ajuma4711f4b12016-05-16 18:48:324325 // The back facing layers are culled from the layer list, and have an empty
4326 // visible rect.
4327 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4328 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4329 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4330 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4331 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324332
ajuma4711f4b12016-05-16 18:48:324333 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324334}
4335
[email protected]989386c2013-07-18 21:37:234336TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324337 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4338 // Verify the behavior of back-face culling for a render surface that is
4339 // created when it flattens its subtree, and its parent has preserves-3d.
4340
danakje4fa7b72016-07-25 22:00:064341 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324342 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4343 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4344 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4345 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284346
[email protected]fb661802013-03-25 01:59:324347 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324348 front_facing_surface->test_properties()->double_sided = false;
4349 back_facing_surface->test_properties()->double_sided = false;
4350
4351 // Everything draws content.
4352 front_facing_surface->SetDrawsContent(true);
4353 back_facing_surface->SetDrawsContent(true);
4354 child1->SetDrawsContent(true);
4355 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324356
4357 gfx::Transform backface_matrix;
4358 backface_matrix.Translate(50.0, 50.0);
4359 backface_matrix.RotateAboutYAxis(180.0);
4360 backface_matrix.Translate(-50.0, -50.0);
4361
danakje4fa7b72016-07-25 22:00:064362 root->SetBounds(gfx::Size(100, 100));
4363 front_facing_surface->SetBounds(gfx::Size(100, 100));
4364 front_facing_surface->test_properties()->force_render_surface = true;
4365 back_facing_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044366 back_facing_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064367 back_facing_surface->test_properties()->force_render_surface = true;
4368 child1->SetBounds(gfx::Size(100, 100));
4369 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324370
[email protected]a9d4d4f2014-06-19 06:49:284371 front_facing_surface->Set3dSortingContextId(1);
4372 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574373
jaydasika6ed869662016-09-21 14:29:594374 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324375
awoloszyne83f28c2014-12-22 15:40:004376 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094377 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004378
4379 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094380 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094381 EXPECT_FALSE(child1->has_render_surface());
4382 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324383
ajuma4711f4b12016-05-16 18:48:324384 EXPECT_EQ(2u, update_layer_list_impl()->size());
4385 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4386 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324387}
4388
enne637715732015-07-07 02:05:264389TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324390 // Verify draw and screen space transforms of layers not in a surface.
danakje4fa7b72016-07-25 22:00:064391 LayerImpl* root = root_layer_for_testing();
4392 root->SetBounds(gfx::Size(100, 100));
4393 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144394
enne637715732015-07-07 02:05:264395 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064396 child->SetPosition(gfx::PointF(2.f, 2.f));
4397 child->SetBounds(gfx::Size(10, 10));
jaydasika8640f9f2015-11-10 01:34:364398 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144399
jaydasika8640f9f2015-11-10 01:34:364400 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064401 child2->SetPosition(gfx::PointF(2.f, 2.f));
4402 child2->SetBounds(gfx::Size(5, 5));
jaydasika8640f9f2015-11-10 01:34:364403 child2->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284404
[email protected]fb661802013-03-25 01:59:324405 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264406 gfx::Size viewport_size(100, 100);
danakje4fa7b72016-07-25 22:00:064407 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144408
danakj59931942016-07-26 22:11:294409 EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale());
4410 EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale());
4411 EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale());
[email protected]518ee582012-10-24 18:29:444412
enne637715732015-07-07 02:05:264413 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144414
danakje4fa7b72016-07-25 22:00:064415 // Verify root transforms
4416 gfx::Transform expected_root_transform;
4417 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4419 root->ScreenSpaceTransform());
4420 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4421 root->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144422
danakje4fa7b72016-07-25 22:00:064423 // Verify results of transformed root rects
4424 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
[email protected]94f206c12012-08-25 00:09:144425
danakje4fa7b72016-07-25 22:00:064426 gfx::RectF root_draw_rect =
4427 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4428 gfx::RectF root_screen_space_rect =
4429 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
[email protected]94f206c12012-08-25 00:09:144430
danakje4fa7b72016-07-25 22:00:064431 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4432 expected_root_draw_rect.Scale(device_scale_factor);
4433 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4434 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144435
jaydasika8640f9f2015-11-10 01:34:364436 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324437 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594438 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4439 expected_child_transform.Translate(child->position().x(),
4440 child->position().y());
[email protected]fb661802013-03-25 01:59:324441 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444442 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324443 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104444 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324445 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444446 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324447 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104448 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144449
jaydasika8640f9f2015-11-10 01:34:364450 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324451 // match.
danakjddaec912015-09-25 19:38:404452 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144453
[email protected]fb661802013-03-25 01:59:324454 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444455 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144456 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104457 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144458
jaydasika8640f9f2015-11-10 01:34:364459 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444460 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364461 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104462 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454463
danakjddaec912015-09-25 19:38:404464 gfx::RectF expected_child_draw_rect(child->position(),
4465 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324466 expected_child_draw_rect.Scale(device_scale_factor);
4467 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4468 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364469 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4470 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144471}
4472
enne637715732015-07-07 02:05:264473TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324474 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324475 gfx::Transform perspective_matrix;
4476 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094477
[email protected]fb661802013-03-25 01:59:324478 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054479 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094480
jaydasikabf1875a2016-06-28 03:39:594481 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064482 root->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094483
4484 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064485 page_scale->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094486
4487 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
danakje4fa7b72016-07-25 22:00:064488 parent->SetBounds(gfx::Size(100, 100));
jaydasika8640f9f2015-11-10 01:34:364489 parent->SetDrawsContent(true);
[email protected]9781afa2013-07-17 23:15:324490
enne637715732015-07-07 02:05:264491 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064492 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4493 perspective_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044494 perspective_surface->test_properties()->transform =
4495 perspective_matrix * scale_small_matrix;
enne637715732015-07-07 02:05:264496 perspective_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064497 perspective_surface->test_properties()->force_render_surface = true;
[email protected]1b30e8e2012-12-21 02:59:094498
enne637715732015-07-07 02:05:264499 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064500 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4501 scale_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044502 scale_surface->test_properties()->transform = scale_small_matrix;
enne637715732015-07-07 02:05:264503 scale_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064504 scale_surface->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:284505
[email protected]fb661802013-03-25 01:59:324506 float device_scale_factor = 2.5f;
4507 float page_scale_factor = 3.f;
sunxdc5d4fb42016-05-27 04:40:094508 root->layer_tree_impl()->SetViewportLayersFromIds(
4509 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4510 Layer::INVALID_ID);
jaydasika4340ea02016-06-06 19:44:264511 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094512 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264513 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4514 root);
[email protected]1b30e8e2012-12-21 02:59:094515
danakj59931942016-07-26 22:11:294516 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4517 parent->GetIdealContentsScale());
4518 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4519 perspective_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594520 // Ideal scale is the max 2d scale component of the combined transform up to
4521 // the nearest render target. Here this includes the layer transform as well
4522 // as the device and page scale factors.
4523 gfx::Transform transform = scale_small_matrix;
4524 transform.Scale(device_scale_factor * page_scale_factor,
4525 device_scale_factor * page_scale_factor);
4526 gfx::Vector2dF scales =
4527 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4528 float max_2d_scale = std::max(scales.x(), scales.y());
danakj59931942016-07-26 22:11:294529 EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594530
4531 // The ideal scale will draw 1:1 with its render target space along
4532 // the larger-scale axis.
4533 gfx::Vector2dF target_space_transform_scales =
4534 MathUtil::ComputeTransform2dScaleComponents(
4535 scale_surface->draw_properties().target_space_transform, 0.f);
4536 EXPECT_FLOAT_EQ(max_2d_scale,
4537 std::max(target_space_transform_scales.x(),
4538 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094539
enne637715732015-07-07 02:05:264540 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094541
[email protected]fb661802013-03-25 01:59:324542 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594543 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4544 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324545 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444546 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094547
[email protected]fb661802013-03-25 01:59:324548 // The scale for the perspective surface is not known, so it is rendered 1:1
4549 // with the screen, and then scaled during drawing.
4550 gfx::Transform expected_perspective_surface_draw_transform;
4551 expected_perspective_surface_draw_transform.Translate(
4552 device_scale_factor * page_scale_factor *
4553 perspective_surface->position().x(),
4554 device_scale_factor * page_scale_factor *
4555 perspective_surface->position().y());
4556 expected_perspective_surface_draw_transform.PreconcatTransform(
4557 perspective_matrix);
4558 expected_perspective_surface_draw_transform.PreconcatTransform(
4559 scale_small_matrix);
4560 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594561 expected_perspective_surface_layer_draw_transform.Scale(
4562 device_scale_factor * page_scale_factor,
4563 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324564 EXPECT_TRANSFORMATION_MATRIX_EQ(
4565 expected_perspective_surface_draw_transform,
4566 perspective_surface->render_surface()->draw_transform());
4567 EXPECT_TRANSFORMATION_MATRIX_EQ(
4568 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444569 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094570}
4571
enne637715732015-07-07 02:05:264572TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294573 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264574 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294575 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4576
4577 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264578 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294579 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4580
jaydasikabf1875a2016-06-28 03:39:594581 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294582 root->SetBounds(gfx::Size(100, 100));
4583
enne637715732015-07-07 02:05:264584 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064585 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044586 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364587 parent->SetDrawsContent(true);
[email protected]35a99a12013-05-09 23:52:294588
enne637715732015-07-07 02:05:264589 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064590 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4591 child_scale->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044592 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364593 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284594
[email protected]fb661802013-03-25 01:59:324595 float device_scale_factor = 2.5f;
4596 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214597
[email protected]989386c2013-07-18 21:37:234598 {
enne637715732015-07-07 02:05:264599 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4600 root);
[email protected]11ec92972012-11-10 03:06:214601
sohan.jyotie3bd6192014-10-13 07:13:594602 // The ideal scale is able to go below 1.
4603 float expected_ideal_scale =
4604 device_scale_factor * page_scale_factor * initial_parent_scale;
4605 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294606 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale());
[email protected]11ec92972012-11-10 03:06:214607
sohan.jyotie3bd6192014-10-13 07:13:594608 expected_ideal_scale = device_scale_factor * page_scale_factor *
4609 initial_parent_scale * initial_child_scale;
4610 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294611 EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale());
[email protected]989386c2013-07-18 21:37:234612 }
[email protected]11ec92972012-11-10 03:06:214613}
4614
enne637715732015-07-07 02:05:264615TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324616 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264617 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324618 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264619
[email protected]fb661802013-03-25 01:59:324620 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264621 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324622 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264623
jaydasikabf1875a2016-06-28 03:39:594624 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294625 root->SetBounds(gfx::Size(100, 100));
4626
enne637715732015-07-07 02:05:264627 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064628 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044629 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364630 parent->SetDrawsContent(true);
[email protected]6a9cff92012-11-08 11:53:264631
enne637715732015-07-07 02:05:264632 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064633 child_scale->SetBounds(gfx::Size(10, 10));
4634 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
jaydasika10d43fc2016-08-18 04:06:044635 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364636 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284637
danakje4fa7b72016-07-25 22:00:064638 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264639
danakj59931942016-07-26 22:11:294640 EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale());
danakje4fa7b72016-07-25 22:00:064641 // Animating layers compute ideal scale in the same way as when
4642 // they are static.
danakj59931942016-07-26 22:11:294643 EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale,
4644 child_scale->GetIdealContentsScale());
[email protected]6a9cff92012-11-08 11:53:264645}
4646
[email protected]989386c2013-07-18 21:37:234647TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594648 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064649 parent->SetBounds(gfx::Size(30, 30));
enneea850232015-07-27 16:43:124650 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064651 parent->Set3dSortingContextId(1);
4652 parent->test_properties()->should_flatten_transform = false;
[email protected]94f206c12012-08-25 00:09:144653
enneea850232015-07-27 16:43:124654 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064655 child->SetBounds(gfx::Size(10, 10));
4656 child->SetPosition(gfx::PointF(2.f, 2.f));
enneea850232015-07-27 16:43:124657 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064658 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:144659
[email protected]fb661802013-03-25 01:59:324660 // This layer should end up in the same surface as child, with the same draw
4661 // and screen space transforms.
enneea850232015-07-27 16:43:124662 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:064663 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
enneea850232015-07-27 16:43:124664 duplicate_child_non_owner->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144665
[email protected]fb661802013-03-25 01:59:324666 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124667 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144668
[email protected]fb661802013-03-25 01:59:324669 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004670 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124671 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144672
[email protected]fb661802013-03-25 01:59:324673 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594674 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324675 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104676 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324677 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444678 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144679
[email protected]fb661802013-03-25 01:59:324680 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594681 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324682 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444683 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144684
[email protected]fb661802013-03-25 01:59:324685 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594686 expected_screen_space_transform.Scale(device_scale_factor,
4687 device_scale_factor);
4688 expected_screen_space_transform.Translate(child->position().x(),
4689 child->position().y());
[email protected]fb661802013-03-25 01:59:324690 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104691 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144692
[email protected]fb661802013-03-25 01:59:324693 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444694 child->DrawTransform();
trchendba8b1502016-07-08 09:47:014695 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform,
ajumad9432e32015-11-30 19:43:444696 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324697 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104698 child->ScreenSpaceTransform(),
4699 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324700 EXPECT_EQ(child->drawable_content_rect(),
4701 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144702 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144703
[email protected]fb661802013-03-25 01:59:324704 gfx::Transform expected_render_surface_draw_transform;
4705 expected_render_surface_draw_transform.Translate(
4706 device_scale_factor * child->position().x(),
4707 device_scale_factor * child->position().y());
4708 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4709 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144710
[email protected]fb661802013-03-25 01:59:324711 gfx::Transform expected_surface_draw_transform;
4712 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4713 device_scale_factor * 2.f);
4714 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4715 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144716
[email protected]fb661802013-03-25 01:59:324717 gfx::Transform expected_surface_screen_space_transform;
4718 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4719 device_scale_factor * 2.f);
4720 EXPECT_TRANSFORMATION_MATRIX_EQ(
4721 expected_surface_screen_space_transform,
4722 child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474723}
4724
[email protected]989386c2013-07-18 21:37:234725TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324726 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
jaydasikabf1875a2016-06-28 03:39:594727 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064728 parent->SetBounds(gfx::Size(33, 31));
enneea850232015-07-27 16:43:124729 parent->SetDrawsContent(true);
[email protected]904e9132012-11-01 00:12:474730
enneea850232015-07-27 16:43:124731 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064732 child->SetBounds(gfx::Size(13, 11));
enneea850232015-07-27 16:43:124733 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064734 child->test_properties()->force_render_surface = true;
[email protected]904e9132012-11-01 00:12:474735
[email protected]873639e2013-07-24 19:56:314736 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124737 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474738
[email protected]fb661802013-03-25 01:59:324739 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004740 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124741 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474742
danakjf78fb272016-07-26 19:06:154743 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324744 child->render_surface()->draw_transform());
danakjf78fb272016-07-26 19:06:154745 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324746 child->render_surface()->draw_transform());
4747 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:154748 gfx::Transform(), child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144749}
4750
jaydasikadb41a582016-03-28 20:48:214751TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314752 scoped_refptr<Layer> root = Layer::Create();
4753 scoped_refptr<Layer> child = Layer::Create();
4754 scoped_refptr<Layer> grand_child = Layer::Create();
4755 scoped_refptr<Layer> mask_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:144756
[email protected]fb661802013-03-25 01:59:324757 child->AddChild(grand_child.get());
4758 child->SetMaskLayer(mask_layer.get());
4759 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144760
ennea7b43c32015-06-18 20:01:334761 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284762
[email protected]fb661802013-03-25 01:59:324763 int nonexistent_id = -1;
xingliu95d9e6b62016-08-18 03:53:084764 LayerTree* layer_tree = host()->GetLayerTree();
4765 EXPECT_EQ(root.get(), layer_tree->LayerById(root->id()));
4766 EXPECT_EQ(child.get(), layer_tree->LayerById(child->id()));
4767 EXPECT_EQ(grand_child.get(), layer_tree->LayerById(grand_child->id()));
4768 EXPECT_EQ(mask_layer.get(), layer_tree->LayerById(mask_layer->id()));
xingliu95d9e6b62016-08-18 03:53:084769 EXPECT_FALSE(layer_tree->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144770}
4771
[email protected]989386c2013-07-18 21:37:234772TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
jaydasikabf1875a2016-06-28 03:39:594773 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324774 LayerImpl* child = AddChild<LayerImpl>(root);
4775 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]498ec6e0e2012-11-30 18:24:574776
danakje4fa7b72016-07-25 22:00:064777 root->SetBounds(gfx::Size(100, 100));
4778 child->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:184779 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:064780 grand_child->SetBounds(gfx::Size(10, 10));
4781 grand_child->SetDrawsContent(true);
ajuma4711f4b12016-05-16 18:48:324782 ExecuteCalculateDrawProperties(root);
ennec1332992015-08-24 19:45:094783 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:574784}
4785
[email protected]989386c2013-07-18 21:37:234786TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164787 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:454788 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:564789 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:014790 FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider,
loyso968163c92016-01-04 23:18:484791 &shared_bitmap_manager, &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:164792 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:484793 std::unique_ptr<LayerImpl> root =
4794 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064795 root->SetBounds(gfx::Size(100, 100));
[email protected]f90fc412013-03-30 20:13:164796 root->SetDrawsContent(true);
4797
danakj60bc3bc2016-04-09 00:24:484798 std::unique_ptr<LayerImpl> child =
4799 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064800 child->SetBounds(gfx::Size(50, 50));
[email protected]f90fc412013-03-30 20:13:164801 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:184802 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:164803
jaydasika9cb21c772016-05-10 22:37:084804 const int child_id = child->id();
jaydasika89f7b5a2016-06-22 02:08:394805 root->test_properties()->AddChild(std::move(child));
jaydasika9cb21c772016-05-10 22:37:084806 root->SetHasRenderSurface(true);
4807 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594808 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
jaydasika4340ea02016-06-06 19:44:264809 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:274810
[email protected]f90fc412013-03-30 20:13:164811 // Add opacity animation.
loyso9556c732016-03-11 07:54:584812 scoped_refptr<AnimationTimeline> timeline =
4813 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4814 host_impl.animation_host()->AddAnimationTimeline(timeline);
vollickef2ae922016-06-29 17:54:274815 host_impl.pending_tree()->SetElementIdsForTesting();
loyso968163c92016-01-04 23:18:484816
vollickef2ae922016-06-29 17:54:274817 ElementId child_element_id =
4818 host_impl.pending_tree()->LayerById(child_id)->element_id();
4819
4820 AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0,
4821 0.0f, 1.0f, false);
[email protected]f90fc412013-03-30 20:13:164822
[email protected]c0ae06c12013-06-24 18:32:194823 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534824 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:384825 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534826 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574827 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:164828
4829 // We should have one render surface and two layers. The child
4830 // layer should be included even though it is transparent.
4831 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:054832 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:074833
4834 // If the root itself is hidden, the child should not be drawn even if it has
4835 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:184836 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054837 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:074838 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:074839 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:384840 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:074841 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574842 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:074843
jaydasika0c2fd472016-03-24 01:26:054844 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:064845 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:054846 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:074847 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014848 EXPECT_FALSE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404849
4850 // A layer should be drawn and it should contribute to drawn surface when
4851 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:184852 root_layer->test_properties()->opacity = 1.0f;
4853 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054854 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:404855 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:404856 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:384857 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:404858 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574859 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:404860
jaydasika0c2fd472016-03-24 01:26:054861 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
4862 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:404863 node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014864 EXPECT_TRUE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404865 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:064866
4867 // But if the opacity of the layer remains 0 after activation, it should not
4868 // be drawn.
4869 host_impl.ActivateSyncTree();
danakj0da42ca62016-07-01 19:42:334870 LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id());
jaydasika8185d302016-04-14 15:20:064871 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
4872
4873 EffectTree& active_effect_tree =
4874 host_impl.active_tree()->property_trees()->effect_tree;
4875 EXPECT_TRUE(active_effect_tree.needs_update());
4876
4877 ExecuteCalculateDrawProperties(active_root);
4878
4879 node = active_effect_tree.Node(active_child->effect_tree_index());
trchendba8b1502016-07-08 09:47:014880 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:064881 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
4882 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:164883}
4884
danakj3f76ace2014-11-18 16:56:004885using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:264886class LCDTextTest : public LayerTreeHostCommonTestBase,
4887 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:364888 public:
4889 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:224890 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
4891 host_impl_(LCDTextTestLayerTreeSettings(),
4892 &task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:164893 &shared_bitmap_manager_,
danakj59931942016-07-26 22:11:294894 &task_graph_runner_) {}
enneaf5bda32015-02-19 01:27:364895
loyso968163c92016-01-04 23:18:484896 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
4897
[email protected]fb661802013-03-25 01:59:324898 protected:
sunxd5a7a4032016-06-01 18:49:224899 LayerTreeSettings LCDTextTestLayerTreeSettings() {
danakj59931942016-07-26 22:11:294900 LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings();
sunxd5a7a4032016-06-01 18:49:224901
4902 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4903 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4904 settings.can_use_lcd_text = can_use_lcd_text_;
4905 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
4906 return settings;
4907 }
4908
dcheng93a52eb2014-12-23 02:14:234909 void SetUp() override {
loyso9556c732016-03-11 07:54:584910 timeline_ =
4911 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4912 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:484913
danakj60bc3bc2016-04-09 00:24:484914 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:364915 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:484916 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:364917 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:484918 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:364919 LayerImpl::Create(host_impl_.active_tree(), 3);
4920
4921 // Stash raw pointers to look at later.
4922 root_ = root_ptr.get();
4923 child_ = child_ptr.get();
4924 grand_child_ = grand_child_ptr.get();
4925
jaydasika89f7b5a2016-06-22 02:08:394926 child_->test_properties()->AddChild(std::move(grand_child_ptr));
4927 root_->test_properties()->AddChild(std::move(child_ptr));
jaydasikabf1875a2016-06-28 03:39:594928 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:594929
vollickef2ae922016-06-29 17:54:274930 host_impl_.active_tree()->SetElementIdsForTesting();
4931
fmalita51b5e202014-11-18 20:11:504932 root_->SetContentsOpaque(true);
4933 child_->SetContentsOpaque(true);
4934 grand_child_->SetContentsOpaque(true);
4935
jaydasika3f930c12015-06-30 15:18:254936 root_->SetDrawsContent(true);
4937 child_->SetDrawsContent(true);
4938 grand_child_->SetDrawsContent(true);
4939
danakje4fa7b72016-07-25 22:00:064940 root_->SetBounds(gfx::Size(1, 1));
4941 child_->SetBounds(gfx::Size(1, 1));
4942 grand_child_->SetBounds(gfx::Size(1, 1));
4943
4944 child_->test_properties()->force_render_surface =
4945 std::tr1::get<2>(GetParam());
[email protected]fb661802013-03-25 01:59:324946 }
[email protected]10aabcc32012-12-13 09:18:594947
[email protected]fb661802013-03-25 01:59:324948 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:004949 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:364950
khushalsagarb64b360d2015-10-21 19:25:164951 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:364952 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:474953 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:364954 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:484955 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:364956
danakj59931942016-07-26 22:11:294957 LayerImpl* root_ = nullptr;
4958 LayerImpl* child_ = nullptr;
4959 LayerImpl* grand_child_ = nullptr;
[email protected]10aabcc32012-12-13 09:18:594960};
4961
[email protected]fb661802013-03-25 01:59:324962TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:004963 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4964 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4965
[email protected]fb661802013-03-25 01:59:324966 // Case 1: Identity transform.
danakj59931942016-07-26 22:11:294967 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:224968 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4969 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4970 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594971
[email protected]fb661802013-03-25 01:59:324972 // Case 2: Integral translation.
4973 gfx::Transform integral_translation;
4974 integral_translation.Translate(1.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:044975 child_->test_properties()->transform = integral_translation;
jaydasika3f930c12015-06-30 15:18:254976 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:294977 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:224978 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4979 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
4980 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594981
[email protected]fb661802013-03-25 01:59:324982 // Case 3: Non-integral translation.
4983 gfx::Transform non_integral_translation;
4984 non_integral_translation.Translate(1.5, 2.5);
jaydasika10d43fc2016-08-18 04:06:044985 child_->test_properties()->transform = non_integral_translation;
jaydasika3f930c12015-06-30 15:18:254986 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:294987 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:224988 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4989 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
4990 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:594991
[email protected]fb661802013-03-25 01:59:324992 // Case 4: Rotation.
4993 gfx::Transform rotation;
4994 rotation.Rotate(10.0);
jaydasika10d43fc2016-08-18 04:06:044995 child_->test_properties()->transform = rotation;
jaydasika3f930c12015-06-30 15:18:254996 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:294997 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:224998 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
4999 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5000 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595001
[email protected]fb661802013-03-25 01:59:325002 // Case 5: Scale.
5003 gfx::Transform scale;
5004 scale.Scale(2.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045005 child_->test_properties()->transform = scale;
jaydasika3f930c12015-06-30 15:18:255006 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295007 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225008 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5009 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5010 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595011
[email protected]fb661802013-03-25 01:59:325012 // Case 6: Skew.
5013 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105014 skew.Skew(10.0, 0.0);
jaydasika10d43fc2016-08-18 04:06:045015 child_->test_properties()->transform = skew;
jaydasika3f930c12015-06-30 15:18:255016 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295017 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225018 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5019 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5020 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595021
[email protected]fb661802013-03-25 01:59:325022 // Case 7: Translucent.
jaydasika10d43fc2016-08-18 04:06:045023 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255024 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185025 child_->test_properties()->opacity = 0.5f;
danakj59931942016-07-26 22:11:295026 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225027 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5028 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5029 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595030
[email protected]fb661802013-03-25 01:59:325031 // Case 8: Sanity check: restore transform and opacity.
jaydasika10d43fc2016-08-18 04:06:045032 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255033 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185034 child_->test_properties()->opacity = 1.f;
danakj59931942016-07-26 22:11:295035 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225036 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5037 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5038 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505039
5040 // Case 9: Non-opaque content.
5041 child_->SetContentsOpaque(false);
danakj59931942016-07-26 22:11:295042 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225043 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5044 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5045 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505046
5047 // Case 10: Sanity check: restore content opaqueness.
5048 child_->SetContentsOpaque(true);
danakj59931942016-07-26 22:11:295049 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225050 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5051 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5052 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595053}
5054
[email protected]fd9a3b6d2013-08-03 00:46:175055TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005056 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335057 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005058
[email protected]fb661802013-03-25 01:59:325059 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
danakj59931942016-07-26 22:11:295060 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225061 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5062 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5063 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595064
[email protected]fb661802013-03-25 01:59:325065 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:185066 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:255067 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
vollickef2ae922016-06-29 17:54:275068
5069 SetElementIdsForTesting();
5070
5071 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5072 10.0, 0.9f, 0.1f, false);
danakj59931942016-07-26 22:11:295073 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
fmalitafcd926a2015-05-13 20:19:335074 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:225075 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5076 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5077 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335078}
5079
5080TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5081 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5082 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5083
5084 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
danakj59931942016-07-26 22:11:295085 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225086 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5087 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5088 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
vollickef2ae922016-06-29 17:54:275089 SetElementIdsForTesting();
fmalitafcd926a2015-05-13 20:19:335090
5091 // Mark contents non-opaque within the first animation frame.
5092 child_->SetContentsOpaque(false);
vollickef2ae922016-06-29 17:54:275093 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5094 10.0, 0.9f, 0.1f, false);
danakj59931942016-07-26 22:11:295095 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
fmalitafcd926a2015-05-13 20:19:335096 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:225097 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5098 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5099 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595100}
5101
5102INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5103 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005104 testing::Combine(testing::Bool(),
5105 testing::Bool(),
5106 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595107
[email protected]989386c2013-07-18 21:37:235108TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165109 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455110 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565111 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165112 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565113 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195114 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195115
danakj60bc3bc2016-04-09 00:24:485116 std::unique_ptr<LayerImpl> root =
5117 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065118 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195119 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065120 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195121
danakj60bc3bc2016-04-09 00:24:485122 std::unique_ptr<LayerImpl> child =
5123 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065124 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195125 child->SetDrawsContent(true);
5126
danakj60bc3bc2016-04-09 00:24:485127 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195128 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065129 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195130 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355131 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195132
jaydasika89f7b5a2016-06-22 02:08:395133 child->test_properties()->AddChild(std::move(grand_child));
5134 root->test_properties()->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005135 root->SetHasRenderSurface(true);
jaydasikabf1875a2016-06-28 03:39:595136 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195137
5138 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535139 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385140 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535141 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575142 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195143
5144 // We should have one render surface and two layers. The grand child has
5145 // hidden itself.
5146 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055147 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5148 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5149 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195150}
5151
[email protected]989386c2013-07-18 21:37:235152TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165153 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455154 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565155 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165156 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565157 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195158 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195159
danakj60bc3bc2016-04-09 00:24:485160 std::unique_ptr<LayerImpl> root =
5161 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065162 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195163 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095164 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195165
danakj60bc3bc2016-04-09 00:24:485166 std::unique_ptr<LayerImpl> child =
5167 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065168 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195169 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355170 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195171
danakj60bc3bc2016-04-09 00:24:485172 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195173 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065174 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195175 grand_child->SetDrawsContent(true);
5176
jaydasika89f7b5a2016-06-22 02:08:395177 child->test_properties()->AddChild(std::move(grand_child));
5178 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:595179 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195180
5181 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535182 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385183 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535184 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575185 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195186
5187 // We should have one render surface and one layers. The child has
5188 // hidden itself and the grand child.
5189 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095190 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5191 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195192}
5193
danakj60bc3bc2016-04-09 00:24:485194void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455195
[email protected]989386c2013-07-18 21:37:235196TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165197 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455198 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565199 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165200 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565201 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455202 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455203
danakj60bc3bc2016-04-09 00:24:485204 std::unique_ptr<LayerImpl> root =
5205 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065206 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305207 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095208 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455209
danakj60bc3bc2016-04-09 00:24:485210 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305211 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065212 copy_grand_parent->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305213 copy_grand_parent->SetDrawsContent(true);
5214 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455215
danakj60bc3bc2016-04-09 00:24:485216 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305217 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065218 copy_parent->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305219 copy_parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065220 copy_parent->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305221 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455222
danakj60bc3bc2016-04-09 00:24:485223 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305224 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065225 copy_request->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305226 copy_request->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065227 copy_request->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305228 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455229
danakj60bc3bc2016-04-09 00:24:485230 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305231 LayerImpl::Create(host_impl.pending_tree(), 5);
danakje4fa7b72016-07-25 22:00:065232 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305233 copy_child->SetDrawsContent(true);
5234 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455235
danakj60bc3bc2016-04-09 00:24:485236 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405237 LayerImpl::Create(host_impl.pending_tree(), 6);
danakje4fa7b72016-07-25 22:00:065238 copy_grand_child->SetBounds(gfx::Size(20, 20));
5239 copy_grand_child->SetDrawsContent(true);
jaydasika86654512016-01-27 17:05:075240 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5241
danakj60bc3bc2016-04-09 00:24:485242 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075243 LayerImpl::Create(host_impl.pending_tree(), 7);
danakje4fa7b72016-07-25 22:00:065244 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305245 copy_grand_parent_sibling_before->SetDrawsContent(true);
5246 LayerImpl* copy_grand_parent_sibling_before_layer =
5247 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535248
danakj60bc3bc2016-04-09 00:24:485249 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075250 LayerImpl::Create(host_impl.pending_tree(), 8);
danakje4fa7b72016-07-25 22:00:065251 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305252 copy_grand_parent_sibling_after->SetDrawsContent(true);
5253 LayerImpl* copy_grand_parent_sibling_after_layer =
5254 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535255
jaydasika89f7b5a2016-06-22 02:08:395256 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
5257 copy_request->test_properties()->AddChild(std::move(copy_child));
5258 copy_parent->test_properties()->AddChild(std::move(copy_request));
5259 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
5260 root->test_properties()->AddChild(
5261 std::move(copy_grand_parent_sibling_before));
5262 root->test_properties()->AddChild(std::move(copy_grand_parent));
5263 root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasikabf1875a2016-06-28 03:39:595264 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285265
[email protected]30fe19ff2013-07-04 00:54:455266 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075267 // hidden subtree on copy_layer. Also hide the copy grand child and its
5268 // subtree.
jaydasika5121caa82016-05-05 15:43:355269 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5270 copy_grand_parent_sibling_before_layer->test_properties()
5271 ->hide_layer_and_subtree = true;
5272 copy_grand_parent_sibling_after_layer->test_properties()
5273 ->hide_layer_and_subtree = true;
5274 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305275
ajumae6f541b2016-05-31 16:50:505276 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305277 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455278
weiliangc51fb255d2015-07-24 15:32:305279 LayerImplList render_surface_layer_list;
5280 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385281 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535282 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575283 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455284
jaydasika2411692c2016-03-23 01:56:095285 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025286 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5287 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5288 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535289
jaydasika86654512016-01-27 17:05:075290 // We should have four render surfaces, one for the root, one for the grand
5291 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455292 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075293 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095294 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075295 EXPECT_EQ(copy_grand_parent_layer->id(),
5296 render_surface_layer_list.at(1)->id());
5297 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5298 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455299
jaydasika86654512016-01-27 17:05:075300 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095301 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5302 EXPECT_EQ(root_layer->id(),
5303 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075304 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095305 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455306
[email protected]7392c7b2014-02-07 08:28:285307 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455308 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305309 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455310 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065311 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455312
5313 // The copy_layer's render surface should have two contributing layers.
5314 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5315 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235316 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305317 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235318 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075319
5320 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5321 // but the copy_layer and copy_child should be drawn for the copy request.
5322 // copy grand child should not be drawn as its hidden even in the copy
5323 // request.
ajumae4af47062016-05-24 23:59:045324 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095325 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075326 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015327 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075328 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015329 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075330 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015331 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075332 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015333 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075334 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015335 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075336
5337 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5338 // actually hidden.
5339 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455340}
5341
[email protected]989386c2013-07-18 21:37:235342TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165343 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455344 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565345 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165346 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565347 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455348 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455349
danakj60bc3bc2016-04-09 00:24:485350 std::unique_ptr<LayerImpl> root =
5351 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065352 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305353 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455354
danakj60bc3bc2016-04-09 00:24:485355 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305356 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:305357 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455358 copy_parent->SetMasksToBounds(true);
5359
danakj60bc3bc2016-04-09 00:24:485360 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305361 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065362 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305363 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065364 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:455365
danakj60bc3bc2016-04-09 00:24:485366 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305367 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065368 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305369 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455370
ajumae6f541b2016-05-31 16:50:505371 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305372 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455373
jaydasika89f7b5a2016-06-22 02:08:395374 copy_layer->test_properties()->AddChild(std::move(copy_child));
5375 copy_parent->test_properties()->AddChild(std::move(copy_layer));
5376 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305377
5378 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055379 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595380 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305381 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385382 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535383 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575384 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455385
xjze19f76402015-11-06 21:48:445386 // We should have two render surface, as the others are clipped out.
5387 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055388 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455389
xjze19f76402015-11-06 21:48:445390 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455391 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055392 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5393 EXPECT_EQ(root_layer->id(),
5394 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455395}
5396
weiliangcde7e0c32016-06-15 15:02:415397TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595398 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065399 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415400 root->SetDrawsContent(true);
5401 root->SetMasksToBounds(true);
5402
5403 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065404 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415405 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065406 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415407
5408 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065409 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5410 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415411 copy_child->SetDrawsContent(true);
5412
5413 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065414 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415415 copy_clip->SetMasksToBounds(true);
5416
5417 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065418 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5419 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415420 copy_clipped_child->SetDrawsContent(true);
5421
5422 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065423 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5424 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415425 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065426 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415427
5428 copy_layer->test_properties()->copy_requests.push_back(
5429 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5430
weiliangce22ce842016-07-04 23:31:535431 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415432 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535433 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415434
5435 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5436 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5437 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5438 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5439
5440 // Case 2: When the non root copy request layer is clipped.
5441 copy_layer->SetBounds(gfx::Size(50, 50));
5442 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535443 copy_layer->test_properties()->copy_requests.push_back(
5444 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415445 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5446
weiliangce22ce842016-07-04 23:31:535447 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415448 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535449 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415450
5451 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5452 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5453 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5454 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515455
5456 // Case 3: When there is device scale factor.
5457 float device_scale_factor = 2.f;
5458 copy_layer->test_properties()->copy_requests.push_back(
5459 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5460
5461 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5462 ExecuteCalculateDrawProperties(root, device_scale_factor);
5463 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5464
5465 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5466 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5467 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5468 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415469}
5470
[email protected]420fdf6e2013-08-26 20:36:385471TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5472 // Ensure that a transform between the layer and its render surface is not a
5473 // problem. Constructs the following layer tree.
5474 //
5475 // root (a render surface)
5476 // + render_surface
5477 // + clip_parent (scaled)
5478 // + intervening_clipping_layer
5479 // + clip_child
5480 //
5481 // The render surface should be resized correctly and the clip child should
5482 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595483 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315484 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5485 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285486 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315487 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285488 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315489 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5490 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565491 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485492 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315493 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565494 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385495
5496 intervening->SetMasksToBounds(true);
5497 clip_parent->SetMasksToBounds(true);
5498
[email protected]420fdf6e2013-08-26 20:36:385499 gfx::Transform scale_transform;
5500 scale_transform.Scale(2, 2);
5501
danakjf78fb272016-07-26 19:06:155502 root->SetBounds(gfx::Size(50, 50));
5503 render_surface->SetBounds(gfx::Size(10, 10));
5504 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:045505 clip_parent->test_properties()->transform = scale_transform;
danakjf78fb272016-07-26 19:06:155506 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5507 clip_parent->SetBounds(gfx::Size(10, 10));
5508 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5509 intervening->SetBounds(gfx::Size(5, 5));
5510 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5511 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315512 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385513
5514 ASSERT_TRUE(root->render_surface());
5515 ASSERT_TRUE(render_surface->render_surface());
5516
5517 // Ensure that we've inherited our clip parent's clip and weren't affected
5518 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145519 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5520 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5521 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385522
5523 // Ensure that the render surface reports a content rect that has been grown
5524 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145525 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5526 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385527
5528 // The above check implies the two below, but they nicely demonstrate that
5529 // we've grown, despite the intervening layer's clip.
5530 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5531 render_surface->render_surface()->content_rect()));
5532 ASSERT_FALSE(intervening->clip_rect().Contains(
5533 render_surface->render_surface()->content_rect()));
5534}
5535
5536TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5537 // Ensure that intervening render surfaces are not a problem in the basic
5538 // case. In the following tree, both render surfaces should be resized to
5539 // accomodate for the clip child, despite an intervening clip.
5540 //
5541 // root (a render surface)
5542 // + clip_parent (masks to bounds)
5543 // + render_surface1 (sets opacity)
5544 // + intervening (masks to bounds)
5545 // + render_surface2 (also sets opacity)
5546 // + clip_child
5547 //
jaydasikabf1875a2016-06-28 03:39:595548 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235549 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5550 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5551 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5552 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5553 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365554 render_surface1->SetDrawsContent(true);
5555 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235556 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385557
jaydasika1c0a27d42016-04-28 01:54:565558 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385559
5560 intervening->SetMasksToBounds(true);
5561 clip_parent->SetMasksToBounds(true);
5562
[email protected]420fdf6e2013-08-26 20:36:385563 gfx::Transform translation_transform;
5564 translation_transform.Translate(2, 2);
5565
danakjf78fb272016-07-26 19:06:155566 root->SetBounds(gfx::Size(50, 50));
5567 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5568 clip_parent->SetBounds(gfx::Size(40, 40));
5569 render_surface1->SetBounds(gfx::Size(10, 10));
5570 render_surface1->test_properties()->force_render_surface = true;
5571 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5572 intervening->SetBounds(gfx::Size(5, 5));
5573 render_surface2->SetBounds(gfx::Size(10, 10));
5574 render_surface2->test_properties()->force_render_surface = true;
5575 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5576 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235577 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385578
5579 EXPECT_TRUE(root->render_surface());
5580 EXPECT_TRUE(render_surface1->render_surface());
5581 EXPECT_TRUE(render_surface2->render_surface());
5582
5583 // Since the render surfaces could have expanded, they should not clip (their
5584 // bounds would no longer be reliable). We should resort to layer clipping
5585 // in this case.
jaydasika6f972de2016-04-07 16:16:145586 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5587 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385588 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145589 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5590 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385591 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5592
5593 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145594 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385595 EXPECT_TRUE(render_surface1->is_clipped());
5596
5597 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145598 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385599 EXPECT_TRUE(render_surface2->is_clipped());
5600
5601 // The content rects of both render surfaces should both have expanded to
5602 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145603 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5604 render_surface1->render_surface()->content_rect());
5605 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5606 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385607
5608 // The clip child should have inherited the clip parent's clip (projected to
5609 // the right space, of course), and should have the correctly sized visible
5610 // content rect.
jaydasika6f972de2016-04-07 16:16:145611 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5612 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385613 EXPECT_TRUE(clip_child->is_clipped());
5614}
5615
5616TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5617 // Ensure that intervening render surfaces are not a problem, even if there
5618 // is a scroll involved. Note, we do _not_ have to consider any other sort
5619 // of transform.
5620 //
5621 // root (a render surface)
5622 // + clip_parent (masks to bounds)
5623 // + render_surface1 (sets opacity)
5624 // + intervening (masks to bounds AND scrolls)
5625 // + render_surface2 (also sets opacity)
5626 // + clip_child
5627 //
jaydasikabf1875a2016-06-28 03:39:595628 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235629 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5630 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5631 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5632 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5633 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365634 render_surface1->SetDrawsContent(true);
5635 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235636 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385637
jaydasika1c0a27d42016-04-28 01:54:565638 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385639
5640 intervening->SetMasksToBounds(true);
5641 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235642 intervening->SetScrollClipLayer(clip_parent->id());
5643 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385644
5645 gfx::Transform translation_transform;
5646 translation_transform.Translate(2, 2);
5647
danakjf78fb272016-07-26 19:06:155648 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:045649 clip_parent->test_properties()->transform = translation_transform;
danakjf78fb272016-07-26 19:06:155650 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5651 clip_parent->SetBounds(gfx::Size(40, 40));
5652 render_surface1->SetBounds(gfx::Size(10, 10));
5653 render_surface1->test_properties()->force_render_surface = true;
5654 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5655 intervening->SetBounds(gfx::Size(5, 5));
5656 render_surface2->SetBounds(gfx::Size(10, 10));
5657 render_surface2->test_properties()->force_render_surface = true;
5658 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5659 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235660 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385661
5662 EXPECT_TRUE(root->render_surface());
5663 EXPECT_TRUE(render_surface1->render_surface());
5664 EXPECT_TRUE(render_surface2->render_surface());
5665
5666 // Since the render surfaces could have expanded, they should not clip (their
5667 // bounds would no longer be reliable). We should resort to layer clipping
5668 // in this case.
jaydasika6f972de2016-04-07 16:16:145669 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5670 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385671 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145672 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5673 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385674 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5675
5676 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145677 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385678 EXPECT_TRUE(render_surface1->is_clipped());
5679
5680 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145681 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385682 EXPECT_TRUE(render_surface2->is_clipped());
5683
5684 // The content rects of both render surfaces should both have expanded to
5685 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145686 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5687 render_surface1->render_surface()->content_rect());
5688 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
5689 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385690
5691 // The clip child should have inherited the clip parent's clip (projected to
5692 // the right space, of course), and should have the correctly sized visible
5693 // content rect.
jaydasika6f972de2016-04-07 16:16:145694 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
5695 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385696 EXPECT_TRUE(clip_child->is_clipped());
5697}
5698
5699TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5700 // Ensures that descendants of the clip child inherit the correct clip.
5701 //
5702 // root (a render surface)
5703 // + clip_parent (masks to bounds)
5704 // + intervening (masks to bounds)
5705 // + clip_child
5706 // + child
5707 //
jaydasikabf1875a2016-06-28 03:39:595708 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175709 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5710 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5711 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5712 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365713 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175714 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385715
jaydasika1c0a27d42016-04-28 01:54:565716 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155717 clip_parent->test_properties()->clip_children =
5718 base::MakeUnique<std::set<LayerImpl*>>();
5719 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385720
danakjf78fb272016-07-26 19:06:155721 root->SetBounds(gfx::Size(50, 50));
5722 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385723 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155724 intervening->SetBounds(gfx::Size(5, 5));
5725 intervening->SetMasksToBounds(true);
5726 clip_child->SetBounds(gfx::Size(60, 60));
5727 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385728
enne2d0d8e62015-08-18 18:29:175729 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385730
5731 EXPECT_TRUE(root->render_surface());
5732
5733 // Neither the clip child nor its descendant should have inherited the clip
5734 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145735 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385736 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145737 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385738 EXPECT_TRUE(child->is_clipped());
5739}
5740
5741TEST_F(LayerTreeHostCommonTest,
5742 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5743 // Ensures that non-descendant clip children in the tree do not affect
5744 // render surfaces.
5745 //
5746 // root (a render surface)
5747 // + clip_parent (masks to bounds)
5748 // + render_surface1
5749 // + clip_child
5750 // + render_surface2
5751 // + non_clip_child
5752 //
5753 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595754 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505755 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5756 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5757 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
enneb441cdd2015-07-28 22:47:505758 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
5759 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385760
jaydasika1c0a27d42016-04-28 01:54:565761 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155762 clip_parent->test_properties()->clip_children =
5763 base::MakeUnique<std::set<LayerImpl*>>();
5764 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385765
5766 clip_parent->SetMasksToBounds(true);
5767 render_surface1->SetMasksToBounds(true);
5768
danakjf78fb272016-07-26 19:06:155769 render_surface1->SetDrawsContent(true);
5770 clip_child->SetDrawsContent(true);
5771 render_surface2->SetDrawsContent(true);
5772 non_clip_child->SetDrawsContent(true);
5773
5774 root->SetBounds(gfx::Size(15, 15));
5775 clip_parent->SetBounds(gfx::Size(10, 10));
5776 render_surface1->SetPosition(gfx::PointF(5, 5));
5777 render_surface1->SetBounds(gfx::Size(5, 5));
5778 render_surface1->test_properties()->force_render_surface = true;
5779 render_surface2->SetBounds(gfx::Size(5, 5));
5780 render_surface2->test_properties()->force_render_surface = true;
5781 clip_child->SetPosition(gfx::PointF(-1, 1));
5782 clip_child->SetBounds(gfx::Size(10, 10));
5783 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:385784
enneb441cdd2015-07-28 22:47:505785 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385786
5787 EXPECT_TRUE(root->render_surface());
5788 EXPECT_TRUE(render_surface1->render_surface());
5789 EXPECT_TRUE(render_surface2->render_surface());
5790
jaydasika6f972de2016-04-07 16:16:145791 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385792 EXPECT_TRUE(render_surface1->is_clipped());
5793
5794 // The render surface should not clip (it has unclipped descendants), instead
5795 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:145796 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5797 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385798 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5799
jaydasika0d98ba92015-11-17 05:17:285800 // That said, it should have grown to accomodate the unclipped descendant and
5801 // its own size.
jaydasika6f972de2016-04-07 16:16:145802 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
5803 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385804
5805 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:145806 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
5807 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385808 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:425809 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385810
5811 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:145812 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
5813 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385814
5815 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:215816 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
5817 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:385818}
5819
weiliangc9ced1592015-11-17 19:04:375820TEST_F(LayerTreeHostCommonTest,
5821 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5822 // Verifies that Render Surfaces are created at the edge of rendering context.
5823
jaydasikabf1875a2016-06-28 03:39:595824 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:265825 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
5826 LayerImpl* child2 = AddChild<LayerImpl>(child1);
5827 LayerImpl* child3 = AddChild<LayerImpl>(child2);
5828 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375829
weiliangc9ced1592015-11-17 19:04:375830 gfx::Size bounds(100, 100);
5831
danakjf78fb272016-07-26 19:06:155832 root->SetBounds(bounds);
5833 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265834 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155835 child1->Set3dSortingContextId(1);
5836 child1->test_properties()->should_flatten_transform = false;
5837 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265838 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375839 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155840 child3->SetBounds(bounds);
5841 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375842 child3->Set3dSortingContextId(1);
jaydasika6ed869662016-09-21 14:29:595843 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
weiliangc9ced1592015-11-17 19:04:375844
5845 // Verify which render surfaces were created.
5846 EXPECT_TRUE(root->has_render_surface());
5847 EXPECT_FALSE(child1->has_render_surface());
5848 EXPECT_TRUE(child2->has_render_surface());
5849 EXPECT_FALSE(child3->has_render_surface());
5850}
5851
[email protected]45948712013-09-27 02:46:485852TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:165853 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455854 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565855 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165856 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565857 &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:265858
danakj60bc3bc2016-04-09 00:24:485859 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:485860 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:485861 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:485862 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:485863 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:485864 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:485865 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:485866 LayerImpl::Create(host_impl.active_tree(), 12345678);
5867
[email protected]45948712013-09-27 02:46:485868 gfx::Size bounds(100, 100);
danakjf78fb272016-07-26 19:06:155869
5870 root->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485871 root->SetDrawsContent(true);
5872
5873 // This layer structure normally forces render surface due to preserves3d
5874 // behavior.
danakjf78fb272016-07-26 19:06:155875 child1->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485876 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155877 child1->Set3dSortingContextId(1);
5878 child1->test_properties()->should_flatten_transform = false;
5879 child2->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485880 child2->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:285881 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155882 child3->SetBounds(bounds);
5883 child3->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:285884 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:575885
jaydasika89f7b5a2016-06-22 02:08:395886 child2->test_properties()->AddChild(std::move(child3));
5887 child1->test_properties()->AddChild(std::move(child2));
5888 root->test_properties()->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:055889 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595890 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
[email protected]45948712013-09-27 02:46:485891
5892 {
5893 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055894 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:485895 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385896 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:485897 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:575898 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:485899
5900 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:025901
5902 int count_represents_target_render_surface = 0;
5903 int count_represents_contributing_render_surface = 0;
5904 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:515905 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5906 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:025907 it != end; ++it) {
5908 if (it.represents_target_render_surface())
5909 count_represents_target_render_surface++;
5910 if (it.represents_contributing_render_surface())
5911 count_represents_contributing_render_surface++;
5912 if (it.represents_itself())
5913 count_represents_itself++;
5914 }
5915
5916 // Two render surfaces.
5917 EXPECT_EQ(2, count_represents_target_render_surface);
5918 // Second render surface contributes to root render surface.
5919 EXPECT_EQ(1, count_represents_contributing_render_surface);
5920 // All 4 layers represent itself.
5921 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:485922 }
5923
5924 {
5925 LayerImplList render_surface_layer_list;
5926 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385927 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:485928 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:575929 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:485930
5931 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:025932
5933 int count_represents_target_render_surface = 0;
5934 int count_represents_contributing_render_surface = 0;
5935 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:515936 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5937 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:025938 it != end; ++it) {
5939 if (it.represents_target_render_surface())
5940 count_represents_target_render_surface++;
5941 if (it.represents_contributing_render_surface())
5942 count_represents_contributing_render_surface++;
5943 if (it.represents_itself())
5944 count_represents_itself++;
5945 }
5946
5947 // Only root layer has a render surface.
5948 EXPECT_EQ(1, count_represents_target_render_surface);
5949 // No layer contributes a render surface to root render surface.
5950 EXPECT_EQ(0, count_represents_contributing_render_surface);
5951 // All 4 layers represent itself.
5952 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:485953 }
5954}
5955
[email protected]a9aa60a82013-08-29 04:28:265956TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:595957 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:335958 LayerImpl* back_facing = AddChild<LayerImpl>(root);
5959 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
5960 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
5961 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
5962 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:155963
jaydasikae00c8a42016-01-28 20:18:335964 child1->SetDrawsContent(true);
5965 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:265966
danakjf78fb272016-07-26 19:06:155967 root->SetBounds(gfx::Size(50, 50));
[email protected]a9d4d4f2014-06-19 06:49:285968 root->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155969 root->test_properties()->should_flatten_transform = false;
5970 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikae00c8a42016-01-28 20:18:335971 back_facing->Set3dSortingContextId(1);
jaydasikaca2605e2016-04-23 02:52:525972 back_facing->test_properties()->should_flatten_transform = false;
danakjf78fb272016-07-26 19:06:155973 render_surface1->SetBounds(gfx::Size(30, 30));
5974 render_surface1->Set3dSortingContextId(1);
5975 render_surface1->test_properties()->should_flatten_transform = false;
5976 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:365977 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155978 render_surface2->SetBounds(gfx::Size(30, 30));
5979 // Different context from the rest.
jaydasikae00c8a42016-01-28 20:18:335980 render_surface2->Set3dSortingContextId(2);
danakjf78fb272016-07-26 19:06:155981 render_surface2->test_properties()->should_flatten_transform = false;
5982 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:365983 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:155984 child1->SetBounds(gfx::Size(20, 20));
5985 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:265986
enne03b0e9a2015-06-19 00:08:025987 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:265988
jaydasikae00c8a42016-01-28 20:18:335989 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
5990 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
5991 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5992 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:025993 ->at(0)
5994 ->render_surface()
5995 ->layer_list()
5996 .size());
5997 EXPECT_EQ(1u, render_surface_layer_list_impl()
5998 ->at(1)
5999 ->render_surface()
6000 ->layer_list()
6001 .size());
[email protected]a9aa60a82013-08-29 04:28:266002
danakjf78fb272016-07-26 19:06:156003 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:266004 rotation_transform.RotateAboutXAxis(180.0);
6005
jaydasika10d43fc2016-08-18 04:06:046006 back_facing->test_properties()->transform = rotation_transform;
jaydasika5aa88b82015-11-10 01:48:036007 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266008
enne03b0e9a2015-06-19 00:08:026009 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266010
jaydasikae00c8a42016-01-28 20:18:336011 // render_surface1 is in the same 3d rendering context as back_facing and is
6012 // not double sided, so it should not be in RSLL. render_surface2 is also not
6013 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6014 // context.
6015 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6016 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026017 ->at(0)
6018 ->render_surface()
6019 ->layer_list()
6020 .size());
[email protected]a9aa60a82013-08-29 04:28:266021}
6022
ajumaaa0d3862015-11-09 22:24:466023TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:596024 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:466025 LayerImpl* child = AddChild<LayerImpl>(root);
6026 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:466027
danakjf78fb272016-07-26 19:06:156028 root->SetBounds(gfx::Size(50, 50));
6029 root->test_properties()->should_flatten_transform = false;
6030 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:366031 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156032 child->test_properties()->should_flatten_transform = false;
6033 grand_child->SetBounds(gfx::Size(20, 20));
6034 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:466035 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:156036 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:466037 ExecuteCalculateDrawProperties(root);
6038
6039 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6040 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6041 ->at(0)
6042 ->render_surface()
6043 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556044
6045 // As all layers have identity transform, we shouldn't check for backface
6046 // visibility.
6047 EXPECT_FALSE(root->should_check_backface_visibility());
6048 EXPECT_FALSE(child->should_check_backface_visibility());
6049 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6050 // As there are no 3d rendering contexts, all layers should use their local
6051 // transform for backface visibility.
6052 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6053 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6054 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6055
danakjf78fb272016-07-26 19:06:156056 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:466057 rotation_transform.RotateAboutXAxis(180.0);
6058
jaydasika10d43fc2016-08-18 04:06:046059 child->test_properties()->transform = rotation_transform;
jaydasika62bd3dd2016-02-04 18:52:556060 child->Set3dSortingContextId(1);
6061 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466062 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6063
6064 ExecuteCalculateDrawProperties(root);
6065 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6066 EXPECT_EQ(0u, render_surface_layer_list_impl()
6067 ->at(0)
6068 ->render_surface()
6069 ->layer_list()
6070 .size());
jaydasika62bd3dd2016-02-04 18:52:556071
6072 // We should check for backface visibilty of child as it has a rotation
6073 // transform. We should also check for grand_child as it uses the backface
6074 // visibility of its parent.
6075 EXPECT_FALSE(root->should_check_backface_visibility());
6076 EXPECT_TRUE(child->should_check_backface_visibility());
6077 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6078 // child uses its local transform for backface visibility as it is the root of
6079 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6080 // the root, but it derives its backface visibility from its parent which uses
6081 // its local transform.
6082 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6083 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6084 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6085
6086 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366087 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556088 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6089
6090 ExecuteCalculateDrawProperties(root);
6091 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6092 EXPECT_EQ(0u, render_surface_layer_list_impl()
6093 ->at(0)
6094 ->render_surface()
6095 ->layer_list()
6096 .size());
6097
6098 // We should check the backface visibility of child as it has a rotation
6099 // transform and for grand_child as it is in a 3d rendering context and not
6100 // the root of it.
6101 EXPECT_FALSE(root->should_check_backface_visibility());
6102 EXPECT_TRUE(child->should_check_backface_visibility());
6103 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6104 // grand_child is in an existing 3d rendering context, so it should not use
6105 // local transform for backface visibility.
6106 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6107 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6108 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466109}
6110
sunxd59dd7da2016-05-19 20:07:476111TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:596112 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:476113 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6114 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6115 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6116
sunxd59dd7da2016-05-19 20:07:476117 gfx::Transform rotate_about_y;
6118 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:476119
danakjf78fb272016-07-26 19:06:156120 root->SetBounds(gfx::Size(50, 50));
6121 root->Set3dSortingContextId(1);
6122 root->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:046123 back_facing->test_properties()->transform = rotate_about_y;
danakjf78fb272016-07-26 19:06:156124 back_facing->SetBounds(gfx::Size(50, 50));
6125 back_facing->Set3dSortingContextId(1);
6126 back_facing->test_properties()->should_flatten_transform = false;
6127 render_surface1->SetBounds(gfx::Size(30, 30));
6128 render_surface1->Set3dSortingContextId(1);
6129 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476130 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156131 render_surface1->test_properties()->force_render_surface = true;
6132 render_surface2->SetBounds(gfx::Size(30, 30));
6133 render_surface2->Set3dSortingContextId(1);
6134 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476135 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156136 render_surface2->test_properties()->force_render_surface = true;
sunxd59dd7da2016-05-19 20:07:476137 ExecuteCalculateDrawProperties(root);
6138
6139 const EffectTree& tree =
6140 root->layer_tree_impl()->property_trees()->effect_tree;
6141 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016142 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476143 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016144 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476145
jaydasika09e16132016-08-24 21:39:346146 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6147 gfx::Transform(), back_facing->transform_tree_index(),
6148 root->layer_tree_impl());
6149 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6150 rotate_about_y, render_surface2->transform_tree_index(),
6151 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476152 ExecuteCalculateDrawProperties(root);
6153 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016154 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476155 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016156 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476157
jaydasika09e16132016-08-24 21:39:346158 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6159 rotate_about_y, render_surface1->transform_tree_index(),
6160 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476161 ExecuteCalculateDrawProperties(root);
6162 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016163 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476164 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016165 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476166}
6167
[email protected]995708c52013-10-17 20:52:596168TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6169 // Checks that the simple case (being clipped by a scroll parent that would
6170 // have been processed before you anyhow) results in the right clips.
6171 //
6172 // + root
6173 // + scroll_parent_border
6174 // | + scroll_parent_clip
6175 // | + scroll_parent
6176 // + scroll_child
6177 //
jaydasikabf1875a2016-06-28 03:39:596178 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:486179 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6180 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6181 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6182 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596183
enne085b48a2015-08-18 17:54:486184 scroll_parent->SetDrawsContent(true);
6185 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596186 scroll_parent_clip->SetMasksToBounds(true);
6187
jaydasika1c0a27d42016-04-28 01:54:566188 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156189 scroll_parent->test_properties()->scroll_children =
6190 base::MakeUnique<std::set<LayerImpl*>>();
6191 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596192
danakjf78fb272016-07-26 19:06:156193 root->SetBounds(gfx::Size(50, 50));
6194 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6195 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6196 scroll_parent->SetBounds(gfx::Size(50, 50));
6197 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:486198 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596199
6200 EXPECT_TRUE(root->render_surface());
6201
jaydasika6f972de2016-04-07 16:16:146202 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596203 EXPECT_TRUE(scroll_child->is_clipped());
6204}
6205
jaydasika8ccff3d2016-01-20 19:51:306206TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6207 // Tests the computation of draw transform for the scroll child when its
6208 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:596209 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:306210 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6211 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6212 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6213 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6214
6215 scroll_parent->SetDrawsContent(true);
6216 scroll_child->SetDrawsContent(true);
6217
jaydasika1c0a27d42016-04-28 01:54:566218 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156219 scroll_parent->test_properties()->scroll_children =
6220 base::MakeUnique<std::set<LayerImpl*>>();
6221 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:306222
danakjf78fb272016-07-26 19:06:156223 root->SetBounds(gfx::Size(50, 50));
6224 scroll_child_target->SetBounds(gfx::Size(50, 50));
6225 scroll_child_target->test_properties()->force_render_surface = true;
6226 scroll_child->SetBounds(gfx::Size(50, 50));
6227 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
6228 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:006229 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156230 scroll_parent_target->test_properties()->force_render_surface = true;
6231 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:306232
jaydasika2489a442016-01-29 02:26:006233 float device_scale_factor = 1.5f;
6234 LayerImplList render_surface_layer_list_impl;
jaydasikab4df4032016-09-13 18:38:496235 gfx::Size device_viewport_size =
6236 gfx::Size(root->bounds().width() * device_scale_factor,
6237 root->bounds().height() * device_scale_factor);
jaydasika2489a442016-01-29 02:26:006238 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasikab4df4032016-09-13 18:38:496239 root, device_viewport_size, gfx::Transform(),
6240 &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006241 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576242 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006243
weiliangc1da3fb892016-03-14 20:23:526244 EXPECT_EQ(scroll_child->effect_tree_index(),
6245 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006246 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6247 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6248 gfx::Transform scale;
6249 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:026250 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306251}
6252
[email protected]08bdf1b2014-04-16 23:23:296253TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:596254 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:196255 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:196256 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:156257
6258 root->SetBounds(gfx::Size(50, 50));
6259 root->SetDrawsContent(true);
6260 root->Set3dSortingContextId(1);
6261 parent->SetBounds(gfx::Size(30, 30));
6262 parent->SetDrawsContent(true);
6263 parent->Set3dSortingContextId(1);
6264 parent->test_properties()->force_render_surface = true;
6265 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:196266 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156267 child->Set3dSortingContextId(1);
6268 child->test_properties()->force_render_surface = true;
enneca33fed2015-07-27 18:22:196269 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296270
enneca33fed2015-07-27 18:22:196271 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296272
6273 gfx::Transform singular_transform;
6274 singular_transform.Scale3d(
6275 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6276
jaydasika10d43fc2016-08-18 04:06:046277 child->test_properties()->transform = singular_transform;
[email protected]08bdf1b2014-04-16 23:23:296278
sunxd71aea3e2016-04-01 23:48:056279 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196280 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296281
enneca33fed2015-07-27 18:22:196282 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296283
6284 // Ensure that the entire subtree under a layer with singular transform does
6285 // not get rendered.
jaydasika10d43fc2016-08-18 04:06:046286 parent->test_properties()->transform = singular_transform;
6287 child->test_properties()->transform = gfx::Transform();
[email protected]08bdf1b2014-04-16 23:23:296288
sunxd71aea3e2016-04-01 23:48:056289 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196290 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296291
enneca33fed2015-07-27 18:22:196292 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296293}
6294
[email protected]995708c52013-10-17 20:52:596295TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6296 // Checks that clipping by a scroll parent that follows you in paint order
6297 // still results in correct clipping.
6298 //
6299 // + root
[email protected]995708c52013-10-17 20:52:596300 // + scroll_parent_border
6301 // + scroll_parent_clip
6302 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026303 // + scroll_child
[email protected]995708c52013-10-17 20:52:596304 //
jaydasikabf1875a2016-06-28 03:39:596305 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026306 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6307 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6308 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6309 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596310
enne03b0e9a2015-06-19 00:08:026311 scroll_parent->SetDrawsContent(true);
6312 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596313
danakjf78fb272016-07-26 19:06:156314 root->SetBounds(gfx::Size(50, 50));
6315 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6316 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:596317 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156318 scroll_parent->SetBounds(gfx::Size(50, 50));
6319 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596320
jaydasika1c0a27d42016-04-28 01:54:566321 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156322 scroll_parent->test_properties()->scroll_children =
6323 base::MakeUnique<std::set<LayerImpl*>>();
6324 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596325
enne03b0e9a2015-06-19 00:08:026326 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596327
6328 EXPECT_TRUE(root->render_surface());
6329
jaydasika6f972de2016-04-07 16:16:146330 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596331 EXPECT_TRUE(scroll_child->is_clipped());
6332}
6333
6334TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6335 // Checks that clipping by a scroll parent and scroll grandparent that follow
6336 // you in paint order still results in correct clipping.
6337 //
6338 // + root
6339 // + scroll_child
6340 // + scroll_parent_border
6341 // | + scroll_parent_clip
6342 // | + scroll_parent
6343 // + scroll_grandparent_border
6344 // + scroll_grandparent_clip
6345 // + scroll_grandparent
6346 //
jaydasikabf1875a2016-06-28 03:39:596347 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026348 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6349 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6350 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6351 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6352 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6353 LayerImpl* scroll_grandparent_clip =
6354 AddChild<LayerImpl>(scroll_grandparent_border);
6355 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596356
enne03b0e9a2015-06-19 00:08:026357 scroll_parent->SetDrawsContent(true);
6358 scroll_grandparent->SetDrawsContent(true);
6359 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596360
6361 scroll_parent_clip->SetMasksToBounds(true);
6362 scroll_grandparent_clip->SetMasksToBounds(true);
6363
jaydasika1c0a27d42016-04-28 01:54:566364 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156365 scroll_parent->test_properties()->scroll_children =
6366 base::MakeUnique<std::set<LayerImpl*>>();
6367 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386368
jaydasika1c0a27d42016-04-28 01:54:566369 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156370 scroll_grandparent->test_properties()->scroll_children =
6371 base::MakeUnique<std::set<LayerImpl*>>();
6372 scroll_grandparent->test_properties()->scroll_children->insert(
6373 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596374
danakjf78fb272016-07-26 19:06:156375 root->SetBounds(gfx::Size(50, 50));
6376 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6377 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6378 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6379 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6380 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6381 scroll_parent->SetBounds(gfx::Size(50, 50));
6382 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596383
enne03b0e9a2015-06-19 00:08:026384 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596385
6386 EXPECT_TRUE(root->render_surface());
6387
jaydasika6f972de2016-04-07 16:16:146388 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596389 EXPECT_TRUE(scroll_child->is_clipped());
6390
6391 // Despite the fact that we visited the above layers out of order to get the
6392 // correct clip, the layer lists should be unaffected.
6393 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026394 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6395 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6396 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596397}
6398
6399TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6400 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226401 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596402 // + root
6403 // + scroll_child
6404 // + scroll_parent_border
6405 // + scroll_parent_clip
6406 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026407 // + render_surface2
[email protected]995708c52013-10-17 20:52:596408 // + scroll_grandparent_border
6409 // + scroll_grandparent_clip
6410 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026411 // + render_surface1
[email protected]995708c52013-10-17 20:52:596412 //
jaydasikabf1875a2016-06-28 03:39:596413 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026414 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596415
enne03b0e9a2015-06-19 00:08:026416 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6417 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596418
enne03b0e9a2015-06-19 00:08:026419 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6420 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6421 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6422 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6423 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6424 LayerImpl* scroll_grandparent_clip =
6425 AddChild<LayerImpl>(scroll_grandparent_border);
6426 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6427 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596428
enne03b0e9a2015-06-19 00:08:026429 scroll_parent->SetDrawsContent(true);
6430 render_surface1->SetDrawsContent(true);
6431 scroll_grandparent->SetDrawsContent(true);
6432 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596433
6434 scroll_parent_clip->SetMasksToBounds(true);
6435 scroll_grandparent_clip->SetMasksToBounds(true);
6436
jaydasika1c0a27d42016-04-28 01:54:566437 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156438 scroll_parent->test_properties()->scroll_children =
6439 base::MakeUnique<std::set<LayerImpl*>>();
6440 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386441
jaydasika1c0a27d42016-04-28 01:54:566442 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156443 scroll_grandparent->test_properties()->scroll_children =
6444 base::MakeUnique<std::set<LayerImpl*>>();
6445 scroll_grandparent->test_properties()->scroll_children->insert(
6446 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596447
danakjf78fb272016-07-26 19:06:156448 root->SetBounds(gfx::Size(50, 50));
6449 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6450 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6451 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6452 render_surface1->SetBounds(gfx::Size(50, 50));
6453 render_surface1->test_properties()->force_render_surface = true;
6454 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6455 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6456 scroll_parent->SetBounds(gfx::Size(50, 50));
6457 render_surface2->SetBounds(gfx::Size(50, 50));
6458 render_surface2->test_properties()->force_render_surface = true;
6459 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596460
enne03b0e9a2015-06-19 00:08:026461 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596462
6463 EXPECT_TRUE(root->render_surface());
6464
jaydasika6f972de2016-04-07 16:16:146465 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596466 EXPECT_TRUE(scroll_child->is_clipped());
6467
6468 // Despite the fact that we had to process the layers out of order to get the
6469 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026470 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6471 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6472 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6473 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6474 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6475 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6476 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596477}
6478
ajuma0b10f942015-03-21 07:45:536479TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6480 // Ensures that when we have a render surface between a fixed position layer
6481 // and its container, we compute the fixed position layer's draw transform
6482 // with respect to that intervening render surface, not with respect to its
6483 // container's render target.
6484 //
6485 // + root
6486 // + render_surface
6487 // + fixed
ajuma737b2702015-05-06 01:18:376488 // + child
ajuma0b10f942015-03-21 07:45:536489 //
jaydasikabf1875a2016-06-28 03:39:596490 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516491 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6492 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6493 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536494
jaydasika6b5a32bf2016-04-22 21:56:366495 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526496 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536497
6498 LayerPositionConstraint constraint;
6499 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526500 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536501
danakjf78fb272016-07-26 19:06:156502 root->SetBounds(gfx::Size(50, 50));
6503 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6504 render_surface->SetBounds(gfx::Size(50, 50));
6505 render_surface->SetDrawsContent(true);
6506 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6507 fixed->SetBounds(gfx::Size(50, 50));
6508 fixed->SetDrawsContent(true);
6509 child->SetPosition(gfx::PointF(1.f, 2.f));
6510 child->SetBounds(gfx::Size(50, 50));
6511 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516512 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536513
jaydasikabaede2d92016-07-20 00:34:326514 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516515 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326516 EffectTree& effect_tree =
6517 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156518
ajuma737b2702015-05-06 01:18:376519 gfx::Transform expected_fixed_draw_transform;
6520 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026521 EXPECT_TRANSFORMATION_MATRIX_EQ(
6522 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326523 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536524
ajuma737b2702015-05-06 01:18:376525 gfx::Transform expected_fixed_screen_space_transform;
6526 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026527 EXPECT_TRANSFORMATION_MATRIX_EQ(
6528 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326529 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376530
6531 gfx::Transform expected_child_draw_transform;
6532 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026533 EXPECT_TRANSFORMATION_MATRIX_EQ(
6534 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326535 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376536
6537 gfx::Transform expected_child_screen_space_transform;
6538 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026539 EXPECT_TRANSFORMATION_MATRIX_EQ(
6540 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326541 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536542}
6543
[email protected]d81752b2013-10-25 08:32:236544TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6545 // This test verifies that a scrolling layer that gets snapped to
6546 // integer coordinates doesn't move a fixed position child.
6547 //
6548 // + root
6549 // + container
6550 // + scroller
6551 // + fixed
6552 //
khushalsagarb64b360d2015-10-21 19:25:166553 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456554 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566555 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166556 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566557 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236558 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486559 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426560 LayerImpl::Create(host_impl.active_tree(), 1);
6561 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486562 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236563 LayerImpl::Create(host_impl.active_tree(), 2);
6564 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486565 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236566 LayerImpl::Create(host_impl.active_tree(), 3);
6567 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486568 std::unique_ptr<LayerImpl> fixed =
6569 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236570 LayerImpl* fixed_layer = fixed.get();
6571
jaydasikaca2605e2016-04-23 02:52:526572 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236573
6574 LayerPositionConstraint constraint;
6575 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526576 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236577
[email protected]adeda572014-01-31 00:49:476578 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236579
[email protected]d81752b2013-10-25 08:32:236580 gfx::Transform container_transform;
6581 container_transform.Translate3d(10.0, 20.0, 0.0);
6582 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6583
danakjf78fb272016-07-26 19:06:156584 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046585 container->test_properties()->transform = container_transform;
danakjf78fb272016-07-26 19:06:156586 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286587 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156588 scroller->SetBounds(gfx::Size(30, 30));
jaydasika0d98ba92015-11-17 05:17:286589 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156590 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286591 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156592
jaydasika89f7b5a2016-06-22 02:08:396593 scroller->test_properties()->AddChild(std::move(fixed));
6594 container->test_properties()->AddChild(std::move(scroller));
6595 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486596 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6597 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236598
6599 // Rounded to integers already.
6600 {
6601 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426602 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236603
6604 LayerImplList render_surface_layer_list;
6605 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386606 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:426607 root->layer_tree_impl()
6608 ->property_trees()
6609 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576610 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236611
6612 EXPECT_TRANSFORMATION_MATRIX_EQ(
6613 container_layer->draw_properties().screen_space_transform,
6614 fixed_layer->draw_properties().screen_space_transform);
6615 EXPECT_VECTOR_EQ(
6616 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6617 container_offset);
6618 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6619 .screen_space_transform.To2dTranslation(),
6620 container_offset - scroll_delta);
6621 }
6622
6623 // Scroll delta requiring rounding.
6624 {
6625 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426626 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236627
6628 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6629
6630 LayerImplList render_surface_layer_list;
6631 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386632 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576633 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236634
6635 EXPECT_TRANSFORMATION_MATRIX_EQ(
6636 container_layer->draw_properties().screen_space_transform,
6637 fixed_layer->draw_properties().screen_space_transform);
6638 EXPECT_VECTOR_EQ(
6639 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6640 container_offset);
6641 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6642 .screen_space_transform.To2dTranslation(),
6643 container_offset - rounded_scroll_delta);
6644 }
[email protected]cf15ad7b2014-04-02 03:59:266645
6646 // Scale is applied earlier in the tree.
6647 {
sunxdb7e79432016-03-09 21:13:426648 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266649 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286650 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:046651 container_layer->test_properties()->transform = scaled_container_transform;
danakj74af409e2016-07-01 00:41:486652
jaydasika0d98ba92015-11-17 05:17:286653 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266654
6655 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426656 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266657
6658 LayerImplList render_surface_layer_list;
6659 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386660 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576661 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266662
6663 EXPECT_TRANSFORMATION_MATRIX_EQ(
6664 container_layer->draw_properties().screen_space_transform,
6665 fixed_layer->draw_properties().screen_space_transform);
6666 EXPECT_VECTOR_EQ(
6667 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6668 container_offset);
6669
jaydasika10d43fc2016-08-18 04:06:046670 container_layer->test_properties()->transform = container_transform;
[email protected]cf15ad7b2014-04-02 03:59:266671 }
[email protected]d81752b2013-10-25 08:32:236672}
6673
miletus2c78036b2015-01-29 20:52:376674TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506675 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6676 // This test verifies that a scrolling layer whose screen space transform is
6677 // animating doesn't get snapped to integer coordinates.
6678 //
6679 // + root
6680 // + animated layer
6681 // + surface
6682 // + container
6683 // + scroller
6684 //
jaydasikabf1875a2016-06-28 03:39:596685 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506686 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6687 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6688 LayerImpl* container = AddChild<LayerImpl>(surface);
6689 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506690
ajuma5e8e40d2015-07-31 01:50:506691 gfx::Transform start_scale;
6692 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156693
6694 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046695 animated_layer->test_properties()->transform = start_scale;
danakjf78fb272016-07-26 19:06:156696 animated_layer->SetBounds(gfx::Size(50, 50));
6697 surface->SetBounds(gfx::Size(50, 50));
6698 surface->test_properties()->force_render_surface = true;
6699 container->SetBounds(gfx::Size(50, 50));
6700 scroller->SetBounds(gfx::Size(100, 100));
6701 scroller->SetScrollClipLayer(container->id());
6702 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506703
6704 gfx::Transform end_scale;
6705 end_scale.Scale(2.f, 2.f);
6706 TransformOperations start_operations;
6707 start_operations.AppendMatrix(start_scale);
6708 TransformOperations end_operations;
6709 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276710 SetElementIdsForTesting();
6711
6712 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6713 timeline_impl(), 1.0,
6714 start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:506715 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426716 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506717
6718 ExecuteCalculateDrawProperties(root);
6719
6720 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6721 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446722 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506723}
6724
sunxd8a9a60982016-07-29 18:46:566725TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6726 // This test verifies that a scrolling child of a scrolling layer doesn't get
6727 // snapped to integer coordinates.
6728 //
6729 // + root
6730 // + container
6731 // + scroller
6732 // + scroll_child
6733 //
6734 scoped_refptr<Layer> root = Layer::Create();
6735 scoped_refptr<Layer> container = Layer::Create();
6736 scoped_refptr<Layer> scroller = Layer::Create();
6737 scoped_refptr<Layer> scroll_child = Layer::Create();
6738 root->AddChild(container);
6739 root->AddChild(scroll_child);
6740 container->AddChild(scroller);
6741 host()->SetRootLayer(root);
6742
6743 scroller->SetScrollClipLayerId(container->id());
6744 scroll_child->SetScrollParent(scroller.get());
6745
6746 gfx::Transform rotate;
6747 rotate.RotateAboutYAxis(30);
6748 root->SetBounds(gfx::Size(50, 50));
6749 container->SetBounds(gfx::Size(50, 50));
6750 scroller->SetBounds(gfx::Size(100, 100));
6751 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6752 scroll_child->SetBounds(gfx::Size(10, 10));
6753 scroll_child->SetTransform(rotate);
6754
6755 ExecuteCalculateDrawProperties(root.get());
6756
6757 host()->host_impl()->CreatePendingTree();
6758 host()->CommitAndCreatePendingTree();
6759 host()->host_impl()->ActivateSyncTree();
6760 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6761
6762 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6763 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6764 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
6765 gfx::Vector2dF scroll_delta(5.f, 9.f);
6766 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6767
6768 ExecuteCalculateDrawProperties(root_impl);
6769
6770 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6771 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6772 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6773
6774 gfx::Transform expected_scroll_child_screen_space_transform;
6775 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6776 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6777 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6778 scroll_child_impl->ScreenSpaceTransform());
6779}
6780
flackr2215b4e2016-09-21 20:16:016781TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
6782 scoped_refptr<Layer> root = Layer::Create();
6783 scoped_refptr<Layer> container = Layer::Create();
6784 scoped_refptr<Layer> scroller = Layer::Create();
6785 scoped_refptr<Layer> sticky_pos = Layer::Create();
6786 root->AddChild(container);
6787 container->AddChild(scroller);
6788 scroller->AddChild(sticky_pos);
6789 host()->SetRootLayer(root);
6790 scroller->SetScrollClipLayerId(container->id());
6791
6792 LayerStickyPositionConstraint sticky_position;
6793 sticky_position.is_sticky = true;
6794 sticky_position.is_anchored_top = true;
6795 sticky_position.top_offset = 10.0f;
6796 sticky_position.scroll_container_relative_sticky_box_rect =
6797 gfx::Rect(10, 20, 10, 10);
6798 sticky_position.scroll_container_relative_containing_block_rect =
6799 gfx::Rect(0, 0, 50, 50);
6800 sticky_pos->SetStickyPositionConstraint(sticky_position);
6801
6802 root->SetBounds(gfx::Size(100, 100));
6803 container->SetBounds(gfx::Size(100, 100));
6804 scroller->SetBounds(gfx::Size(1000, 1000));
6805 sticky_pos->SetBounds(gfx::Size(10, 10));
6806 sticky_pos->SetPosition(gfx::PointF(10, 20));
6807
6808 ExecuteCalculateDrawProperties(root.get());
6809 host()->host_impl()->CreatePendingTree();
6810 host()->CommitAndCreatePendingTree();
6811 host()->host_impl()->ActivateSyncTree();
6812 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6813
6814 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6815 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6816 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6817
6818 ExecuteCalculateDrawProperties(root_impl);
6819 EXPECT_VECTOR2DF_EQ(
6820 gfx::Vector2dF(10.f, 20.f),
6821 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6822
6823 // Scroll less than sticking point, sticky element should move with scroll as
6824 // we haven't gotten to the initial sticky item location yet.
6825 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6826 ExecuteCalculateDrawProperties(root_impl);
6827 EXPECT_VECTOR2DF_EQ(
6828 gfx::Vector2dF(5.f, 15.f),
6829 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6830
6831 // Scroll past the sticking point, the Y coordinate should now be clamped.
6832 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6833 ExecuteCalculateDrawProperties(root_impl);
6834 EXPECT_VECTOR2DF_EQ(
6835 gfx::Vector2dF(-5.f, 10.f),
6836 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6837 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6838 ExecuteCalculateDrawProperties(root_impl);
6839 EXPECT_VECTOR2DF_EQ(
6840 gfx::Vector2dF(-5.f, 10.f),
6841 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6842
6843 // Scroll past the end of the sticky container (note: this element does not
6844 // have its own layer as it does not need to be composited).
6845 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6846 ExecuteCalculateDrawProperties(root_impl);
6847 EXPECT_VECTOR2DF_EQ(
6848 gfx::Vector2dF(-5.f, -10.f),
6849 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6850}
6851
6852TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
6853 scoped_refptr<Layer> root = Layer::Create();
6854 scoped_refptr<Layer> container = Layer::Create();
6855 scoped_refptr<Layer> scroller = Layer::Create();
6856 scoped_refptr<Layer> sticky_pos = Layer::Create();
6857 root->AddChild(container);
6858 container->AddChild(scroller);
6859 scroller->AddChild(sticky_pos);
6860 host()->SetRootLayer(root);
6861 scroller->SetScrollClipLayerId(container->id());
6862
6863 LayerStickyPositionConstraint sticky_position;
6864 sticky_position.is_sticky = true;
6865 sticky_position.is_anchored_bottom = true;
6866 sticky_position.bottom_offset = 10.0f;
6867 sticky_position.scroll_container_relative_sticky_box_rect =
6868 gfx::Rect(0, 150, 10, 10);
6869 sticky_position.scroll_container_relative_containing_block_rect =
6870 gfx::Rect(0, 100, 50, 50);
6871 sticky_pos->SetStickyPositionConstraint(sticky_position);
6872
6873 root->SetBounds(gfx::Size(100, 100));
6874 container->SetBounds(gfx::Size(100, 100));
6875 scroller->SetBounds(gfx::Size(1000, 1000));
6876 sticky_pos->SetBounds(gfx::Size(10, 10));
6877 sticky_pos->SetPosition(gfx::PointF(0, 150));
6878
6879 ExecuteCalculateDrawProperties(root.get());
6880 host()->host_impl()->CreatePendingTree();
6881 host()->CommitAndCreatePendingTree();
6882 host()->host_impl()->ActivateSyncTree();
6883 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6884
6885 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6886 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6887 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6888
6889 // Initially the sticky element is moved up to the top of the container.
6890 ExecuteCalculateDrawProperties(root_impl);
6891 EXPECT_VECTOR2DF_EQ(
6892 gfx::Vector2dF(0.f, 100.f),
6893 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6894 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6895 ExecuteCalculateDrawProperties(root_impl);
6896 EXPECT_VECTOR2DF_EQ(
6897 gfx::Vector2dF(0.f, 95.f),
6898 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6899
6900 // Once we get past the top of the container it moves to be aligned 10px
6901 // up from the the bottom of the scroller.
6902 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
6903 ExecuteCalculateDrawProperties(root_impl);
6904 EXPECT_VECTOR2DF_EQ(
6905 gfx::Vector2dF(0.f, 80.f),
6906 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6907 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
6908 ExecuteCalculateDrawProperties(root_impl);
6909 EXPECT_VECTOR2DF_EQ(
6910 gfx::Vector2dF(0.f, 80.f),
6911 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6912
6913 // Once we scroll past its initial location, it sticks there.
6914 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
6915 ExecuteCalculateDrawProperties(root_impl);
6916 EXPECT_VECTOR2DF_EQ(
6917 gfx::Vector2dF(0.f, 0.f),
6918 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6919}
6920
6921TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
6922 scoped_refptr<Layer> root = Layer::Create();
6923 scoped_refptr<Layer> container = Layer::Create();
6924 scoped_refptr<Layer> scroller = Layer::Create();
6925 scoped_refptr<Layer> sticky_pos = Layer::Create();
6926 root->AddChild(container);
6927 container->AddChild(scroller);
6928 scroller->AddChild(sticky_pos);
6929 host()->SetRootLayer(root);
6930 scroller->SetScrollClipLayerId(container->id());
6931
6932 LayerStickyPositionConstraint sticky_position;
6933 sticky_position.is_sticky = true;
6934 sticky_position.is_anchored_left = true;
6935 sticky_position.is_anchored_right = true;
6936 sticky_position.left_offset = 10.f;
6937 sticky_position.right_offset = 10.f;
6938 sticky_position.scroll_container_relative_sticky_box_rect =
6939 gfx::Rect(145, 0, 10, 10);
6940 sticky_position.scroll_container_relative_containing_block_rect =
6941 gfx::Rect(100, 0, 100, 100);
6942 sticky_pos->SetStickyPositionConstraint(sticky_position);
6943
6944 root->SetBounds(gfx::Size(100, 100));
6945 container->SetBounds(gfx::Size(100, 100));
6946 scroller->SetBounds(gfx::Size(1000, 1000));
6947 sticky_pos->SetBounds(gfx::Size(10, 10));
6948 sticky_pos->SetPosition(gfx::PointF(145, 0));
6949
6950 ExecuteCalculateDrawProperties(root.get());
6951 host()->host_impl()->CreatePendingTree();
6952 host()->CommitAndCreatePendingTree();
6953 host()->host_impl()->ActivateSyncTree();
6954 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6955
6956 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6957 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6958 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6959
6960 // Initially the sticky element is moved the leftmost side of the container.
6961 ExecuteCalculateDrawProperties(root_impl);
6962 EXPECT_VECTOR2DF_EQ(
6963 gfx::Vector2dF(100.f, 0.f),
6964 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6965 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
6966 ExecuteCalculateDrawProperties(root_impl);
6967 EXPECT_VECTOR2DF_EQ(
6968 gfx::Vector2dF(95.f, 0.f),
6969 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6970
6971 // Once we get past the left side of the container it moves to be aligned 10px
6972 // up from the the right of the scroller.
6973 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
6974 ExecuteCalculateDrawProperties(root_impl);
6975 EXPECT_VECTOR2DF_EQ(
6976 gfx::Vector2dF(80.f, 0.f),
6977 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6978 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
6979 ExecuteCalculateDrawProperties(root_impl);
6980 EXPECT_VECTOR2DF_EQ(
6981 gfx::Vector2dF(80.f, 0.f),
6982 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6983
6984 // When we get to the sticky element's original position we stop sticking
6985 // to the right.
6986 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
6987 ExecuteCalculateDrawProperties(root_impl);
6988 EXPECT_VECTOR2DF_EQ(
6989 gfx::Vector2dF(50.f, 0.f),
6990 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6991 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
6992 ExecuteCalculateDrawProperties(root_impl);
6993 EXPECT_VECTOR2DF_EQ(
6994 gfx::Vector2dF(40.f, 0.f),
6995 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6996
6997 // The element starts sticking to the left once we scroll far enough.
6998 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
6999 ExecuteCalculateDrawProperties(root_impl);
7000 EXPECT_VECTOR2DF_EQ(
7001 gfx::Vector2dF(10.f, 0.f),
7002 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7003 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
7004 ExecuteCalculateDrawProperties(root_impl);
7005 EXPECT_VECTOR2DF_EQ(
7006 gfx::Vector2dF(10.f, 0.f),
7007 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7008
7009 // Finally it stops sticking when it hits the right side of the container.
7010 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
7011 ExecuteCalculateDrawProperties(root_impl);
7012 EXPECT_VECTOR2DF_EQ(
7013 gfx::Vector2dF(0.f, 0.f),
7014 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7015 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
7016 ExecuteCalculateDrawProperties(root_impl);
7017 EXPECT_VECTOR2DF_EQ(
7018 gfx::Vector2dF(-5.f, 0.f),
7019 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7020}
7021
7022// This test ensures that the compositor sticky position code correctly accounts
7023// for the element having been given a position from the main thread sticky
7024// position code.
7025TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
7026 scoped_refptr<Layer> root = Layer::Create();
7027 scoped_refptr<Layer> container = Layer::Create();
7028 scoped_refptr<Layer> scroller = Layer::Create();
7029 scoped_refptr<Layer> sticky_pos = Layer::Create();
7030 root->AddChild(container);
7031 container->AddChild(scroller);
7032 scroller->AddChild(sticky_pos);
7033 host()->SetRootLayer(root);
7034 scroller->SetScrollClipLayerId(container->id());
7035
7036 LayerStickyPositionConstraint sticky_position;
7037 sticky_position.is_sticky = true;
7038 sticky_position.is_anchored_top = true;
7039 sticky_position.top_offset = 10.0f;
7040 sticky_position.scroll_container_relative_sticky_box_rect =
7041 gfx::Rect(10, 20, 10, 10);
7042 sticky_position.scroll_container_relative_containing_block_rect =
7043 gfx::Rect(0, 0, 50, 50);
7044 sticky_pos->SetStickyPositionConstraint(sticky_position);
7045
7046 root->SetBounds(gfx::Size(100, 100));
7047 container->SetBounds(gfx::Size(100, 100));
7048 scroller->SetBounds(gfx::Size(1000, 1000));
7049 sticky_pos->SetBounds(gfx::Size(10, 10));
7050 sticky_pos->SetPosition(gfx::PointF(10, 20));
7051
7052 ExecuteCalculateDrawProperties(root.get());
7053 host()->host_impl()->CreatePendingTree();
7054 host()->CommitAndCreatePendingTree();
7055 host()->host_impl()->ActivateSyncTree();
7056 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7057
7058 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7059 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7060 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7061
7062 ExecuteCalculateDrawProperties(root_impl);
7063 EXPECT_VECTOR2DF_EQ(
7064 gfx::Vector2dF(10.f, 20.f),
7065 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7066
7067 // Scroll less than sticking point, sticky element should move with scroll as
7068 // we haven't gotten to the initial sticky item location yet.
7069 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7070 ExecuteCalculateDrawProperties(root_impl);
7071 EXPECT_VECTOR2DF_EQ(
7072 gfx::Vector2dF(5.f, 15.f),
7073 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7074
7075 // Scroll past the sticking point, the Y coordinate should now be clamped.
7076 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7077 ExecuteCalculateDrawProperties(root_impl);
7078 EXPECT_VECTOR2DF_EQ(
7079 gfx::Vector2dF(-5.f, 10.f),
7080 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7081
7082 // Now the main thread commits the new position of the sticky element.
7083 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
7084 sticky_pos->SetPosition(gfx::PointF(10, 25));
7085 ExecuteCalculateDrawProperties(root.get());
7086 host()->host_impl()->CreatePendingTree();
7087 host()->CommitAndCreatePendingTree();
7088 host()->host_impl()->ActivateSyncTree();
7089 layer_tree_impl = host()->host_impl()->active_tree();
7090 root_impl = layer_tree_impl->LayerById(root->id());
7091 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7092 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7093
7094 // The element should still be where it was before. We reset the delta to
7095 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
7096 // thread.
7097 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7098 ExecuteCalculateDrawProperties(root_impl);
7099 EXPECT_VECTOR2DF_EQ(
7100 gfx::Vector2dF(-5.f, 10.f),
7101 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7102
7103 // And if we scroll a little further it remains there.
7104 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7105 ExecuteCalculateDrawProperties(root_impl);
7106 EXPECT_VECTOR2DF_EQ(
7107 gfx::Vector2dF(-5.f, 10.f),
7108 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7109}
7110
7111// A transform on a sticky element should not affect its sticky position.
7112TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7113 scoped_refptr<Layer> root = Layer::Create();
7114 scoped_refptr<Layer> container = Layer::Create();
7115 scoped_refptr<Layer> scroller = Layer::Create();
7116 scoped_refptr<Layer> sticky_pos = Layer::Create();
7117 root->AddChild(container);
7118 container->AddChild(scroller);
7119 scroller->AddChild(sticky_pos);
7120 host()->SetRootLayer(root);
7121 scroller->SetScrollClipLayerId(container->id());
7122 gfx::Transform t;
7123 t.Scale(2, 2);
7124 sticky_pos->SetTransform(t);
7125
7126 LayerStickyPositionConstraint sticky_position;
7127 sticky_position.is_sticky = true;
7128 sticky_position.is_anchored_top = true;
7129 sticky_position.top_offset = 0.0f;
7130 sticky_position.scroll_container_relative_sticky_box_rect =
7131 gfx::Rect(0, 20, 10, 10);
7132 sticky_position.scroll_container_relative_containing_block_rect =
7133 gfx::Rect(0, 0, 50, 50);
7134 sticky_pos->SetStickyPositionConstraint(sticky_position);
7135
7136 root->SetBounds(gfx::Size(100, 100));
7137 container->SetBounds(gfx::Size(100, 100));
7138 scroller->SetBounds(gfx::Size(1000, 1000));
7139 sticky_pos->SetBounds(gfx::Size(10, 10));
7140 sticky_pos->SetPosition(gfx::PointF(0, 20));
7141
7142 ExecuteCalculateDrawProperties(root.get());
7143 host()->host_impl()->CreatePendingTree();
7144 host()->CommitAndCreatePendingTree();
7145 host()->host_impl()->ActivateSyncTree();
7146 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7147
7148 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7149 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7150 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7151
7152 ExecuteCalculateDrawProperties(root_impl);
7153 EXPECT_VECTOR2DF_EQ(
7154 gfx::Vector2dF(0.f, 20.f),
7155 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7156
7157 // Scroll less than sticking point, sticky element should move with scroll as
7158 // we haven't gotten to the initial sticky item location yet.
7159 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7160 ExecuteCalculateDrawProperties(root_impl);
7161 EXPECT_VECTOR2DF_EQ(
7162 gfx::Vector2dF(0.f, 5.f),
7163 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7164
7165 // Scroll past the sticking point, the box is positioned at the scroller
7166 // edge.
7167 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7168 ExecuteCalculateDrawProperties(root_impl);
7169 EXPECT_VECTOR2DF_EQ(
7170 gfx::Vector2dF(0.f, 0.f),
7171 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7172 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7173 ExecuteCalculateDrawProperties(root_impl);
7174 EXPECT_VECTOR2DF_EQ(
7175 gfx::Vector2dF(0.f, 0.f),
7176 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7177
7178 // Scroll past the end of the sticky container.
7179 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7180 ExecuteCalculateDrawProperties(root_impl);
7181 EXPECT_VECTOR2DF_EQ(
7182 gfx::Vector2dF(0.f, -10.f),
7183 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7184}
7185
7186// Tests that a transform does not affect the sticking points. The sticky
7187// element will however move relative to the viewport due to its transform.
7188TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7189 scoped_refptr<Layer> root = Layer::Create();
7190 scoped_refptr<Layer> container = Layer::Create();
7191 scoped_refptr<Layer> scroller = Layer::Create();
7192 scoped_refptr<Layer> sticky_container = Layer::Create();
7193 scoped_refptr<Layer> sticky_pos = Layer::Create();
7194 root->AddChild(container);
7195 container->AddChild(scroller);
7196 scroller->AddChild(sticky_container);
7197 sticky_container->AddChild(sticky_pos);
7198 host()->SetRootLayer(root);
7199 scroller->SetScrollClipLayerId(container->id());
7200 gfx::Transform t;
7201 t.Scale(2, 2);
7202 sticky_container->SetTransform(t);
7203
7204 LayerStickyPositionConstraint sticky_position;
7205 sticky_position.is_sticky = true;
7206 sticky_position.is_anchored_top = true;
7207 sticky_position.top_offset = 0.0f;
7208 sticky_position.scroll_container_relative_sticky_box_rect =
7209 gfx::Rect(0, 20, 10, 10);
7210 sticky_position.scroll_container_relative_containing_block_rect =
7211 gfx::Rect(0, 0, 50, 50);
7212 sticky_pos->SetStickyPositionConstraint(sticky_position);
7213
7214 root->SetBounds(gfx::Size(100, 100));
7215 container->SetBounds(gfx::Size(100, 100));
7216 scroller->SetBounds(gfx::Size(1000, 1000));
7217 sticky_container->SetBounds(gfx::Size(50, 50));
7218 sticky_pos->SetBounds(gfx::Size(10, 10));
7219 sticky_pos->SetPosition(gfx::PointF(0, 20));
7220
7221 ExecuteCalculateDrawProperties(root.get());
7222 host()->host_impl()->CreatePendingTree();
7223 host()->CommitAndCreatePendingTree();
7224 host()->host_impl()->ActivateSyncTree();
7225 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7226
7227 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7228 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7229 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7230
7231 ExecuteCalculateDrawProperties(root_impl);
7232 EXPECT_VECTOR2DF_EQ(
7233 gfx::Vector2dF(0.f, 40.f),
7234 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7235
7236 // Scroll less than sticking point, sticky element should move with scroll as
7237 // we haven't gotten to the initial sticky item location yet.
7238 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7239 ExecuteCalculateDrawProperties(root_impl);
7240 EXPECT_VECTOR2DF_EQ(
7241 gfx::Vector2dF(0.f, 25.f),
7242 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7243
7244 // Scroll past the sticking point, the box is positioned at the scroller
7245 // edge but is also scaled by its container so it begins to move down.
7246 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7247 ExecuteCalculateDrawProperties(root_impl);
7248 EXPECT_VECTOR2DF_EQ(
7249 gfx::Vector2dF(0.f, 25.f),
7250 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7251 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7252 ExecuteCalculateDrawProperties(root_impl);
7253 EXPECT_VECTOR2DF_EQ(
7254 gfx::Vector2dF(0.f, 30.f),
7255 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7256
7257 // Scroll past the end of the sticky container.
7258 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7259 ExecuteCalculateDrawProperties(root_impl);
7260 EXPECT_VECTOR2DF_EQ(
7261 gfx::Vector2dF(0.f, 30.f),
7262 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7263}
7264
jaydasikaaf1582f2016-08-10 18:39:387265TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7266 scoped_refptr<Layer> root = Layer::Create();
7267 scoped_refptr<Layer> container = Layer::Create();
7268 scoped_refptr<Layer> scroller = Layer::Create();
7269 scoped_refptr<Layer> fixed_pos = Layer::Create();
7270
7271 scroller->SetIsContainerForFixedPositionLayers(true);
7272 root->AddChild(container);
7273 container->AddChild(scroller);
7274 scroller->AddChild(fixed_pos);
7275 host()->SetRootLayer(root);
7276
7277 LayerPositionConstraint fixed_position;
7278 fixed_position.set_is_fixed_position(true);
7279 scroller->SetScrollClipLayerId(container->id());
7280 fixed_pos->SetPositionConstraint(fixed_position);
7281
7282 root->SetBounds(gfx::Size(50, 50));
7283 container->SetBounds(gfx::Size(50, 50));
7284 scroller->SetBounds(gfx::Size(50, 50));
7285 fixed_pos->SetBounds(gfx::Size(50, 50));
7286
7287 gfx::Transform rotate;
7288 rotate.RotateAboutXAxis(20);
7289 container->SetTransform(rotate);
7290
7291 ExecuteCalculateDrawProperties(root.get());
khushalsagar86928f92016-08-17 21:49:057292 TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree;
jaydasikaaf1582f2016-08-10 18:39:387293 gfx::Transform transform;
7294 tree.ComputeTranslation(fixed_pos->transform_tree_index(),
7295 container->transform_tree_index(), &transform);
7296 EXPECT_TRUE(transform.IsIdentity());
7297}
7298
sunxd8a9a60982016-07-29 18:46:567299TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
7300 // This test verifies that a fixed pos child of a scrolling layer doesn't get
7301 // snapped to integer coordinates.
7302 //
7303 // + root
7304 // + container
7305 // + scroller
7306 // + fixed_pos
7307 //
7308 scoped_refptr<Layer> root = Layer::Create();
7309 scoped_refptr<Layer> container = Layer::Create();
7310 scoped_refptr<Layer> scroller = Layer::Create();
7311 scoped_refptr<Layer> fixed_pos = Layer::Create();
7312
7313 scroller->SetIsContainerForFixedPositionLayers(true);
7314
7315 root->AddChild(container);
7316 container->AddChild(scroller);
7317 scroller->AddChild(fixed_pos);
7318 host()->SetRootLayer(root);
7319
7320 LayerPositionConstraint fixed_position;
7321 fixed_position.set_is_fixed_position(true);
7322 scroller->SetScrollClipLayerId(container->id());
7323 fixed_pos->SetPositionConstraint(fixed_position);
7324
7325 root->SetBounds(gfx::Size(50, 50));
7326 container->SetBounds(gfx::Size(50, 50));
7327 scroller->SetBounds(gfx::Size(100, 100));
7328 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7329 fixed_pos->SetBounds(gfx::Size(10, 10));
7330
7331 ExecuteCalculateDrawProperties(root.get());
7332
7333 host()->host_impl()->CreatePendingTree();
7334 host()->CommitAndCreatePendingTree();
7335 host()->host_impl()->ActivateSyncTree();
7336 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7337
7338 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7339 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7340 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
7341 gfx::Vector2dF scroll_delta(5.f, 9.f);
7342 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7343
7344 ExecuteCalculateDrawProperties(root_impl);
7345
7346 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7347 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7348 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7349
7350 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
7351 10.3f);
7352 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
7353 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
7354}
7355
[email protected]1c3626e2014-04-09 17:49:227356class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7357 public:
danakj60bc3bc2016-04-09 00:24:487358 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227359 LayerTreeImpl* tree_impl,
7360 int id) {
danakj60bc3bc2016-04-09 00:24:487361 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227362 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7363 }
7364
dcheng716bedf2014-10-21 09:51:087365 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227366
[email protected]1c3626e2014-04-09 17:49:227367 private:
7368 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7369 int id)
[email protected]a57cb8b12014-06-13 18:15:377370 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227371 SetDrawsContent(true);
7372 }
[email protected]1c3626e2014-04-09 17:49:227373};
7374
7375TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167376 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:227377 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567378 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017379 LayerTreeSettings settings = host()->GetSettings();
ajumab4a846f22015-08-24 19:13:447380 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167381 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7382 &shared_bitmap_manager, &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:487383 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227384 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487385 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227386 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487387 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227388 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487389 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227390 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7391
7392 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7393 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7394 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097395 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227396
danakjf78fb272016-07-26 19:06:157397 grand_parent->SetBounds(gfx::Size(1, 2));
7398 parent->SetBounds(gfx::Size(1, 2));
7399 child->SetBounds(gfx::Size(1, 2));
7400 grand_child->SetBounds(gfx::Size(1, 2));
7401
jaydasika89f7b5a2016-06-22 02:08:397402 child->test_properties()->AddChild(std::move(grand_child));
7403 parent->test_properties()->AddChild(std::move(child));
7404 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597405 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:057406
jaydasika2411692c2016-03-23 01:56:097407 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227408
7409 // No layers have animations.
sunxdf468675e2016-06-30 23:56:187410 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7411 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7412 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7413 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227414
sunxdf468675e2016-06-30 23:56:187415 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7416 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7417 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7418 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037419
[email protected]1c3626e2014-04-09 17:49:227420 TransformOperations translation;
7421 translation.AppendTranslate(1.f, 2.f, 3.f);
7422
loyso968163c92016-01-04 23:18:487423 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587424 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7425 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487426
vollickef2ae922016-06-29 17:54:277427 host_impl.active_tree()->SetElementIdsForTesting();
loysodb006882016-09-14 00:31:517428
7429 scoped_refptr<AnimationPlayer> grand_parent_player =
7430 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7431 timeline->AttachPlayer(grand_parent_player);
7432 grand_parent_player->AttachElement(grand_parent_raw->element_id());
7433
7434 scoped_refptr<AnimationPlayer> parent_player =
7435 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7436 timeline->AttachPlayer(parent_player);
7437 parent_player->AttachElement(parent_raw->element_id());
7438
7439 scoped_refptr<AnimationPlayer> child_player =
7440 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7441 timeline->AttachPlayer(child_player);
7442 child_player->AttachElement(child_raw->element_id());
7443
7444 scoped_refptr<AnimationPlayer> grand_child_player =
7445 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7446 timeline->AttachPlayer(grand_child_player);
7447 grand_child_player->AttachElement(grand_child_raw->element_id());
7448
7449 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7450 translation);
[email protected]1c3626e2014-04-09 17:49:227451
7452 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187453 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7454 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7455 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7456 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227457
sunxdf468675e2016-06-30 23:56:187458 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7459 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7460 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7461 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037462
[email protected]1c3626e2014-04-09 17:49:227463 TransformOperations scale;
7464 scale.AppendScale(5.f, 4.f, 3.f);
7465
loysodb006882016-09-14 00:31:517466 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7467 scale);
ajumacaaa9b32015-08-04 15:55:297468 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097469 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227470
7471 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:187472 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7473 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7474 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
7475 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227476
sunxdf468675e2016-06-30 23:56:187477 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7478 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7479 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
7480 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037481
loysodb006882016-09-14 00:31:517482 AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0,
7483 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097484 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7485 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227486
7487 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187488 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7489 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:227490 // We don't support combining animated scales from two nodes; 0.f means
7491 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:187492 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7493 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227494
sunxdf468675e2016-06-30 23:56:187495 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7496 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
7497 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7498 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037499
loysodb006882016-09-14 00:31:517500 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7501 scale);
ajumacaaa9b32015-08-04 15:55:297502 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097503 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227504
7505 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187506 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7507 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7508 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7509 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227510
sunxdf468675e2016-06-30 23:56:187511 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7512 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7513 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7514 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037515
loysodb006882016-09-14 00:31:517516 grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7517 parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7518 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
[email protected]1c3626e2014-04-09 17:49:227519
7520 TransformOperations perspective;
7521 perspective.AppendPerspective(10.f);
7522
loysodb006882016-09-14 00:31:517523 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7524 perspective);
ajumab4a846f22015-08-24 19:13:447525 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097526 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227527
7528 // |child| has a scale-affecting animation but computing the maximum of this
7529 // animation is not supported.
sunxdf468675e2016-06-30 23:56:187530 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7531 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7532 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7533 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227534
sunxdf468675e2016-06-30 23:56:187535 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7536 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7537 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7538 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037539
vollickef2ae922016-06-29 17:54:277540 AbortAnimationsOnElementWithPlayer(child_raw->element_id(), timeline,
7541 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227542 gfx::Transform scale_matrix;
7543 scale_matrix.Scale(1.f, 2.f);
jaydasika10d43fc2016-08-18 04:06:047544 grand_parent_raw->test_properties()->transform = scale_matrix;
7545 parent_raw->test_properties()->transform = scale_matrix;
jaydasika2411692c2016-03-23 01:56:097546 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487547
loysodb006882016-09-14 00:31:517548 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7549 scale);
jaydasika2411692c2016-03-23 01:56:097550 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227551
7552 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7553 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:187554 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7555 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7556 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
7557 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227558
sunxdf468675e2016-06-30 23:56:187559 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7560 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7561 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
7562 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037563
[email protected]1c3626e2014-04-09 17:49:227564 gfx::Transform perspective_matrix;
7565 perspective_matrix.ApplyPerspectiveDepth(2.f);
jaydasika10d43fc2016-08-18 04:06:047566 child_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097567 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7568 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227569
7570 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187571 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7572 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7573 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7574 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227575
sunxdf468675e2016-06-30 23:56:187576 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7577 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7578 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7579 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037580
jaydasika10d43fc2016-08-18 04:06:047581 parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097582 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7583 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227584
7585 // |parent| and |child| have transforms that are neither translations nor
7586 // scales.
sunxdf468675e2016-06-30 23:56:187587 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7588 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7589 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7590 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227591
sunxdf468675e2016-06-30 23:56:187592 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7593 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7594 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7595 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037596
jaydasika10d43fc2016-08-18 04:06:047597 parent_raw->test_properties()->transform = gfx::Transform();
7598 child_raw->test_properties()->transform = gfx::Transform();
7599 grand_parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097600 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227601
jaydasika2411692c2016-03-23 01:56:097602 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227603
7604 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187605 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7606 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7607 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7608 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037609
sunxdf468675e2016-06-30 23:56:187610 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7611 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7612 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7613 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227614}
7615
danakj59931942016-07-26 22:11:297616static void GatherDrawnLayers(const LayerImplList* rsll,
[email protected]390bb1ff2014-05-09 17:14:407617 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517618 for (LayerIterator it = LayerIterator::Begin(rsll),
7619 end = LayerIterator::End(rsll);
7620 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407621 LayerImpl* layer = *it;
7622 if (it.represents_itself())
7623 drawn_layers->insert(layer);
7624
7625 if (!it.represents_contributing_render_surface())
7626 continue;
7627
ajuma1d4026a32016-06-14 13:18:507628 if (layer->render_surface()->MaskLayer())
7629 drawn_layers->insert(layer->render_surface()->MaskLayer());
[email protected]390bb1ff2014-05-09 17:14:407630 }
7631}
7632
7633TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167634 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407635 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567636 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167637 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567638 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407639
danakj60bc3bc2016-04-09 00:24:487640 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407641 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487642 std::unique_ptr<LayerImpl> parent =
7643 LayerImpl::Create(host_impl.active_tree(), 3);
7644 std::unique_ptr<LayerImpl> child =
7645 LayerImpl::Create(host_impl.active_tree(), 5);
7646 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407647 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487648 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407649 LayerImpl::Create(host_impl.active_tree(), 9);
7650
7651 LayerImpl* grand_parent_raw = grand_parent.get();
7652 LayerImpl* parent_raw = parent.get();
7653 LayerImpl* child_raw = child.get();
7654 LayerImpl* grand_child1_raw = grand_child1.get();
7655 LayerImpl* grand_child2_raw = grand_child2.get();
7656
danakjf78fb272016-07-26 19:06:157657 grand_parent->SetBounds(gfx::Size(1, 2));
7658 parent->SetBounds(gfx::Size(1, 2));
7659 child->SetBounds(gfx::Size(1, 2));
7660 grand_child1->SetBounds(gfx::Size(1, 2));
7661 grand_child2->SetBounds(gfx::Size(1, 2));
7662
jaydasika89f7b5a2016-06-22 02:08:397663 child->test_properties()->AddChild(std::move(grand_child1));
7664 child->test_properties()->AddChild(std::move(grand_child2));
7665 parent->test_properties()->AddChild(std::move(child));
7666 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597667 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407668
[email protected]390bb1ff2014-05-09 17:14:407669 // Start with nothing being drawn.
7670 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407671
ajuma0adb5902016-04-28 16:32:387672 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7673 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7674 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7675 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7676 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407677
7678 std::set<LayerImpl*> expected;
7679 std::set<LayerImpl*> actual;
7680 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7681 EXPECT_EQ(expected, actual);
7682
7683 // If we force render surface, but none of the layers are in the layer list,
7684 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007685 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127686 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407687
7688 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407689
ajuma0adb5902016-04-28 16:32:387690 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7691 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7692 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7693 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7694 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407695
7696 expected.clear();
7697 actual.clear();
7698 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7699 EXPECT_EQ(expected, actual);
7700
7701 // However, if we say that this layer also draws content, it will appear in
7702 // RSLL.
7703 grand_child1_raw->SetDrawsContent(true);
7704
7705 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407706
ajuma0adb5902016-04-28 16:32:387707 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7708 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7709 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7710 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7711 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407712
7713 expected.clear();
7714 expected.insert(grand_child1_raw);
7715
7716 actual.clear();
7717 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7718 EXPECT_EQ(expected, actual);
7719
7720 // Now child is forced to have a render surface, and one if its children draws
7721 // content.
7722 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007723 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127724 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007725 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407726 grand_child2_raw->SetDrawsContent(true);
7727
7728 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407729
ajuma0adb5902016-04-28 16:32:387730 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7731 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7732 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7733 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7734 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407735
7736 expected.clear();
7737 expected.insert(grand_child2_raw);
7738
7739 actual.clear();
7740 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7741 EXPECT_EQ(expected, actual);
7742
7743 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:507744 child_raw->test_properties()->SetMaskLayer(
7745 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047746 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407747
7748 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407749
ajuma0adb5902016-04-28 16:32:387750 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7751 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7752 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507753 EXPECT_TRUE(child_raw->test_properties()
7754 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387755 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7756 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407757
7758 expected.clear();
7759 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507760 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407761
7762 expected.clear();
7763 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507764 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407765
7766 actual.clear();
7767 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7768 EXPECT_EQ(expected, actual);
7769
[email protected]390bb1ff2014-05-09 17:14:407770 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407771
ajuma0adb5902016-04-28 16:32:387772 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7773 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7774 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507775 EXPECT_TRUE(child_raw->test_properties()
7776 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387777 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7778 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407779
7780 expected.clear();
7781 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507782 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407783
7784 actual.clear();
7785 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7786 EXPECT_EQ(expected, actual);
7787
ajuma1d4026a32016-06-14 13:18:507788 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407789
7790 // With nothing drawing, we should have no layers.
7791 grand_child2_raw->SetDrawsContent(false);
7792
7793 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407794
ajuma0adb5902016-04-28 16:32:387795 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7796 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7797 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507798 EXPECT_FALSE(child_raw->test_properties()
7799 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387800 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7801 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407802
7803 expected.clear();
7804 actual.clear();
7805 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7806 EXPECT_EQ(expected, actual);
7807
7808 // Child itself draws means that we should have the child and the mask in the
7809 // list.
7810 child_raw->SetDrawsContent(true);
7811
7812 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407813
ajuma0adb5902016-04-28 16:32:387814 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7815 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7816 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507817 EXPECT_TRUE(child_raw->test_properties()
7818 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387819 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7820 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407821
7822 expected.clear();
7823 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:507824 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407825 actual.clear();
7826 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7827 EXPECT_EQ(expected, actual);
7828
ajuma1d4026a32016-06-14 13:18:507829 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:047830 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407831
7832 // Now everyone's a member!
7833 grand_parent_raw->SetDrawsContent(true);
7834 parent_raw->SetDrawsContent(true);
7835 child_raw->SetDrawsContent(true);
7836 grand_child1_raw->SetDrawsContent(true);
7837 grand_child2_raw->SetDrawsContent(true);
7838
7839 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407840
ajuma0adb5902016-04-28 16:32:387841 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7842 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
7843 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
7844 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7845 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407846
7847 expected.clear();
7848 expected.insert(grand_parent_raw);
7849 expected.insert(parent_raw);
7850 expected.insert(child_raw);
7851 expected.insert(grand_child1_raw);
7852 expected.insert(grand_child2_raw);
7853
7854 actual.clear();
7855 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7856 EXPECT_EQ(expected, actual);
7857}
[email protected]18e69652014-06-13 12:50:587858
7859TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167860 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587861 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567862 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017863 LayerTreeSettings settings = host()->GetSettings();
enne637715732015-07-07 02:05:267864 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167865 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7866 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587867
danakj60bc3bc2016-04-09 00:24:487868 std::unique_ptr<LayerImpl> root =
7869 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:587870 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:487871 std::unique_ptr<LayerImpl> child1 =
7872 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:587873 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:487874 std::unique_ptr<LayerImpl> child2 =
7875 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:587876 LayerImpl* child2_layer = child2.get();
7877
danakjf78fb272016-07-26 19:06:157878 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:587879 scale_transform_child1.Scale(2, 3);
7880 scale_transform_child2.Scale(4, 5);
7881
danakjf78fb272016-07-26 19:06:157882 root->SetBounds(gfx::Size(1, 1));
7883 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:047884 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:157885 child1_layer->SetBounds(gfx::Size(1, 1));
7886 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587887
ajuma1d4026a32016-06-14 13:18:507888 child1_layer->test_properties()->SetMaskLayer(
7889 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:587890
danakjf78fb272016-07-26 19:06:157891 root->test_properties()->AddChild(std::move(child1));
7892 root->test_properties()->AddChild(std::move(child2));
7893 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7894 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:587895
7896 ExecuteCalculateDrawProperties(root_layer);
7897
7898 TransformOperations scale;
7899 scale.AppendScale(5.f, 8.f, 3.f);
7900
loyso9556c732016-03-11 07:54:587901 scoped_refptr<AnimationTimeline> timeline =
7902 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7903 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487904
jaydasika10d43fc2016-08-18 04:06:047905 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:157906 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:287907 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:277908 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
7909 1.0, TransformOperations(), scale);
7910
jaydasika2411692c2016-03-23 01:56:097911 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587912 ExecuteCalculateDrawProperties(root_layer);
7913
enne637715732015-07-07 02:05:267914 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7915 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:507916 EXPECT_FLOAT_EQ(
7917 3.f,
7918 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267919 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587920
sunxdf468675e2016-06-30 23:56:187921 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7922 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7923 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587924
[email protected]18e69652014-06-13 12:50:587925 // Changing page-scale would affect ideal_contents_scale and
7926 // maximum_animation_contents_scale.
7927
7928 float page_scale_factor = 3.f;
7929 float device_scale_factor = 1.0f;
7930 std::vector<LayerImpl*> render_surface_layer_list;
7931 gfx::Size device_viewport_size =
7932 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7933 root_layer->bounds().height() * device_scale_factor);
7934 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387935 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:587936
7937 inputs.page_scale_factor = page_scale_factor;
7938 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117939 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:577940 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587941
enne637715732015-07-07 02:05:267942 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7943 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587944 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267945 9.f,
ajuma1d4026a32016-06-14 13:18:507946 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267947 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587948
sunxdf468675e2016-06-30 23:56:187949 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7950 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7951 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587952
[email protected]18e69652014-06-13 12:50:587953 // Changing device-scale would affect ideal_contents_scale and
7954 // maximum_animation_contents_scale.
7955
7956 device_scale_factor = 4.0f;
7957 inputs.device_scale_factor = device_scale_factor;
7958 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097959 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:577960 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587961
enne637715732015-07-07 02:05:267962 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7963 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587964 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267965 36.f,
ajuma1d4026a32016-06-14 13:18:507966 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267967 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587968
sunxdf468675e2016-06-30 23:56:187969 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7970 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7971 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
7972}
7973
7974TEST_F(LayerTreeHostCommonTest, AnimationScales) {
7975 FakeImplTaskRunnerProvider task_runner_provider;
7976 TestSharedBitmapManager shared_bitmap_manager;
7977 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017978 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:187979 settings.layer_transforms_should_scale_layer_contents = true;
7980 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7981 &shared_bitmap_manager, &task_graph_runner);
7982
7983 std::unique_ptr<LayerImpl> root =
7984 LayerImpl::Create(host_impl.active_tree(), 1);
7985 LayerImpl* root_layer = root.get();
7986 std::unique_ptr<LayerImpl> child1 =
7987 LayerImpl::Create(host_impl.active_tree(), 2);
7988 LayerImpl* child1_layer = child1.get();
7989 std::unique_ptr<LayerImpl> child2 =
7990 LayerImpl::Create(host_impl.active_tree(), 3);
7991 LayerImpl* child2_layer = child2.get();
7992
7993 root->test_properties()->AddChild(std::move(child1));
7994 child1_layer->test_properties()->AddChild(std::move(child2));
7995 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7996
7997 host_impl.active_tree()->SetElementIdsForTesting();
7998
danakjf78fb272016-07-26 19:06:157999 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:188000 scale_transform_child1.Scale(2, 3);
8001 scale_transform_child2.Scale(4, 5);
8002
danakjf78fb272016-07-26 19:06:158003 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048004 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158005 child1_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048006 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158007 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:188008
8009 TransformOperations scale;
8010 scale.AppendScale(5.f, 8.f, 3.f);
8011
8012 scoped_refptr<AnimationTimeline> timeline =
8013 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8014 host_impl.animation_host()->AddAnimationTimeline(timeline);
8015
8016 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8017 1.0, TransformOperations(), scale);
8018
sunxdf468675e2016-06-30 23:56:188019 // Correctly computes animation scale when rebuilding property trees.
8020 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8021 ExecuteCalculateDrawProperties(root_layer);
8022
8023 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8024 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8025 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
8026
8027 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8028 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
8029 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
8030
8031 // Correctly updates animation scale when layer property changes.
jaydasika10d43fc2016-08-18 04:06:048032 child1_layer->test_properties()->transform = gfx::Transform();
jaydasika09e16132016-08-24 21:39:348033 root_layer->layer_tree_impl()
8034 ->property_trees()
8035 ->transform_tree.OnTransformAnimated(gfx::Transform(),
8036 child1_layer->transform_tree_index(),
8037 root_layer->layer_tree_impl());
sunxdf468675e2016-06-30 23:56:188038 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
8039 ExecuteCalculateDrawProperties(root_layer);
8040 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
8041 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
8042
8043 // Do not update animation scale if already updated.
8044 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
8045 child2_layer->transform_tree_index(), 100.f, 100.f);
8046 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
8047 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
8048}
8049
8050TEST_F(LayerTreeHostCommonTest,
8051 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
8052 // Returns empty scale if layer_transforms_should_scale_layer_contents is
8053 // false.
8054 FakeImplTaskRunnerProvider task_runner_provider;
8055 TestSharedBitmapManager shared_bitmap_manager;
8056 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018057 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188058 settings.layer_transforms_should_scale_layer_contents = false;
8059 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
8060 &shared_bitmap_manager, &task_graph_runner);
8061
8062 std::unique_ptr<LayerImpl> root =
8063 LayerImpl::Create(host_impl.active_tree(), 1);
8064 LayerImpl* root_layer = root.get();
8065 std::unique_ptr<LayerImpl> child =
8066 LayerImpl::Create(host_impl.active_tree(), 2);
8067 LayerImpl* child_layer = child.get();
8068
8069 root->test_properties()->AddChild(std::move(child));
8070 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8071
8072 host_impl.active_tree()->SetElementIdsForTesting();
8073
danakjf78fb272016-07-26 19:06:158074 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:188075 scale_transform_child.Scale(4, 5);
8076
danakjf78fb272016-07-26 19:06:158077 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048078 child_layer->test_properties()->transform = scale_transform_child;
danakjf78fb272016-07-26 19:06:158079 child_layer->SetBounds(gfx::Size(1, 1));
8080
sunxdf468675e2016-06-30 23:56:188081 TransformOperations scale;
8082 scale.AppendScale(5.f, 8.f, 3.f);
8083
8084 scoped_refptr<AnimationTimeline> timeline =
8085 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8086 host_impl.animation_host()->AddAnimationTimeline(timeline);
8087
8088 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
8089 1.0, TransformOperations(), scale);
8090
sunxdf468675e2016-06-30 23:56:188091 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8092 ExecuteCalculateDrawProperties(root_layer);
8093
8094 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8095 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
8096
8097 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8098 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:588099}
8100
danakjf6069db2014-09-13 00:46:478101TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598102 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148103 LayerImpl* clip = AddChild<LayerImpl>(root);
8104 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:478105
danakjf78fb272016-07-26 19:06:158106 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:148107 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158108 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:478109 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158110 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:148111 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158112 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:478113
8114 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:148115 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:148116 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakjf78fb272016-07-26 19:06:158117 root, device_viewport_size, gfx::Transform(),
ajuma0adb5902016-04-28 16:32:388118 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:478119 inputs.device_scale_factor = 2.f;
8120 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:298121 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:578122 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478123
8124 // Layers in the root render surface have their visible content rect clipped
8125 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148126 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478127
8128 // Layers drawing to a child render surface should still have their visible
8129 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148130 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478131}
8132
timav599f4359d2014-12-05 00:12:228133TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168134 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:228135 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568136 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168137 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568138 &task_graph_runner);
timav599f4359d2014-12-05 00:12:228139
8140 // Set two layers: the root layer clips it's child,
8141 // the child draws its content.
8142
8143 gfx::Size root_size = gfx::Size(300, 500);
8144
8145 // Sublayer should be bigger than the root enlarged by bounds_delta.
8146 gfx::Size sublayer_size = gfx::Size(300, 1000);
8147
8148 // Device viewport accomidated the root and the top controls.
8149 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:228150
miletus8bd08a622015-06-16 18:44:528151 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:598152 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:228153 LayerImpl::Create(host_impl.active_tree(), 1));
8154
jaydasikabf1875a2016-06-28 03:39:598155 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:158156 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:228157 root->SetMasksToBounds(true);
8158
jaydasika89f7b5a2016-06-22 02:08:398159 root->test_properties()->AddChild(
8160 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:228161
jaydasikafc66cfb2016-06-10 04:34:228162 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:158163 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:228164 sublayer->SetDrawsContent(true);
8165
danakj74af409e2016-07-01 00:41:488166 host_impl.active_tree()->BuildPropertyTreesForTesting();
8167
timav599f4359d2014-12-05 00:12:228168 LayerImplList layer_impl_list;
8169 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388170 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:228171
sunxdb365de02016-04-28 20:32:578172 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438173 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228174
8175 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578176 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228177
8178 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8179 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438180 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228181}
8182
ajumadd2802e72015-06-30 20:28:298183TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318184 scoped_refptr<Layer> root = Layer::Create();
8185 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8186 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8187 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8188 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298189
8190 root->AddChild(inner_viewport_container_layer);
8191 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8192 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8193 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8194
8195 inner_viewport_scroll_layer->SetScrollClipLayerId(
8196 inner_viewport_container_layer->id());
8197 outer_viewport_scroll_layer->SetScrollClipLayerId(
8198 outer_viewport_container_layer->id());
8199
8200 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8201 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8202
8203 host()->SetRootLayer(root);
khushalsagar86928f92016-08-17 21:49:058204 host()->GetLayerTree()->RegisterViewportLayers(
8205 nullptr, root, inner_viewport_scroll_layer, outer_viewport_scroll_layer);
ajumadd2802e72015-06-30 20:28:298206
loyso0940d412016-03-14 01:30:318207 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8208 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298209
8210 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8211 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8212
8213 LayerPositionConstraint fixed_to_right;
8214 fixed_to_right.set_is_fixed_position(true);
8215 fixed_to_right.set_is_fixed_to_right_edge(true);
8216
8217 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8218 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8219
jaydasika6ed869662016-09-21 14:29:598220 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298221
8222 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8223 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8224 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8225
8226 LayerPositionConstraint fixed_to_left;
8227 fixed_to_left.set_is_fixed_position(true);
8228 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8229
jaydasika6ed869662016-09-21 14:29:598230 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298231 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8232 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8233
8234 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8235
jaydasika6ed869662016-09-21 14:29:598236 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298237 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8238 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8239}
8240
vollick7d83b452015-02-24 20:18:068241TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
sunxd713aedbd2016-08-10 22:22:148242 host_impl()->CreatePendingTree();
8243 std::unique_ptr<LayerImpl> pending_root =
8244 LayerImpl::Create(host_impl()->pending_tree(), 1);
8245 LayerImpl* root = pending_root.get();
8246 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root));
8247 std::unique_ptr<LayerImpl> animated_ptr =
8248 LayerImpl::Create(host_impl()->pending_tree(), 2);
8249 LayerImpl* animated = animated_ptr.get();
8250 root->test_properties()->AddChild(std::move(animated_ptr));
vollick7d83b452015-02-24 20:18:068251
sunxd713aedbd2016-08-10 22:22:148252 animated->SetDrawsContent(true);
8253 host_impl()->pending_tree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278254
danakjf78fb272016-07-26 19:06:158255 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:068256 root->SetMasksToBounds(true);
sunxd713aedbd2016-08-10 22:22:148257 root->test_properties()->force_render_surface = true;
8258 animated->test_properties()->opacity = 0.f;
danakjf78fb272016-07-26 19:06:158259 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:068260
sunxd713aedbd2016-08-10 22:22:148261 AddOpacityTransitionToElementWithPlayer(
8262 animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false);
8263 animated->test_properties()->opacity_can_animate = true;
8264 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598265 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
vollick7d83b452015-02-24 20:18:068266
sunxd713aedbd2016-08-10 22:22:148267 EXPECT_FALSE(animated->visible_layer_rect().IsEmpty());
vollick7d83b452015-02-24 20:18:068268}
8269
ajumaa92fdc12015-03-31 22:47:418270TEST_F(LayerTreeHostCommonTest,
8271 VisibleContentRectForAnimatedLayerWithSingularTransform) {
sunxd713aedbd2016-08-10 22:22:148272 LayerImpl* root = root_layer_for_testing();
8273 LayerImpl* clip = AddChild<LayerImpl>(root);
8274 LayerImpl* animated = AddChild<LayerImpl>(clip);
8275 LayerImpl* surface = AddChild<LayerImpl>(animated);
8276 LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface);
ajumaa92fdc12015-03-31 22:47:418277
sunxd713aedbd2016-08-10 22:22:148278 SetElementIdsForTesting();
ajumaa92fdc12015-03-31 22:47:418279
sunxd713aedbd2016-08-10 22:22:148280 animated->SetDrawsContent(true);
8281 surface->SetDrawsContent(true);
8282 descendant_of_animation->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278283
ajumaa92fdc12015-03-31 22:47:418284 gfx::Transform uninvertible_matrix;
8285 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8286
danakjf78fb272016-07-26 19:06:158287 root->SetBounds(gfx::Size(100, 100));
8288 clip->SetBounds(gfx::Size(10, 10));
8289 clip->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:048290 animated->test_properties()->transform = uninvertible_matrix;
danakjf78fb272016-07-26 19:06:158291 animated->SetBounds(gfx::Size(120, 120));
8292 surface->SetBounds(gfx::Size(100, 100));
sunxd713aedbd2016-08-10 22:22:148293 surface->test_properties()->force_render_surface = true;
danakjf78fb272016-07-26 19:06:158294 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:418295
8296 TransformOperations start_transform_operations;
8297 start_transform_operations.AppendMatrix(uninvertible_matrix);
8298 TransformOperations end_transform_operations;
8299
sunxd713aedbd2016-08-10 22:22:148300 AddAnimatedTransformToElementWithPlayer(
8301 animated->element_id(), timeline_impl(), 10.0, start_transform_operations,
8302 end_transform_operations);
jaydasika6ed869662016-09-21 14:29:598303 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
ajumaa92fdc12015-03-31 22:47:418304
8305 // The animated layer has a singular transform and maps to a non-empty rect in
8306 // clipped target space, so is treated as fully visible.
sunxd713aedbd2016-08-10 22:22:148307 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418308
8309 // The singular transform on |animated| is flattened when inherited by
8310 // |surface|, and this happens to make it invertible.
sunxd713aedbd2016-08-10 22:22:148311 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect());
8312 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418313
8314 gfx::Transform zero_matrix;
8315 zero_matrix.Scale3d(0.f, 0.f, 0.f);
jaydasika09e16132016-08-24 21:39:348316 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
8317 zero_matrix, animated->transform_tree_index(), root->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:598318 // While computing visible rects by combining clips in screen space, we set
8319 // the entire layer as visible if the screen space transform is singular. This
8320 // is not always true when we combine clips in target space because if the
8321 // intersection of combined_clip in taret space with layer_rect projected to
8322 // target space is empty, we set it to an empty rect.
8323 bool skip_verify_visible_rect_calculations = true;
8324 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
8325 root, skip_verify_visible_rect_calculations);
ajumaa92fdc12015-03-31 22:47:418326
8327 // The animated layer maps to the empty rect in clipped target space, so is
8328 // treated as having an empty visible rect.
sunxd713aedbd2016-08-10 22:22:148329 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418330
jaydasika6ed869662016-09-21 14:29:598331 // The animated layer will be treated as fully visible when we combine clips
8332 // in screen space.
8333 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
8334 root->layer_tree_impl()->property_trees(), animated);
8335 EXPECT_EQ(gfx::Rect(120, 120), visible_rect);
8336
ajumaa92fdc12015-03-31 22:47:418337 // This time, flattening does not make |animated|'s transform invertible. This
8338 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348339 // |surface| and layers that draw into it as having empty visible rect.
sunxd713aedbd2016-08-10 22:22:148340 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect());
8341 EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418342}
8343
ajuma20384bf2016-07-22 13:26:158344// Verify that having animated opacity but current opacity 1 still creates
8345// a render surface.
8346TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
8347 LayerImpl* root = root_layer_for_testing();
8348 LayerImpl* child = AddChild<LayerImpl>(root);
8349 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:158350
danakjf78fb272016-07-26 19:06:158351 root->SetBounds(gfx::Size(50, 50));
8352 child->SetBounds(gfx::Size(50, 50));
8353 child->SetDrawsContent(true);
8354 grandchild->SetBounds(gfx::Size(50, 50));
8355 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:158356
8357 SetElementIdsForTesting();
8358 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
8359 10.0, 1.f, 0.2f, false);
8360 ExecuteCalculateDrawProperties(root);
8361
8362 EXPECT_EQ(1.f, child->Opacity());
8363 EXPECT_TRUE(root->has_render_surface());
8364 EXPECT_TRUE(child->has_render_surface());
8365 EXPECT_FALSE(grandchild->has_render_surface());
8366}
8367
enne92f2f6d92015-02-25 23:13:318368// Verify that having an animated filter (but no current filter, as these
8369// are mutually exclusive) correctly creates a render surface.
8370TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598371 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328372 LayerImpl* child = AddChild<LayerImpl>(root);
8373 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318374
danakjf78fb272016-07-26 19:06:158375 root->SetBounds(gfx::Size(50, 50));
8376 child->SetBounds(gfx::Size(50, 50));
8377 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:318378
vollickef2ae922016-06-29 17:54:278379 SetElementIdsForTesting();
8380 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
8381 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:328382 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318383
ennec1332992015-08-24 19:45:098384 EXPECT_TRUE(root->has_render_surface());
8385 EXPECT_TRUE(child->has_render_surface());
8386 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318387
ajumacb2b74432016-07-21 19:11:158388 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8389 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:318390
8391 EXPECT_FALSE(root->FilterIsAnimating());
8392 EXPECT_TRUE(child->FilterIsAnimating());
8393 EXPECT_FALSE(grandchild->FilterIsAnimating());
8394}
8395
ajuma315a4782015-07-24 21:16:348396// Verify that having a filter animation with a delayed start time creates a
8397// render surface.
8398TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598399 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328400 LayerImpl* child = AddChild<LayerImpl>(root);
8401 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348402
danakjf78fb272016-07-26 19:06:158403 root->SetBounds(gfx::Size(50, 50));
8404 child->SetBounds(gfx::Size(50, 50));
8405 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:348406
vollickef2ae922016-06-29 17:54:278407 SetElementIdsForTesting();
8408
danakj60bc3bc2016-04-09 00:24:488409 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348410 KeyframedFilterAnimationCurve::Create());
8411 FilterOperations start_filters;
8412 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8413 FilterOperations end_filters;
8414 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8415 curve->AddKeyframe(
8416 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8417 curve->AddKeyframe(FilterKeyframe::Create(
8418 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488419 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308420 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558421 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348422 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348423
vollickef2ae922016-06-29 17:54:278424 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
8425 std::move(animation));
ajuma4711f4b12016-05-16 18:48:328426 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348427
ennec1332992015-08-24 19:45:098428 EXPECT_TRUE(root->has_render_surface());
8429 EXPECT_TRUE(child->has_render_surface());
8430 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348431
ajumacb2b74432016-07-21 19:11:158432 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8433 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:348434
8435 EXPECT_FALSE(root->FilterIsAnimating());
8436 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8437 EXPECT_FALSE(child->FilterIsAnimating());
8438 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8439 EXPECT_FALSE(grandchild->FilterIsAnimating());
8440 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8441}
8442
vollick0120eb22015-03-02 03:07:348443// Ensures that the property tree code accounts for offsets between fixed
8444// position layers and their respective containers.
8445TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:598446 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148447 LayerImpl* child = AddChild<LayerImpl>(root);
8448 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348449
danakjf78fb272016-07-26 19:06:158450 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:348451 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528452 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158453 child->SetPosition(gfx::PointF(1000, 1000));
8454 child->SetBounds(gfx::Size(50, 50));
8455 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8456 grandchild->SetBounds(gfx::Size(50, 50));
8457 grandchild->SetDrawsContent(true);
8458
vollick0120eb22015-03-02 03:07:348459 LayerPositionConstraint constraint;
8460 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528461 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:348462
jaydasika6f972de2016-04-07 16:16:148463 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348464
jaydasika6f972de2016-04-07 16:16:148465 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348466}
8467
ajuma0178b522015-07-02 21:08:418468// Ensures that the property tree code accounts for offsets between fixed
8469// position containers and their transform tree parents, when a fixed position
8470// layer's container is its layer tree parent, but this parent doesn't have its
8471// own transform tree node.
8472TEST_F(LayerTreeHostCommonTest,
8473 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:598474 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148475 LayerImpl* child = AddChild<LayerImpl>(root);
8476 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418477
danakjf78fb272016-07-26 19:06:158478 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:418479 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158480 root->test_properties()->is_container_for_fixed_position_layers = true;
8481 child->SetPosition(gfx::PointF(1000, 1000));
8482 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:528483 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158484 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8485 grandchild->SetBounds(gfx::Size(50, 50));
8486 grandchild->SetDrawsContent(true);
8487
ajuma0178b522015-07-02 21:08:418488 LayerPositionConstraint constraint;
8489 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528490 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:418491
jaydasika6f972de2016-04-07 16:16:148492 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418493
jaydasika6f972de2016-04-07 16:16:148494 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418495}
8496
vollick8c824742015-03-20 22:21:088497TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:598498 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148499 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8500 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088501 gfx::Transform translate_z;
8502 translate_z.Translate3d(0, 0, 10);
8503
danakjf78fb272016-07-26 19:06:158504 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:528505 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088506
danakjf78fb272016-07-26 19:06:158507 frame_clip->SetPosition(gfx::PointF(500, 100));
8508 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:088509 frame_clip->SetMasksToBounds(true);
8510
danakjf78fb272016-07-26 19:06:158511 fixed->SetBounds(gfx::Size(1000, 1000));
8512 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088513
8514 LayerPositionConstraint constraint;
8515 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528516 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:088517
jaydasika6f972de2016-04-07 16:16:148518 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088519
8520 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148521 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088522}
8523
vollick06ca3e832015-03-31 19:37:128524TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:598525 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148526 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8527 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8528 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8529
danakjf78fb272016-07-26 19:06:158530 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:148531 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158532 root->test_properties()->is_container_for_fixed_position_layers = true;
8533 frame_clip->SetPosition(gfx::PointF(500, 100));
8534 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148535 frame_clip->SetMasksToBounds(true);
8536 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158537 scroller->SetBounds(gfx::Size(1000, 1000));
jaydasika6f972de2016-04-07 16:16:148538 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8539 scroller->SetScrollClipLayer(frame_clip->id());
8540 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158541 fixed->SetPosition(gfx::PointF(100, 100));
8542 fixed->SetBounds(gfx::Size(50, 50));
8543 fixed->SetMasksToBounds(true);
8544 fixed->SetDrawsContent(true);
8545 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:128546
8547 LayerPositionConstraint constraint;
8548 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528549 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128550
jaydasika6f972de2016-04-07 16:16:148551 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128552
8553 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148554 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128555}
8556
vollick5057e1e2015-04-17 19:12:328557TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:328558 gfx::Transform translate;
8559 gfx::Transform rotate;
8560
8561 translate.Translate(10, 10);
8562 rotate.Rotate(45);
8563
loyso0940d412016-03-14 01:30:318564 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:158565 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:328566 root->SetIsContainerForFixedPositionLayers(true);
8567
ennea7b43c32015-06-18 20:01:338568 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328569
jaydasika6ed869662016-09-21 14:29:598570 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ennea7b43c32015-06-18 20:01:338571 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328572
8573 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338574 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328575
8576 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338577 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328578}
8579
ajumab0e0c1c2015-04-23 00:29:238580TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:598581 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148582 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238583
ajumab0e0c1c2015-04-23 00:29:238584 gfx::Transform scale_matrix;
8585 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:238586
danakjf78fb272016-07-26 19:06:158587 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148588 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048589 child->test_properties()->transform = scale_matrix;
danakjf78fb272016-07-26 19:06:158590 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148591 child->SetDrawsContent(true);
8592
8593 ExecuteCalculateDrawProperties(root);
8594 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238595
jaydasika38be7a822016-04-21 16:07:068596 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238597
jaydasika6f972de2016-04-07 16:16:148598 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8599 ExecuteCalculateDrawProperties(root);
8600 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238601}
8602
ajumaf09db8962015-04-24 21:55:348603TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:598604 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148605 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8606 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348607
ajumaf09db8962015-04-24 21:55:348608 gfx::Transform scale;
8609 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:158610
8611 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:048612 scroll_child->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:158613 scroll_child->SetBounds(gfx::Size(40, 40));
8614 scroll_child->SetDrawsContent(true);
8615 scroll_parent->SetBounds(gfx::Size(30, 30));
8616 scroll_parent->SetDrawsContent(true);
8617
8618 scroll_child->test_properties()->scroll_parent = scroll_parent;
8619 scroll_parent->test_properties()->scroll_children =
8620 base::MakeUnique<std::set<LayerImpl*>>();
8621 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:348622
jaydasika6f972de2016-04-07 16:16:148623 ExecuteCalculateDrawProperties(root);
8624 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348625
8626 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148627 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8628 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8629 ExecuteCalculateDrawProperties(root);
8630 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348631}
8632
danakj60bc3bc2016-04-09 00:24:488633static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128634
sunxded58688e2016-01-11 21:01:028635TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8636 // If the layer has a node in effect_tree, the return value of
8637 // num_copy_requests_in_target_subtree() must be equal to the actual number
8638 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8639 // to be the value of its nearest ancestor that owns an effect node and
8640 // greater than or equal to the actual number of copy requests in the
8641 // sub-layer_tree.
8642
loyso0940d412016-03-14 01:30:318643 scoped_refptr<Layer> root = Layer::Create();
8644 scoped_refptr<Layer> child1 = Layer::Create();
8645 scoped_refptr<Layer> child2 = Layer::Create();
8646 scoped_refptr<Layer> grandchild = Layer::Create();
8647 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028648
8649 root->AddChild(child1);
8650 root->AddChild(child2);
8651 child1->AddChild(grandchild);
8652 grandchild->AddChild(greatgrandchild);
8653 host()->SetRootLayer(root);
8654
8655 child1->RequestCopyOfOutput(
8656 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8657 greatgrandchild->RequestCopyOfOutput(
8658 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8659 child2->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598660 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:028661
8662 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8663 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8664 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8665 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8666 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8667}
8668
vollick2175fae82015-04-27 21:18:128669TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:318670 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328671 FakeContentLayerClient client;
8672 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128673 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318674 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128675 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318676 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258677 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318678 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:158679
8680 root->SetBounds(gfx::Size(100, 100));
8681 child->SetBounds(gfx::Size(10, 10));
8682 grandchild->SetBounds(gfx::Size(10, 10));
8683 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128684
8685 root->AddChild(child);
8686 child->AddChild(grandchild);
8687 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:338688 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:088689 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278690
vollick2175fae82015-04-27 21:18:128691 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598692 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148693 const LayerList* update_list = GetUpdateLayerList();
8694 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128695
8696 // Now we will reset the visible rect from property trees for the grandchild,
8697 // and we will configure |child| in several ways that should force the subtree
8698 // to be skipped. The visible content rect for |grandchild| should, therefore,
8699 // remain empty.
vollick2175fae82015-04-27 21:18:128700 gfx::Transform singular;
8701 singular.matrix().set(0, 0, 0);
8702
8703 child->SetTransform(singular);
jaydasika6ed869662016-09-21 14:29:598704 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148705 update_list = GetUpdateLayerList();
8706 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
danakjf78fb272016-07-26 19:06:158707 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128708
8709 child->SetHideLayerAndSubtree(true);
jaydasika6ed869662016-09-21 14:29:598710 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148711 update_list = GetUpdateLayerList();
8712 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128713 child->SetHideLayerAndSubtree(false);
8714
ajuma315a4782015-07-24 21:16:348715 gfx::Transform zero_z_scale;
8716 zero_z_scale.Scale3d(1, 1, 0);
8717 child->SetTransform(zero_z_scale);
8718
8719 // Add a transform animation with a start delay. Now, even though |child| has
8720 // a singular transform, the subtree should still get processed.
8721 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488722 std::unique_ptr<Animation> animation = Animation::Create(
8723 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308724 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558725 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348726 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278727 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
8728 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598729 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148730 update_list = GetUpdateLayerList();
8731 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348732
vollickef2ae922016-06-29 17:54:278733 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
8734 animation_id);
danakjf78fb272016-07-26 19:06:158735 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128736 child->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:598737 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148738 update_list = GetUpdateLayerList();
8739 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128740
8741 // Now, even though child has zero opacity, we will configure |grandchild| and
8742 // |greatgrandchild| in several ways that should force the subtree to be
8743 // processed anyhow.
jaydasika86654512016-01-27 17:05:078744 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128745 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
jaydasika6ed869662016-09-21 14:29:598746 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148747 update_list = GetUpdateLayerList();
8748 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:348749
8750 // Add an opacity animation with a start delay.
8751 animation_id = 1;
8752 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488753 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308754 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558755 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348756 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278757 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
8758 std::move(animation));
jaydasika6ed869662016-09-21 14:29:598759 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:148760 update_list = GetUpdateLayerList();
8761 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:128762}
8763
sunxd71aea3e2016-04-01 23:48:058764TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168765 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128766 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568767 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168768 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568769 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128770
danakj60bc3bc2016-04-09 00:24:488771 std::unique_ptr<LayerImpl> root =
8772 LayerImpl::Create(host_impl.active_tree(), 1);
8773 std::unique_ptr<LayerImpl> child =
8774 LayerImpl::Create(host_impl.active_tree(), 2);
8775 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:128776 LayerImpl::Create(host_impl.active_tree(), 3);
8777
danakj60bc3bc2016-04-09 00:24:488778 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:258779 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128780
danakjf78fb272016-07-26 19:06:158781 root->SetBounds(gfx::Size(100, 100));
8782 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128783 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158784 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128785 grandchild->SetDrawsContent(true);
8786 greatgrandchild->SetDrawsContent(true);
8787
jaydasika2411692c2016-03-23 01:56:098788 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128789 LayerImpl* child_ptr = child.get();
8790 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128791
jaydasika89f7b5a2016-06-22 02:08:398792 child->test_properties()->AddChild(std::move(grandchild));
8793 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:598794 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:128795
vollickef2ae922016-06-29 17:54:278796 host_impl.active_tree()->SetElementIdsForTesting();
8797
vollick2175fae82015-04-27 21:18:128798 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598799 // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058800 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128801
8802 // Now we will reset the visible rect from property trees for the grandchild,
8803 // and we will configure |child| in several ways that should force the subtree
8804 // to be skipped. The visible content rect for |grandchild| should, therefore,
8805 // remain empty.
weiliangcc97575c2016-03-03 18:34:278806 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058807
vollick2175fae82015-04-27 21:18:128808 gfx::Transform singular;
8809 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058810 // This line is used to make the results of skipping and not skipping layers
8811 // different.
8812 singular.matrix().set(0, 1, 1);
8813
8814 gfx::Transform rotate;
8815 rotate.Rotate(90);
8816
8817 gfx::Transform rotate_back_and_translate;
8818 rotate_back_and_translate.RotateAboutYAxis(180);
8819 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128820
jaydasika10d43fc2016-08-18 04:06:048821 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058822 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598823 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278824 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048825 child_ptr->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:128826
jaydasika5121caa82016-05-05 15:43:358827 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika6ed869662016-09-21 14:29:598828 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278829 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358830 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128831
jaydasikab5bc1a22016-08-24 02:59:058832 child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated(
8833 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:598834 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278835 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188836 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:128837
jaydasika10d43fc2016-08-18 04:06:048838 root_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058839 // Force transform tree to have a node for child, so that ancestor's
8840 // invertible transform can be tested.
jaydasika10d43fc2016-08-18 04:06:048841 child_ptr->test_properties()->transform = rotate;
sunxd71aea3e2016-04-01 23:48:058842 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598843 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058844 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048845 root_ptr->test_properties()->transform = gfx::Transform();
8846 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:058847
jaydasikaab317e02016-06-01 00:53:188848 root_ptr->test_properties()->opacity = 0.f;
8849 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:058850 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598851 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058852 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188853 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058854
jaydasikaab317e02016-06-01 00:53:188855 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:128856 // Now, even though child has zero opacity, we will configure |grandchild| and
8857 // |greatgrandchild| in several ways that should force the subtree to be
8858 // processed anyhow.
ajumae6f541b2016-05-31 16:50:508859 grandchild_ptr->test_properties()->copy_requests.push_back(
8860 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:098861 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598862 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:278863 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:508864
8865 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:188866 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058867
8868 // A double sided render surface with backface visible should not be skipped
8869 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8870 child_ptr->SetHasRenderSurface(true);
jaydasika6b5a32bf2016-04-22 21:56:368871 child_ptr->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:048872 child_ptr->test_properties()->transform = rotate_back_and_translate;
sunxd71aea3e2016-04-01 23:48:058873 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598874 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058875 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:048876 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:058877
danakj60bc3bc2016-04-09 00:24:488878 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058879 KeyframedTransformAnimationCurve::Create());
8880 TransformOperations start;
8881 start.AppendTranslate(1.f, 2.f, 3.f);
8882 gfx::Transform transform;
8883 transform.Scale3d(1.0, 2.0, 3.0);
8884 TransformOperations operation;
8885 operation.AppendMatrix(transform);
8886 curve->AddKeyframe(
8887 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8888 curve->AddKeyframe(TransformKeyframe::Create(
8889 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:488890 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:058891 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8892 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588893 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278894 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:058895 host_impl.active_tree()
8896 ->animation_host()
vollickef2ae922016-06-29 17:54:278897 ->GetElementAnimationsForElementId(root_ptr->element_id())
sunxd71aea3e2016-04-01 23:48:058898 ->AddAnimation(std::move(transform_animation));
8899 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8900 child_ptr->SetScrollClipLayer(root_ptr->id());
jaydasika10d43fc2016-08-18 04:06:048901 root_ptr->test_properties()->transform = singular;
8902 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:058903 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598904 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:278905 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058906
loysofb69174e2016-04-27 00:58:588907 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278908 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:058909}
8910
jaydasikaf187b06b2016-04-11 23:30:278911TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:598912 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:278913 LayerImpl* child = AddChild<LayerImpl>(root);
8914 LayerImpl* grand_child = AddChild<LayerImpl>(child);
8915
vollickef2ae922016-06-29 17:54:278916 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:278917
8918 gfx::Transform singular;
8919 singular.matrix().set(0, 0, 0);
8920 singular.matrix().set(0, 1, 1);
8921
danakjf78fb272016-07-26 19:06:158922 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:048923 child->test_properties()->transform = singular;
danakjf78fb272016-07-26 19:06:158924 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278925 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158926 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278927 grand_child->SetDrawsContent(true);
8928
danakj25c52c32016-04-12 21:51:088929 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:278930 KeyframedTransformAnimationCurve::Create());
8931 TransformOperations start;
8932 start.AppendTranslate(1.f, 2.f, 3.f);
8933 gfx::Transform transform;
8934 transform.Scale3d(1.0, 2.0, 3.0);
8935 TransformOperations operation;
8936 operation.AppendMatrix(transform);
8937 curve->AddKeyframe(
8938 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8939 curve->AddKeyframe(TransformKeyframe::Create(
8940 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:088941 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:278942 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8943 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588944 host_impl()->active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278945 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:278946 host_impl()
8947 ->active_tree()
8948 ->animation_host()
vollickef2ae922016-06-29 17:54:278949 ->GetElementAnimationsForElementId(grand_child->element_id())
jaydasikaf187b06b2016-04-11 23:30:278950 ->AddAnimation(std::move(transform_animation));
8951
8952 ExecuteCalculateDrawProperties(root);
8953 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
8954 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
8955
loysofb69174e2016-04-27 00:58:588956 host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278957 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:278958}
8959
sunxd71aea3e2016-04-01 23:48:058960TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8961 FakeImplTaskRunnerProvider task_runner_provider;
8962 TestSharedBitmapManager shared_bitmap_manager;
8963 TestTaskGraphRunner task_graph_runner;
8964 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
8965 &task_graph_runner);
8966
sunxd71aea3e2016-04-01 23:48:058967 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:488968 std::unique_ptr<LayerImpl> root =
8969 LayerImpl::Create(host_impl.pending_tree(), 1);
8970 std::unique_ptr<LayerImpl> child =
8971 LayerImpl::Create(host_impl.pending_tree(), 2);
8972 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:058973 LayerImpl::Create(host_impl.pending_tree(), 3);
8974
danakj60bc3bc2016-04-09 00:24:488975 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:058976 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8977
danakjf78fb272016-07-26 19:06:158978 root->SetBounds(gfx::Size(100, 100));
8979 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058980 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158981 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058982 grandchild->SetDrawsContent(true);
8983 greatgrandchild->SetDrawsContent(true);
8984
sunxd71aea3e2016-04-01 23:48:058985 LayerImpl* root_ptr = root.get();
8986 LayerImpl* grandchild_ptr = grandchild.get();
8987
jaydasika89f7b5a2016-06-22 02:08:398988 child->test_properties()->AddChild(std::move(grandchild));
8989 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:058990
jaydasikabf1875a2016-06-28 03:39:598991 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:278992 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:058993
8994 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:598995 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:058996 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8997
danakj60bc3bc2016-04-09 00:24:488998 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058999 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:499000 std::unique_ptr<TimingFunction> func =
9001 CubicBezierTimingFunction::CreatePreset(
9002 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:059003 curve->AddKeyframe(
9004 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9005 curve->AddKeyframe(
9006 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489007 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059008 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9009 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:589010 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279011 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:059012 host_impl.active_tree()
9013 ->animation_host()
vollickef2ae922016-06-29 17:54:279014 ->GetElementAnimationsForElementId(root_ptr->element_id())
sunxd71aea3e2016-04-01 23:48:059015 ->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189016 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059017 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9018 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599019 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059020 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9021
loysofb69174e2016-04-27 00:58:589022 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279023 root_ptr->element_id(), player.get());
vollick2175fae82015-04-27 21:18:129024}
9025
9026TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:599027 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149028 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129029
danakjf78fb272016-07-26 19:06:159030 root->SetBounds(gfx::Size(100, 100));
9031 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149032 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129033
jaydasika6f972de2016-04-07 16:16:149034 ExecuteCalculateDrawProperties(root);
9035 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279036 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129037
jaydasika5121caa82016-05-05 15:43:359038 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149039 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9040 ExecuteCalculateDrawProperties(root);
9041 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359042 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129043
9044 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149045 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9046 ExecuteCalculateDrawProperties(root);
9047 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129048 child->SetBounds(gfx::Size(10, 10));
9049
9050 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369051 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129052 rotate.RotateAboutXAxis(180.f);
jaydasika10d43fc2016-08-18 04:06:049053 child->test_properties()->transform = rotate;
jaydasika6f972de2016-04-07 16:16:149054 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9055 ExecuteCalculateDrawProperties(root);
9056 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369057 child->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049058 child->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129059
jaydasikaab317e02016-06-01 00:53:189060 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149061 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9062 ExecuteCalculateDrawProperties(root);
9063 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129064}
9065
jaydasika3d10aa62015-05-06 17:50:449066TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9067 // Ensure that the treewalk in LayerTreeHostCommom::
9068 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319069 scoped_refptr<Layer> root = Layer::Create();
9070 scoped_refptr<Layer> parent = Layer::Create();
9071 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449072
danakjf78fb272016-07-26 19:06:159073 root->SetBounds(gfx::Size(100, 100));
9074 parent->SetBounds(gfx::Size(100, 100));
9075 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:449076 child->SetClipParent(root.get());
9077
danakjf78fb272016-07-26 19:06:159078 root->AddChild(parent);
9079 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:339080 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449081
jaydasika3d10aa62015-05-06 17:50:449082 child->RequestCopyOfOutput(
9083 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029084
jaydasika6ed869662016-09-21 14:29:599085 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029086 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9087
9088 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika6ed869662016-09-21 14:29:599089 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029090 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449091}
9092
vollick692444f2015-05-20 15:39:149093TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:159094 scoped_refptr<Layer> root = Layer::Create();
9095 root->SetBounds(gfx::Size(800, 800));
9096
vollick692444f2015-05-20 15:39:149097 gfx::Transform translate_z;
9098 translate_z.Translate3d(0, 0, 10);
9099
loyso0940d412016-03-14 01:30:319100 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:159101 child->SetTransform(translate_z);
9102 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:149103
9104 root->AddChild(child);
9105
ennea7b43c32015-06-18 20:01:339106 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149107
jaydasika6ed869662016-09-21 14:29:599108 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149109 EXPECT_NE(-1, child->transform_tree_index());
9110
9111 child->RemoveFromParent();
9112
jaydasika6ed869662016-09-21 14:29:599113 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149114 EXPECT_EQ(-1, child->transform_tree_index());
9115}
9116
jaydasika67d7989e2015-08-06 21:55:349117TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9118 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:599119 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349120 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9121 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9122 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9123 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9124
jaydasika67d7989e2015-08-06 21:55:349125 // This transform should be a significant one so that a transform node is
9126 // formed for it.
9127 gfx::Transform transform1;
9128 transform1.RotateAboutYAxis(45);
9129 transform1.RotateAboutXAxis(30);
9130 // This transform should be a 3d transform as we want the render surface
9131 // to flatten the transform
9132 gfx::Transform transform2;
9133 transform2.Translate3d(10, 10, 10);
9134
danakjf78fb272016-07-26 19:06:159135 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049136 significant_transform->test_properties()->transform = transform1;
danakjf78fb272016-07-26 19:06:159137 significant_transform->SetBounds(gfx::Size(30, 30));
9138 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349139 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159140 layer_clips_subtree->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049141 render_surface->test_properties()->transform = transform2;
danakjf78fb272016-07-26 19:06:159142 render_surface->SetBounds(gfx::Size(30, 30));
9143 render_surface->test_properties()->force_render_surface = true;
9144 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349145 test_layer->SetDrawsContent(true);
9146
jaydasika5237db02016-09-20 01:34:309147 float device_scale_factor = 1.f;
9148 float page_scale_factor = 1.f;
9149 LayerImpl* page_scale_layer = nullptr;
9150 // Visible rects computed by combining clips in target space and root space
9151 // don't match because of rotation transforms. So, we skip
9152 // verify_visible_rect_calculations.
9153 bool skip_verify_visible_rect_calculations = true;
9154 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
9155 page_scale_layer,
9156 skip_verify_visible_rect_calculations);
jaydasika67d7989e2015-08-06 21:55:349157
ajumae4af47062016-05-24 23:59:049158 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:349159 root->layer_tree_impl()->property_trees()->transform_tree;
9160 TransformNode* transform_node =
9161 transform_tree.Node(significant_transform->transform_tree_index());
9162 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9163
weiliangcc154ce22015-12-09 03:39:269164 EXPECT_TRUE(root->has_render_surface());
9165 EXPECT_FALSE(significant_transform->has_render_surface());
9166 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9167 EXPECT_TRUE(render_surface->has_render_surface());
9168 EXPECT_FALSE(test_layer->has_render_surface());
9169
ajumae4af47062016-05-24 23:59:049170 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:349171 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
trchendba8b1502016-07-08 09:47:019172 EXPECT_FALSE(clip_node->applies_local_clip);
weiliangcd15784432016-06-07 17:57:339173 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect());
jaydasika5237db02016-09-20 01:34:309174
9175 // Also test the visible rects computed by combining clips in root space.
9176 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
9177 root->layer_tree_impl()->property_trees(), test_layer);
9178 EXPECT_EQ(gfx::Rect(30, 20), visible_rect);
jaydasika67d7989e2015-08-06 21:55:349179}
9180
9181TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9182 // Ensure that when parent clip node's transform is an ancestor of current
9183 // clip node's target, clip is 'projected' from parent space to current
9184 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:599185 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349186 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9187 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9188 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9189
jaydasika67d7989e2015-08-06 21:55:349190 gfx::Transform transform;
9191 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:159192
9193 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049194 clip_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159195 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349196 clip_layer->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049197 target_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159198 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349199 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159200 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349201 test_layer->SetDrawsContent(true);
9202
jaydasika67d7989e2015-08-06 21:55:349203 ExecuteCalculateDrawProperties(root);
9204
weiliangcc97575c2016-03-03 18:34:279205 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349206}
9207
jaydasika7d5c1ed2015-08-14 14:27:029208TEST_F(LayerTreeHostCommonTest,
9209 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9210 // Ensure clip rect is calculated correctly when render surface has unclipped
9211 // descendants.
jaydasikabf1875a2016-06-28 03:39:599212 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:029213 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9214 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9215 LayerImpl* render_surface =
9216 AddChild<LayerImpl>(between_clip_parent_and_child);
9217 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9218
weiliangcbb2e8642016-03-04 00:24:429219 gfx::Transform translate;
9220 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029221
danakjf78fb272016-07-26 19:06:159222 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049223 clip_parent->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159224 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:429225 clip_parent->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049226 between_clip_parent_and_child->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159227 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
9228 render_surface->SetBounds(gfx::Size(30, 30));
9229 render_surface->test_properties()->force_render_surface = true;
9230 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:029231 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159232
jaydasika1c0a27d42016-04-28 01:54:569233 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159234 clip_parent->test_properties()->clip_children =
9235 base::MakeUnique<std::set<LayerImpl*>>();
9236 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:029237
9238 ExecuteCalculateDrawProperties(root);
9239
weiliangcbb2e8642016-03-04 00:24:429240 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259241 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569242 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9243 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029244}
9245
jaydasika571dd2cf2015-09-25 20:55:429246TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089247 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9248 // Ensure that the visible layer rect of a descendant of a surface with
9249 // unclipped descendants is computed correctly, when the surface doesn't apply
9250 // a clip.
jaydasikabf1875a2016-06-28 03:39:599251 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:089252 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9253 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9254 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9255 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9256
danakjf78fb272016-07-26 19:06:159257 root->SetBounds(gfx::Size(30, 10));
9258 clip_parent->SetBounds(gfx::Size(30, 30));
9259 render_surface->SetBounds(gfx::Size(10, 15));
9260 render_surface->test_properties()->force_render_surface = true;
9261 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:089262 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159263 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:089264 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159265
jaydasika1c0a27d42016-04-28 01:54:569266 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159267 clip_parent->test_properties()->clip_children =
9268 base::MakeUnique<std::set<LayerImpl*>>();
9269 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:089270
9271 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:189272 EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect());
ajuma01734dd02015-10-07 01:22:089273}
9274
9275TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429276 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:599277 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429278 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9279 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9280 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9281 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9282 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9283
danakjf78fb272016-07-26 19:06:159284 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429285 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159286 clip_parent->SetBounds(gfx::Size(30, 30));
9287 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429288 render_surface->SetMasksToBounds(true);
9289 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159290 render_surface->test_properties()->force_render_surface = true;
9291 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429292 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159293 clip_child->SetBounds(gfx::Size(50, 50));
9294 clip_child->SetDrawsContent(true);
9295 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429296 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429297
danakjf78fb272016-07-26 19:06:159298 clip_child->test_properties()->clip_parent = clip_parent;
9299 clip_parent->test_properties()->clip_children =
9300 base::MakeUnique<std::set<LayerImpl*>>();
9301 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:429302
9303 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569304 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9305 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429306 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9307 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9308}
9309
ajumae2b7a5c2015-09-30 21:41:429310TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:599311 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:429312 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9313 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9314 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9315
danakjf78fb272016-07-26 19:06:159316 root->SetBounds(gfx::Size(50, 50));
9317 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429318 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159319 render_surface->SetBounds(gfx::Size(30, 30));
9320 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:429321 render_surface->SetMasksToBounds(true);
9322 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159323 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429324 clip_child->SetDrawsContent(true);
9325
jaydasika1c0a27d42016-04-28 01:54:569326 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159327 clip_parent->test_properties()->clip_children =
9328 base::MakeUnique<std::set<LayerImpl*>>();
9329 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:429330
9331 ExecuteCalculateDrawProperties(root);
9332
9333 // The clip child should inherit its clip parent's clipping state, not its
9334 // tree parent's clipping state.
9335 EXPECT_FALSE(clip_parent->is_clipped());
9336 EXPECT_TRUE(render_surface->is_clipped());
9337 EXPECT_FALSE(clip_child->is_clipped());
9338}
9339
jaydasika77a4a072015-10-20 21:47:279340TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9341 // Tests the value of render surface content rect when we have multiple types
9342 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9343 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:599344 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279345 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9346 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9347 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9348 LayerImpl* unclipped_desc_surface2 =
9349 AddChild<LayerImpl>(unclipped_desc_surface);
9350 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9351 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9352
danakjf78fb272016-07-26 19:06:159353 root->SetBounds(gfx::Size(80, 80));
9354 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:279355 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159356 unclipped_surface->SetDrawsContent(true);
9357 unclipped_surface->test_properties()->force_render_surface = true;
9358 clip_parent->SetBounds(gfx::Size(50, 50));
9359 clip_parent->SetMasksToBounds(true);
9360 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279361 unclipped_desc_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159362 unclipped_desc_surface->SetDrawsContent(true);
9363 unclipped_desc_surface->test_properties()->force_render_surface = true;
9364 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
9365 unclipped_desc_surface2->SetDrawsContent(true);
9366 unclipped_desc_surface2->test_properties()->force_render_surface = true;
9367 clip_child->SetBounds(gfx::Size(100, 100));
9368 clipped_surface->SetBounds(gfx::Size(70, 70));
9369 clipped_surface->SetDrawsContent(true);
9370 clipped_surface->test_properties()->force_render_surface = true;
9371
9372 clip_child->test_properties()->clip_parent = clip_parent;
9373 clip_parent->test_properties()->clip_children =
9374 base::MakeUnique<std::set<LayerImpl*>>();
9375 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279376
9377 ExecuteCalculateDrawProperties(root);
9378 EXPECT_EQ(gfx::Rect(50, 50),
9379 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:569380 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:279381 unclipped_desc_surface->render_surface()->content_rect());
9382 EXPECT_EQ(gfx::Rect(50, 50),
9383 unclipped_desc_surface2->render_surface()->content_rect());
9384 EXPECT_EQ(gfx::Rect(50, 50),
9385 clipped_surface->render_surface()->content_rect());
9386}
9387
9388TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9389 // Tests the value of render surface content rect when we have a layer that
9390 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:599391 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279392 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9393 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9394 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9395 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9396 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9397
jaydasika77a4a072015-10-20 21:47:279398 gfx::Transform translate;
9399 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:159400
jaydasika778cb272016-08-15 19:00:549401 gfx::Transform rotate;
9402 rotate.RotateAboutXAxis(10);
9403
danakjf78fb272016-07-26 19:06:159404 root->SetBounds(gfx::Size(100, 100));
9405 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279406 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159407 surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049408 surface->test_properties()->transform = rotate;
danakjf78fb272016-07-26 19:06:159409 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:279410 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159411 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:049412 unclipped_desc_surface->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159413 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9414 unclipped_desc_surface->SetDrawsContent(true);
9415 unclipped_desc_surface->test_properties()->force_render_surface = true;
9416 clip_child->SetBounds(gfx::Size(100, 100));
9417 clip_child->SetDrawsContent(true);
9418
9419 clip_child->test_properties()->clip_parent = clip_parent;
9420 clip_parent->test_properties()->clip_children =
9421 base::MakeUnique<std::set<LayerImpl*>>();
9422 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279423
9424 ExecuteCalculateDrawProperties(root);
9425
9426 EXPECT_EQ(gfx::Rect(10, 10),
9427 unclipped_desc_surface->render_surface()->content_rect());
9428}
9429
jaydasika2c8c2872015-10-21 23:28:219430TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:599431 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:219432 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9433 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9434 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9435 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9436 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9437
jaydasika2c8c2872015-10-21 23:28:219438
jaydasika2c8c2872015-10-21 23:28:219439 gfx::Transform scale;
9440 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:159441
9442 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:049443 surface->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159444 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:219445 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159446 surface->test_properties()->force_render_surface = true;
9447 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:219448 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159449 clip_parent->SetBounds(gfx::Size(50, 50));
9450 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9451 unclipped_desc_surface->SetDrawsContent(true);
9452 unclipped_desc_surface->test_properties()->force_render_surface = true;
9453 clip_child->SetBounds(gfx::Size(100, 100));
9454 clip_child->SetDrawsContent(true);
9455
9456 clip_child->test_properties()->clip_parent = clip_parent;
9457 clip_parent->test_properties()->clip_children =
9458 base::MakeUnique<std::set<LayerImpl*>>();
9459 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:219460
9461 ExecuteCalculateDrawProperties(root);
9462
9463 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9464}
9465
jaydasika60f85862015-10-01 20:36:149466TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:599467 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:149468 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9469 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9470
jaydasika86654512016-01-27 17:05:079471 gfx::Transform translation;
9472 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:149473
danakjf78fb272016-07-26 19:06:159474 root->SetBounds(gfx::Size(30, 30));
9475 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:149476 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159477 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049478 test_layer->test_properties()->transform = translation;
danakjf78fb272016-07-26 19:06:159479 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:149480 test_layer->SetDrawsContent(true);
dtapuskaee0b6982016-01-29 15:14:489481 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
danakjf78fb272016-07-26 19:06:159482 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:149483
9484 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:029485 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
9486 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149487}
9488
jaydasikae4910fa22015-10-09 00:52:099489TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:599490 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:099491 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9492 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9493 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9494
danakjf78fb272016-07-26 19:06:159495 root->SetBounds(gfx::Size(30, 30));
9496 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:099497 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159498 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099499 render_surface->SetMasksToBounds(true);
9500 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159501 render_surface->test_properties()->force_render_surface = true;
9502 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099503 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:099504
danakjf78fb272016-07-26 19:06:159505 clip_child->test_properties()->clip_parent = clip_parent;
9506 clip_parent->test_properties()->clip_children =
9507 base::MakeUnique<std::set<LayerImpl*>>();
9508 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:099509
9510 ExecuteCalculateDrawProperties(root);
jaydasikab4df4032016-09-13 18:38:499511 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
jaydasikae4910fa22015-10-09 00:52:099512}
9513
jaydasika571dd2cf2015-09-25 20:55:429514TEST_F(LayerTreeHostCommonTest,
9515 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:599516 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429517 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9518 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:159519
9520 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429521 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369522 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159523 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429524 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369525 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159526 render_surface->test_properties()->force_render_surface = true;
9527 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429528 test_layer->SetMasksToBounds(true);
9529 test_layer->SetDrawsContent(true);
9530 ExecuteCalculateDrawProperties(root);
9531
9532 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9533 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9534 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9535}
9536
jaydasikab5504ca2015-12-18 23:41:559537TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9538 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:599539 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:559540 LayerImpl* hidden = AddChild<LayerImpl>(root);
9541 LayerImpl* test = AddChild<LayerImpl>(hidden);
9542
danakjf78fb272016-07-26 19:06:159543 root->SetBounds(gfx::Size(30, 30));
9544 hidden->SetBounds(gfx::Size(30, 30));
9545 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:359546 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:159547 test->SetBounds(gfx::Size(30, 30));
9548 test->test_properties()->force_render_surface = true;
9549
jaydasikab5504ca2015-12-18 23:41:559550 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079551 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559552
jaydasika5121caa82016-05-05 15:43:359553 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559554 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9555 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079556 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559557}
9558
jaydasikac0137282015-10-01 15:50:309559TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:599560 LayerImpl* root = root_layer_for_testing();
jaydasikac0137282015-10-01 15:50:309561 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9562 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9563 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9564
danakjf78fb272016-07-26 19:06:159565 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309566 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159567 render_surface1->SetPosition(gfx::PointF(10, 10));
9568 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309569 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159570 render_surface1->test_properties()->force_render_surface = true;
9571 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309572 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159573 render_surface2->test_properties()->force_render_surface = true;
9574 clip_child->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309575
danakjf78fb272016-07-26 19:06:159576 clip_child->test_properties()->clip_parent = root;
9577 root->test_properties()->clip_children =
9578 base::MakeUnique<std::set<LayerImpl*>>();
9579 root->test_properties()->clip_children->insert(clip_child);
9580
jaydasikac0137282015-10-01 15:50:309581 ExecuteCalculateDrawProperties(root);
9582
9583 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379584 // A clip node is created for every render surface and for layers that have
9585 // local clip. So, here it should be craeted for every layer.
9586 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309587}
9588
ajumadb6216f2c2016-06-07 21:44:059589TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
9590 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599591 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:099592 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509593 child->test_properties()->SetMaskLayer(
9594 LayerImpl::Create(root->layer_tree_impl(), 100));
9595 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:099596
jaydasika224bca02015-12-18 02:37:099597 gfx::Transform transform;
9598 transform.Translate(10, 10);
9599
danakjf78fb272016-07-26 19:06:159600 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:099601 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:049602 child->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159603 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:099604 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:159605 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:099606 ExecuteCalculateDrawProperties(root);
9607
ajumadb6216f2c2016-06-07 21:44:059608 // The render surface created for the mask has no contributing content, so the
9609 // mask isn't a drawn RSLL member. This means it has an empty visible rect,
9610 // but its screen space transform can still be computed correctly on-demand.
ajuma1d4026a32016-06-14 13:18:509611 EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member());
9612 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
9613 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059614
9615 // Make the child's render surface have contributing content.
9616 child->SetDrawsContent(true);
9617 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9618 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509619 EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member());
9620 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
9621 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059622
jaydasika224bca02015-12-18 02:37:099623 transform.Translate(10, 10);
jaydasika10d43fc2016-08-18 04:06:049624 child->test_properties()->transform = transform;
jaydasika224bca02015-12-18 02:37:099625 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9626 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509627 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
9628 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:059629}
9630
jaydasikaf62311f2016-04-20 14:38:459631TEST_F(LayerTreeHostCommonTest,
9632 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:599633 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:459634 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9635 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9636 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9637 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:459638
9639 gfx::Transform scale;
9640 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:159641
9642 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049643 render_surface1->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159644 render_surface1->SetBounds(gfx::Size(30, 30));
9645 render_surface1->test_properties()->force_render_surface = true;
9646 between_targets->SetBounds(gfx::Size(30, 30));
9647 render_surface2->SetBounds(gfx::Size(30, 30));
9648 render_surface2->test_properties()->force_render_surface = true;
9649 test_layer->SetBounds(gfx::Size(30, 30));
9650 test_layer->SetDrawsContent(true);
9651
jaydasikaf62311f2016-04-20 14:38:459652 // We want layer between the two targets to create a clip node and transform
9653 // node but it shouldn't create a render surface.
9654 between_targets->SetMasksToBounds(true);
9655 between_targets->Set3dSortingContextId(2);
9656
9657 ExecuteCalculateDrawProperties(root);
9658
9659 TransformTree& tree =
9660 root->layer_tree_impl()->property_trees()->transform_tree;
9661 TransformNode* node = tree.Node(render_surface1->transform_tree_index());
jaydasika6be761602016-07-18 20:11:439662 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459663
9664 node = tree.Node(between_targets->transform_tree_index());
jaydasika6be761602016-07-18 20:11:439665 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:459666
9667 node = tree.Node(render_surface2->transform_tree_index());
jaydasika6be761602016-07-18 20:11:439668 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459669
9670 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9671}
9672
jaydasika3c5633d2016-08-25 00:39:229673TEST_F(LayerTreeHostCommonTest, NoisyTransform) {
9674 LayerImpl* root = root_layer_for_testing();
9675 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9676 LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface);
9677 LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface);
9678 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip);
9679
9680 scroll_child->test_properties()->scroll_parent = scroll_parent;
9681 scroll_parent->test_properties()->scroll_children =
9682 base::MakeUnique<std::set<LayerImpl*>>();
9683 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
9684 scroll_parent->SetScrollClipLayer(scroll_clip->id());
9685
9686 scroll_parent->SetDrawsContent(true);
9687 scroll_child->SetDrawsContent(true);
9688 render_surface->test_properties()->force_render_surface = true;
9689
9690 // A noisy transform that's invertible.
9691 gfx::Transform transform;
9692 transform.matrix().setDouble(0, 0, 6.12323e-17);
9693 transform.matrix().setDouble(0, 2, 1);
9694 transform.matrix().setDouble(2, 2, 6.12323e-17);
9695 transform.matrix().setDouble(2, 0, -1);
9696
9697 scroll_child->test_properties()->transform = transform;
9698 render_surface->test_properties()->transform = transform;
9699
9700 root->SetBounds(gfx::Size(30, 30));
9701 scroll_child->SetBounds(gfx::Size(30, 30));
9702 scroll_parent->SetBounds(gfx::Size(30, 30));
9703 ExecuteCalculateDrawProperties(root);
9704
9705 gfx::Transform expected;
9706 expected.matrix().setDouble(0, 0, 3.749395e-33);
9707 expected.matrix().setDouble(0, 2, 6.12323e-17);
9708 expected.matrix().setDouble(2, 0, -1);
9709 expected.matrix().setDouble(2, 2, 6.12323e-17);
9710 EXPECT_TRANSFORMATION_MATRIX_EQ(expected,
9711 scroll_child->ScreenSpaceTransform());
9712}
9713
jaydasika5160e672015-10-15 15:25:149714TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:599715 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:149716 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059717 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149718
sunxd71aea3e2016-04-01 23:48:059719 child->SetDrawsContent(true);
9720 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149721
9722 gfx::Transform large_transform;
9723 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9724 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9725 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9726 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9727
danakjf78fb272016-07-26 19:06:159728 root->SetBounds(gfx::Size(30, 30));
9729 render_surface1->SetBounds(gfx::Size(30, 30));
9730 render_surface1->test_properties()->force_render_surface = true;
9731
sunxd71aea3e2016-04-01 23:48:059732 // TODO(sunxd): we make child have no render surface, because if the
9733 // child has one, the large transform applied to child will result in NaNs in
9734 // the draw_transform of the render_surface, thus make draw property updates
9735 // skip the child layer. We need further investigation into this to know
9736 // what exactly happens here.
jaydasika10d43fc2016-08-18 04:06:049737 child->test_properties()->transform = large_transform;
danakjf78fb272016-07-26 19:06:159738 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:149739
9740 ExecuteCalculateDrawProperties(root);
9741
jaydasika5160e672015-10-15 15:25:149742 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:059743 render_surface1->render_surface()->DrawableContentRect());
9744
9745 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9746 std::isnan(child->DrawTransform().matrix().get(0, 0));
9747 EXPECT_TRUE(is_inf_or_nan);
9748
9749 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9750 std::isnan(child->DrawTransform().matrix().get(1, 1));
9751 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149752
danakj59931942016-07-26 22:11:299753 // The root layer should be in the RenderSurfaceLayerListImpl.
9754 const auto* rsll = render_surface_layer_list_impl();
9755 EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end());
jaydasika5160e672015-10-15 15:25:149756}
9757
jaydasika8d6efe2e2016-05-17 15:37:219758TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:219759 scoped_refptr<Layer> root = Layer::Create();
9760 scoped_refptr<LayerWithForcedDrawsContent> child =
9761 make_scoped_refptr(new LayerWithForcedDrawsContent());
9762 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:219763 host()->SetRootLayer(root);
9764
danakjf78fb272016-07-26 19:06:159765 root->SetBounds(gfx::Size(100, 100));
9766 child->SetBounds(gfx::Size(20, 20));
jaydasika6ed869662016-09-21 14:29:599767 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219768
9769 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9770 // property trees as a new effect node will be created.
9771 child->SetOpacity(0.5f);
9772 PropertyTrees* property_trees = host()->property_trees();
9773 EXPECT_TRUE(property_trees->needs_rebuild);
9774
jaydasika6ed869662016-09-21 14:29:599775 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219776 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9777 property_trees->effect_id_to_index_map.end());
9778
9779 // child already has an effect node. Changing its opacity shouldn't trigger
9780 // a property trees rebuild.
9781 child->SetOpacity(0.8f);
9782 property_trees = host()->property_trees();
9783 EXPECT_FALSE(property_trees->needs_rebuild);
9784
jaydasika6ed869662016-09-21 14:29:599785 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219786 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9787 property_trees->effect_id_to_index_map.end());
9788
9789 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
9790 // property trees as the effect node may no longer be needed.
9791 child->SetOpacity(1.f);
9792 property_trees = host()->property_trees();
9793 EXPECT_TRUE(property_trees->needs_rebuild);
9794
jaydasika6ed869662016-09-21 14:29:599795 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:219796 EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()),
9797 property_trees->effect_id_to_index_map.end());
9798}
9799
jaydasika9cb21c772016-05-10 22:37:089800TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:089801 scoped_refptr<Layer> root = Layer::Create();
9802 scoped_refptr<LayerWithForcedDrawsContent> animated =
9803 make_scoped_refptr(new LayerWithForcedDrawsContent());
9804 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:089805 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:089806 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279807
danakjf78fb272016-07-26 19:06:159808 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:089809 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159810 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:089811 animated->SetOpacity(0.f);
9812
9813 scoped_refptr<AnimationPlayer> player =
9814 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9815 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279816
9817 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:089818
9819 int animation_id = 0;
9820 std::unique_ptr<Animation> animation = Animation::Create(
9821 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
9822 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559823 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:089824 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9825 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279826 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9827 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:089828
jaydasika6ed869662016-09-21 14:29:599829 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika9cb21c772016-05-10 22:37:089830
khushalsagar86928f92016-08-17 21:49:059831 EffectTree& tree = root->GetLayerTree()->property_trees()->effect_tree;
jaydasika9cb21c772016-05-10 22:37:089832 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019833 EXPECT_FALSE(node->is_currently_animating_opacity);
9834 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089835
9836 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:589837 host()->AnimateLayers(
jaydasika9cb21c772016-05-10 22:37:089838 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9839 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019840 EXPECT_TRUE(node->is_currently_animating_opacity);
9841 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089842
9843 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
9844 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019845 EXPECT_FALSE(node->is_currently_animating_opacity);
9846 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089847}
9848
jaydasika6c3404e92016-05-19 02:40:369849TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:369850 scoped_refptr<Layer> root = Layer::Create();
9851 scoped_refptr<LayerWithForcedDrawsContent> animated =
9852 make_scoped_refptr(new LayerWithForcedDrawsContent());
9853 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:369854 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:089855 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279856
danakjf78fb272016-07-26 19:06:159857 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:369858 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159859 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:369860
9861 scoped_refptr<AnimationPlayer> player =
9862 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9863 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279864 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:369865
9866 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
9867 KeyframedTransformAnimationCurve::Create());
9868 TransformOperations start;
9869 start.AppendTranslate(1.f, 2.f, 3.f);
9870 gfx::Transform transform;
9871 transform.Scale3d(1.0, 2.0, 3.0);
9872 TransformOperations operation;
9873 operation.AppendMatrix(transform);
9874 curve->AddKeyframe(
9875 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9876 curve->AddKeyframe(TransformKeyframe::Create(
9877 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
9878 std::unique_ptr<Animation> animation(
9879 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9880 animation->set_fill_mode(Animation::FillMode::NONE);
9881 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9882 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279883 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9884 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:369885
jaydasika6ed869662016-09-21 14:29:599886 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika6c3404e92016-05-19 02:40:369887
khushalsagar86928f92016-08-17 21:49:059888 TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree;
jaydasika6c3404e92016-05-19 02:40:369889 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019890 EXPECT_FALSE(node->is_currently_animating);
9891 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369892
9893 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:589894 host()->AnimateLayers(
jaydasika6c3404e92016-05-19 02:40:369895 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9896 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019897 EXPECT_TRUE(node->is_currently_animating);
9898 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369899
9900 player->AbortAnimations(TargetProperty::TRANSFORM,
9901 false /*needs_completion*/);
9902 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019903 EXPECT_FALSE(node->is_currently_animating);
9904 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369905}
9906
khushalsagar37694212016-01-15 20:46:489907TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9908 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9909 scroll.layer_id = 2;
9910 scroll.scroll_delta = gfx::Vector2d(5, 10);
9911
9912 proto::ScrollUpdateInfo proto;
9913 scroll.ToProtobuf(&proto);
9914 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9915 new_scroll.FromProtobuf(proto);
9916
9917 EXPECT_EQ(scroll, new_scroll);
9918}
9919
9920TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9921 ScrollAndScaleSet scroll_and_scale_set;
9922
9923 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9924 scroll1.layer_id = 1;
9925 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9926 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9927 scroll2.layer_id = 2;
9928 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9929 scroll_and_scale_set.scrolls.push_back(scroll1);
9930 scroll_and_scale_set.scrolls.push_back(scroll2);
9931
9932 scroll_and_scale_set.page_scale_delta = 0.3f;
9933 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
9934 scroll_and_scale_set.top_controls_delta = 0.9f;
9935
9936 proto::ScrollAndScaleSet proto;
9937 scroll_and_scale_set.ToProtobuf(&proto);
9938 ScrollAndScaleSet new_scroll_and_scale_set;
9939 new_scroll_and_scale_set.FromProtobuf(proto);
9940
9941 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
9942}
9943
sunxdea1df782016-01-28 00:12:339944TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9945 // Test the behavior of scroll tree builder
9946 // Topology:
sunxdcfccd1b32016-02-11 00:54:209947 // +root1(1)[inner_viewport_container_layer]
9948 // +-page_scale_layer
9949 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9950 // scrollable, inner_viewport_scroll_layer]
9951 // +------child6(6)[kScrollbarScrolling]
9952 // +--------grand_child10(10)[kScrollbarScrolling]
9953 // +----parent3(3)
9954 // +------child7(7)[scrollable]
9955 // +------child8(8)[scroll_parent=7]
9956 // +--------grand_child11(11)[scrollable]
9957 // +----parent4(4)
9958 // +------child9(9)
9959 // +--------grand_child12(12)
9960 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339961 //
9962 // Expected scroll tree topology:
9963 // +property_tree_root---owner:-1
9964 // +--root---owner:1, id:1
9965 // +----node---owner:2, id:2
9966 // +------node---owner:6, id:3
9967 // +----node---owner:7, id:4
9968 // +------node---owner:11, id:5
9969 // +----node---owner:5, id:6
9970 //
9971 // Extra check:
9972 // scroll_tree_index() of:
9973 // grand_child10:3
9974 // parent3:1
9975 // child8:4
9976 // parent4:1
9977 // child9:1
9978 // grand_child12:1
loyso0940d412016-03-14 01:30:319979 scoped_refptr<Layer> root1 = Layer::Create();
9980 scoped_refptr<Layer> page_scale_layer = Layer::Create();
9981 scoped_refptr<Layer> parent2 = Layer::Create();
9982 scoped_refptr<Layer> parent3 = Layer::Create();
9983 scoped_refptr<Layer> parent4 = Layer::Create();
9984 scoped_refptr<Layer> parent5 = Layer::Create();
9985 scoped_refptr<Layer> child6 = Layer::Create();
9986 scoped_refptr<Layer> child7 = Layer::Create();
9987 scoped_refptr<Layer> child8 = Layer::Create();
9988 scoped_refptr<Layer> child9 = Layer::Create();
9989 scoped_refptr<Layer> grand_child10 = Layer::Create();
9990 scoped_refptr<Layer> grand_child11 = Layer::Create();
9991 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:339992
sunxdcfccd1b32016-02-11 00:54:209993 root1->AddChild(page_scale_layer);
9994 page_scale_layer->AddChild(parent2);
9995 page_scale_layer->AddChild(parent3);
9996 page_scale_layer->AddChild(parent4);
9997 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:339998 parent2->AddChild(child6);
9999 parent3->AddChild(child7);
10000 parent3->AddChild(child8);
10001 parent4->AddChild(child9);
10002 child6->AddChild(grand_child10);
10003 child8->AddChild(grand_child11);
10004 child9->AddChild(grand_child12);
10005 host()->SetRootLayer(root1);
10006
10007 parent2->AddMainThreadScrollingReasons(
10008 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf2016-02-03 02:47:4810009 parent2->AddMainThreadScrollingReasons(
10010 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310011 parent2->SetScrollClipLayerId(root1->id());
10012 child6->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810013 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310014 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810015 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310016
sunxdcfccd1b32016-02-11 00:54:2010017 child7->SetScrollClipLayerId(parent3->id());
10018
sunxdea1df782016-01-28 00:12:3310019 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:2010020 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:3310021
10022 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010023 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310024
khushalsagar86928f92016-08-17 21:49:0510025 host()->GetLayerTree()->RegisterViewportLayers(nullptr, page_scale_layer,
10026 parent2, nullptr);
jaydasika6ed869662016-09-21 14:29:5910027 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get());
sunxdea1df782016-01-28 00:12:3310028
10029 const int kInvalidPropertyTreeNodeId = -1;
10030 const int kRootPropertyTreeNodeId = 0;
10031
10032 // Property tree root
ajumae4af47062016-05-24 23:59:0410033 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010034 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010035 property_trees.is_main_thread = true;
10036 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410037 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310038 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10039 property_tree_root->id = kRootPropertyTreeNodeId;
10040 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
10041 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
trchendba8b1502016-07-08 09:47:0110042 property_tree_root->scrollable = false;
10043 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf2016-02-03 02:47:4810044 MainThreadScrollingReason::kNotScrollingOnMain;
trchendba8b1502016-07-08 09:47:0110045 property_tree_root->contains_non_fast_scrollable_region = false;
10046 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310047
10048 // The node owned by root1
10049 ScrollNode scroll_root1;
10050 scroll_root1.id = 1;
10051 scroll_root1.owner_id = root1->id();
trchendba8b1502016-07-08 09:47:0110052 scroll_root1.user_scrollable_horizontal = true;
10053 scroll_root1.user_scrollable_vertical = true;
10054 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310055 expected_scroll_tree.Insert(scroll_root1, 0);
10056
10057 // The node owned by parent2
10058 ScrollNode scroll_parent2;
10059 scroll_parent2.id = 2;
10060 scroll_parent2.owner_id = parent2->id();
trchendba8b1502016-07-08 09:47:0110061 scroll_parent2.scrollable = true;
10062 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf2016-02-03 02:47:4810063 parent2->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110064 scroll_parent2.scroll_clip_layer_bounds = root1->bounds();
10065 scroll_parent2.bounds = parent2->bounds();
10066 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
10067 scroll_parent2.is_inner_viewport_scroll_layer = true;
10068 scroll_parent2.user_scrollable_horizontal = true;
10069 scroll_parent2.user_scrollable_vertical = true;
10070 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310071 expected_scroll_tree.Insert(scroll_parent2, 1);
10072
10073 // The node owned by child6
10074 ScrollNode scroll_child6;
10075 scroll_child6.id = 3;
10076 scroll_child6.owner_id = child6->id();
trchendba8b1502016-07-08 09:47:0110077 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf2016-02-03 02:47:4810078 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110079 scroll_child6.should_flatten = true;
10080 scroll_child6.user_scrollable_horizontal = true;
10081 scroll_child6.user_scrollable_vertical = true;
10082 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310083 expected_scroll_tree.Insert(scroll_child6, 2);
10084
10085 // The node owned by child7, child7 also owns a transform node
10086 ScrollNode scroll_child7;
10087 scroll_child7.id = 4;
10088 scroll_child7.owner_id = child7->id();
trchendba8b1502016-07-08 09:47:0110089 scroll_child7.scrollable = true;
10090 scroll_child7.scroll_clip_layer_bounds = parent3->bounds();
10091 scroll_child7.bounds = child7->bounds();
10092 scroll_child7.user_scrollable_horizontal = true;
10093 scroll_child7.user_scrollable_vertical = true;
10094 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310095 expected_scroll_tree.Insert(scroll_child7, 1);
10096
10097 // The node owned by grand_child11, grand_child11 also owns a transform node
10098 ScrollNode scroll_grand_child11;
10099 scroll_grand_child11.id = 5;
10100 scroll_grand_child11.owner_id = grand_child11->id();
trchendba8b1502016-07-08 09:47:0110101 scroll_grand_child11.scrollable = true;
10102 scroll_grand_child11.user_scrollable_horizontal = true;
10103 scroll_grand_child11.user_scrollable_vertical = true;
10104 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310105 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10106
10107 // The node owned by parent5
10108 ScrollNode scroll_parent5;
10109 scroll_parent5.id = 8;
10110 scroll_parent5.owner_id = parent5->id();
trchendba8b1502016-07-08 09:47:0110111 scroll_parent5.contains_non_fast_scrollable_region = true;
10112 scroll_parent5.bounds = gfx::Size(10, 10);
10113 scroll_parent5.should_flatten = true;
10114 scroll_parent5.user_scrollable_horizontal = true;
10115 scroll_parent5.user_scrollable_vertical = true;
10116 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310117 expected_scroll_tree.Insert(scroll_parent5, 1);
10118
sunxdc044b11a2016-03-16 16:23:2010119 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10120 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10121 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10122 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310123 expected_scroll_tree.set_needs_update(false);
10124
10125 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10126
10127 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010128 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310129 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10130 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10131 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10132 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10133 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10134 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10135}
10136
[email protected]ba565742012-11-10 09:29:4810137} // namespace
10138} // namespace cc