blob: 090f0d5c57009a2dc132bb90d9aab7669d33f804 [file] [log] [blame]
ajumae2b7a5c2015-09-30 21:41:421// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_common.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj6496cba2014-10-16 01:31:089#include <algorithm>
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]995708c52013-10-17 20:52:5911#include <set>
vmpstra370ef52015-11-18 10:41:2812#include <vector>
[email protected]995708c52013-10-17 20:52:5913
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
loyso968163c92016-01-04 23:18:4815#include "cc/animation/animation_host.h"
16#include "cc/animation/animation_id_provider.h"
sunxd71aea3e2016-04-01 23:48:0517#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3418#include "cc/animation/keyframed_animation_curve.h"
[email protected]1c3626e2014-04-09 17:49:2219#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5220#include "cc/base/math_util.h"
sunxd29f17bf422016-02-03 02:47:4821#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5924#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5225#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4026#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2827#include "cc/layers/render_surface_impl.h"
jaydasika69c77aa2016-07-14 22:48:4828#include "cc/layers/texture_layer_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4529#include "cc/output/copy_output_request.h"
30#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0331#include "cc/test/animation_test_common.h"
danakj1120f4c2016-09-15 02:05:3232#include "cc/test/fake_compositor_frame_sink.h"
vollick2175fae82015-04-27 21:18:1233#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1634#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2835#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4536#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5937#include "cc/test/fake_picture_layer.h"
38#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0339#include "cc/test/geometry_test_utils.h"
danakj59931942016-07-26 22:11:2940#include "cc/test/layer_test_common.h"
reveman34b7a1522015-03-23 20:27:4741#include "cc/test/test_task_graph_runner.h"
trchendba8b1502016-07-08 09:47:0142#include "cc/trees/clip_node.h"
ennef6903532015-08-18 05:10:1543#include "cc/trees/draw_property_utils.h"
trchendba8b1502016-07-08 09:47:0144#include "cc/trees/effect_node.h"
[email protected]556fd292013-03-18 08:03:0445#include "cc/trees/layer_tree_impl.h"
danakj59931942016-07-26 22:11:2946#include "cc/trees/property_tree_builder.h"
trchendba8b1502016-07-08 09:47:0147#include "cc/trees/scroll_node.h"
[email protected]556fd292013-03-18 08:03:0448#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1649#include "cc/trees/task_runner_provider.h"
trchendba8b1502016-07-08 09:47:0150#include "cc/trees/transform_node.h"
[email protected]7f0c53db2012-10-02 00:23:1851#include "testing/gtest/include/gtest/gtest.h"
ajumae947a352017-01-10 19:17:4952#include "third_party/skia/include/core/SkImageFilter.h"
jbroman1c44d5b52016-06-06 21:19:3053#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
ajumae947a352017-01-10 19:17:4954#include "third_party/skia/include/effects/SkXfermodeImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2055#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3756#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0057#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1458
[email protected]ba565742012-11-10 09:29:4859namespace cc {
[email protected]94f206c12012-08-25 00:09:1460namespace {
61
danakj59931942016-07-26 22:11:2962class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings {
63 public:
64 VerifyTreeCalcsLayerTreeSettings() {
jaydasika853306a2016-07-29 19:28:3465 verify_clip_tree_calculations = true;
danakj59931942016-07-26 22:11:2966 }
67};
68
69class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest {
70 public:
71 LayerTreeHostCommonTestBase()
72 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {}
73 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings)
74 : LayerTestCommon::LayerImplTest(settings) {}
75
76 static void SetScrollOffsetDelta(LayerImpl* layer_impl,
77 const gfx::Vector2dF& delta) {
78 if (layer_impl->layer_tree_impl()
79 ->property_trees()
80 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(),
81 delta))
vollickc9696912016-09-16 16:02:4782 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id());
danakj59931942016-07-26 22:11:2983 }
84
85 static float GetMaximumAnimationScale(LayerImpl* layer_impl) {
86 return layer_impl->layer_tree_impl()
87 ->property_trees()
88 ->GetAnimationScales(layer_impl->transform_tree_index(),
89 layer_impl->layer_tree_impl())
90 .maximum_animation_scale;
91 }
92
93 static float GetStartingAnimationScale(LayerImpl* layer_impl) {
94 return layer_impl->layer_tree_impl()
95 ->property_trees()
96 ->GetAnimationScales(layer_impl->transform_tree_index(),
97 layer_impl->layer_tree_impl())
98 .starting_animation_scale;
99 }
100
101 void ExecuteCalculateDrawProperties(Layer* root_layer,
102 float device_scale_factor,
103 float page_scale_factor,
flackre310f292016-10-12 21:09:28104 Layer* page_scale_layer,
flackra283bed2016-10-31 14:49:42105 Layer* inner_viewport_scroll_layer,
106 Layer* outer_viewport_scroll_layer) {
danakj59931942016-07-26 22:11:29107 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer);
108
109 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
110 gfx::Size device_viewport_size =
111 gfx::Size(root_layer->bounds().width() * device_scale_factor,
112 root_layer->bounds().height() * device_scale_factor);
113
114 // We are probably not testing what is intended if the root_layer bounds are
115 // empty.
116 DCHECK(!root_layer->bounds().IsEmpty());
117 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
118 root_layer, device_viewport_size);
119 inputs.device_scale_factor = device_scale_factor;
120 inputs.page_scale_factor = page_scale_factor;
121 inputs.page_scale_layer = page_scale_layer;
flackre310f292016-10-12 21:09:28122 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
flackra283bed2016-10-31 14:49:42123 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer;
danakj59931942016-07-26 22:11:29124 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
125 }
126
jaydasika5237db02016-09-20 01:34:30127 void ExecuteCalculateDrawProperties(
128 LayerImpl* root_layer,
129 float device_scale_factor,
130 float page_scale_factor,
131 LayerImpl* page_scale_layer,
flackre310f292016-10-12 21:09:28132 LayerImpl* inner_viewport_scroll_layer,
flackra283bed2016-10-31 14:49:42133 LayerImpl* outer_viewport_scroll_layer,
jaydasika5237db02016-09-20 01:34:30134 bool skip_verify_visible_rect_calculations = false) {
danakj59931942016-07-26 22:11:29135 if (device_scale_factor !=
136 root_layer->layer_tree_impl()->device_scale_factor())
137 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
138
139 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
140
141 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
142
143 gfx::Size device_viewport_size =
144 gfx::Size(root_layer->bounds().width() * device_scale_factor,
145 root_layer->bounds().height() * device_scale_factor);
146
147 render_surface_layer_list_impl_.reset(new LayerImplList);
148
149 // We are probably not testing what is intended if the root_layer bounds are
150 // empty.
151 DCHECK(!root_layer->bounds().IsEmpty());
152 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
153 root_layer, device_viewport_size,
154 render_surface_layer_list_impl_.get());
155 inputs.device_scale_factor = device_scale_factor;
156 inputs.page_scale_factor = page_scale_factor;
157 inputs.page_scale_layer = page_scale_layer;
flackre310f292016-10-12 21:09:28158 inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer;
flackra283bed2016-10-31 14:49:42159 inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer;
danakj59931942016-07-26 22:11:29160 inputs.can_adjust_raster_scales = true;
jaydasika5237db02016-09-20 01:34:30161 if (skip_verify_visible_rect_calculations)
162 inputs.verify_visible_rect_calculations = false;
danakj59931942016-07-26 22:11:29163
164 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
165 }
166
167 template <class LayerType>
168 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
169 LayerType* page_scale_application_layer = nullptr;
flackre310f292016-10-12 21:09:28170 LayerType* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:42171 LayerType* outer_viewport_scroll_layer = nullptr;
172 ExecuteCalculateDrawProperties(
173 root_layer, 1.f, 1.f, page_scale_application_layer,
174 inner_viewport_scroll_layer, outer_viewport_scroll_layer);
danakj59931942016-07-26 22:11:29175 }
176
177 template <class LayerType>
178 void ExecuteCalculateDrawProperties(LayerType* root_layer,
179 float device_scale_factor) {
180 LayerType* page_scale_application_layer = nullptr;
flackre310f292016-10-12 21:09:28181 LayerType* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:42182 LayerType* outer_viewport_scroll_layer = nullptr;
183 ExecuteCalculateDrawProperties(
184 root_layer, device_scale_factor, 1.f, page_scale_application_layer,
185 inner_viewport_scroll_layer, outer_viewport_scroll_layer);
danakj59931942016-07-26 22:11:29186 }
187
sunxd713aedbd2016-08-10 22:22:14188 const LayerList* GetUpdateLayerList() { return &update_layer_list_; }
189
jaydasika6ed869662016-09-21 14:29:59190 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(Layer* root_layer) {
khushalsagarb69ba9452017-01-27 22:20:07191 DCHECK(root_layer->layer_tree_host());
danakj59931942016-07-26 22:11:29192 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer);
193
194 bool can_render_to_separate_surface = true;
195
196 const Layer* page_scale_layer =
khushalsagarb69ba9452017-01-27 22:20:07197 root_layer->layer_tree_host()->page_scale_layer();
danakj59931942016-07-26 22:11:29198 Layer* inner_viewport_scroll_layer =
khushalsagarb69ba9452017-01-27 22:20:07199 root_layer->layer_tree_host()->inner_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29200 Layer* outer_viewport_scroll_layer =
khushalsagarb69ba9452017-01-27 22:20:07201 root_layer->layer_tree_host()->outer_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29202 const Layer* overscroll_elasticity_layer =
khushalsagarb69ba9452017-01-27 22:20:07203 root_layer->layer_tree_host()->overscroll_elasticity_layer();
danakj59931942016-07-26 22:11:29204 gfx::Vector2dF elastic_overscroll =
khushalsagarb69ba9452017-01-27 22:20:07205 root_layer->layer_tree_host()->elastic_overscroll();
danakj59931942016-07-26 22:11:29206 float page_scale_factor = 1.f;
207 float device_scale_factor = 1.f;
208 gfx::Size device_viewport_size =
209 gfx::Size(root_layer->bounds().width() * device_scale_factor,
210 root_layer->bounds().height() * device_scale_factor);
211 PropertyTrees* property_trees =
khushalsagarb69ba9452017-01-27 22:20:07212 root_layer->layer_tree_host()->property_trees();
danakj59931942016-07-26 22:11:29213 update_layer_list_.clear();
214 PropertyTreeBuilder::BuildPropertyTrees(
215 root_layer, page_scale_layer, inner_viewport_scroll_layer,
216 outer_viewport_scroll_layer, overscroll_elasticity_layer,
217 elastic_overscroll, page_scale_factor, device_scale_factor,
218 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees);
219 draw_property_utils::UpdatePropertyTrees(property_trees,
220 can_render_to_separate_surface);
221 draw_property_utils::FindLayersThatNeedUpdates(
khushalsagarb69ba9452017-01-27 22:20:07222 root_layer->layer_tree_host(), property_trees, &update_layer_list_);
danakj59931942016-07-26 22:11:29223 }
224
jaydasika6ed869662016-09-21 14:29:59225 void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
226 LayerImpl* root_layer,
227 bool skip_verify_visible_rect_calculations = false) {
danakj59931942016-07-26 22:11:29228 DCHECK(root_layer->layer_tree_impl());
229 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer);
230
231 bool can_render_to_separate_surface = true;
232
233 LayerImpl* page_scale_layer = nullptr;
234 LayerImpl* inner_viewport_scroll_layer =
235 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
236 LayerImpl* outer_viewport_scroll_layer =
237 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
238 LayerImpl* overscroll_elasticity_layer =
239 root_layer->layer_tree_impl()->OverscrollElasticityLayer();
240 gfx::Vector2dF elastic_overscroll =
241 root_layer->layer_tree_impl()->elastic_overscroll()->Current(
242 root_layer->layer_tree_impl()->IsActiveTree());
243 float page_scale_factor = 1.f;
244 float device_scale_factor = 1.f;
245 gfx::Size device_viewport_size =
246 gfx::Size(root_layer->bounds().width() * device_scale_factor,
247 root_layer->bounds().height() * device_scale_factor);
248 update_layer_list_impl_.reset(new LayerImplList);
249 root_layer->layer_tree_impl()->BuildLayerListForTesting();
jaydasika6ed869662016-09-21 14:29:59250 PropertyTrees* property_trees =
251 root_layer->layer_tree_impl()->property_trees();
danakj59931942016-07-26 22:11:29252 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects(
253 root_layer, page_scale_layer, inner_viewport_scroll_layer,
254 outer_viewport_scroll_layer, overscroll_elasticity_layer,
255 elastic_overscroll, page_scale_factor, device_scale_factor,
256 gfx::Rect(device_viewport_size), gfx::Transform(),
jaydasika6ed869662016-09-21 14:29:59257 can_render_to_separate_surface, property_trees,
danakj59931942016-07-26 22:11:29258 update_layer_list_impl_.get());
jaydasika6ed869662016-09-21 14:29:59259 draw_property_utils::VerifyClipTreeCalculations(*update_layer_list_impl_,
260 property_trees);
261 if (!skip_verify_visible_rect_calculations)
262 draw_property_utils::VerifyVisibleRectsCalculations(
263 *update_layer_list_impl_, property_trees);
danakj59931942016-07-26 22:11:29264 }
265
266 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(
267 LayerImpl* root_layer) {
268 gfx::Size device_viewport_size =
269 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height());
270 render_surface_layer_list_impl_.reset(new LayerImplList);
271
272 DCHECK(!root_layer->bounds().IsEmpty());
273 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
274 root_layer, device_viewport_size,
275 render_surface_layer_list_impl_.get());
276 inputs.can_adjust_raster_scales = true;
277 inputs.can_render_to_separate_surface = false;
278
279 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
280 }
281
282 bool UpdateLayerListImplContains(int id) const {
283 for (auto* layer : *update_layer_list_impl_) {
284 if (layer->id() == id)
285 return true;
286 }
287 return false;
288 }
289
290 bool UpdateLayerListContains(int id) const {
291 for (const auto& layer : update_layer_list_) {
292 if (layer->id() == id)
293 return true;
294 }
295 return false;
296 }
297
298 const LayerImplList* render_surface_layer_list_impl() const {
299 return render_surface_layer_list_impl_.get();
300 }
301 const LayerImplList* update_layer_list_impl() const {
302 return update_layer_list_impl_.get();
303 }
304 const LayerList& update_layer_list() const { return update_layer_list_; }
305
sunxd713aedbd2016-08-10 22:22:14306 bool VerifyLayerInList(scoped_refptr<Layer> layer,
307 const LayerList* layer_list) {
308 return std::find(layer_list->begin(), layer_list->end(), layer) !=
309 layer_list->end();
310 }
311
danakj59931942016-07-26 22:11:29312 private:
313 std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_;
314 LayerList update_layer_list_;
315 std::unique_ptr<LayerImplList> update_layer_list_impl_;
316};
317
318class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
319 public testing::Test {};
320
[email protected]96baf3e2012-10-22 23:09:55321class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32322 public:
loyso0940d412016-03-14 01:30:31323 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14324
danakj59931942016-07-26 22:11:29325 bool DrawsContent() const override { return true; }
[email protected]d58499a2012-10-09 22:27:47326
[email protected]fb661802013-03-25 01:59:32327 private:
dcheng716bedf2014-10-21 09:51:08328 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:14329};
330
danakj59931942016-07-26 22:11:29331class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings {
enne637715732015-07-07 02:05:26332 public:
333 LayerTreeSettingsScaleContent() {
334 layer_transforms_should_scale_layer_contents = true;
335 }
336};
337
danakj59931942016-07-26 22:11:29338class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase,
339 public testing::Test {
enne637715732015-07-07 02:05:26340 public:
341 LayerTreeHostCommonScalingTest()
danakj59931942016-07-26 22:11:29342 : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {}
enne637715732015-07-07 02:05:26343};
344
weiliangc6da32862016-04-20 16:40:11345class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
346 public:
347 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
348
349 LayerImpl* TestVisibleRectAndDrawableContentRect(
350 const gfx::Rect& target_rect,
351 const gfx::Transform& layer_transform,
352 const gfx::Rect& layer_rect) {
jaydasikabf1875a2016-06-28 03:39:59353 LayerImpl* root = root_layer_for_testing();
weiliangc6da32862016-04-20 16:40:11354 LayerImpl* target = AddChild<LayerImpl>(root);
355 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
356
357 root->SetDrawsContent(true);
358 target->SetDrawsContent(true);
359 target->SetMasksToBounds(true);
360 drawing_layer->SetDrawsContent(true);
361
danakje4fa7b72016-07-25 22:00:06362 root->SetBounds(gfx::Size(500, 500));
363 root->test_properties()->force_render_surface = true;
364 target->SetPosition(gfx::PointF(target_rect.origin()));
365 target->SetBounds(target_rect.size());
366 target->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:04367 drawing_layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06368 drawing_layer->SetPosition(gfx::PointF(layer_rect.origin()));
369 drawing_layer->SetBounds(layer_rect.size());
370 drawing_layer->test_properties()->should_flatten_transform = false;
weiliangc6da32862016-04-20 16:40:11371
372 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
373 ExecuteCalculateDrawProperties(root);
374
375 return drawing_layer;
376 }
377};
378
[email protected]989386c2013-07-18 21:37:23379TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32380 // Sanity check: For layers positioned at zero, with zero size,
381 // and with identity transforms, then the draw transform,
382 // screen space transform, and the hierarchy passed on to children
383 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14384
jaydasikabf1875a2016-06-28 03:39:59385 LayerImpl* parent = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51386 LayerImpl* child = AddChild<LayerImpl>(parent);
387 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28388
danakje4fa7b72016-07-25 22:00:06389 parent->SetBounds(gfx::Size(100, 100));
[email protected]94f206c12012-08-25 00:09:14390
sunxdfd920f3f2016-04-05 16:17:51391 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14392
danakjf78fb272016-07-26 19:06:15393 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
394 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51395 child->ScreenSpaceTransform());
danakjf78fb272016-07-26 19:06:15396 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51397 grand_child->DrawTransform());
danakjf78fb272016-07-26 19:06:15398 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51399 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14400}
401
jaydasika322436372015-12-16 23:42:38402TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
403 // Tests that effect tree node gets a valid transform id when a layer
404 // has opacity but doesn't create a render surface.
jaydasikabf1875a2016-06-28 03:39:59405 LayerImpl* parent = root_layer_for_testing();
jaydasika322436372015-12-16 23:42:38406 LayerImpl* child = AddChild<LayerImpl>(parent);
407 child->SetDrawsContent(true);
408
danakje4fa7b72016-07-25 22:00:06409 parent->SetBounds(gfx::Size(100, 100));
410 child->SetPosition(gfx::PointF(10, 10));
411 child->SetBounds(gfx::Size(100, 100));
jaydasikaab317e02016-06-01 00:53:18412 child->test_properties()->opacity = 0.f;
jaydasika322436372015-12-16 23:42:38413 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04414 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38415 parent->layer_tree_impl()->property_trees()->effect_tree;
416 EffectNode* node = effect_tree.Node(child->effect_tree_index());
417 const int transform_tree_size = parent->layer_tree_impl()
418 ->property_trees()
419 ->transform_tree.next_available_id();
trchendba8b1502016-07-08 09:47:01420 EXPECT_LT(node->transform_id, transform_tree_size);
jaydasika322436372015-12-16 23:42:38421}
422
[email protected]989386c2013-07-18 21:37:23423TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
jaydasikabf1875a2016-06-28 03:39:59424 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51425 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14426
jaydasikabaede2d92016-07-20 00:34:32427 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51428 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32429 EffectTree& effect_tree =
430 host_impl()->active_tree()->property_trees()->effect_tree;
enne826452722015-08-18 22:22:31431
danakje4fa7b72016-07-25 22:00:06432 root->SetBounds(gfx::Size(1, 2));
433
434 // Case 1: Setting the bounds of the layer should not affect either the draw
[email protected]fb661802013-03-25 01:59:32435 // transform or the screenspace transform.
danakje4fa7b72016-07-25 22:00:06436 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51437 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31438 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15439 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32440 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31441 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15442 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32443 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14444
danakje4fa7b72016-07-25 22:00:06445 // Case 2: The anchor point by itself (without a layer transform) should have
[email protected]fb661802013-03-25 01:59:32446 // no effect on the transforms.
danakje4fa7b72016-07-25 22:00:06447 layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
448 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51449 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
450 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31451 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15452 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32453 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31454 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15455 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32456 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14457
danakje4fa7b72016-07-25 22:00:06458 // Case 3: A change in actual position affects both the draw transform and
[email protected]fb661802013-03-25 01:59:32459 // screen space transform.
460 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05461 position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06462 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51463 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
464 ExecuteCalculateDrawProperties(root);
465 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32466 position_transform,
467 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31468 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27469 position_transform,
jaydasikabaede2d92016-07-20 00:34:32470 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14471
danakje4fa7b72016-07-25 22:00:06472 // Case 4: In the correct sequence of transforms, the layer transform should
473 // pre-multiply the translation-to-center. This is easily tested by using a
[email protected]fb661802013-03-25 01:59:32474 // scale transform, because scale and translation are not commutative.
475 gfx::Transform layer_transform;
476 layer_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:04477 layer->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06478 layer->test_properties()->transform_origin = gfx::Point3F();
479 layer->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51480 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
481 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31482 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32483 layer_transform,
484 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31485 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32486 layer_transform,
487 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14488
danakje4fa7b72016-07-25 22:00:06489 // Case 5: The layer transform should occur with respect to the anchor point.
[email protected]fb661802013-03-25 01:59:32490 gfx::Transform translation_to_anchor;
491 translation_to_anchor.Translate(5.0, 0.0);
492 gfx::Transform expected_result =
493 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06494 layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f);
sunxdfd920f3f2016-04-05 16:17:51495 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
496 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31497 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32498 expected_result,
499 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31500 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32501 expected_result,
502 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14503
danakje4fa7b72016-07-25 22:00:06504 // Case 6: Verify that position pre-multiplies the layer transform. The
[email protected]fb661802013-03-25 01:59:32505 // current implementation of CalculateDrawProperties does this implicitly, but
506 // it is still worth testing to detect accidental regressions.
507 expected_result = position_transform * translation_to_anchor *
508 layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06509 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51510 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
511 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31512 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32513 expected_result,
514 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31515 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32516 expected_result,
517 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14518}
519
[email protected]989386c2013-07-18 21:37:23520TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13521 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32522 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01523 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32524 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
525 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16526 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32527 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20528
khushalsagarb64b360d2015-10-21 19:25:16529 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:56530 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:22531 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20532
danakj60bc3bc2016-04-09 00:24:48533 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32534 LayerImpl::Create(host_impl.active_tree(), 1));
535 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28536 sublayer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:06537 sublayer->SetBounds(gfx::Size(500, 500));
[email protected]657b24c2013-03-06 09:01:20538
danakj60bc3bc2016-04-09 00:24:48539 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32540 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47541 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
danakje4fa7b72016-07-25 22:00:06542 scroll_layer->SetBounds(gfx::Size(10, 20));
danakj60bc3bc2016-04-09 00:24:48543 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
[email protected]adeda572014-01-31 00:49:47544 LayerImpl::Create(host_impl.active_tree(), 4));
545 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
546
547 scroll_layer->SetScrollClipLayer(clip_layer->id());
548 clip_layer->SetBounds(
549 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
550 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
551 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42552 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32553 gfx::Transform impl_transform;
jaydasika89f7b5a2016-06-22 02:08:39554 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47555 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
jaydasika89f7b5a2016-06-22 02:08:39556 clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42557 scroll_layer_raw_ptr->layer_tree_impl()
558 ->property_trees()
559 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
560 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20561
danakj60bc3bc2016-04-09 00:24:48562 std::unique_ptr<LayerImpl> root(
563 LayerImpl::Create(host_impl.active_tree(), 3));
danakje4fa7b72016-07-25 22:00:06564 root->SetBounds(gfx::Size(3, 4));
jaydasika89f7b5a2016-06-22 02:08:39565 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr));
jaydasika2411692c2016-03-23 01:56:09566 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59567 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
[email protected]657b24c2013-03-06 09:01:20568
jaydasikaa534a472016-03-31 01:12:16569 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28570 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42571 nullptr, nullptr);
danakjf78fb272016-07-26 19:06:15572 gfx::Transform expected_transform;
[email protected]fb661802013-03-25 01:59:32573 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33574 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16575 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33576 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16577 page_scale * kDeviceScale));
578 expected_transform.Scale(page_scale * kDeviceScale,
579 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32580 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44581 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32582 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10583 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20584
[email protected]fb661802013-03-25 01:59:32585 gfx::Transform arbitrary_translate;
586 const float kTranslateX = 10.6f;
587 const float kTranslateY = 20.6f;
588 arbitrary_translate.Translate(kTranslateX, kTranslateY);
jaydasika10d43fc2016-08-18 04:06:04589 scroll_layer->test_properties()->transform = arbitrary_translate;
jaydasika2411692c2016-03-23 01:56:09590 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16591 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28592 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42593 nullptr, nullptr);
[email protected]fb661802013-03-25 01:59:32594 expected_transform.MakeIdentity();
595 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16596 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
597 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33598 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16599 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
600 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33601 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16602 expected_transform.Scale(page_scale * kDeviceScale,
603 page_scale * kDeviceScale);
604 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
605 sublayer->DrawTransform());
606
607 // Test that page scale is updated even when we don't rebuild property trees.
608 page_scale = 1.888f;
609 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
jaydasikaf419bf72016-06-15 10:21:21610 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(),
611 Layer::INVALID_ID, Layer::INVALID_ID);
jaydasikaa534a472016-03-31 01:12:16612 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
613 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
614 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28615 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42616 nullptr, nullptr);
jaydasikaa534a472016-03-31 01:12:16617
618 expected_transform.MakeIdentity();
619 expected_transform.Translate(
620 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
621 sub_layer_screen_position.x() * page_scale *
622 kDeviceScale),
623 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
624 sub_layer_screen_position.y() * page_scale *
625 kDeviceScale));
626 expected_transform.Scale(page_scale * kDeviceScale,
627 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32628 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44629 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20630}
631
[email protected]989386c2013-07-18 21:37:23632TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
jaydasikabf1875a2016-06-28 03:39:59633 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51634 LayerImpl* parent = AddChild<LayerImpl>(root);
635 LayerImpl* child = AddChild<LayerImpl>(parent);
636 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28637
[email protected]fb661802013-03-25 01:59:32638 // One-time setup of root layer
danakje4fa7b72016-07-25 22:00:06639 root->SetBounds(gfx::Size(1, 2));
enne826452722015-08-18 22:22:31640
jaydasikabaede2d92016-07-20 00:34:32641 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51642 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32643 EffectTree& effect_tree =
644 host_impl()->active_tree()->property_trees()->effect_tree;
[email protected]ecc12622012-10-30 20:45:42645
[email protected]fb661802013-03-25 01:59:32646 // Case 1: parent's anchor point should not affect child or grand_child.
danakje4fa7b72016-07-25 22:00:06647 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
648 parent->SetBounds(gfx::Size(10, 12));
649 child->SetBounds(gfx::Size(16, 18));
650 grand_child->SetBounds(gfx::Size(76, 78));
sunxdfd920f3f2016-04-05 16:17:51651 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31652
653 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15654 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32655 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31656 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15657 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32658 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
659 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15660 gfx::Transform(), draw_property_utils::DrawTransform(
661 grand_child, transform_tree, effect_tree));
jaydasikabaede2d92016-07-20 00:34:32662 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15663 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32664 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14665
[email protected]fb661802013-03-25 01:59:32666 // Case 2: parent's position affects child and grand_child.
667 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05668 parent_position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06669 parent->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51670 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
671 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31672 EXPECT_TRANSFORMATION_MATRIX_EQ(
673 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32674 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31675 EXPECT_TRANSFORMATION_MATRIX_EQ(
676 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32677 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
678 EXPECT_TRANSFORMATION_MATRIX_EQ(
679 parent_position_transform, draw_property_utils::DrawTransform(
680 grand_child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31681 EXPECT_TRANSFORMATION_MATRIX_EQ(
682 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32683 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14684
[email protected]fb661802013-03-25 01:59:32685 // Case 3: parent's local transform affects child and grandchild
686 gfx::Transform parent_layer_transform;
687 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
688 gfx::Transform parent_translation_to_anchor;
689 parent_translation_to_anchor.Translate(2.5, 3.0);
690 gfx::Transform parent_composite_transform =
691 parent_translation_to_anchor * parent_layer_transform *
692 Inverse(parent_translation_to_anchor);
jaydasika10d43fc2016-08-18 04:06:04693 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06694 parent->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51695 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
696 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31697 EXPECT_TRANSFORMATION_MATRIX_EQ(
698 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32699 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31700 EXPECT_TRANSFORMATION_MATRIX_EQ(
701 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32702 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
enne826452722015-08-18 22:22:31703 EXPECT_TRANSFORMATION_MATRIX_EQ(
704 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32705 draw_property_utils::DrawTransform(grand_child, transform_tree,
706 effect_tree));
enne826452722015-08-18 22:22:31707 EXPECT_TRANSFORMATION_MATRIX_EQ(
708 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32709 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14710}
711
[email protected]989386c2013-07-18 21:37:23712TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:59713 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28714 LayerImpl* parent = AddChildToRoot<LayerImpl>();
715 LayerImpl* child = AddChild<LayerImpl>(parent);
716 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]94f206c12012-08-25 00:09:14717
[email protected]fb661802013-03-25 01:59:32718 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05719 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32720 gfx::Transform parent_translation_to_anchor;
721 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44722
[email protected]fb661802013-03-25 01:59:32723 gfx::Transform parent_composite_transform =
724 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39725 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32726 gfx::Vector2dF parent_composite_scale =
727 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
728 1.f);
729 gfx::Transform surface_sublayer_transform;
730 surface_sublayer_transform.Scale(parent_composite_scale.x(),
731 parent_composite_scale.y());
732 gfx::Transform surface_sublayer_composite_transform =
733 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14734
danakje4fa7b72016-07-25 22:00:06735 root->SetBounds(gfx::Size(1, 2));
jaydasika10d43fc2016-08-18 04:06:04736 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06737 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
738 parent->SetBounds(gfx::Size(100, 120));
739 child->SetBounds(gfx::Size(16, 18));
740 child->test_properties()->force_render_surface = true;
741 grand_child->SetBounds(gfx::Size(8, 10));
742 grand_child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28743 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14744
[email protected]fb661802013-03-25 01:59:32745 // Render surface should have been created now.
746 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25747 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14748
[email protected]fb661802013-03-25 01:59:32749 // The child layer's draw transform should refer to its new render surface.
750 // The screen-space transform, however, should still refer to the root.
751 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44752 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32753 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10754 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14755
[email protected]fb661802013-03-25 01:59:32756 // Because the grand_child is the only drawable content, the child's render
757 // surface will tighten its bounds to the grand_child. The scale at which the
758 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25759 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
760 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14761
[email protected]fb661802013-03-25 01:59:32762 // The screen space is the same as the target since the child surface draws
763 // into the root.
764 EXPECT_TRANSFORMATION_MATRIX_EQ(
765 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25766 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14767}
768
ajuma51d73f72015-10-19 19:43:58769TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:59770 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:58771 LayerImpl* parent = AddChildToRoot<LayerImpl>();
772 LayerImpl* child = AddChild<LayerImpl>(parent);
773 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma51d73f72015-10-19 19:43:58774
775 gfx::Transform parent_transform;
776 parent_transform.Translate(10.0, 10.0);
777
778 gfx::Transform child_transform;
779 child_transform.Rotate(45.0);
780
danakje4fa7b72016-07-25 22:00:06781 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:04782 parent->test_properties()->transform = parent_transform;
danakje4fa7b72016-07-25 22:00:06783 parent->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:04784 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:06785 child->SetBounds(gfx::Size(10, 10));
786 child->test_properties()->force_render_surface = true;
787 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
788 grand_child->SetBounds(gfx::Size(20, 20));
789 grand_child->SetDrawsContent(true);
ajuma51d73f72015-10-19 19:43:58790
791 gfx::Transform expected_grand_child_screen_space_transform;
792 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
793 expected_grand_child_screen_space_transform.Rotate(45.0);
794 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
795
796 // First compute draw properties with separate surfaces enabled.
797 ExecuteCalculateDrawProperties(root);
798
799 // The grand child's draw transform should be its offset wrt the child.
800 gfx::Transform expected_grand_child_draw_transform;
801 expected_grand_child_draw_transform.Translate(2.0, 2.0);
802 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44803 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58804 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10805 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58806
807 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
808
809 // With separate surfaces disabled, the grand child's draw transform should be
810 // the same as its screen space transform.
811 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44812 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58813 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10814 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58815}
816
[email protected]989386c2013-07-18 21:37:23817TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32818 // This test creates a more complex tree and verifies it all at once. This
819 // covers the following cases:
820 // - layers that are described w.r.t. a render surface: should have draw
821 // transforms described w.r.t. that surface
822 // - A render surface described w.r.t. an ancestor render surface: should
823 // have a draw transform described w.r.t. that ancestor surface
[email protected]fb661802013-03-25 01:59:32824 // - Sanity check on recursion: verify transforms of layers described w.r.t.
825 // a render surface that is described w.r.t. an ancestor render surface.
826 // - verifying that each layer has a reference to the correct render surface
827 // and render target values.
828
jaydasikabf1875a2016-06-28 03:39:59829 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28830 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36831 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28832 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36833 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28834 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36835 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28836 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36837 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28838 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36839 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28840 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36841 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28842 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36843 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28844 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
845 grand_child_of_rs1->SetDrawsContent(true);
846 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
847 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32848
[email protected]fb661802013-03-25 01:59:32849 // In combination with descendant draws content, opacity != 1 forces the layer
850 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18851 render_surface1->test_properties()->opacity = 0.5f;
852 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32853
[email protected]fb661802013-03-25 01:59:32854 // All layers in the tree are initialized with an anchor at .25 and a size of
wangxianzhu932d7f12016-09-30 05:47:00855 // (10,10). Matrix "A" is the composite layer transform used in all layers.
[email protected]fb661802013-03-25 01:59:32856 gfx::Transform translation_to_anchor;
857 translation_to_anchor.Translate(2.5, 0.0);
858 gfx::Transform layer_transform;
859 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32860
861 gfx::Transform A =
862 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32863
864 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39865 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32866 gfx::Transform surface1_sublayer_transform;
867 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
868 surface1_parent_transform_scale.y());
869
870 // SS1 = transform given to the subtree of render_surface1
871 gfx::Transform SS1 = surface1_sublayer_transform;
872 // S1 = transform to move from render_surface1 pixels to the layer space of
873 // the owning layer
874 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
875
876 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39877 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32878 gfx::Transform surface2_sublayer_transform;
879 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
880 surface2_parent_transform_scale.y());
881
882 // SS2 = transform given to the subtree of render_surface2
883 gfx::Transform SS2 = surface2_sublayer_transform;
884 // S2 = transform to move from render_surface2 pixels to the layer space of
885 // the owning layer
886 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
887
danakje4fa7b72016-07-25 22:00:06888 root->SetBounds(gfx::Size(1, 2));
889 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04890 parent->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06891 parent->SetBounds(gfx::Size(10, 10));
892 render_surface1->test_properties()->transform_origin =
893 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04894 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06895 render_surface1->SetBounds(gfx::Size(10, 10));
896 render_surface1->test_properties()->force_render_surface = true;
897 render_surface2->test_properties()->transform_origin =
898 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04899 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06900 render_surface2->SetBounds(gfx::Size(10, 10));
901 render_surface2->test_properties()->force_render_surface = true;
902 child_of_root->test_properties()->transform_origin =
903 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04904 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06905 child_of_root->SetBounds(gfx::Size(10, 10));
906 child_of_rs1->test_properties()->transform_origin =
907 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04908 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06909 child_of_rs1->SetBounds(gfx::Size(10, 10));
910 child_of_rs2->test_properties()->transform_origin =
911 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04912 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06913 child_of_rs2->SetBounds(gfx::Size(10, 10));
914 grand_child_of_root->test_properties()->transform_origin =
915 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04916 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06917 grand_child_of_root->SetBounds(gfx::Size(10, 10));
918 grand_child_of_rs1->test_properties()->transform_origin =
919 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04920 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06921 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
922 grand_child_of_rs2->test_properties()->transform_origin =
923 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04924 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06925 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:32926
enne25dea3f2015-07-27 16:44:28927 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32928
929 // Only layers that are associated with render surfaces should have an actual
930 // RenderSurface() value.
931 ASSERT_TRUE(root->render_surface());
932 ASSERT_FALSE(child_of_root->render_surface());
933 ASSERT_FALSE(grand_child_of_root->render_surface());
934
935 ASSERT_TRUE(render_surface1->render_surface());
936 ASSERT_FALSE(child_of_rs1->render_surface());
937 ASSERT_FALSE(grand_child_of_rs1->render_surface());
938
939 ASSERT_TRUE(render_surface2->render_surface());
940 ASSERT_FALSE(child_of_rs2->render_surface());
941 ASSERT_FALSE(grand_child_of_rs2->render_surface());
942
943 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25944 EXPECT_EQ(root->render_surface(), parent->render_target());
945 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
946 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32947
weiliangc189c1a12016-04-11 16:16:25948 EXPECT_EQ(render_surface1->render_surface(),
949 render_surface1->render_target());
950 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
951 EXPECT_EQ(render_surface1->render_surface(),
952 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32953
weiliangc189c1a12016-04-11 16:16:25954 EXPECT_EQ(render_surface2->render_surface(),
955 render_surface2->render_target());
956 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
957 EXPECT_EQ(render_surface2->render_surface(),
958 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32959
960 // Verify layer draw transforms note that draw transforms are described with
961 // respect to the nearest ancestor render surface but screen space transforms
962 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44963 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
964 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39965 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44966 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32967
ajumad9432e32015-11-30 19:43:44968 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
969 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39970 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44971 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32972
ajumad9432e32015-11-30 19:43:44973 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
974 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39975 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44976 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32977
978 // Verify layer screen-space transforms
979 //
ajumab6aa1c62015-12-01 21:01:10980 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
981 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
982 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
983 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32984
[email protected]baf64d062014-02-16 22:10:39985 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10986 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39987 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10988 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39989 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10990 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32991
[email protected]baf64d062014-02-16 22:10:39992 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10993 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39994 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10995 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39996 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10997 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32998
999 // Verify render surface transforms.
1000 //
1001 // Draw transform of render surface 1 is described with respect to root.
1002 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391003 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321004 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391005 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321006 // Draw transform of render surface 2 is described with respect to render
1007 // surface 1.
1008 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391009 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321010 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391011 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321012 render_surface2->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321013
1014 // Sanity check. If these fail there is probably a bug in the test itself. It
1015 // is expected that we correctly set up transforms so that the y-component of
1016 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:101017 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:261018 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101019 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321020 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101021 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321022
[email protected]803f6b52013-09-12 00:51:261023 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101024 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
1025 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321026 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101027 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321028
[email protected]803f6b52013-09-12 00:51:261029 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:101030 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
1031 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321032 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101033 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321034}
1035
[email protected]989386c2013-07-18 21:37:231036TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321037 // For layers that flatten their subtree, there should be an orthographic
1038 // projection (for x and y values) in the middle of the transform sequence.
1039 // Note that the way the code is currently implemented, it is not expected to
1040 // use a canonical orthographic projection.
1041
jaydasikabf1875a2016-06-28 03:39:591042 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:281043 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:361044 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:281045 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1046 grand_child->SetDrawsContent(true);
1047 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1048 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321049
1050 gfx::Transform rotation_about_y_axis;
1051 rotation_about_y_axis.RotateAboutYAxis(30.0);
1052
danakje4fa7b72016-07-25 22:00:061053 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041054 child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061055 child->SetBounds(gfx::Size(10, 10));
1056 child->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041057 grand_child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061058 grand_child->SetBounds(gfx::Size(10, 10));
1059 great_grand_child->SetBounds(gfx::Size(10, 10));
[email protected]d600df7d2013-08-03 02:34:281060
[email protected]fb661802013-03-25 01:59:321061 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521062 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
1063 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
1064 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
1065 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:321066
1067 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1068 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1069 gfx::Transform expected_grand_child_draw_transform =
1070 rotation_about_y_axis; // draws onto child's render surface
1071 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1072 flattened_rotation_about_y.FlattenTo2d();
1073 gfx::Transform expected_grand_child_screen_space_transform =
1074 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081075 gfx::Transform expected_great_grand_child_draw_transform =
1076 flattened_rotation_about_y;
1077 gfx::Transform expected_great_grand_child_screen_space_transform =
1078 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321079
enne25dea3f2015-07-27 16:44:281080 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321081
1082 // The child's draw transform should have been taken by its surface.
1083 ASSERT_TRUE(child->render_surface());
1084 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1085 child->render_surface()->draw_transform());
1086 EXPECT_TRANSFORMATION_MATRIX_EQ(
1087 expected_child_screen_space_transform,
1088 child->render_surface()->screen_space_transform());
danakje4fa7b72016-07-25 22:00:061089 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321090 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101091 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321092 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441093 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321094 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101095 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081096 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441097 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081098 EXPECT_TRANSFORMATION_MATRIX_EQ(
1099 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101100 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321101}
1102
ajumadbd92cb2015-07-16 13:47:061103TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasikabf1875a2016-06-28 03:39:591104 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:141105 LayerImpl* child = AddChild<LayerImpl>(root);
1106 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061107
1108 gfx::Transform child_transform;
1109 child_transform.Translate(50.0, 50.0);
1110 child_transform.RotateAboutZAxis(30.0);
1111
1112 gfx::Transform grand_child_transform;
1113 grand_child_transform.RotateAboutYAxis(90.0);
1114
danakje4fa7b72016-07-25 22:00:061115 root->SetBounds(gfx::Size(200, 200));
jaydasika10d43fc2016-08-18 04:06:041116 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:061117 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:041118 grand_child->test_properties()->transform = grand_child_transform;
danakje4fa7b72016-07-25 22:00:061119 grand_child->SetBounds(gfx::Size(100, 100));
jaydasikaca2605e2016-04-23 02:52:521120 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141121 grand_child->SetDrawsContent(true);
jaydasika6ed869662016-09-21 14:29:591122 float device_scale_factor = 1.f;
1123 float page_scale_factor = 1.f;
1124 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:281125 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:421126 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika6ed869662016-09-21 14:29:591127 // Visible rects computed by combining clips in target space and root space
1128 // don't match because of rotation transforms. So, we skip
1129 // verify_visible_rect_calculations.
1130 bool skip_verify_visible_rect_calculations = true;
1131 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:281132 page_scale_layer, inner_viewport_scroll_layer,
flackra283bed2016-10-31 14:49:421133 outer_viewport_scroll_layer,
jaydasika6ed869662016-09-21 14:29:591134 skip_verify_visible_rect_calculations);
ajumadbd92cb2015-07-16 13:47:061135
1136 // Mapping grand_child's bounds to target space produces a non-empty rect
1137 // that is fully contained within the target's bounds, so grand_child should
1138 // be considered fully visible.
1139 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141140 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061141}
1142
[email protected]989386c2013-07-18 21:37:231143TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321144 // A layer that is empty in one axis, but not the other, was accidentally
1145 // skipping a necessary translation. Without that translation, the coordinate
1146 // space of the layer's draw transform is incorrect.
1147 //
1148 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1149 // but if that layer becomes a render surface, then its draw transform is
1150 // implicitly inherited by the rest of the subtree, which then is positioned
1151 // incorrectly as a result.
1152
jaydasikabf1875a2016-06-28 03:39:591153 LayerImpl* root = root_layer_for_testing();
ennec1332992015-08-24 19:45:091154 LayerImpl* child = AddChild<LayerImpl>(root);
1155 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1156 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321157
danakje4fa7b72016-07-25 22:00:061158 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:321159 // The child height is zero, but has non-zero width that should be accounted
1160 // for while computing draw transforms.
danakje4fa7b72016-07-25 22:00:061161 child->SetBounds(gfx::Size(10, 0));
1162 child->test_properties()->force_render_surface = true;
1163 grand_child->SetBounds(gfx::Size(10, 10));
ennec1332992015-08-24 19:45:091164 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321165
ennec1332992015-08-24 19:45:091166 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321167 // This is the real test, the rest are sanity checks.
danakje4fa7b72016-07-25 22:00:061168 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:321169 child->render_surface()->draw_transform());
danakje4fa7b72016-07-25 22:00:061170 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1171 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441172 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321173}
1174
jaydasika9bbee9b2016-01-13 00:36:481175TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
jaydasikabf1875a2016-06-28 03:39:591176 LayerImpl* root = root_layer_for_testing();
jaydasika9bbee9b2016-01-13 00:36:481177 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1178 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1179 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1180
jaydasika9bbee9b2016-01-13 00:36:481181 gfx::Transform translate;
1182 translate.Translate3d(5, 5, 5);
danakje4fa7b72016-07-25 22:00:061183
1184 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041185 render_surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061186 render_surface->SetBounds(gfx::Size(100, 100));
1187 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041188 child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061189 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041190 grand_child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061191 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika9bbee9b2016-01-13 00:36:481192 grand_child->SetDrawsContent(true);
1193
1194 // render_surface will have a sublayer scale because of device scale factor.
1195 float device_scale_factor = 2.0f;
1196 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481197 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381198 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481199 inputs.device_scale_factor = device_scale_factor;
1200 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571201 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481202
1203 // Between grand_child and render_surface, we translate by (10, 10) and scale
1204 // by a factor of 2.
1205 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1206 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1207 expected_translation);
1208}
1209
[email protected]989386c2013-07-18 21:37:231210TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321211 // Transformations applied at the root of the tree should be forwarded
1212 // to child layers instead of applied to the root RenderSurface.
jaydasikabf1875a2016-06-28 03:39:591213 LayerImpl* root = root_layer_for_testing();
enned3f61fb02015-08-18 22:54:391214 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061215
1216 root->SetDrawsContent(true);
jaydasikab874eddc2016-11-02 22:34:281217 root->SetBounds(gfx::Size(100, 100));
enned3f61fb02015-08-18 22:54:391218 child->SetDrawsContent(true);
enned3f61fb02015-08-18 22:54:391219 child->SetScrollClipLayer(root->id());
jaydasikab874eddc2016-11-02 22:34:281220 child->SetBounds(gfx::Size(100, 100));
1221 child->SetMasksToBounds(true);
[email protected]f224cc92013-06-06 23:23:321222
[email protected]f224cc92013-06-06 23:23:321223 gfx::Transform translate;
1224 translate.Translate(50, 50);
[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(), translate, &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 translate, root->draw_properties().target_space_transform);
1233 EXPECT_TRANSFORMATION_MATRIX_EQ(
1234 translate, 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());
jaydasikab874eddc2016-11-02 22:34:281237 EXPECT_TRANSFORMATION_MATRIX_EQ(translate, child->ScreenSpaceTransform());
1238 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231239 }
[email protected]f224cc92013-06-06 23:23:321240
1241 gfx::Transform scale;
1242 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231243 {
enned3f61fb02015-08-18 22:54:391244 LayerImplList render_surface_layer_list_impl;
1245 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381246 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321247 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571248 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021249 EXPECT_TRANSFORMATION_MATRIX_EQ(
1250 scale, root->draw_properties().target_space_transform);
1251 EXPECT_TRANSFORMATION_MATRIX_EQ(
1252 scale, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151253 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021254 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281255 EXPECT_TRANSFORMATION_MATRIX_EQ(scale, child->ScreenSpaceTransform());
1256 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231257 }
[email protected]f224cc92013-06-06 23:23:321258
1259 gfx::Transform rotate;
1260 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231261 {
enned3f61fb02015-08-18 22:54:391262 LayerImplList render_surface_layer_list_impl;
1263 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381264 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321265 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571266 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021267 EXPECT_TRANSFORMATION_MATRIX_EQ(
1268 rotate, root->draw_properties().target_space_transform);
1269 EXPECT_TRANSFORMATION_MATRIX_EQ(
1270 rotate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151271 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021272 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281273 EXPECT_TRANSFORMATION_MATRIX_EQ(rotate, child->ScreenSpaceTransform());
1274 EXPECT_EQ(gfx::Rect(-4, 0, 104, 104), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231275 }
[email protected]f224cc92013-06-06 23:23:321276
1277 gfx::Transform composite;
1278 composite.ConcatTransform(translate);
1279 composite.ConcatTransform(scale);
1280 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231281 {
enned3f61fb02015-08-18 22:54:391282 LayerImplList render_surface_layer_list_impl;
1283 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381284 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321285 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571286 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021287 EXPECT_TRANSFORMATION_MATRIX_EQ(
1288 composite, root->draw_properties().target_space_transform);
1289 EXPECT_TRANSFORMATION_MATRIX_EQ(
1290 composite, 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());
jaydasikab874eddc2016-11-02 22:34:281293 EXPECT_TRANSFORMATION_MATRIX_EQ(composite, child->ScreenSpaceTransform());
1294 EXPECT_EQ(gfx::Rect(89, 103, 208, 208), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231295 }
[email protected]f224cc92013-06-06 23:23:321296
[email protected]9781afa2013-07-17 23:15:321297 // Verify it composes correctly with device scale.
1298 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231299
1300 {
enned3f61fb02015-08-18 22:54:391301 LayerImplList render_surface_layer_list_impl;
1302 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381303 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531304 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321305 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571306 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231307 gfx::Transform device_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101308 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
weiliangcc3517722016-06-28 22:52:021309 EXPECT_TRANSFORMATION_MATRIX_EQ(
1310 device_scaled_translate,
1311 root->draw_properties().target_space_transform);
1312 EXPECT_TRANSFORMATION_MATRIX_EQ(
1313 device_scaled_translate,
1314 child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151315 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021316 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281317 EXPECT_TRANSFORMATION_MATRIX_EQ(device_scaled_translate,
1318 child->ScreenSpaceTransform());
1319 EXPECT_EQ(gfx::Rect(50, 50, 150, 150), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231320 }
[email protected]9781afa2013-07-17 23:15:321321
1322 // Verify it composes correctly with page scale.
1323 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231324
1325 {
enned3f61fb02015-08-18 22:54:391326 LayerImplList render_surface_layer_list_impl;
1327 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381328 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531329 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391330 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321331 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571332 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231333 gfx::Transform page_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101334 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
weiliangcc3517722016-06-28 22:52:021335 EXPECT_TRANSFORMATION_MATRIX_EQ(
1336 page_scaled_translate, root->draw_properties().target_space_transform);
1337 EXPECT_TRANSFORMATION_MATRIX_EQ(
1338 page_scaled_translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151339 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021340 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281341 EXPECT_TRANSFORMATION_MATRIX_EQ(page_scaled_translate,
1342 child->ScreenSpaceTransform());
1343 EXPECT_EQ(gfx::Rect(50, 50, 200, 200), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231344 }
[email protected]9781afa2013-07-17 23:15:321345
[email protected]f224cc92013-06-06 23:23:321346 // Verify that it composes correctly with transforms directly on root layer.
jaydasika10d43fc2016-08-18 04:06:041347 root->test_properties()->transform = composite;
[email protected]989386c2013-07-18 21:37:231348
1349 {
enned3f61fb02015-08-18 22:54:391350 LayerImplList render_surface_layer_list_impl;
1351 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381352 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391353 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571354 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231355 gfx::Transform compositeSquared = composite;
1356 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261357 EXPECT_TRANSFORMATION_MATRIX_EQ(
1358 compositeSquared, root->draw_properties().target_space_transform);
1359 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391360 compositeSquared, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151361 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021362 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281363 EXPECT_TRANSFORMATION_MATRIX_EQ(compositeSquared,
1364 child->ScreenSpaceTransform());
1365 EXPECT_EQ(gfx::Rect(254, 316, 428, 428), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231366 }
[email protected]f224cc92013-06-06 23:23:321367}
1368
[email protected]989386c2013-07-18 21:37:231369TEST_F(LayerTreeHostCommonTest,
1370 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
danakje4fa7b72016-07-25 22:00:061371 LayerImpl* root = root_layer_for_testing();
enneea850232015-07-27 16:43:121372 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1373 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
danakje4fa7b72016-07-25 22:00:061374
1375 root->SetBounds(gfx::Size(10, 10));
1376 root->SetMasksToBounds(true);
1377 render_surface1->SetBounds(gfx::Size(10, 10));
1378 render_surface1->test_properties()->force_render_surface = true;
enneea850232015-07-27 16:43:121379 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061380 child->SetPosition(gfx::PointF(30.f, 30.f));
1381 child->SetBounds(gfx::Size(10, 10));
1382 ExecuteCalculateDrawProperties(root);
[email protected]d600df7d2013-08-03 02:34:281383
danakje4fa7b72016-07-25 22:00:061384 // The child layer's content is entirely outside the root's clip rect, so
[email protected]fb661802013-03-25 01:59:321385 // the intermediate render surface should not be listed here, even if it was
1386 // forced to be created. Render surfaces without children or visible content
1387 // are unexpected at draw time (e.g. we might try to create a content texture
1388 // of size 0).
danakje4fa7b72016-07-25 22:00:061389 ASSERT_TRUE(root->render_surface());
enneea850232015-07-27 16:43:121390 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321391}
1392
[email protected]989386c2013-07-18 21:37:231393TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
danakje4fa7b72016-07-25 22:00:061394 LayerImpl* root = root_layer_for_testing();
1395 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
enne03b0e9a2015-06-19 00:08:021396 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
[email protected]d600df7d2013-08-03 02:34:281397
danakje4fa7b72016-07-25 22:00:061398 render_surface1->SetBounds(gfx::Size(10, 10));
1399 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181400 render_surface1->test_properties()->opacity = 0.f;
danakje4fa7b72016-07-25 22:00:061401 child->SetBounds(gfx::Size(10, 10));
1402 child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321403
enne03b0e9a2015-06-19 00:08:021404 LayerImplList render_surface_layer_list;
1405 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061406 root, root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531407 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571408 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321409
1410 // Since the layer is transparent, render_surface1->render_surface() should
1411 // not have gotten added anywhere. Also, the drawable content rect should not
1412 // have been extended by the children.
danakje4fa7b72016-07-25 22:00:061413 ASSERT_TRUE(root->render_surface());
1414 EXPECT_EQ(0U, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:321415 EXPECT_EQ(1U, render_surface_layer_list.size());
danakje4fa7b72016-07-25 22:00:061416 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
1417 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321418}
1419
hendrikwc266f7b2015-08-21 23:41:341420TEST_F(LayerTreeHostCommonTest,
1421 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
danakje4fa7b72016-07-25 22:00:061422 LayerImpl* root = root_layer_for_testing();
1423 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
hendrikwc266f7b2015-08-21 23:41:341424 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
hendrikwc266f7b2015-08-21 23:41:341425
danakje4fa7b72016-07-25 22:00:061426 root->SetBounds(gfx::Size(10, 10));
1427 render_surface1->SetBounds(gfx::Size(10, 10));
1428 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181429 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071430 render_surface1->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341431 FilterOperations filters;
1432 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
ajuma50bce7e2016-06-24 20:56:041433 render_surface1->test_properties()->background_filters = filters;
danakje4fa7b72016-07-25 22:00:061434 child->SetBounds(gfx::Size(10, 10));
1435 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341436
jaydasika369c24b2016-04-06 23:44:161437 {
1438 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161439 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061440 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161441 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571442 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161443 EXPECT_EQ(2U, render_surface_layer_list.size());
1444 }
hendrikwc266f7b2015-08-21 23:41:341445 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161446 // shouldn't be skipped and should be drawn.
danakje4fa7b72016-07-25 22:00:061447 ASSERT_TRUE(root->render_surface());
1448 EXPECT_EQ(1U, root->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361449 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
danakje4fa7b72016-07-25 22:00:061450 root->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161451 EffectTree& effect_tree =
danakje4fa7b72016-07-25 22:00:061452 root->layer_tree_impl()->property_trees()->effect_tree;
jaydasika369c24b2016-04-06 23:44:161453 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011454 EXPECT_TRUE(node->is_drawn);
jaydasika369c24b2016-04-06 23:44:161455
danakje4fa7b72016-07-25 22:00:061456 // When root is transparent, the layer should not be drawn.
jaydasika898b2f12016-08-20 04:22:091457 effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(),
1458 root->layer_tree_impl());
1459 effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(),
1460 root->layer_tree_impl());
jaydasika8185d302016-04-14 15:20:061461 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161462 {
1463 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161464 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061465 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161466 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571467 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161468 }
1469
1470 node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011471 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:061472 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341473}
1474
senorblanco38858c52016-01-20 23:15:001475TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
jaydasikabf1875a2016-06-28 03:39:591476 LayerImpl* root = root_layer_for_testing();
senorblanco38858c52016-01-20 23:15:001477 LayerImpl* parent = AddChild<LayerImpl>(root);
1478 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1479 LayerImpl* child2 = AddChild<LayerImpl>(parent);
senorblanco38858c52016-01-20 23:15:001480
senorblanco38858c52016-01-20 23:15:001481 gfx::Transform scale_matrix;
1482 scale_matrix.Scale(2.0f, 2.0f);
danakje4fa7b72016-07-25 22:00:061483
1484 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041485 parent->test_properties()->transform = scale_matrix;
senorblanco38858c52016-01-20 23:15:001486 FilterOperations filters;
1487 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
ajumacb2b74432016-07-21 19:11:151488 parent->test_properties()->filters = filters;
danakje4fa7b72016-07-25 22:00:061489 parent->test_properties()->force_render_surface = true;
1490 child1->SetBounds(gfx::Size(25, 25));
1491 child1->SetDrawsContent(true);
1492 child1->test_properties()->force_render_surface = true;
1493 child2->SetPosition(gfx::PointF(25, 25));
1494 child2->SetBounds(gfx::Size(25, 25));
1495 child2->SetDrawsContent(true);
1496 child2->test_properties()->force_render_surface = true;
senorblanco38858c52016-01-20 23:15:001497
1498 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001499 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381500 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001501 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571502 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001503
1504 ASSERT_TRUE(parent->render_surface());
1505 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1506 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman1c44d5b52016-06-06 21:19:301507
1508 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1509 // blur (-30,-30 110x110), and then scaled by the scale matrix
1510 // (-60,-60 220x220).
1511 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
senorblanco38858c52016-01-20 23:15:001512 parent->render_surface()->DrawableContentRect());
1513}
1514
jbroman1c44d5b52016-06-06 21:19:301515TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
jaydasikabf1875a2016-06-28 03:39:591516 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301517 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061518
1519 root->SetBounds(gfx::Size(100, 100));
1520 child->SetBounds(gfx::Size(25, 25));
jbroman1c44d5b52016-06-06 21:19:301521 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061522 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301523 FilterOperations filters;
1524 filters.Append(FilterOperation::CreateReferenceFilter(
1525 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151526 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301527 ExecuteCalculateDrawProperties(root);
1528
1529 // The render surface's size should be unaffected by the offset image filter;
1530 // it need only have a drawable content rect large enough to contain the
1531 // contents (at the new offset).
1532 ASSERT_TRUE(child->render_surface());
1533 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1534 child->render_surface()->DrawableContentRect());
1535}
1536
1537TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1538 const float device_scale_factor = 2.0f;
1539
jaydasikabf1875a2016-06-28 03:39:591540 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301541 LayerImpl* child = AddChild<LayerImpl>(root);
jbroman1c44d5b52016-06-06 21:19:301542
danakje4fa7b72016-07-25 22:00:061543 root->SetBounds(gfx::Size(100, 100));
1544 child->SetBounds(gfx::Size(25, 25));
1545 child->SetDrawsContent(true);
1546 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301547
1548 FilterOperations filters;
1549 filters.Append(FilterOperation::CreateReferenceFilter(
1550 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151551 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301552
1553 ExecuteCalculateDrawProperties(root, device_scale_factor);
1554
1555 // The render surface's size should be unaffected by the offset image filter;
1556 // it need only have a drawable content rect large enough to contain the
1557 // contents (at the new offset). All coordinates should be scaled by 2,
1558 // corresponding to the device scale factor.
1559 ASSERT_TRUE(child->render_surface());
1560 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1561 child->render_surface()->DrawableContentRect());
1562}
1563
rosca948d29d2014-11-09 10:25:131564TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
danakje4fa7b72016-07-25 22:00:061565 LayerImpl* root = root_layer_for_testing();
1566 LayerImpl* child = AddChild<LayerImpl>(root);
1567
1568 root->SetBounds(gfx::Size(10, 10));
1569 child->SetBounds(gfx::Size(10, 10));
enned5f4ddd2015-08-18 16:50:061570 child->SetDrawsContent(true);
reedcc9c70f2016-11-22 04:26:011571 child->test_properties()->blend_mode = SkBlendMode::kMultiply;
jaydasikaab317e02016-06-01 00:53:181572 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061573 child->test_properties()->force_render_surface = true;
1574 ExecuteCalculateDrawProperties(root);
rosca948d29d2014-11-09 10:25:131575
1576 // Since the child layer has a blend mode other than normal, it should get
1577 // its own render surface. Also, layer's draw_properties should contain the
1578 // default blend mode, since the render surface becomes responsible for
1579 // applying the blend mode.
1580 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291581 EXPECT_EQ(1.0f, child->draw_opacity());
1582 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
reedcc9c70f2016-11-22 04:26:011583 EXPECT_EQ(SkBlendMode::kSrcOver, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131584}
1585
jaydasikafbdb86e2016-01-21 18:57:511586TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
jaydasikabf1875a2016-06-28 03:39:591587 LayerImpl* root = root_layer_for_testing();
jaydasikafbdb86e2016-01-21 18:57:511588 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1589 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1590 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1591
danakje4fa7b72016-07-25 22:00:061592 root->SetBounds(gfx::Size(10, 10));
1593 surface1->SetBounds(gfx::Size(10, 10));
jaydasikafbdb86e2016-01-21 18:57:511594 surface1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181595 surface1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061596 surface1->test_properties()->force_render_surface = true;
1597 not_surface->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:181598 not_surface->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061599 surface2->SetBounds(gfx::Size(10, 10));
1600 surface2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181601 surface2->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061602 surface2->test_properties()->force_render_surface = true;
jaydasikafbdb86e2016-01-21 18:57:511603 ExecuteCalculateDrawProperties(root);
1604
1605 ASSERT_TRUE(surface1->render_surface());
1606 ASSERT_FALSE(not_surface->render_surface());
1607 ASSERT_TRUE(surface2->render_surface());
1608 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1609 // surface2's draw opacity should include the opacity of not-surface and
1610 // itself, but not the opacity of surface1.
1611 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1612}
1613
ajuma51d73f72015-10-19 19:43:581614TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1615 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1616 // the product of all ancestor layer opacties and the layer's own opacity.
1617 // (Rendering will still be incorrect in situations where we really do need
1618 // surfaces to apply opacity, such as when we have overlapping layers with an
1619 // ancestor whose opacity is <1.)
jaydasikabf1875a2016-06-28 03:39:591620 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581621 LayerImpl* parent = AddChild<LayerImpl>(root);
1622 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1623 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1624 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1625 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1626 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1627
danakje4fa7b72016-07-25 22:00:061628 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581629 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061630 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581631 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061632 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581633 child1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181634 child1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061635 child1->test_properties()->force_render_surface = true;
1636 child2->SetBounds(gfx::Size(100, 100));
1637 child2->SetDrawsContent(true);
1638 grand_child->SetBounds(gfx::Size(100, 100));
1639 grand_child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181640 grand_child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061641 grand_child->test_properties()->force_render_surface = true;
1642 leaf_node1->SetBounds(gfx::Size(100, 100));
1643 leaf_node1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181644 leaf_node1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061645 leaf_node2->SetBounds(gfx::Size(100, 100));
1646 leaf_node2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181647 leaf_node2->test_properties()->opacity = 0.5f;
ajuma51d73f72015-10-19 19:43:581648
1649 // With surfaces enabled, each layer's draw opacity is the product of layer
1650 // opacities on the path from the layer to its render target, not including
1651 // the opacity of the layer that owns the target surface (since that opacity
1652 // is applied by the surface).
1653 ExecuteCalculateDrawProperties(root);
1654 EXPECT_EQ(1.f, root->draw_opacity());
1655 EXPECT_EQ(1.f, parent->draw_opacity());
1656 EXPECT_EQ(1.f, child1->draw_opacity());
1657 EXPECT_EQ(1.f, child2->draw_opacity());
1658 EXPECT_EQ(1.f, grand_child->draw_opacity());
1659 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1660 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1661
1662 // With surfaces disabled, each layer's draw opacity is the product of layer
1663 // opacities on the path from the layer to the root.
1664 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1665 EXPECT_EQ(1.f, root->draw_opacity());
1666 EXPECT_EQ(1.f, parent->draw_opacity());
1667 EXPECT_EQ(0.5f, child1->draw_opacity());
1668 EXPECT_EQ(1.f, child2->draw_opacity());
1669 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1670 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1671 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1672}
1673
[email protected]989386c2013-07-18 21:37:231674TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
danakje4fa7b72016-07-25 22:00:061675 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:261676 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1677 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261678
danakje4fa7b72016-07-25 22:00:061679 root->SetBounds(gfx::Size(10, 10));
1680 render_surface1->SetBounds(gfx::Size(10, 10));
jaydasika6b5a32bf2016-04-22 21:56:361681 render_surface1->test_properties()->force_render_surface = true;
danakje4fa7b72016-07-25 22:00:061682 child->SetBounds(gfx::Size(10, 10));
1683 child->SetDrawsContent(true);
weiliangceffae0462015-12-08 23:17:261684
[email protected]989386c2013-07-18 21:37:231685 {
jaydasika6ed869662016-09-21 14:29:591686 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:321687
[email protected]989386c2013-07-18 21:37:231688 // The root layer always creates a render surface
danakje4fa7b72016-07-25 22:00:061689 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091690 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231691 }
[email protected]fb661802013-03-25 01:59:321692
[email protected]989386c2013-07-18 21:37:231693 {
jaydasika6b5a32bf2016-04-22 21:56:361694 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261695 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:591696 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
danakje4fa7b72016-07-25 22:00:061697 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091698 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231699 }
[email protected]fb661802013-03-25 01:59:321700}
1701
ajuma246190a2015-03-11 20:56:031702TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1703 // Render surfaces act as a flattening point for their subtree, so should
1704 // always flatten the target-to-screen space transform seen by descendants.
jaydasikabf1875a2016-06-28 03:39:591705 LayerImpl* root = root_layer_for_testing();
enne1a79c5542015-08-18 19:43:571706 LayerImpl* parent = AddChild<LayerImpl>(root);
1707 LayerImpl* child = AddChild<LayerImpl>(parent);
1708 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1709
ajuma246190a2015-03-11 20:56:031710 gfx::Transform rotation_about_y_axis;
1711 rotation_about_y_axis.RotateAboutYAxis(30.0);
ajuma246190a2015-03-11 20:56:031712
danakje4fa7b72016-07-25 22:00:061713 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041714 parent->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061715 parent->SetBounds(gfx::Size(10, 10));
1716 parent->test_properties()->force_render_surface = true;
1717 child->SetBounds(gfx::Size(10, 10));
1718 child->SetDrawsContent(true);
1719 grand_child->SetBounds(gfx::Size(10, 10));
1720 grand_child->SetDrawsContent(true);
jaydasikaca2605e2016-04-23 02:52:521721 grand_child->test_properties()->should_flatten_transform = false;
enne1a79c5542015-08-18 19:43:571722 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031723
1724 EXPECT_TRUE(parent->render_surface());
1725 EXPECT_FALSE(child->render_surface());
1726 EXPECT_FALSE(grand_child->render_surface());
1727
danakje4fa7b72016-07-25 22:00:061728 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1729 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441730 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031731
1732 // The screen-space transform inherited by |child| and |grand_child| should
1733 // have been flattened at their render target. In particular, the fact that
1734 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
danakje4fa7b72016-07-25 22:00:061735 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1736 flattened_rotation_about_y.FlattenTo2d();
ajuma246190a2015-03-11 20:56:031737 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101738 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031739 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101740 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031741}
1742
[email protected]989386c2013-07-18 21:37:231743TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321744 // The entire subtree of layers that are outside the clip rect should be
1745 // culled away, and should not affect the render_surface_layer_list.
1746 //
1747 // The test tree is set up as follows:
1748 // - all layers except the leaf_nodes are forced to be a new render surface
1749 // that have something to draw.
1750 // - parent is a large container layer.
danakje4fa7b72016-07-25 22:00:061751 // - child has MasksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321752 // - grand_child is positioned outside of the child's bounds
1753 // - great_grand_child is also kept outside child's bounds.
1754 //
1755 // In this configuration, grand_child and great_grand_child are completely
1756 // outside the clip rect, and they should never get scheduled on the list of
1757 // render surfaces.
[email protected]fb661802013-03-25 01:59:321758
danakje4fa7b72016-07-25 22:00:061759 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571760 LayerImpl* child = AddChildToRoot<LayerImpl>();
1761 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1762 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281763
danakje4fa7b72016-07-25 22:00:061764 // leaf_node1 ensures that root and child are kept on the
[email protected]fb661802013-03-25 01:59:321765 // render_surface_layer_list, even though grand_child and great_grand_child
1766 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571767 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
weiliangcfb3d5eaa2015-07-28 23:54:571768 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
[email protected]fb661802013-03-25 01:59:321769
danakje4fa7b72016-07-25 22:00:061770 root->SetBounds(gfx::Size(500, 500));
1771 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321772 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061773 child->test_properties()->force_render_surface = true;
1774 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1775 grand_child->SetBounds(gfx::Size(10, 10));
1776 great_grand_child->SetBounds(gfx::Size(10, 10));
1777 leaf_node1->SetBounds(gfx::Size(500, 500));
1778 leaf_node1->SetDrawsContent(true);
1779 leaf_node1->SetBounds(gfx::Size(20, 20));
1780 leaf_node2->SetDrawsContent(true);
1781 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321782
weiliangcfb3d5eaa2015-07-28 23:54:571783 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061784 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
weiliangcfb3d5eaa2015-07-28 23:54:571785 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321786}
1787
[email protected]989386c2013-07-18 21:37:231788TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321789 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571790 // of the surface.
[email protected]fb661802013-03-25 01:59:321791
1792 // The test tree is set up as follows:
danakje4fa7b72016-07-25 22:00:061793 // - root is a container layer that masksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321794 // - child is a render surface, which has a clip rect set to the bounds of
danakje4fa7b72016-07-25 22:00:061795 // the root.
[email protected]fb661802013-03-25 01:59:321796 // - grand_child is a render surface, and the only visible content in child.
danakje4fa7b72016-07-25 22:00:061797 // It is positioned outside of the clip rect from root.
[email protected]fb661802013-03-25 01:59:321798
1799 // In this configuration, grand_child should be outside the clipped
1800 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571801 // render_surface_layer_list.
1802
danakje4fa7b72016-07-25 22:00:061803 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571804 LayerImpl* child = AddChildToRoot<LayerImpl>();
1805 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1806 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
[email protected]fb661802013-03-25 01:59:321807
danakje4fa7b72016-07-25 22:00:061808 root->SetMasksToBounds(true);
1809 root->SetBounds(gfx::Size(100, 100));
1810 child->SetBounds(gfx::Size(20, 20));
1811 child->test_properties()->force_render_surface = true;
1812 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1813 grand_child->SetBounds(gfx::Size(10, 10));
1814 grand_child->test_properties()->force_render_surface = true;
1815 leaf_node->SetBounds(gfx::Size(10, 10));
1816 leaf_node->SetDrawsContent(true);
1817 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321818
weiliangcfb3d5eaa2015-07-28 23:54:571819 // We should cull child and grand_child from the
1820 // render_surface_layer_list.
1821 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061822 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321823}
1824
ajumae2b7a5c2015-09-30 21:41:421825TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1826 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321827 // - the layer clips its subtree, e.g. masks to bounds,
1828 // - the layer is clipped by an ancestor that contributes to the same
1829 // render target,
1830 // - a surface is clipped by an ancestor that contributes to the same
1831 // render target.
1832 //
1833 // In particular, for a layer that owns a render surface:
1834 // - the render surface inherits any clip from ancestors, and does NOT
1835 // pass that clipped status to the layer itself.
1836 // - but if the layer itself masks to bounds, it is considered clipped
1837 // and propagates the clip to the subtree.
1838
jaydasikabf1875a2016-06-28 03:39:591839 LayerImpl* root = root_layer_for_testing();
enne76bf8982015-08-18 17:55:331840 LayerImpl* parent = AddChild<LayerImpl>(root);
1841 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1842 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1843 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1844 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
enne76bf8982015-08-18 17:55:331845 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
enne76bf8982015-08-18 17:55:331846
danakje4fa7b72016-07-25 22:00:061847 root->SetBounds(gfx::Size(100, 100));
1848 parent->SetBounds(gfx::Size(100, 100));
1849 parent->SetDrawsContent(true);
1850 child1->SetBounds(gfx::Size(100, 100));
1851 child1->SetDrawsContent(true);
1852 child2->SetBounds(gfx::Size(100, 100));
1853 child2->SetDrawsContent(true);
1854 child2->test_properties()->force_render_surface = true;
1855 grand_child->SetBounds(gfx::Size(100, 100));
1856 grand_child->SetDrawsContent(true);
1857 leaf_node1->SetBounds(gfx::Size(100, 100));
1858 leaf_node1->SetDrawsContent(true);
1859 leaf_node2->SetBounds(gfx::Size(100, 100));
1860 leaf_node2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331861
1862 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521863 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331864
weiliangce3f09a612016-03-16 17:02:521865 ASSERT_TRUE(root->render_surface());
1866 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331867
weiliangce3f09a612016-03-16 17:02:521868 EXPECT_FALSE(root->is_clipped());
1869 EXPECT_TRUE(root->render_surface()->is_clipped());
1870 EXPECT_FALSE(parent->is_clipped());
1871 EXPECT_FALSE(child1->is_clipped());
1872 EXPECT_FALSE(child2->is_clipped());
1873 EXPECT_FALSE(child2->render_surface()->is_clipped());
1874 EXPECT_FALSE(grand_child->is_clipped());
1875 EXPECT_FALSE(leaf_node1->is_clipped());
1876 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331877
danakje4fa7b72016-07-25 22:00:061878 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
enne76bf8982015-08-18 17:55:331879 // surface are clipped. But layers that contribute to child2's surface are
1880 // not clipped explicitly because child2's surface already accounts for
1881 // that clip.
weiliangce3f09a612016-03-16 17:02:521882 parent->SetMasksToBounds(true);
1883 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331884
weiliangce3f09a612016-03-16 17:02:521885 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331886
weiliangce3f09a612016-03-16 17:02:521887 ASSERT_TRUE(root->render_surface());
1888 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331889
weiliangce3f09a612016-03-16 17:02:521890 EXPECT_FALSE(root->is_clipped());
1891 EXPECT_TRUE(root->render_surface()->is_clipped());
1892 EXPECT_TRUE(parent->is_clipped());
1893 EXPECT_TRUE(child1->is_clipped());
1894 EXPECT_FALSE(child2->is_clipped());
1895 EXPECT_TRUE(child2->render_surface()->is_clipped());
1896 EXPECT_TRUE(grand_child->is_clipped());
1897 EXPECT_TRUE(leaf_node1->is_clipped());
1898 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331899
weiliangce3f09a612016-03-16 17:02:521900 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331901
danakje4fa7b72016-07-25 22:00:061902 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
enne76bf8982015-08-18 17:55:331903 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521904 child2->SetMasksToBounds(true);
1905 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331906
weiliangce3f09a612016-03-16 17:02:521907 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331908
weiliangce3f09a612016-03-16 17:02:521909 ASSERT_TRUE(root->render_surface());
1910 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331911
weiliangce3f09a612016-03-16 17:02:521912 EXPECT_FALSE(root->is_clipped());
1913 EXPECT_TRUE(root->render_surface()->is_clipped());
1914 EXPECT_FALSE(parent->is_clipped());
1915 EXPECT_FALSE(child1->is_clipped());
1916 EXPECT_TRUE(child2->is_clipped());
1917 EXPECT_FALSE(child2->render_surface()->is_clipped());
1918 EXPECT_FALSE(grand_child->is_clipped());
1919 EXPECT_FALSE(leaf_node1->is_clipped());
1920 EXPECT_TRUE(leaf_node2->is_clipped());
1921}
1922
1923TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1924 // Tests that when as long as layer is clipped, it's clip rect is set to
1925 // correct value.
jaydasikabf1875a2016-06-28 03:39:591926 LayerImpl* root = root_layer_for_testing();
weiliangce3f09a612016-03-16 17:02:521927 LayerImpl* parent = AddChild<LayerImpl>(root);
1928 LayerImpl* child = AddChild<LayerImpl>(parent);
1929
danakje4fa7b72016-07-25 22:00:061930 root->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521931 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061932 parent->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521933 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061934 child->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521935 child->SetDrawsContent(true);
weiliangce3f09a612016-03-16 17:02:521936 child->SetMasksToBounds(true);
1937
1938 ExecuteCalculateDrawProperties(root);
1939
1940 EXPECT_FALSE(root->is_clipped());
1941 EXPECT_FALSE(parent->is_clipped());
1942 EXPECT_TRUE(child->is_clipped());
1943 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1944
1945 parent->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061946 child->SetPosition(gfx::PointF(100.f, 100.f));
weiliangce3f09a612016-03-16 17:02:521947 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1948
1949 ExecuteCalculateDrawProperties(root);
1950
1951 EXPECT_FALSE(root->is_clipped());
1952 EXPECT_TRUE(parent->is_clipped());
1953 EXPECT_TRUE(child->is_clipped());
1954 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321955}
1956
ajuma51d73f72015-10-19 19:43:581957TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1958 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1959 // when a layer or its ancestor has a clip; in particular, if a layer
1960 // is_clipped, so is its entire subtree (since there are no render surfaces
1961 // that can reset is_clipped).
jaydasikabf1875a2016-06-28 03:39:591962 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581963 LayerImpl* parent = AddChild<LayerImpl>(root);
1964 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1965 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1966 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1967 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1968 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1969
danakje4fa7b72016-07-25 22:00:061970 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581971 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061972 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581973 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061974 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581975 child1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061976 child1->test_properties()->force_render_surface = true;
1977 child2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581978 child2->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061979 grand_child->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581980 grand_child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061981 grand_child->test_properties()->force_render_surface = true;
1982 leaf_node1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581983 leaf_node1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061984 leaf_node2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581985 leaf_node2->SetDrawsContent(true);
1986
ajuma51d73f72015-10-19 19:43:581987 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1988 // or without surfaces.
1989 ExecuteCalculateDrawProperties(root);
1990 EXPECT_FALSE(root->is_clipped());
1991 EXPECT_FALSE(parent->is_clipped());
1992 EXPECT_FALSE(child1->is_clipped());
1993 EXPECT_FALSE(child2->is_clipped());
1994 EXPECT_FALSE(grand_child->is_clipped());
1995 EXPECT_FALSE(leaf_node1->is_clipped());
1996 EXPECT_FALSE(leaf_node2->is_clipped());
1997
1998 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1999 EXPECT_FALSE(root->is_clipped());
2000 EXPECT_FALSE(parent->is_clipped());
2001 EXPECT_FALSE(child1->is_clipped());
2002 EXPECT_FALSE(child2->is_clipped());
2003 EXPECT_FALSE(grand_child->is_clipped());
2004 EXPECT_FALSE(leaf_node1->is_clipped());
2005 EXPECT_FALSE(leaf_node2->is_clipped());
2006
2007 // Case 2: The root is clipped. With surfaces, this only persists until the
2008 // next render surface. Without surfaces, the entire tree is clipped.
2009 root->SetMasksToBounds(true);
2010 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2011 ExecuteCalculateDrawProperties(root);
2012 EXPECT_TRUE(root->is_clipped());
2013 EXPECT_TRUE(parent->is_clipped());
2014 EXPECT_FALSE(child1->is_clipped());
2015 EXPECT_TRUE(child2->is_clipped());
2016 EXPECT_FALSE(grand_child->is_clipped());
2017 EXPECT_FALSE(leaf_node1->is_clipped());
2018 EXPECT_TRUE(leaf_node2->is_clipped());
2019
2020 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2021 EXPECT_TRUE(root->is_clipped());
2022 EXPECT_TRUE(parent->is_clipped());
2023 EXPECT_TRUE(child1->is_clipped());
2024 EXPECT_TRUE(child2->is_clipped());
2025 EXPECT_TRUE(grand_child->is_clipped());
2026 EXPECT_TRUE(leaf_node1->is_clipped());
2027 EXPECT_TRUE(leaf_node2->is_clipped());
2028
2029 root->SetMasksToBounds(false);
2030
2031 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2032 // until the next render surface. Without surfaces, parent's entire subtree is
2033 // clipped.
2034 parent->SetMasksToBounds(true);
2035 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2036 ExecuteCalculateDrawProperties(root);
2037 EXPECT_FALSE(root->is_clipped());
2038 EXPECT_TRUE(parent->is_clipped());
2039 EXPECT_FALSE(child1->is_clipped());
2040 EXPECT_TRUE(child2->is_clipped());
2041 EXPECT_FALSE(grand_child->is_clipped());
2042 EXPECT_FALSE(leaf_node1->is_clipped());
2043 EXPECT_TRUE(leaf_node2->is_clipped());
2044
2045 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2046 EXPECT_FALSE(root->is_clipped());
2047 EXPECT_TRUE(parent->is_clipped());
2048 EXPECT_TRUE(child1->is_clipped());
2049 EXPECT_TRUE(child2->is_clipped());
2050 EXPECT_TRUE(grand_child->is_clipped());
2051 EXPECT_TRUE(leaf_node1->is_clipped());
2052 EXPECT_TRUE(leaf_node2->is_clipped());
2053
2054 parent->SetMasksToBounds(false);
2055
2056 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2057 // has no non-surface children. Without surfaces, child1's entire subtree is
2058 // clipped.
2059 child1->SetMasksToBounds(true);
2060 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2061 ExecuteCalculateDrawProperties(root);
2062 EXPECT_FALSE(root->is_clipped());
2063 EXPECT_FALSE(parent->is_clipped());
2064 EXPECT_TRUE(child1->is_clipped());
2065 EXPECT_FALSE(child2->is_clipped());
2066 EXPECT_FALSE(grand_child->is_clipped());
2067 EXPECT_FALSE(leaf_node1->is_clipped());
2068 EXPECT_FALSE(leaf_node2->is_clipped());
2069
2070 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2071 EXPECT_FALSE(root->is_clipped());
2072 EXPECT_FALSE(parent->is_clipped());
2073 EXPECT_TRUE(child1->is_clipped());
2074 EXPECT_FALSE(child2->is_clipped());
2075 EXPECT_TRUE(grand_child->is_clipped());
2076 EXPECT_TRUE(leaf_node1->is_clipped());
2077 EXPECT_FALSE(leaf_node2->is_clipped());
2078
2079 child1->SetMasksToBounds(false);
2080
2081 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2082 // surfaces is the same.
2083 leaf_node1->SetMasksToBounds(true);
2084 leaf_node2->SetMasksToBounds(true);
2085 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2086 ExecuteCalculateDrawProperties(root);
2087 EXPECT_FALSE(root->is_clipped());
2088 EXPECT_FALSE(parent->is_clipped());
2089 EXPECT_FALSE(child1->is_clipped());
2090 EXPECT_FALSE(child2->is_clipped());
2091 EXPECT_FALSE(grand_child->is_clipped());
2092 EXPECT_TRUE(leaf_node1->is_clipped());
2093 EXPECT_TRUE(leaf_node2->is_clipped());
2094
2095 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2096 EXPECT_FALSE(root->is_clipped());
2097 EXPECT_FALSE(parent->is_clipped());
2098 EXPECT_FALSE(child1->is_clipped());
2099 EXPECT_FALSE(child2->is_clipped());
2100 EXPECT_FALSE(grand_child->is_clipped());
2101 EXPECT_TRUE(leaf_node1->is_clipped());
2102 EXPECT_TRUE(leaf_node2->is_clipped());
2103}
2104
[email protected]fd9a3b6d2013-08-03 00:46:172105TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322106 // Verify that layers get the appropriate DrawableContentRect when their
danakje4fa7b72016-07-25 22:00:062107 // parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322108 //
2109 // grand_child1 - completely inside the region; DrawableContentRect should
2110 // be the layer rect expressed in target space.
danakje4fa7b72016-07-25 22:00:062111 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
[email protected]fb661802013-03-25 01:59:322112 // will be the intersection of layer bounds and the mask region.
danakje4fa7b72016-07-25 22:00:062113 // grand_child3 - partially clipped and MasksToBounds; the
[email protected]fb661802013-03-25 01:59:322114 // DrawableContentRect will still be the intersection of layer bounds and
2115 // the mask region.
2116 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2117 // be empty.
[email protected]fb661802013-03-25 01:59:322118
jaydasikabf1875a2016-06-28 03:39:592119 LayerImpl* parent = root_layer_for_testing();
enne07405c772015-08-18 17:56:452120 LayerImpl* child = AddChild<LayerImpl>(parent);
2121 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2122 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2123 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2124 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322125
danakje4fa7b72016-07-25 22:00:062126 parent->SetBounds(gfx::Size(500, 500));
[email protected]fb661802013-03-25 01:59:322127 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062128 child->SetBounds(gfx::Size(20, 20));
2129 child->test_properties()->force_render_surface = true;
2130 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2131 grand_child1->SetBounds(gfx::Size(10, 10));
2132 grand_child1->SetDrawsContent(true);
2133 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2134 grand_child2->SetBounds(gfx::Size(10, 10));
2135 grand_child2->SetDrawsContent(true);
2136 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
[email protected]fb661802013-03-25 01:59:322137 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062138 grand_child3->SetBounds(gfx::Size(10, 10));
2139 grand_child3->SetDrawsContent(true);
2140 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2141 grand_child4->SetBounds(gfx::Size(10, 10));
2142 grand_child4->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452143 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322144
hush6b614212014-12-04 22:37:322145 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2146 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2147 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322148 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2149}
2150
[email protected]989386c2013-07-18 21:37:232151TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322152 // Verify that render surfaces (and their layers) get the appropriate
danakje4fa7b72016-07-25 22:00:062153 // clip rects when their parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322154 //
2155 // Layers that own render surfaces (at least for now) do not inherit any
2156 // clipping; instead the surface will enforce the clip for the entire subtree.
2157 // They may still have a clip rect of their own layer bounds, however, if
danakje4fa7b72016-07-25 22:00:062158 // MasksToBounds was true.
jaydasikabf1875a2016-06-28 03:39:592159 LayerImpl* parent = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:572160 LayerImpl* child = AddChildToRoot<LayerImpl>();
2161 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2162 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2163 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2164 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:062165 // The leaf nodes ensure that these grand_children become render surfaces for
[email protected]fb661802013-03-25 01:59:322166 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572167 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
weiliangcfb3d5eaa2015-07-28 23:54:572168 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
weiliangcfb3d5eaa2015-07-28 23:54:572169 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
weiliangcfb3d5eaa2015-07-28 23:54:572170 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
[email protected]fb661802013-03-25 01:59:322171
danakje4fa7b72016-07-25 22:00:062172 parent->SetBounds(gfx::Size(500, 500));
2173 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:322174 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062175 child->test_properties()->force_render_surface = true;
2176 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2177 grand_child1->SetBounds(gfx::Size(10, 10));
2178 grand_child1->test_properties()->force_render_surface = true;
2179 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2180 grand_child2->SetBounds(gfx::Size(10, 10));
2181 grand_child2->test_properties()->force_render_surface = true;
2182 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
2183 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322184 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062185 grand_child3->test_properties()->force_render_surface = true;
2186 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2187 grand_child4->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322188 grand_child4->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062189 grand_child4->test_properties()->force_render_surface = true;
2190 leaf_node1->SetBounds(gfx::Size(10, 10));
2191 leaf_node1->SetDrawsContent(true);
2192 leaf_node2->SetBounds(gfx::Size(10, 10));
2193 leaf_node2->SetDrawsContent(true);
2194 leaf_node3->SetBounds(gfx::Size(10, 10));
2195 leaf_node3->SetDrawsContent(true);
2196 leaf_node4->SetBounds(gfx::Size(10, 10));
2197 leaf_node4->SetDrawsContent(true);
weiliangcfb3d5eaa2015-07-28 23:54:572198 ExecuteCalculateDrawProperties(parent);
2199
[email protected]fb661802013-03-25 01:59:322200 ASSERT_TRUE(grand_child1->render_surface());
2201 ASSERT_TRUE(grand_child2->render_surface());
2202 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322203
2204 // Surfaces are clipped by their parent, but un-affected by the owning layer's
danakje4fa7b72016-07-25 22:00:062205 // MasksToBounds.
hush6b614212014-12-04 22:37:322206 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2207 grand_child1->render_surface()->clip_rect());
2208 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2209 grand_child2->render_surface()->clip_rect());
2210 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2211 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322212}
2213
ajuma51d73f72015-10-19 19:43:582214TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2215 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2216 // intersection of all ancestor clips in screen space; in particular, if a
2217 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2218 // subtree (since there are no render surfaces that can reset the clip_rect).
jaydasikabf1875a2016-06-28 03:39:592219 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582220 LayerImpl* parent = AddChild<LayerImpl>(root);
2221 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2222 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2223 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2224 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2225 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2226
danakje4fa7b72016-07-25 22:00:062227 root->SetBounds(gfx::Size(100, 100));
2228 parent->SetPosition(gfx::PointF(2.f, 2.f));
2229 parent->SetBounds(gfx::Size(400, 400));
2230 child1->SetPosition(gfx::PointF(4.f, 4.f));
2231 child1->SetBounds(gfx::Size(800, 800));
2232 child2->SetPosition(gfx::PointF(3.f, 3.f));
2233 child2->SetBounds(gfx::Size(800, 800));
2234 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2235 grand_child->SetBounds(gfx::Size(1500, 1500));
2236 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
2237 leaf_node1->SetBounds(gfx::Size(2000, 2000));
2238 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
2239 leaf_node2->SetBounds(gfx::Size(2000, 2000));
2240
ajuma51d73f72015-10-19 19:43:582241 root->SetDrawsContent(true);
2242 parent->SetDrawsContent(true);
2243 child1->SetDrawsContent(true);
2244 child2->SetDrawsContent(true);
2245 grand_child->SetDrawsContent(true);
2246 leaf_node1->SetDrawsContent(true);
2247 leaf_node2->SetDrawsContent(true);
2248
danakje4fa7b72016-07-25 22:00:062249 root->test_properties()->force_render_surface = true;
2250 child1->test_properties()->force_render_surface = true;
2251 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582252
2253 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2254 // bounds in target space. The only thing that changes when surfaces are
2255 // disabled is that target space is always screen space.
2256 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262257 EXPECT_TRUE(root->has_render_surface());
2258 EXPECT_FALSE(parent->has_render_surface());
2259 EXPECT_TRUE(child1->has_render_surface());
2260 EXPECT_FALSE(child2->has_render_surface());
2261 EXPECT_TRUE(grand_child->has_render_surface());
2262 EXPECT_FALSE(leaf_node1->has_render_surface());
2263 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422264 EXPECT_FALSE(root->is_clipped());
2265 EXPECT_FALSE(parent->is_clipped());
2266 EXPECT_FALSE(child1->is_clipped());
2267 EXPECT_FALSE(child2->is_clipped());
2268 EXPECT_FALSE(grand_child->is_clipped());
2269 EXPECT_FALSE(leaf_node1->is_clipped());
2270 EXPECT_FALSE(leaf_node2->is_clipped());
2271 EXPECT_TRUE(root->render_surface()->is_clipped());
2272 EXPECT_FALSE(child1->render_surface()->is_clipped());
2273 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2274 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582275
2276 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422277 EXPECT_FALSE(root->is_clipped());
2278 EXPECT_FALSE(parent->is_clipped());
2279 EXPECT_FALSE(child1->is_clipped());
2280 EXPECT_FALSE(child2->is_clipped());
2281 EXPECT_FALSE(grand_child->is_clipped());
2282 EXPECT_FALSE(leaf_node1->is_clipped());
2283 EXPECT_FALSE(leaf_node2->is_clipped());
2284 EXPECT_TRUE(root->render_surface()->is_clipped());
2285 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582286
2287 // Case 2: The root is clipped. In this case, layers that draw into the root
2288 // render surface are clipped by the root's bounds.
2289 root->SetMasksToBounds(true);
2290 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362291 root->test_properties()->force_render_surface = true;
2292 child1->test_properties()->force_render_surface = true;
2293 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582294 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262295 EXPECT_TRUE(root->has_render_surface());
2296 EXPECT_FALSE(parent->has_render_surface());
2297 EXPECT_TRUE(child1->has_render_surface());
2298 EXPECT_FALSE(child2->has_render_surface());
2299 EXPECT_TRUE(grand_child->has_render_surface());
2300 EXPECT_FALSE(leaf_node1->has_render_surface());
2301 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422302 EXPECT_TRUE(root->is_clipped());
2303 EXPECT_TRUE(parent->is_clipped());
2304 EXPECT_FALSE(child1->is_clipped());
2305 EXPECT_TRUE(child1->render_surface()->is_clipped());
2306 EXPECT_TRUE(child2->is_clipped());
2307 EXPECT_FALSE(grand_child->is_clipped());
2308 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2309 EXPECT_FALSE(leaf_node1->is_clipped());
2310 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582311 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2312 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422313 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582314 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582315 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2316
2317 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422318 EXPECT_TRUE(root->is_clipped());
2319 EXPECT_TRUE(parent->is_clipped());
2320 EXPECT_TRUE(child1->is_clipped());
2321 EXPECT_TRUE(child2->is_clipped());
2322 EXPECT_TRUE(grand_child->is_clipped());
2323 EXPECT_TRUE(leaf_node1->is_clipped());
2324 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582325 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2326 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2327 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2328 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2329 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2330 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2331 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2332
2333 root->SetMasksToBounds(false);
2334
2335 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2336 // parent clip rect only contributes to the subtree rooted at child2, since
2337 // the subtree rooted at child1 renders into a separate surface. Similarly,
2338 // child1's clip rect doesn't contribute to its descendants, since its only
2339 // child is a render surface. However, without surfaces, these clip rects
2340 // contribute to all descendants.
2341 parent->SetMasksToBounds(true);
2342 child1->SetMasksToBounds(true);
2343 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362344 root->test_properties()->force_render_surface = true;
2345 child1->test_properties()->force_render_surface = true;
2346 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582347 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262348 EXPECT_TRUE(root->has_render_surface());
2349 EXPECT_FALSE(parent->has_render_surface());
2350 EXPECT_TRUE(child1->has_render_surface());
2351 EXPECT_FALSE(child2->has_render_surface());
2352 EXPECT_TRUE(grand_child->has_render_surface());
2353 EXPECT_FALSE(leaf_node1->has_render_surface());
2354 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422355 EXPECT_FALSE(root->is_clipped());
2356 EXPECT_TRUE(root->render_surface()->is_clipped());
2357 EXPECT_TRUE(parent->is_clipped());
2358 EXPECT_TRUE(child1->is_clipped());
2359 EXPECT_TRUE(child2->is_clipped());
2360 EXPECT_FALSE(grand_child->is_clipped());
2361 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2362 EXPECT_FALSE(leaf_node1->is_clipped());
2363 EXPECT_TRUE(leaf_node2->is_clipped());
2364 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582365 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2366 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2367 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422368 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582369 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2370
2371 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422372 EXPECT_FALSE(root->is_clipped());
2373 EXPECT_TRUE(root->render_surface()->is_clipped());
2374 EXPECT_TRUE(parent->is_clipped());
2375 EXPECT_TRUE(child1->is_clipped());
2376 EXPECT_TRUE(child2->is_clipped());
2377 EXPECT_TRUE(grand_child->is_clipped());
2378 EXPECT_TRUE(leaf_node1->is_clipped());
2379 EXPECT_TRUE(leaf_node2->is_clipped());
2380 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582381 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2382 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2383 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2384 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2385 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2386 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2387}
2388
jaydasika8d0064f2016-06-02 23:34:542389TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
jaydasikabf1875a2016-06-28 03:39:592390 LayerImpl* root = root_layer_for_testing();
jaydasika8d0064f2016-06-02 23:34:542391 LayerImpl* parent = AddChild<LayerImpl>(root);
2392 LayerImpl* child = AddChild<LayerImpl>(parent);
2393 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2394 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2395
danakje4fa7b72016-07-25 22:00:062396 root->SetBounds(gfx::Size(100, 100));
2397 parent->SetPosition(gfx::PointF(2.f, 2.f));
2398 parent->SetBounds(gfx::Size(400, 400));
2399 parent->SetMasksToBounds(true);
2400 child->SetPosition(gfx::PointF(4.f, 4.f));
2401 child->SetBounds(gfx::Size(800, 800));
2402 child->SetMasksToBounds(true);
2403 child->test_properties()->force_render_surface = true;
2404 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2405 grand_child->SetBounds(gfx::Size(1500, 1500));
2406 grand_child->test_properties()->force_render_surface = true;
2407 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2408 leaf_node->SetBounds(gfx::Size(2000, 2000));
2409
jaydasika8d0064f2016-06-02 23:34:542410 root->SetDrawsContent(true);
2411 parent->SetDrawsContent(true);
2412 child->SetDrawsContent(true);
2413 grand_child->SetDrawsContent(true);
2414 leaf_node->SetDrawsContent(true);
2415
jaydasika8d0064f2016-06-02 23:34:542416 host_impl()->set_resourceless_software_draw_for_testing();
2417 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2418 gfx::PointF test_point(90.f, 90.f);
2419 LayerImpl* result_layer =
2420 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2421 ASSERT_TRUE(result_layer);
2422 EXPECT_EQ(leaf_node, result_layer);
2423}
2424
ajuma51d73f72015-10-19 19:43:582425TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2426 // Tests that draw properties are computed correctly when we disable and then
2427 // re-enable separate surfaces.
jaydasikabf1875a2016-06-28 03:39:592428 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582429 LayerImpl* parent = AddChild<LayerImpl>(root);
2430 LayerImpl* child = AddChild<LayerImpl>(parent);
2431 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2432 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2433
danakje4fa7b72016-07-25 22:00:062434 root->SetBounds(gfx::Size(100, 100));
2435 parent->SetPosition(gfx::PointF(2.f, 2.f));
2436 parent->SetBounds(gfx::Size(400, 400));
2437 parent->SetMasksToBounds(true);
2438 child->SetPosition(gfx::PointF(4.f, 4.f));
2439 child->SetBounds(gfx::Size(800, 800));
2440 child->SetMasksToBounds(true);
2441 child->test_properties()->force_render_surface = true;
2442 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2443 grand_child->SetBounds(gfx::Size(1500, 1500));
2444 grand_child->test_properties()->force_render_surface = true;
2445 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2446 leaf_node->SetBounds(gfx::Size(2000, 2000));
2447
ajuma51d73f72015-10-19 19:43:582448 root->SetDrawsContent(true);
2449 parent->SetDrawsContent(true);
2450 child->SetDrawsContent(true);
2451 grand_child->SetDrawsContent(true);
2452 leaf_node->SetDrawsContent(true);
2453
ajuma51d73f72015-10-19 19:43:582454 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2455 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2456
2457 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2458 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2459
2460 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422461 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252462 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582463 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022464 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2465 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582466
2467 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422468 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582469 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2470 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022471 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces,
2472 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582473
2474 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422475 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252476 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582477 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022478 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2479 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582480}
2481
[email protected]989386c2013-07-18 21:37:232482TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
danakje4fa7b72016-07-25 22:00:062483 LayerImpl* root = root_layer_for_testing();
enneab0fee42015-07-07 17:36:422484 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2485 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2486 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2487 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2488 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2489 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2490 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2491 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322492
danakje4fa7b72016-07-25 22:00:062493 root->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362494 render_surface1->SetDrawsContent(true);
2495 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422496 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362497 render_surface2->SetDrawsContent(true);
2498 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422499 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362500 child_of_root->SetDrawsContent(true);
2501 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322502
2503 gfx::Transform layer_transform;
2504 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322505
jaydasika10d43fc2016-08-18 04:06:042506 root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062507 root->SetPosition(gfx::PointF(2.5f, 0.f));
2508 root->SetBounds(gfx::Size(10, 10));
2509 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042510 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062511 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2512 render_surface1->SetBounds(gfx::Size(10, 10));
2513 render_surface1->test_properties()->transform_origin =
2514 gfx::Point3F(0.25f, 0.f, 0.f);
2515 render_surface1->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042516 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062517 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2518 render_surface2->SetBounds(gfx::Size(10, 10));
2519 render_surface2->test_properties()->transform_origin =
2520 gfx::Point3F(0.25f, 0.f, 0.f);
2521 render_surface2->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042522 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062523 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2524 child_of_root->SetBounds(gfx::Size(10, 10));
2525 child_of_root->test_properties()->transform_origin =
2526 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042527 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062528 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2529 child_of_rs1->SetBounds(gfx::Size(10, 10));
2530 child_of_rs1->test_properties()->transform_origin =
2531 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042532 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062533 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2534 child_of_rs2->SetBounds(gfx::Size(10, 10));
2535 child_of_rs2->test_properties()->transform_origin =
2536 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042537 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062538 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2539 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2540 grand_child_of_root->test_properties()->transform_origin =
2541 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042542 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062543 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2544 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2545 grand_child_of_rs1->test_properties()->transform_origin =
2546 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042547 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062548 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2549 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2550 grand_child_of_rs2->test_properties()->transform_origin =
2551 gfx::Point3F(0.25f, 0.f, 0.f);
[email protected]fb661802013-03-25 01:59:322552
danakje4fa7b72016-07-25 22:00:062553 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:272554 SetElementIdsForTesting();
jaydasika9cb21c772016-05-10 22:37:082555
loyso9556c732016-03-11 07:54:582556 // Put an animated opacity on the render surface.
vollickef2ae922016-06-29 17:54:272557 AddOpacityTransitionToElementWithPlayer(
2558 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322559
loyso9556c732016-03-11 07:54:582560 // Also put an animated opacity on a layer without descendants.
vollickef2ae922016-06-29 17:54:272561 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2562 timeline_impl(), 10.0, 1.f, 0.f,
2563 false);
[email protected]fb661802013-03-25 01:59:322564
loyso9556c732016-03-11 07:54:582565 // Put a transform animation on the render surface.
vollickef2ae922016-06-29 17:54:272566 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2567 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322568
loyso9556c732016-03-11 07:54:582569 // Also put transform animations on grand_child_of_root, and
2570 // grand_child_of_rs2
vollickef2ae922016-06-29 17:54:272571 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2572 timeline_impl(), 10.0, 30, 0);
2573 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2574 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322575
danakje4fa7b72016-07-25 22:00:062576 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2577 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322578
2579 // Only layers that are associated with render surfaces should have an actual
2580 // RenderSurface() value.
danakje4fa7b72016-07-25 22:00:062581 ASSERT_TRUE(root->render_surface());
[email protected]fb661802013-03-25 01:59:322582 ASSERT_FALSE(child_of_root->render_surface());
2583 ASSERT_FALSE(grand_child_of_root->render_surface());
2584
2585 ASSERT_TRUE(render_surface1->render_surface());
2586 ASSERT_FALSE(child_of_rs1->render_surface());
2587 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2588
2589 ASSERT_TRUE(render_surface2->render_surface());
2590 ASSERT_FALSE(child_of_rs2->render_surface());
2591 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2592
2593 // Verify all render target accessors
danakje4fa7b72016-07-25 22:00:062594 EXPECT_EQ(root->render_surface(), root->render_target());
2595 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
2596 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322597
weiliangc189c1a12016-04-11 16:16:252598 EXPECT_EQ(render_surface1->render_surface(),
2599 render_surface1->render_target());
2600 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2601 EXPECT_EQ(render_surface1->render_surface(),
2602 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322603
weiliangc189c1a12016-04-11 16:16:252604 EXPECT_EQ(render_surface2->render_surface(),
2605 render_surface2->render_target());
2606 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2607 EXPECT_EQ(render_surface2->render_surface(),
2608 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322609
[email protected]fb661802013-03-25 01:59:322610 // Verify screen_space_transform_is_animating values
danakje4fa7b72016-07-25 22:00:062611 EXPECT_FALSE(root->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322612 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2613 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2614 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322615 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2616 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2617 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322618 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2619 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2620
2621 // Sanity check. If these fail there is probably a bug in the test itself.
2622 // It is expected that we correctly set up transforms so that the y-component
2623 // of the screen-space transform encodes the "depth" of the layer in the tree.
danakje4fa7b72016-07-25 22:00:062624 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262625 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102626 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322627 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102628 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322629
[email protected]803f6b52013-09-12 00:51:262630 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102631 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2632 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322633 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102634 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322635
[email protected]803f6b52013-09-12 00:51:262636 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102637 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2638 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322639 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102640 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322641}
2642
ajuma9384b9c22015-09-17 20:35:032643TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
danakje4fa7b72016-07-25 22:00:062644 LayerImpl* root = root_layer_for_testing();
ajuma9384b9c22015-09-17 20:35:032645 LayerImpl* child = AddChildToRoot<LayerImpl>();
2646 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2647
ajuma9384b9c22015-09-17 20:35:032648 gfx::Transform large_transform;
2649 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2650
danakje4fa7b72016-07-25 22:00:062651 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042652 child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062653 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042654 grand_child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062655 grand_child->SetBounds(gfx::Size(10, 10));
2656 grand_child->SetDrawsContent(true);
2657 ExecuteCalculateDrawProperties(root);
ajuma9384b9c22015-09-17 20:35:032658
2659 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2660}
2661
ajuma315a4782015-07-24 21:16:342662TEST_F(LayerTreeHostCommonTest,
2663 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
danakje4fa7b72016-07-25 22:00:062664 LayerImpl* root = root_layer_for_testing();
2665 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma315a4782015-07-24 21:16:342666 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2667 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2668
danakje4fa7b72016-07-25 22:00:062669 root->SetDrawsContent(true);
ajuma315a4782015-07-24 21:16:342670 child->SetDrawsContent(true);
2671 grand_child->SetDrawsContent(true);
2672 great_grand_child->SetDrawsContent(true);
2673
danakje4fa7b72016-07-25 22:00:062674 root->SetBounds(gfx::Size(10, 10));
2675 child->SetBounds(gfx::Size(10, 10));
2676 grand_child->SetBounds(gfx::Size(10, 10));
2677 great_grand_child->SetBounds(gfx::Size(10, 10));
ajuma315a4782015-07-24 21:16:342678
vollickef2ae922016-06-29 17:54:272679 SetElementIdsForTesting();
2680
ajuma315a4782015-07-24 21:16:342681 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482682 std::unique_ptr<Animation> animation = Animation::Create(
2683 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302684 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552685 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342686 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:272687 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2688 std::move(animation));
danakje4fa7b72016-07-25 22:00:062689 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:342690
danakje4fa7b72016-07-25 22:00:062691 EXPECT_FALSE(root->screen_space_transform_is_animating());
ajuma315a4782015-07-24 21:16:342692 EXPECT_FALSE(child->screen_space_transform_is_animating());
2693
2694 EXPECT_FALSE(grand_child->TransformIsAnimating());
2695 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2696 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2697 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2698}
2699
weiliangc6da32862016-04-20 16:40:112700TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2701 // Test visible layer rect and drawable content rect are calculated correctly
2702 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322703
[email protected]2c7c6702013-03-26 03:14:052704 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322705 gfx::Transform layer_to_surface_transform;
2706
2707 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232708 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112709 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2710 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2711 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2712 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2713 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2714 EXPECT_EQ(expected_drawable_content_rect,
2715 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322716
2717 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052718 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112719 expected_visible_layer_rect = gfx::Rect();
2720 expected_drawable_content_rect = gfx::Rect();
2721 drawing_layer = TestVisibleRectAndDrawableContentRect(
2722 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2723 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2724 EXPECT_EQ(expected_drawable_content_rect,
2725 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322726
2727 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052728 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112729 expected_visible_layer_rect = gfx::Rect(20, 20);
2730 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
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
weiliangc6da32862016-04-20 16:40:112738TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2739 // Test visible layer rect and drawable content rect are calculated correctly
2740 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322741
[email protected]2c7c6702013-03-26 03:14:052742 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2743 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322744 gfx::Transform layer_to_surface_transform;
2745
2746 // Case 1: Layer is contained within the surface.
2747 layer_to_surface_transform.MakeIdentity();
2748 layer_to_surface_transform.Translate(50.0, 50.0);
2749 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112750 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2751 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2752 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2753 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2754 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2755 EXPECT_EQ(expected_drawable_content_rect,
2756 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322757
2758 // Case 2: Layer is outside the surface rect.
2759 layer_to_surface_transform.MakeIdentity();
2760 layer_to_surface_transform.Translate(-50.0, 0.0);
2761 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112762 expected_visible_layer_rect = gfx::Rect();
2763 expected_drawable_content_rect = gfx::Rect();
2764 drawing_layer = TestVisibleRectAndDrawableContentRect(
2765 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2766 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2767 EXPECT_EQ(expected_drawable_content_rect,
2768 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322769
2770 // Case 3: The layer is rotated about its top-left corner. In surface space,
2771 // the layer is oriented diagonally, with the left half outside of the render
2772 // surface. In this case, the g should still be the entire layer
2773 // (remember the g is computed in layer space); both the top-left
2774 // and bottom-right corners of the layer are still visible.
2775 layer_to_surface_transform.MakeIdentity();
2776 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112777 expected_visible_layer_rect = gfx::Rect(30, 30);
2778 expected_drawable_content_rect = gfx::Rect(22, 43);
2779 drawing_layer = TestVisibleRectAndDrawableContentRect(
2780 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2781 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2782 EXPECT_EQ(expected_drawable_content_rect,
2783 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322784
2785 // Case 4: The layer is rotated about its top-left corner, and translated
2786 // upwards. In surface space, the layer is oriented diagonally, with only the
2787 // top corner of the surface overlapping the layer. In layer space, the render
2788 // surface overlaps the right side of the layer. The g should be
2789 // the layer's right half.
2790 layer_to_surface_transform.MakeIdentity();
2791 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2792 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112793 // Right half of layer bounds.
2794 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2795 expected_drawable_content_rect = gfx::Rect(22, 22);
2796 drawing_layer = TestVisibleRectAndDrawableContentRect(
2797 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2798 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2799 EXPECT_EQ(expected_drawable_content_rect,
2800 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322801}
2802
weiliangc6da32862016-04-20 16:40:112803TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2804 // Test visible layer rect and drawable content rect are calculated correctly
2805 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322806
[email protected]2c7c6702013-03-26 03:14:052807 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2808 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322809 gfx::Transform layer_to_surface_transform;
2810
2811 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2812 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112813 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322814 layer_to_surface_transform.MakeIdentity();
2815 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112816 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2817 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2818 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2819 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2820 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2821 EXPECT_EQ(expected_drawable_content_rect,
2822 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322823
2824 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2825 // degrees, but shifted to the side so only the right-half the layer would be
2826 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112827 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262828 SkMScalar half_width_of_rotated_layer =
2829 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322830 layer_to_surface_transform.MakeIdentity();
2831 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232832 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2833 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112834 // Tight half of the layer.
2835 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2836 expected_drawable_content_rect = gfx::Rect(36, 100);
2837 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
weiliangc6da32862016-04-20 16:40:112844TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2845 // Test visible layer rect and drawable content rect are calculated correctly
2846 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322847
[email protected]2c7c6702013-03-26 03:14:052848 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2849 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322850 gfx::Transform layer_to_surface_transform;
2851
2852 // Case 1: Even though the layer is twice as large as the surface, due to
2853 // perspective foreshortening, the layer will fit fully in the surface when
2854 // its translated more than the perspective amount.
2855 layer_to_surface_transform.MakeIdentity();
2856
2857 // The following sequence of transforms applies the perspective about the
2858 // center of the surface.
2859 layer_to_surface_transform.Translate(50.0, 50.0);
2860 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2861 layer_to_surface_transform.Translate(-50.0, -50.0);
2862
2863 // This translate places the layer in front of the surface's projection plane.
2864 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2865
weiliangc6da32862016-04-20 16:40:112866 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2867 // offset by layer position.
2868 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2869 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2870 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2871 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2872 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2873 EXPECT_EQ(expected_drawable_content_rect,
2874 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322875
2876 // Case 2: same projection as before, except that the layer is also translated
2877 // to the side, so that only the right half of the layer should be visible.
2878 //
2879 // Explanation of expected result: The perspective ratio is (z distance
2880 // between layer and camera origin) / (z distance between projection plane and
2881 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112882 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322883 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112884 // -25 == -100 in the layer's units.
2885 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2886 // Visible layer rect is moved by 100, and drawable content rect is in target
2887 // space and is moved by 25.
2888 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2889 expected_drawable_content_rect = gfx::Rect(13, 38);
2890 drawing_layer = TestVisibleRectAndDrawableContentRect(
2891 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2892 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2893 EXPECT_EQ(expected_drawable_content_rect,
2894 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322895}
2896
weiliangc6da32862016-04-20 16:40:112897TEST_F(LayerTreeHostCommonDrawRectsTest,
2898 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322899 // There is currently no explicit concept of an orthographic projection plane
2900 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2901 // are technically behind the surface in an orthographic world should not be
2902 // clipped when they are flattened to the surface.
2903
[email protected]2c7c6702013-03-26 03:14:052904 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2905 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322906 gfx::Transform layer_to_surface_transform;
2907
2908 // This sequence of transforms effectively rotates the layer about the y-axis
2909 // at the center of the layer.
2910 layer_to_surface_transform.MakeIdentity();
2911 layer_to_surface_transform.Translate(50.0, 0.0);
2912 layer_to_surface_transform.RotateAboutYAxis(45.0);
2913 layer_to_surface_transform.Translate(-50.0, 0.0);
2914
weiliangc6da32862016-04-20 16:40:112915 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2916 // space.
2917 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2918 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2919 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2920 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2921 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2922 EXPECT_EQ(expected_drawable_content_rect,
2923 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322924}
2925
weiliangc6da32862016-04-20 16:40:112926TEST_F(LayerTreeHostCommonDrawRectsTest,
2927 DrawRectsFor3dPerspectiveWhenClippedByW) {
2928 // Test visible layer rect and drawable content rect are calculated correctly
2929 // when projecting a surface onto a layer, but the layer is partially behind
2930 // the camera (not just behind the projection plane). In this case, the
2931 // cartesian coordinates may seem to be valid, but actually they are not. The
2932 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2933 // coordinates before converting to cartesian coordinates. The drawable
2934 // content rect would be entire surface rect because layer is rotated at the
2935 // camera position.
[email protected]fb661802013-03-25 01:59:322936
weiliangc6da32862016-04-20 16:40:112937 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2938 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322939 gfx::Transform layer_to_surface_transform;
2940
2941 // The layer is positioned so that the right half of the layer should be in
2942 // front of the camera, while the other half is behind the surface's
2943 // projection plane. The following sequence of transforms applies the
2944 // perspective and rotation about the center of the layer.
2945 layer_to_surface_transform.MakeIdentity();
2946 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112947 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2948 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2949 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322950
2951 // Sanity check that this transform does indeed cause w < 0 when applying the
2952 // transform, otherwise this code is not testing the intended scenario.
2953 bool clipped;
2954 MathUtil::MapQuad(layer_to_surface_transform,
2955 gfx::QuadF(gfx::RectF(layer_content_rect)),
2956 &clipped);
2957 ASSERT_TRUE(clipped);
2958
weiliangc6da32862016-04-20 16:40:112959 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2960 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2961 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2962 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2963 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2964 EXPECT_EQ(expected_drawable_content_rect,
2965 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322966}
2967
weiliangc6da32862016-04-20 16:40:112968TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322969 // To determine visible rect in layer space, there needs to be an
2970 // un-projection from surface space to layer space. When the original
2971 // transform was a perspective projection that was clipped, it returns a rect
2972 // that encloses the clipped bounds. Un-projecting this new rect may require
2973 // clipping again.
2974
2975 // This sequence of transforms causes one corner of the layer to protrude
2976 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:112977 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
2978 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322979 gfx::Transform layer_to_surface_transform;
2980 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:112981 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:322982 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2983 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2984 layer_to_surface_transform.RotateAboutYAxis(45.0);
2985 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:112986 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:322987
2988 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2989 // code is not testing the intended scenario.
2990 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442991 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2992 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322993 MathUtil::ProjectQuad(
2994 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2995 ASSERT_TRUE(clipped);
2996
2997 // Only the corner of the layer is not visible on the surface because of being
2998 // clipped. But, the net result of rounding visible region to an axis-aligned
2999 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:113000 gfx::Rect expected_visible_layer_rect = layer_content_rect;
3001 gfx::Rect expected_drawable_content_rect = target_surface_rect;
3002 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3003 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3004 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3005 EXPECT_EQ(expected_drawable_content_rect,
3006 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323007}
3008
miletus9d3da522015-06-05 19:45:073009TEST_F(LayerTreeHostCommonTest,
3010 VisibleRectsForPositionedRootLayerClippedByViewport) {
jaydasikabf1875a2016-06-28 03:39:593011 LayerImpl* root = root_layer_for_testing();
miletus9d3da522015-06-05 19:45:073012
danakje4fa7b72016-07-25 22:00:063013 root->SetPosition(gfx::PointF(60, 70));
3014 root->SetBounds(gfx::Size(100, 100));
3015 root->SetDrawsContent(true);
enne6c281f6e2015-08-18 23:23:003016 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:073017
danakj5e6ff6d2015-09-05 04:43:443018 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:073019 root->render_surface()->DrawableContentRect());
3020 // In target space, not clipped.
3021 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3022 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:443023 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:073024}
3025
[email protected]989386c2013-07-18 21:37:233026TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
jaydasikabf1875a2016-06-28 03:39:593027 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173028 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173029 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173030 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063031
3032 root->SetBounds(gfx::Size(100, 100));
3033 child1_layer->SetBounds(gfx::Size(50, 50));
3034 child1_layer->SetDrawsContent(true);
3035 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
3036 child2_layer->SetBounds(gfx::Size(50, 50));
3037 child2_layer->SetDrawsContent(true);
3038 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
3039 child3_layer->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173040 child3_layer->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173041 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323042
danakj5e6ff6d2015-09-05 04:43:443043 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323044 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323045
danakj64767d902015-06-19 00:10:433046 // Layers that do not draw content should have empty visible_layer_rects.
3047 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323048
danakj64767d902015-06-19 00:10:433049 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173050 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3051 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3052 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323053
3054 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173055 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3056 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3057 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323058}
3059
[email protected]989386c2013-07-18 21:37:233060TEST_F(LayerTreeHostCommonTest,
3061 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
jaydasikabf1875a2016-06-28 03:39:593062 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173063 LayerImpl* child = AddChildToRoot<LayerImpl>();
3064 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173065 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173066 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:283067
danakje4fa7b72016-07-25 22:00:063068 root->SetBounds(gfx::Size(100, 100));
3069 child->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323070 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063071 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
3072 grand_child1->SetBounds(gfx::Size(50, 50));
3073 grand_child1->SetDrawsContent(true);
3074 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
3075 grand_child2->SetBounds(gfx::Size(50, 50));
3076 grand_child2->SetDrawsContent(true);
3077 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
3078 grand_child3->SetBounds(gfx::Size(50, 50));
3079 grand_child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173080 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323081
danakj5e6ff6d2015-09-05 04:43:443082 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323083 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323084
3085 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433086 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3087 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323088
3089 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433090 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3091 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3092 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323093
3094 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323095 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3096 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323097 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3098}
3099
ajuma27442dd2015-03-30 19:19:483100TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasikabf1875a2016-06-28 03:39:593101 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:143102 LayerImpl* child = AddChild<LayerImpl>(root);
3103 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483104
ajuma27442dd2015-03-30 19:19:483105 gfx::Transform child_scale_matrix;
3106 child_scale_matrix.Scale(0.25f, 0.25f);
3107 gfx::Transform grand_child_scale_matrix;
3108 grand_child_scale_matrix.Scale(0.246f, 0.246f);
ajuma27442dd2015-03-30 19:19:483109
danakje4fa7b72016-07-25 22:00:063110 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043111 child->test_properties()->transform = child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063112 child->SetBounds(gfx::Size(10, 10));
ajuma27442dd2015-03-30 19:19:483113 child->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:043114 grand_child->test_properties()->transform = grand_child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063115 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:143116 grand_child->SetDrawsContent(true);
3117 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483118
weiliangcd15784432016-06-07 17:57:333119 // The visible rect is expanded to integer coordinates.
3120 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483121}
3122
ajumae947a352017-01-10 19:17:493123TEST_F(LayerTreeHostCommonTest, VisibleRectWithClippingAndFilters) {
3124 LayerImpl* root = root_layer_for_testing();
3125 LayerImpl* clip = AddChild<LayerImpl>(root);
3126 LayerImpl* filter = AddChild<LayerImpl>(clip);
3127 LayerImpl* filter_child = AddChild<LayerImpl>(filter);
3128
3129 root->SetBounds(gfx::Size(100, 100));
3130 clip->SetBounds(gfx::Size(10, 10));
3131 filter->test_properties()->force_render_surface = true;
3132 filter_child->SetBounds(gfx::Size(2000, 2000));
3133 filter_child->SetPosition(gfx::PointF(-50, -50));
3134 filter_child->SetDrawsContent(true);
3135
3136 clip->SetMasksToBounds(true);
3137
3138 ExecuteCalculateDrawProperties(root);
3139 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
3140 EXPECT_EQ(gfx::Rect(10, 10), filter->render_surface()->content_rect());
3141
3142 FilterOperations blur_filter;
3143 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3144 filter->test_properties()->filters = blur_filter;
3145 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3146
3147 ExecuteCalculateDrawProperties(root);
3148
3149 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
3150 EXPECT_EQ(gfx::Rect(-12, -12, 34, 34),
3151 filter->render_surface()->content_rect());
3152
3153 gfx::Transform vertical_flip;
3154 vertical_flip.Scale(1, -1);
3155 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
3156 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
3157 FilterOperations reflection_filter;
3158 reflection_filter.Append(
3159 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
3160 SkBlendMode::kSrcOver, std::move(flip_filter))));
3161 filter->test_properties()->filters = reflection_filter;
3162 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3163
3164 ExecuteCalculateDrawProperties(root);
3165
3166 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
3167 EXPECT_EQ(gfx::Rect(0, -10, 10, 20),
3168 filter->render_surface()->content_rect());
3169}
3170
3171TEST_F(LayerTreeHostCommonTest, VisibleRectWithScalingClippingAndFilters) {
3172 LayerImpl* root = root_layer_for_testing();
3173 LayerImpl* scale = AddChild<LayerImpl>(root);
3174 LayerImpl* clip = AddChild<LayerImpl>(scale);
3175 LayerImpl* filter = AddChild<LayerImpl>(clip);
3176 LayerImpl* filter_child = AddChild<LayerImpl>(filter);
3177
3178 root->SetBounds(gfx::Size(100, 100));
3179 clip->SetBounds(gfx::Size(10, 10));
3180 filter->test_properties()->force_render_surface = true;
3181 filter_child->SetBounds(gfx::Size(2000, 2000));
3182 filter_child->SetPosition(gfx::PointF(-50, -50));
3183 filter_child->SetDrawsContent(true);
3184
3185 clip->SetMasksToBounds(true);
3186
3187 gfx::Transform scale_transform;
3188 scale_transform.Scale(3, 3);
3189 scale->test_properties()->transform = scale_transform;
3190
3191 ExecuteCalculateDrawProperties(root);
3192 EXPECT_EQ(gfx::Rect(50, 50, 10, 10), filter_child->visible_layer_rect());
3193 EXPECT_EQ(gfx::Rect(30, 30), filter->render_surface()->content_rect());
3194
3195 FilterOperations blur_filter;
3196 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3197 filter->test_properties()->filters = blur_filter;
3198 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3199
3200 ExecuteCalculateDrawProperties(root);
3201
3202 EXPECT_EQ(gfx::Rect(38, 38, 34, 34), filter_child->visible_layer_rect());
3203 EXPECT_EQ(gfx::Rect(-36, -36, 102, 102),
3204 filter->render_surface()->content_rect());
3205
3206 gfx::Transform vertical_flip;
3207 vertical_flip.Scale(1, -1);
3208 sk_sp<SkImageFilter> flip_filter = SkImageFilter::MakeMatrixFilter(
3209 vertical_flip.matrix(), kLow_SkFilterQuality, nullptr);
3210 FilterOperations reflection_filter;
3211 reflection_filter.Append(
3212 FilterOperation::CreateReferenceFilter(SkXfermodeImageFilter::Make(
3213 SkBlendMode::kSrcOver, std::move(flip_filter))));
3214 filter->test_properties()->filters = reflection_filter;
3215 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3216
3217 ExecuteCalculateDrawProperties(root);
3218
3219 EXPECT_EQ(gfx::Rect(50, 40, 10, 20), filter_child->visible_layer_rect());
3220 EXPECT_EQ(gfx::Rect(0, -30, 30, 60),
3221 filter->render_surface()->content_rect());
3222}
3223
3224TEST_F(LayerTreeHostCommonTest, ClipRectWithClipParentAndFilters) {
3225 LayerImpl* root = root_layer_for_testing();
3226 LayerImpl* clip = AddChild<LayerImpl>(root);
3227 LayerImpl* filter = AddChild<LayerImpl>(clip);
3228 LayerImpl* filter_child_1 = AddChild<LayerImpl>(filter);
3229 LayerImpl* filter_child_2 = AddChild<LayerImpl>(filter);
3230
3231 root->SetBounds(gfx::Size(100, 100));
3232 clip->SetBounds(gfx::Size(10, 10));
3233 filter->test_properties()->force_render_surface = true;
3234
3235 filter_child_1->SetBounds(gfx::Size(20, 20));
3236 filter_child_1->SetDrawsContent(true);
3237 filter_child_2->SetBounds(gfx::Size(20, 20));
3238 filter_child_2->SetDrawsContent(true);
3239
3240 root->SetMasksToBounds(true);
3241 clip->SetMasksToBounds(true);
3242
3243 root->test_properties()->clip_children =
3244 base::MakeUnique<std::set<LayerImpl*>>();
3245 root->test_properties()->clip_children->insert(filter_child_1);
3246 filter_child_1->test_properties()->clip_parent = root;
3247
3248 ExecuteCalculateDrawProperties(root);
3249 EXPECT_TRUE(filter_child_1->is_clipped());
3250 EXPECT_TRUE(filter_child_2->is_clipped());
3251 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
3252 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
3253
3254 FilterOperations blur_filter;
3255 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3256 filter->test_properties()->filters = blur_filter;
3257 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3258
3259 ExecuteCalculateDrawProperties(root);
3260
3261 EXPECT_TRUE(filter_child_1->is_clipped());
3262 EXPECT_TRUE(filter_child_2->is_clipped());
3263 EXPECT_EQ(gfx::Rect(100, 100), filter_child_1->clip_rect());
3264 EXPECT_EQ(gfx::Rect(10, 10), filter_child_2->clip_rect());
3265}
3266
3267TEST_F(LayerTreeHostCommonTest, ClipRectWithClippedDescendantOfFilter) {
3268 LayerImpl* root = root_layer_for_testing();
3269 LayerImpl* filter = AddChild<LayerImpl>(root);
3270 LayerImpl* clip = AddChild<LayerImpl>(filter);
3271 LayerImpl* filter_grand_child = AddChild<LayerImpl>(clip);
3272
3273 root->SetBounds(gfx::Size(100, 100));
3274 filter->test_properties()->force_render_surface = true;
3275
3276 clip->SetBounds(gfx::Size(10, 10));
3277 clip->SetMasksToBounds(true);
3278
3279 filter_grand_child->SetBounds(gfx::Size(20, 20));
3280 filter_grand_child->SetDrawsContent(true);
3281
3282 ExecuteCalculateDrawProperties(root);
3283 EXPECT_TRUE(filter_grand_child->is_clipped());
3284 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
3285
3286 FilterOperations blur_filter;
3287 blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
3288 filter->test_properties()->filters = blur_filter;
3289 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3290
3291 ExecuteCalculateDrawProperties(root);
3292
3293 EXPECT_TRUE(filter_grand_child->is_clipped());
3294 EXPECT_EQ(gfx::Rect(10, 10), filter_grand_child->clip_rect());
3295}
3296
[email protected]989386c2013-07-18 21:37:233297TEST_F(LayerTreeHostCommonTest,
3298 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593299 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173300 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3301 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173302 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173303 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
danakje4fa7b72016-07-25 22:00:063304
3305 root->SetBounds(gfx::Size(100, 100));
3306 render_surface->SetBounds(gfx::Size(3, 4));
3307 render_surface->test_properties()->force_render_surface = true;
3308 child1->SetPosition(gfx::PointF(5.f, 5.f));
3309 child1->SetBounds(gfx::Size(50, 50));
3310 child1->SetDrawsContent(true);
3311 child2->SetPosition(gfx::PointF(75.f, 75.f));
3312 child2->SetBounds(gfx::Size(50, 50));
3313 child2->SetDrawsContent(true);
3314 child3->SetPosition(gfx::PointF(125.f, 125.f));
3315 child3->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173316 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173317 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323318
weiliangc0dece732015-07-27 19:06:173319 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323320
danakj5e6ff6d2015-09-05 04:43:443321 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323322 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323323
3324 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433325 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173326 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323327
3328 // An unclipped surface grows its DrawableContentRect to include all drawable
3329 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443330 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173331 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323332
3333 // All layers that draw content into the unclipped surface are also unclipped.
jaydasika94bebdd2016-09-16 22:11:183334 // Only the viewport clip should apply
danakj64767d902015-06-19 00:10:433335 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183336 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3337 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323338
hush6b614212014-12-04 22:37:323339 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3340 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3341 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323342}
3343
[email protected]989386c2013-07-18 21:37:233344TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583345 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:593346 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:583347 LayerImpl* parent = AddChild<LayerImpl>(root);
3348 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3349 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3350 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3351 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3352 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3353 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3354
danakje4fa7b72016-07-25 22:00:063355 root->SetBounds(gfx::Size(100, 100));
3356 parent->SetPosition(gfx::PointF(2.f, 2.f));
3357 parent->SetBounds(gfx::Size(400, 400));
3358 child1->SetPosition(gfx::PointF(4.f, 4.f));
3359 child1->SetBounds(gfx::Size(800, 800));
3360 child1->test_properties()->force_render_surface = true;
3361 child2->SetPosition(gfx::PointF(3.f, 3.f));
3362 child2->SetBounds(gfx::Size(800, 800));
3363 child2->test_properties()->force_render_surface = true;
3364 grand_child1->SetPosition(gfx::PointF(8.f, 8.f));
3365 grand_child1->SetBounds(gfx::Size(1500, 1500));
3366 grand_child2->SetPosition(gfx::PointF(7.f, 7.f));
3367 grand_child2->SetBounds(gfx::Size(1500, 1500));
3368 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
3369 leaf_node1->SetBounds(gfx::Size(2000, 2000));
3370 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
3371 leaf_node2->SetBounds(gfx::Size(2000, 2000));
3372
ajuma51d73f72015-10-19 19:43:583373 root->SetDrawsContent(true);
3374 parent->SetDrawsContent(true);
3375 child1->SetDrawsContent(true);
3376 child2->SetDrawsContent(true);
3377 grand_child1->SetDrawsContent(true);
3378 grand_child2->SetDrawsContent(true);
3379 leaf_node1->SetDrawsContent(true);
3380 leaf_node2->SetDrawsContent(true);
3381
jaydasika94bebdd2016-09-16 22:11:183382 // Case 1: No layers clip. Visible rects are clipped by the viewport.
ajuma51d73f72015-10-19 19:43:583383 // Each layer's drawable content rect is its bounds in target space; the only
3384 // thing that changes with surfaces disabled is that target space is always
3385 // screen space.
ajuma35b24f62017-01-27 21:23:093386 child1->test_properties()->force_render_surface = true;
3387 child2->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:583388 ExecuteCalculateDrawProperties(root);
3389 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3390 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183391 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3392 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3393 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3394 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3395 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3396 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583397
3398 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3399 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3400 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3401 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3402 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3403 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3404 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3405 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3406
3407 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3408 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3409 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3410 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3411 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3412 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3413 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3414 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3415 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3416
3417 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3418 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3419 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3420 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3421 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3422 grand_child1->drawable_content_rect());
3423 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3424 grand_child2->drawable_content_rect());
3425 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3426 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3427
3428 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3429 // all visible layer rects are clipped by the intersection of all ancestor
3430 // clips, whether or not surfaces are disabled. However, drawable content
3431 // rects are clipped only until the next render surface is reached, so
3432 // descendants of parent have their drawable content rects clipped only when
3433 // surfaces are disabled.
3434 parent->SetMasksToBounds(true);
3435 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3436 ExecuteCalculateDrawProperties(root);
3437 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3438 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3439 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3440 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3441 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3442 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3443 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3444 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3445
3446 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3447 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3448 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3449 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3450 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3451 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3452 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3453 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3454
3455 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3456 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3457 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3458 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3459 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3460 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3461 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3462 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3463 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3464
3465 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3466 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3467 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3468 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3469 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3470 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3471 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3472 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3473
3474 parent->SetMasksToBounds(false);
3475
3476 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
jaydasika526eae0a2016-09-02 01:47:593477 // layers have their visible rects clipped by them; Similarly, descendants of
3478 // these layers have their drawable content rects clipped by them.
ajuma51d73f72015-10-19 19:43:583479 child1->SetMasksToBounds(true);
3480 grand_child2->SetMasksToBounds(true);
3481 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3482 ExecuteCalculateDrawProperties(root);
3483 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3484 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593485 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183486 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593487 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3488 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3489 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3490 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583491
3492 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3493 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3494 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3495 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3496 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3497 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3498 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3499 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3500
3501 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3502 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3503 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3504 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3505 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3506 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3507 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3508 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3509 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3510
3511 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3512 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3513 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3514 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3515 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3516 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3517 grand_child2->drawable_content_rect());
3518 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3519 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3520}
3521
3522TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023523 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
jaydasikabf1875a2016-06-28 03:39:593524 LayerImpl* root = root_layer_for_testing();
enne6c281f6e2015-08-18 23:23:003525 LayerImpl* child1 = AddChild<LayerImpl>(root);
3526 LayerImpl* child2 = AddChild<LayerImpl>(root);
3527 LayerImpl* child3 = AddChild<LayerImpl>(root);
hush887bb542014-12-02 22:49:023528
danakje4fa7b72016-07-25 22:00:063529 root->SetBounds(gfx::Size(100, 100));
3530 child1->SetPosition(gfx::PointF(5.f, 5.f));
3531 child1->SetBounds(gfx::Size(50, 50));
3532 child1->SetDrawsContent(true);
3533 child2->SetPosition(gfx::PointF(75.f, 75.f));
3534 child2->SetBounds(gfx::Size(50, 50));
3535 child2->SetDrawsContent(true);
3536 child3->SetPosition(gfx::PointF(125.f, 125.f));
3537 child3->SetBounds(gfx::Size(50, 50));
3538 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023539
enne6c281f6e2015-08-18 23:23:003540 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023541 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003542 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383543 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023544
sunxdb365de02016-04-28 20:32:573545 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023546 ASSERT_TRUE(root->render_surface());
3547 EXPECT_FALSE(root->is_clipped());
3548
3549 gfx::Rect empty;
3550 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3551 EXPECT_TRUE(root->render_surface()->is_clipped());
3552
3553 // Visible content rect calculation will check if the target surface is
3554 // clipped or not. An empty clip rect does not indicate the render surface
3555 // is unclipped.
danakj64767d902015-06-19 00:10:433556 EXPECT_EQ(empty, child1->visible_layer_rect());
3557 EXPECT_EQ(empty, child2->visible_layer_rect());
3558 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023559}
3560
3561TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233562 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
jaydasikabf1875a2016-06-28 03:39:593563 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173564 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063565
3566 root->SetBounds(gfx::Size(100, 100));
3567 child->SetPosition(gfx::PointF(5.f, 5.f));
3568 child->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173569 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283570
[email protected]630ddad2013-08-16 03:01:323571 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473572 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323573 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473574
jaydasika10d43fc2016-08-18 04:06:043575 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173576 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473577
danakj64767d902015-06-19 00:10:433578 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473579 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323580
[email protected]08bdf1b2014-04-16 23:23:293581 // Case 2: a matrix with flattened z, uninvertible and not visible according
3582 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323583 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263584 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323585 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3586
jaydasika10d43fc2016-08-18 04:06:043587 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173588 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323589
danakj64767d902015-06-19 00:10:433590 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293591 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323592
[email protected]08bdf1b2014-04-16 23:23:293593 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323594 uninvertible_matrix.MakeIdentity();
3595 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263596 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323597 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3598
jaydasika10d43fc2016-08-18 04:06:043599 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173600 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323601
danakj64767d902015-06-19 00:10:433602 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293603 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473604}
3605
[email protected]989386c2013-07-18 21:37:233606TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563607 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
jaydasikabf1875a2016-06-28 03:39:593608 LayerImpl* root = root_layer_for_testing();
ajumaae0dc2d2015-08-05 21:55:563609 LayerImpl* child = AddChildToRoot<LayerImpl>();
3610 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaae0dc2d2015-08-05 21:55:563611
ajumaae0dc2d2015-08-05 21:55:563612 gfx::Transform perspective;
3613 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3614
3615 gfx::Transform rotation;
3616 rotation.RotateAboutYAxis(45.0);
3617
danakje4fa7b72016-07-25 22:00:063618 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043619 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063620 child->SetPosition(gfx::PointF(10.f, 10.f));
3621 child->SetBounds(gfx::Size(100, 100));
3622 child->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:203623 child->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:063624 child->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:043625 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063626 grand_child->SetBounds(gfx::Size(100, 100));
3627 grand_child->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:203628 child->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:063629 grand_child->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203630 grand_child->test_properties()->sorting_context_id = 1;
ajumaae0dc2d2015-08-05 21:55:563631 ExecuteCalculateDrawProperties(root);
3632
3633 // Though all layers have invertible transforms, matrix multiplication using
3634 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053635 EXPECT_FALSE(root->layer_tree_impl()
3636 ->property_trees()
3637 ->transform_tree.Node(grand_child->transform_tree_index())
trchendba8b1502016-07-08 09:47:013638 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563639
sunxd71aea3e2016-04-01 23:48:053640 // CalcDrawProps skips a subtree when a layer's screen space transform is
3641 // uninvertible
3642 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563643}
3644
jaydasika69c77aa2016-07-14 22:48:483645TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) {
3646 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika69c77aa2016-07-14 22:48:483647 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323648 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3649 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223650 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483651
3652 std::unique_ptr<LayerImpl> root =
3653 LayerImpl::Create(host_impl.active_tree(), 1);
3654 std::unique_ptr<LayerImpl> child =
3655 LayerImpl::Create(host_impl.active_tree(), 2);
3656 std::unique_ptr<TextureLayerImpl> surface =
3657 TextureLayerImpl::Create(host_impl.active_tree(), 3);
3658 std::unique_ptr<TextureLayerImpl> surface_child =
3659 TextureLayerImpl::Create(host_impl.active_tree(), 4);
3660 std::unique_ptr<TextureLayerImpl> surface_sibling =
3661 TextureLayerImpl::Create(host_impl.active_tree(), 5);
3662 std::unique_ptr<TextureLayerImpl> surface_child_mask =
3663 TextureLayerImpl::Create(host_impl.active_tree(), 6);
3664
3665 surface->SetDrawsContent(true);
3666 surface_child->SetDrawsContent(true);
3667 surface_sibling->SetDrawsContent(true);
3668 surface_child_mask->SetDrawsContent(true);
3669 surface->SetContentsOpaque(true);
3670 surface_child->SetContentsOpaque(true);
3671 surface_sibling->SetContentsOpaque(true);
3672 surface_child_mask->SetContentsOpaque(true);
3673
jaydasika69c77aa2016-07-14 22:48:483674 gfx::Transform translate;
3675 translate.Translate(20.f, 20.f);
3676
danakje4fa7b72016-07-25 22:00:063677 root->SetBounds(gfx::Size(1000, 1000));
3678 child->SetBounds(gfx::Size(300, 300));
jaydasika10d43fc2016-08-18 04:06:043679 surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:063680 surface->SetBounds(gfx::Size(300, 300));
3681 surface->test_properties()->force_render_surface = true;
3682 surface_child->SetBounds(gfx::Size(300, 300));
3683 surface_child->test_properties()->force_render_surface = true;
3684 surface_sibling->SetBounds(gfx::Size(200, 200));
jaydasika69c77aa2016-07-14 22:48:483685
3686 LayerImpl* surface_ptr = surface.get();
3687 LayerImpl* surface_child_ptr = surface_child.get();
3688 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3689
3690 host_impl.SetViewportSize(root->bounds());
3691
3692 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3693 surface->test_properties()->AddChild(std::move(surface_child));
3694 child->test_properties()->AddChild(std::move(surface));
3695 child->test_properties()->AddChild(std::move(surface_sibling));
3696 root->test_properties()->AddChild(std::move(child));
3697 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3698 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323699 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika69c77aa2016-07-14 22:48:483700 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3701 bool update_lcd_text = false;
3702 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3703
3704 EXPECT_TRANSFORMATION_MATRIX_EQ(
3705 surface_ptr->render_surface()->draw_transform(), translate);
3706 // surface_sibling draws into the root render surface and occludes
3707 // surface_child's contents.
3708 Occlusion actual_occlusion =
3709 surface_child_ptr->render_surface()->occlusion_in_content_space();
3710 Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()),
3711 SimpleEnclosedRegion(gfx::Rect(200, 200)));
3712 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3713
3714 // Mask layer should have the same occlusion.
3715 actual_occlusion =
3716 surface_child_mask_ptr->draw_properties().occlusion_in_content_space;
3717 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3718}
3719
jaydasika2a1718b2016-10-26 22:58:023720TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) {
3721 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika2a1718b2016-10-26 22:58:023722 TestTaskGraphRunner task_graph_runner;
3723 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3724 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223725 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika2a1718b2016-10-26 22:58:023726
3727 std::unique_ptr<LayerImpl> root =
3728 LayerImpl::Create(host_impl.active_tree(), 1);
3729 std::unique_ptr<TextureLayerImpl> child =
3730 TextureLayerImpl::Create(host_impl.active_tree(), 2);
3731
3732 LayerImpl* child_ptr = child.get();
3733
3734 root->SetBounds(gfx::Size(100, 100));
3735 child->SetBounds(gfx::Size(100, 100));
3736 child->SetDrawsContent(true);
3737 gfx::Transform fractional_translate;
3738 fractional_translate.Translate(10.5f, 20.3f);
3739 child->test_properties()->transform = fractional_translate;
3740
3741 host_impl.SetViewportSize(root->bounds());
3742
3743 root->test_properties()->AddChild(std::move(child));
3744 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3745 host_impl.SetVisible(true);
3746 host_impl.InitializeRenderer(compositor_frame_sink.get());
3747 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3748 bool update_lcd_text = false;
3749 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3750
3751 EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate);
3752 fractional_translate.RoundTranslationComponents();
3753 EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(),
3754 fractional_translate);
3755 gfx::RectF layer_bounds_in_screen_space =
3756 MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(),
3757 gfx::RectF(gfx::SizeF(child_ptr->bounds())));
3758 EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f));
3759}
3760
ajumaae0dc2d2015-08-05 21:55:563761TEST_F(LayerTreeHostCommonTest,
3762 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163763 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563764 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323765 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3766 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223767 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483768
danakj60bc3bc2016-04-09 00:24:483769 std::unique_ptr<LayerImpl> root =
3770 LayerImpl::Create(host_impl.active_tree(), 1);
3771 std::unique_ptr<LayerImpl> child =
3772 LayerImpl::Create(host_impl.active_tree(), 2);
3773 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563774 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483775 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563776 LayerImpl::Create(host_impl.active_tree(), 4);
ajumaae0dc2d2015-08-05 21:55:563777
ajumaae0dc2d2015-08-05 21:55:563778 gfx::Transform perspective;
3779 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3780
3781 gfx::Transform rotation;
3782 rotation.RotateAboutYAxis(45.0);
3783
danakje4fa7b72016-07-25 22:00:063784 root->SetBounds(gfx::Size(1000, 1000));
jaydasika10d43fc2016-08-18 04:06:043785 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063786 child->SetPosition(gfx::PointF(10.f, 10.f));
3787 child->SetBounds(gfx::Size(300, 300));
3788 child->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203789 child->test_properties()->sorting_context_id = 1;
jaydasika10d43fc2016-08-18 04:06:043790 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063791 grand_child->SetBounds(gfx::Size(200, 200));
3792 grand_child->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:203793 grand_child->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:063794 occluding_child->SetBounds(gfx::Size(200, 200));
3795 occluding_child->test_properties()->should_flatten_transform = false;
3796
3797 child->SetDrawsContent(true);
3798 grand_child->SetDrawsContent(true);
3799 occluding_child->SetDrawsContent(true);
3800 occluding_child->SetContentsOpaque(true);
ajumaae0dc2d2015-08-05 21:55:563801
3802 host_impl.SetViewportSize(root->bounds());
3803
jaydasika89f7b5a2016-06-22 02:08:393804 child->test_properties()->AddChild(std::move(grand_child));
3805 root->test_properties()->AddChild(std::move(child));
3806 root->test_properties()->AddChild(std::move(occluding_child));
jaydasikabf1875a2016-06-28 03:39:593807 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
sievers71c62dd52015-10-07 01:44:393808 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323809 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika4340ea02016-06-06 19:44:263810 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563811 bool update_lcd_text = false;
3812 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3813
jaydasikafc66cfb2016-06-10 04:34:223814 LayerImpl* grand_child_ptr = host_impl.active_tree()
jaydasikabf1875a2016-06-28 03:39:593815 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:223816 ->test_properties()
3817 ->children[0]
3818 ->test_properties()
3819 ->children[0];
ajumaae0dc2d2015-08-05 21:55:563820
3821 // Though all layers have invertible transforms, matrix multiplication using
3822 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053823 EXPECT_FALSE(
3824 host_impl.active_tree()
3825 ->property_trees()
3826 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
trchendba8b1502016-07-08 09:47:013827 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563828
sunxd71aea3e2016-04-01 23:48:053829 // Since |grand_child| has an uninvertible screen space transform, it is
3830 // skipped so
3831 // that we are not computing its occlusion_in_content_space.
3832 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563833 EXPECT_EQ(
3834 layer_bounds,
3835 grand_child_ptr->draw_properties()
3836 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3837}
3838
3839TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233840 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593841 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173842 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3843 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173844 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173845 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283846
danakje4fa7b72016-07-25 22:00:063847 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323848 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063849 render_surface->SetBounds(gfx::Size(3, 4));
3850 render_surface->test_properties()->force_render_surface = true;
3851 child1->SetPosition(gfx::PointF(5.f, 5.f));
3852 child1->SetBounds(gfx::Size(50, 50));
3853 child1->SetDrawsContent(true);
3854 child2->SetPosition(gfx::PointF(75.f, 75.f));
3855 child2->SetBounds(gfx::Size(50, 50));
3856 child2->SetDrawsContent(true);
3857 child3->SetPosition(gfx::PointF(125.f, 125.f));
3858 child3->SetBounds(gfx::Size(50, 50));
3859 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173860 ExecuteCalculateDrawProperties(root);
3861
3862 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323863
danakj5e6ff6d2015-09-05 04:43:443864 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323865 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323866
3867 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433868 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173869 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323870
3871 // A clipped surface grows its DrawableContentRect to include all drawable
3872 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443873 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173874 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323875
3876 // All layers that draw content into the surface have their visible content
3877 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433878 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3879 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3880 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323881
3882 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323883 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3884 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3885 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323886}
3887
[email protected]989386c2013-07-18 21:37:233888TEST_F(LayerTreeHostCommonTest,
3889 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323890 // Check that clipping does not propagate down surfaces.
jaydasikabf1875a2016-06-28 03:39:593891 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173892 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3893 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3894 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173895 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173896 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283897
danakje4fa7b72016-07-25 22:00:063898 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323899 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063900 render_surface1->SetBounds(gfx::Size(3, 4));
3901 render_surface1->test_properties()->force_render_surface = true;
3902 render_surface2->SetBounds(gfx::Size(7, 13));
3903 render_surface2->test_properties()->force_render_surface = true;
3904 child1->SetPosition(gfx::PointF(5.f, 5.f));
3905 child1->SetBounds(gfx::Size(50, 50));
3906 child1->SetDrawsContent(true);
3907 child2->SetPosition(gfx::PointF(75.f, 75.f));
3908 child2->SetBounds(gfx::Size(50, 50));
3909 child2->SetDrawsContent(true);
3910 child3->SetPosition(gfx::PointF(125.f, 125.f));
3911 child3->SetBounds(gfx::Size(50, 50));
3912 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173913 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323914
3915 ASSERT_TRUE(render_surface1->render_surface());
3916 ASSERT_TRUE(render_surface2->render_surface());
3917
danakj5e6ff6d2015-09-05 04:43:443918 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323919 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323920
3921 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433922 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3923 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3924 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323925
3926 // A clipped surface grows its DrawableContentRect to include all drawable
3927 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443928 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323929 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323930
3931 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3932 // is only implicitly clipped by render_surface1's content rect. So,
3933 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443934 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323935 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323936
jaydasika94bebdd2016-09-16 22:11:183937 // All layers that draw content into render_surface2 think they are unclipped
3938 // by the surface. So, only the viewport clip applies.
danakj64767d902015-06-19 00:10:433939 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183940 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3941 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323942
3943 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323944 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3945 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3946 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323947}
3948
[email protected]989386c2013-07-18 21:37:233949TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463950 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593951 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463952 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3953 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3954 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3955 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
jaydasika27d0f2e2015-10-16 23:52:463956
danakje4fa7b72016-07-25 22:00:063957 root->SetBounds(gfx::Size(100, 100));
3958 render_surface1->SetBounds(gfx::Size(100, 100));
3959 render_surface1->test_properties()->force_render_surface = true;
3960 child1->SetBounds(gfx::Size(500, 500));
3961 child1->SetDrawsContent(true);
3962 child2->SetBounds(gfx::Size(700, 700));
3963 child2->SetDrawsContent(true);
3964 render_surface2->SetBounds(gfx::Size(1000, 1000));
3965 render_surface2->test_properties()->force_render_surface = true;
3966 render_surface2->SetDrawsContent(true);
jaydasika27d0f2e2015-10-16 23:52:463967
3968 child1->SetMasksToBounds(true);
3969 child2->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463970 ExecuteCalculateDrawProperties(root);
jaydasika526eae0a2016-09-02 01:47:593971 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463972 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3973}
3974
3975TEST_F(LayerTreeHostCommonTest,
3976 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593977 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463978 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3979 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3980 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3981 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3982
danakje4fa7b72016-07-25 22:00:063983 root->SetBounds(gfx::Size(100, 100));
3984
3985 clip_parent->SetBounds(gfx::Size(50, 50));
3986 clip_parent->SetMasksToBounds(true);
3987 clip_parent->test_properties()->clip_children =
3988 base::MakeUnique<std::set<LayerImpl*>>();
3989 clip_parent->test_properties()->clip_children->insert(clip_child);
3990
3991 render_surface1->SetBounds(gfx::Size(20, 20));
3992 render_surface1->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463993 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063994 render_surface1->test_properties()->force_render_surface = true;
3995
3996 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika27d0f2e2015-10-16 23:52:463997 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563998 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika27d0f2e2015-10-16 23:52:463999
danakje4fa7b72016-07-25 22:00:064000 render_surface2->SetBounds(gfx::Size(60, 60));
4001 render_surface2->SetDrawsContent(true);
4002 render_surface2->test_properties()->force_render_surface = true;
jaydasika27d0f2e2015-10-16 23:52:464003
4004 ExecuteCalculateDrawProperties(root);
4005 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
4006 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
4007 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
4008}
4009
jaydasika1f5312d2015-10-21 21:34:324010TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
jaydasikabf1875a2016-06-28 03:39:594011 LayerImpl* root = root_layer_for_testing();
jaydasika1f5312d2015-10-21 21:34:324012 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4013 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4014 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
4015 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
4016
danakje4fa7b72016-07-25 22:00:064017 root->SetBounds(gfx::Size(100, 100));
4018
4019 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
4020 clip_parent->SetBounds(gfx::Size(50, 50));
4021 clip_parent->test_properties()->clip_children =
4022 base::MakeUnique<std::set<LayerImpl*>>();
4023 clip_parent->test_properties()->clip_children->insert(clip_child);
4024
4025 render_surface1->SetBounds(gfx::Size(20, 20));
jaydasika1f5312d2015-10-21 21:34:324026 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064027 render_surface1->test_properties()->force_render_surface = true;
4028
4029 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika1f5312d2015-10-21 21:34:324030 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:564031 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika1f5312d2015-10-21 21:34:324032
danakje4fa7b72016-07-25 22:00:064033 render_surface2->SetBounds(gfx::Size(60, 60));
4034 render_surface2->SetDrawsContent(true);
4035 render_surface2->test_properties()->force_render_surface = true;
4036
jaydasika1f5312d2015-10-21 21:34:324037 clip_parent->SetMasksToBounds(true);
4038 render_surface1->SetMasksToBounds(true);
4039
4040 ExecuteCalculateDrawProperties(root);
4041 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
4042}
4043
jaydasika77a4a072015-10-20 21:47:274044TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
4045 // Test that only drawn layers contribute to render surface content rect.
jaydasikabf1875a2016-06-28 03:39:594046 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:274047 LayerImpl* surface = AddChildToRoot<LayerImpl>();
4048 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
4049
danakje4fa7b72016-07-25 22:00:064050 root->SetBounds(gfx::Size(200, 200));
4051 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:274052 surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064053 surface->test_properties()->force_render_surface = true;
4054 test_layer->SetBounds(gfx::Size(150, 150));
jaydasika77a4a072015-10-20 21:47:274055
4056 ExecuteCalculateDrawProperties(root);
4057 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
4058
4059 test_layer->SetDrawsContent(true);
4060 ExecuteCalculateDrawProperties(root);
4061 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
4062}
4063
jaydasika27d0f2e2015-10-16 23:52:464064TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
4065 // Tests visible rects computation when we have unclipped_surface->
4066 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
4067 // of surface_with_unclipped_descendants doesn't propagate to the
4068 // clipped_surface below it.
jaydasikabf1875a2016-06-28 03:39:594069 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:464070 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
4071 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
4072 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
4073 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
4074 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
4075
danakje4fa7b72016-07-25 22:00:064076 root->SetBounds(gfx::Size(100, 100));
jaydasika27d0f2e2015-10-16 23:52:464077
danakje4fa7b72016-07-25 22:00:064078 unclipped_surface->SetBounds(gfx::Size(30, 30));
4079 unclipped_surface->SetDrawsContent(true);
4080 unclipped_surface->test_properties()->force_render_surface = true;
4081
4082 clip_parent->SetBounds(gfx::Size(50, 50));
4083 clip_parent->test_properties()->clip_children =
4084 base::MakeUnique<std::set<LayerImpl*>>();
4085 clip_parent->test_properties()->clip_children->insert(clip_child);
4086
4087 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
4088 unclipped_desc_surface->SetDrawsContent(true);
4089 unclipped_desc_surface->test_properties()->force_render_surface = true;
4090
4091 clip_child->SetBounds(gfx::Size(60, 60));
4092 clip_child->test_properties()->clip_parent = clip_parent;
4093
4094 clipped_surface->SetBounds(gfx::Size(60, 60));
4095 clipped_surface->SetDrawsContent(true);
4096 clipped_surface->test_properties()->force_render_surface = true;
4097
jaydasika27d0f2e2015-10-16 23:52:464098 clip_parent->SetMasksToBounds(true);
4099
4100 ExecuteCalculateDrawProperties(root);
4101 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
4102 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
4103 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
4104}
4105
4106TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
4107 // Tests visible rects computation when we have unclipped_surface->
4108 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
4109 // of root propagate to the clipped_surface.
jaydasikabf1875a2016-06-28 03:39:594110 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:464111 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
4112 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
4113 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
4114 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
4115 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
4116
danakje4fa7b72016-07-25 22:00:064117 root->SetBounds(gfx::Size(10, 10));
jaydasika27d0f2e2015-10-16 23:52:464118
danakje4fa7b72016-07-25 22:00:064119 unclipped_surface->SetBounds(gfx::Size(50, 50));
4120 unclipped_surface->SetDrawsContent(true);
4121 unclipped_surface->test_properties()->force_render_surface = true;
4122
4123 clip_parent->SetBounds(gfx::Size(50, 50));
4124 clip_parent->test_properties()->clip_children =
4125 base::MakeUnique<std::set<LayerImpl*>>();
4126 clip_parent->test_properties()->clip_children->insert(clip_child);
4127
4128 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
4129 unclipped_desc_surface->SetDrawsContent(true);
4130 unclipped_desc_surface->test_properties()->force_render_surface = true;
4131
4132 clip_child->SetBounds(gfx::Size(100, 100));
4133 clip_child->test_properties()->clip_parent = clip_parent;
4134
4135 clipped_surface->SetBounds(gfx::Size(50, 50));
4136 clipped_surface->SetDrawsContent(true);
4137 clipped_surface->test_properties()->force_render_surface = true;
4138
jaydasika27d0f2e2015-10-16 23:52:464139 clip_parent->SetMasksToBounds(true);
4140 unclipped_desc_surface->SetMasksToBounds(true);
4141
4142 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:184143 EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:594144 EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:464145 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
4146}
4147
4148TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:234149 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:324150 // Layers that have non-axis aligned bounds (due to transforms) have an
4151 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:594152 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174153 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4154 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:284155
[email protected]fb661802013-03-25 01:59:324156 gfx::Transform child_rotation;
4157 child_rotation.Rotate(45.0);
[email protected]fb661802013-03-25 01:59:324158
danakje4fa7b72016-07-25 22:00:064159 root->SetBounds(gfx::Size(100, 100));
4160 render_surface->SetBounds(gfx::Size(3, 4));
4161 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:044162 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:064163 child1->SetPosition(gfx::PointF(25.f, 25.f));
4164 child1->SetBounds(gfx::Size(50, 50));
4165 child1->SetDrawsContent(true);
4166 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:174167 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:324168
weiliangc0dece732015-07-27 19:06:174169 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324170
danakj5e6ff6d2015-09-05 04:43:444171 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:324172 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324173
4174 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:434175 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:174176 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324177
4178 // The unclipped surface grows its DrawableContentRect to include all drawable
4179 // regions of the subtree.
4180 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4181 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:264182 gfx::Rect(50 - diagonal_radius,
4183 50 - diagonal_radius,
4184 diagonal_radius * 2,
4185 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444186 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174187 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324188
4189 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434190 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324191 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324192}
4193
[email protected]989386c2013-07-18 21:37:234194TEST_F(LayerTreeHostCommonTest,
4195 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324196 // Layers that have non-axis aligned bounds (due to transforms) have an
4197 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:594198 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174199 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4200 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:284201
[email protected]fb661802013-03-25 01:59:324202 gfx::Transform child_rotation;
4203 child_rotation.Rotate(45.0);
[email protected]a2566412014-06-05 03:14:204204
danakje4fa7b72016-07-25 22:00:064205 root->SetBounds(gfx::Size(50, 50));
[email protected]fb661802013-03-25 01:59:324206 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064207 render_surface->SetBounds(gfx::Size(3, 4));
4208 render_surface->test_properties()->force_render_surface = true;
4209 child1->SetPosition(gfx::PointF(25.f, 25.f));
4210 child1->SetBounds(gfx::Size(50, 50));
4211 child1->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:044212 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:064213 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:174214 ExecuteCalculateDrawProperties(root);
4215
4216 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324217
4218 // The clipped surface clamps the DrawableContentRect that encloses the
4219 // rotated layer.
4220 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264221 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4222 50 - diagonal_radius,
4223 diagonal_radius * 2,
4224 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444225 gfx::RectF expected_surface_drawable_content(
4226 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324227 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174228 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324229
4230 // On the clipped surface, only a quarter of the child1 is visible, but when
4231 // rotating it back to child1's content space, the actual enclosing rect ends
4232 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:334233 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324234
4235 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324236 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324237}
4238
[email protected]989386c2013-07-18 21:37:234239TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594240 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174241 FakePictureLayerImpl* render_surface1 =
4242 AddChildToRoot<FakePictureLayerImpl>();
weiliangc0dece732015-07-27 19:06:174243 FakePictureLayerImpl* render_surface2 =
4244 AddChild<FakePictureLayerImpl>(render_surface1);
weiliangc0dece732015-07-27 19:06:174245 FakePictureLayerImpl* child1 =
4246 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174247 FakePictureLayerImpl* child2 =
4248 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174249 FakePictureLayerImpl* child3 =
4250 AddChild<FakePictureLayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:284251
danakje4fa7b72016-07-25 22:00:064252 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324253 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064254 render_surface1->SetBounds(gfx::Size(3, 4));
4255 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
4256 render_surface1->SetDrawsContent(true);
4257 render_surface1->test_properties()->force_render_surface = true;
4258 render_surface2->SetBounds(gfx::Size(7, 13));
4259 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
4260 render_surface2->SetDrawsContent(true);
4261 render_surface2->test_properties()->force_render_surface = true;
4262 child1->SetBounds(gfx::Size(50, 50));
4263 child1->SetPosition(gfx::PointF(5.f, 5.f));
4264 child1->SetDrawsContent(true);
4265 child2->SetBounds(gfx::Size(50, 50));
4266 child2->SetPosition(gfx::PointF(75.f, 75.f));
4267 child2->SetDrawsContent(true);
4268 child3->SetBounds(gfx::Size(50, 50));
4269 child3->SetPosition(gfx::PointF(125.f, 125.f));
4270 child3->SetDrawsContent(true);
4271 float device_scale_factor = 2.f;
weiliangc0dece732015-07-27 19:06:174272 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324273
4274 ASSERT_TRUE(render_surface1->render_surface());
4275 ASSERT_TRUE(render_surface2->render_surface());
4276
4277 // drawable_content_rects for all layers and surfaces are scaled by
4278 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444279 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324280 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444281 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324282 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324283
4284 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4285 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444286 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324287 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324288
hush6b614212014-12-04 22:37:324289 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4290 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4291 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324292
4293 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434294 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324295
sohan.jyotie3bd6192014-10-13 07:13:594296 // All layer visible content rects are not expressed in content space of each
4297 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434298 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4299 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4300 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:184301 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect());
4302 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324303}
4304
[email protected]989386c2013-07-18 21:37:234305TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324306 // Verify the behavior of back-face culling when there are no preserve-3d
4307 // layers. Note that 3d transforms still apply in this case, but they are
4308 // "flattened" to each parent layer according to current W3C spec.
4309
danakje4fa7b72016-07-25 22:00:064310 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324311 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4312 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4313 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4314 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4315 LayerImpl* front_facing_child_of_front_facing_surface =
4316 AddChild<LayerImpl>(front_facing_surface);
4317 LayerImpl* back_facing_child_of_front_facing_surface =
4318 AddChild<LayerImpl>(front_facing_surface);
4319 LayerImpl* front_facing_child_of_back_facing_surface =
4320 AddChild<LayerImpl>(back_facing_surface);
4321 LayerImpl* back_facing_child_of_back_facing_surface =
4322 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284323
[email protected]fb661802013-03-25 01:59:324324 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324325 front_facing_child->test_properties()->double_sided = false;
4326 back_facing_child->test_properties()->double_sided = false;
4327 front_facing_surface->test_properties()->double_sided = false;
4328 back_facing_surface->test_properties()->double_sided = false;
4329 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4330 false;
4331 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4332 false;
4333 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4334 false;
4335 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4336 false;
4337
4338 // Everything draws content.
4339 front_facing_child->SetDrawsContent(true);
4340 back_facing_child->SetDrawsContent(true);
4341 front_facing_surface->SetDrawsContent(true);
4342 back_facing_surface->SetDrawsContent(true);
4343 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4344 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4345 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4346 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324347
4348 gfx::Transform backface_matrix;
4349 backface_matrix.Translate(50.0, 50.0);
4350 backface_matrix.RotateAboutYAxis(180.0);
4351 backface_matrix.Translate(-50.0, -50.0);
4352
danakje4fa7b72016-07-25 22:00:064353 root->SetBounds(gfx::Size(100, 100));
4354 front_facing_child->SetBounds(gfx::Size(100, 100));
4355 back_facing_child->SetBounds(gfx::Size(100, 100));
4356 front_facing_surface->SetBounds(gfx::Size(100, 100));
4357 back_facing_surface->SetBounds(gfx::Size(100, 100));
4358 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4359 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4360 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4361 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324362
danakje4fa7b72016-07-25 22:00:064363 front_facing_surface->test_properties()->force_render_surface = true;
4364 back_facing_surface->test_properties()->force_render_surface = true;
[email protected]fb661802013-03-25 01:59:324365
jaydasika10d43fc2016-08-18 04:06:044366 back_facing_child->test_properties()->transform = backface_matrix;
4367 back_facing_surface->test_properties()->transform = backface_matrix;
4368 back_facing_child_of_front_facing_surface->test_properties()->transform =
4369 backface_matrix;
4370 back_facing_child_of_back_facing_surface->test_properties()->transform =
4371 backface_matrix;
danakje4fa7b72016-07-25 22:00:064372
4373 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
4374 // spec, these layers should blindly use their own local transforms to
4375 // determine back-face culling.
jaydasika6ed869662016-09-21 14:29:594376 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324377
4378 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094379 EXPECT_FALSE(front_facing_child->has_render_surface());
4380 EXPECT_FALSE(back_facing_child->has_render_surface());
4381 EXPECT_TRUE(front_facing_surface->has_render_surface());
4382 EXPECT_TRUE(back_facing_surface->has_render_surface());
4383 EXPECT_FALSE(
4384 front_facing_child_of_front_facing_surface->has_render_surface());
4385 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4386 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4387 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324388
trchen75204782016-11-03 01:05:424389 EXPECT_EQ(3u, update_layer_list_impl()->size());
ajuma4711f4b12016-05-16 18:48:324390 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4391 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4392 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534393 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324394}
4395
[email protected]989386c2013-07-18 21:37:234396TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324397 // Verify the behavior of back-face culling when preserves-3d transform style
4398 // is used.
4399
danakje4fa7b72016-07-25 22:00:064400 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:264401 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4402 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4403 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4404 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4405 LayerImpl* front_facing_child_of_front_facing_surface =
4406 AddChild<LayerImpl>(front_facing_surface);
4407 LayerImpl* back_facing_child_of_front_facing_surface =
4408 AddChild<LayerImpl>(front_facing_surface);
4409 LayerImpl* front_facing_child_of_back_facing_surface =
4410 AddChild<LayerImpl>(back_facing_surface);
4411 LayerImpl* back_facing_child_of_back_facing_surface =
4412 AddChild<LayerImpl>(back_facing_surface);
4413 // Opacity will not force creation of render surfaces in this case because of
4414 // the preserve-3d transform style. Instead, an example of when a surface
wangxianzhu932d7f12016-09-30 05:47:004415 // would be created with preserve-3d is when there is a mask layer.
4416 LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface);
4417 LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284418
[email protected]fb661802013-03-25 01:59:324419 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364420 front_facing_child->test_properties()->double_sided = false;
4421 back_facing_child->test_properties()->double_sided = false;
4422 front_facing_surface->test_properties()->double_sided = false;
4423 back_facing_surface->test_properties()->double_sided = false;
4424 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4425 false;
4426 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4427 false;
4428 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4429 false;
4430 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4431 false;
[email protected]fb661802013-03-25 01:59:324432
weiliangcc154ce22015-12-09 03:39:264433 // Everything draws content.
4434 front_facing_child->SetDrawsContent(true);
4435 back_facing_child->SetDrawsContent(true);
4436 front_facing_surface->SetDrawsContent(true);
4437 back_facing_surface->SetDrawsContent(true);
4438 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4439 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4440 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4441 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
wangxianzhu932d7f12016-09-30 05:47:004442 dummy_mask_layer1->SetDrawsContent(true);
4443 dummy_mask_layer2->SetDrawsContent(true);
weiliangcc154ce22015-12-09 03:39:264444
[email protected]fb661802013-03-25 01:59:324445 gfx::Transform backface_matrix;
4446 backface_matrix.Translate(50.0, 50.0);
4447 backface_matrix.RotateAboutYAxis(180.0);
4448 backface_matrix.Translate(-50.0, -50.0);
4449
danakje4fa7b72016-07-25 22:00:064450 root->SetBounds(gfx::Size(100, 100));
4451 front_facing_child->SetBounds(gfx::Size(100, 100));
4452 back_facing_child->SetBounds(gfx::Size(100, 100));
4453 front_facing_surface->SetBounds(gfx::Size(100, 100));
4454 back_facing_surface->SetBounds(gfx::Size(100, 100));
4455 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4456 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4457 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4458 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4459
jaydasika10d43fc2016-08-18 04:06:044460 back_facing_child->test_properties()->transform = backface_matrix;
4461 back_facing_surface->test_properties()->transform = backface_matrix;
4462 back_facing_child_of_front_facing_surface->test_properties()->transform =
4463 backface_matrix;
4464 back_facing_child_of_back_facing_surface->test_properties()->transform =
4465 backface_matrix;
danakje4fa7b72016-07-25 22:00:064466
[email protected]fb661802013-03-25 01:59:324467 // Each surface creates its own new 3d rendering context (as defined by W3C
4468 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4469 // rendering context should use the transform with respect to that context.
4470 // This 3d rendering context occurs when (a) parent's transform style is flat
4471 // and (b) the layer's transform style is preserve-3d.
danakje4fa7b72016-07-25 22:00:064472 front_facing_surface->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:204473 front_facing_surface->test_properties()->sorting_context_id = 1;
danakje4fa7b72016-07-25 22:00:064474 back_facing_surface->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:204475 back_facing_surface->test_properties()->sorting_context_id = 1;
4476 front_facing_child_of_front_facing_surface->test_properties()
4477 ->sorting_context_id = 1;
4478 back_facing_child_of_front_facing_surface->test_properties()
4479 ->sorting_context_id = 1;
4480 front_facing_child_of_back_facing_surface->test_properties()
4481 ->sorting_context_id = 1;
4482 back_facing_child_of_back_facing_surface->test_properties()
4483 ->sorting_context_id = 1;
[email protected]fb661802013-03-25 01:59:324484
jaydasika6ed869662016-09-21 14:29:594485 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324486
awoloszyne83f28c2014-12-22 15:40:004487 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094488 EXPECT_FALSE(front_facing_child->has_render_surface());
4489 EXPECT_FALSE(back_facing_child->has_render_surface());
4490 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094491 // We expect that a has_render_surface was created but not used.
4492 EXPECT_TRUE(back_facing_surface->has_render_surface());
4493 EXPECT_FALSE(
4494 front_facing_child_of_front_facing_surface->has_render_surface());
4495 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4496 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4497 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324498
weiliangcc154ce22015-12-09 03:39:264499 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324500
weiliangcc154ce22015-12-09 03:39:264501 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4502 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4503 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534504 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324505}
4506
[email protected]989386c2013-07-18 21:37:234507TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324508 // Verify that layers are appropriately culled when their back face is showing
4509 // and they are not double sided, while animations are going on.
4510 //
ajuma4711f4b12016-05-16 18:48:324511 // Even layers that are animating get culled if their back face is showing and
4512 // they are not double sided.
danakje4fa7b72016-07-25 22:00:064513 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324514 LayerImpl* child = AddChildToRoot<LayerImpl>();
4515 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4516 LayerImpl* child_of_animating_surface =
4517 AddChild<LayerImpl>(animating_surface);
4518 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4519 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284520
[email protected]fb661802013-03-25 01:59:324521 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324522 child->test_properties()->double_sided = false;
4523 child2->test_properties()->double_sided = false;
4524 animating_surface->test_properties()->double_sided = false;
4525 child_of_animating_surface->test_properties()->double_sided = false;
4526 animating_child->test_properties()->double_sided = false;
4527
4528 // Everything draws content.
4529 child->SetDrawsContent(true);
4530 child2->SetDrawsContent(true);
4531 animating_surface->SetDrawsContent(true);
4532 child_of_animating_surface->SetDrawsContent(true);
4533 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324534
4535 gfx::Transform backface_matrix;
4536 backface_matrix.Translate(50.0, 50.0);
4537 backface_matrix.RotateAboutYAxis(180.0);
4538 backface_matrix.Translate(-50.0, -50.0);
4539
vollickef2ae922016-06-29 17:54:274540 SetElementIdsForTesting();
4541
loyso9556c732016-03-11 07:54:584542 // Animate the transform on the render surface.
vollickef2ae922016-06-29 17:54:274543 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
4544 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584545 // This is just an animating layer, not a surface.
vollickef2ae922016-06-29 17:54:274546 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
4547 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324548
danakje4fa7b72016-07-25 22:00:064549 root->SetBounds(gfx::Size(100, 100));
4550 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044551 child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064552 animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044553 animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064554 animating_surface->test_properties()->force_render_surface = true;
4555 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044556 child_of_animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064557 animating_child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044558 animating_child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064559 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324560
jaydasika6ed869662016-09-21 14:29:594561 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324562
ennec1332992015-08-24 19:45:094563 EXPECT_FALSE(child->has_render_surface());
4564 EXPECT_TRUE(animating_surface->has_render_surface());
4565 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4566 EXPECT_FALSE(animating_child->has_render_surface());
4567 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324568
ajuma4711f4b12016-05-16 18:48:324569 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534570
ajuma4711f4b12016-05-16 18:48:324571 // The back facing layers are culled from the layer list, and have an empty
4572 // visible rect.
4573 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4574 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4575 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4576 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4577 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324578
ajuma4711f4b12016-05-16 18:48:324579 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324580}
4581
[email protected]989386c2013-07-18 21:37:234582TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324583 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4584 // Verify the behavior of back-face culling for a render surface that is
4585 // created when it flattens its subtree, and its parent has preserves-3d.
4586
danakje4fa7b72016-07-25 22:00:064587 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324588 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4589 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4590 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4591 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284592
[email protected]fb661802013-03-25 01:59:324593 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324594 front_facing_surface->test_properties()->double_sided = false;
4595 back_facing_surface->test_properties()->double_sided = false;
4596
4597 // Everything draws content.
4598 front_facing_surface->SetDrawsContent(true);
4599 back_facing_surface->SetDrawsContent(true);
4600 child1->SetDrawsContent(true);
4601 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324602
4603 gfx::Transform backface_matrix;
4604 backface_matrix.Translate(50.0, 50.0);
4605 backface_matrix.RotateAboutYAxis(180.0);
4606 backface_matrix.Translate(-50.0, -50.0);
4607
danakje4fa7b72016-07-25 22:00:064608 root->SetBounds(gfx::Size(100, 100));
4609 front_facing_surface->SetBounds(gfx::Size(100, 100));
4610 front_facing_surface->test_properties()->force_render_surface = true;
4611 back_facing_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044612 back_facing_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064613 back_facing_surface->test_properties()->force_render_surface = true;
4614 child1->SetBounds(gfx::Size(100, 100));
4615 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324616
wkormanf09921d2017-01-07 01:01:204617 front_facing_surface->test_properties()->sorting_context_id = 1;
4618 back_facing_surface->test_properties()->sorting_context_id = 1;
[email protected]56fffdd2014-02-11 19:50:574619
jaydasika6ed869662016-09-21 14:29:594620 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324621
awoloszyne83f28c2014-12-22 15:40:004622 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094623 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004624
4625 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094626 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094627 EXPECT_FALSE(child1->has_render_surface());
4628 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324629
ajuma4711f4b12016-05-16 18:48:324630 EXPECT_EQ(2u, update_layer_list_impl()->size());
4631 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4632 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324633}
4634
enne637715732015-07-07 02:05:264635TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324636 // Verify draw and screen space transforms of layers not in a surface.
danakje4fa7b72016-07-25 22:00:064637 LayerImpl* root = root_layer_for_testing();
4638 root->SetBounds(gfx::Size(100, 100));
4639 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144640
enne637715732015-07-07 02:05:264641 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064642 child->SetPosition(gfx::PointF(2.f, 2.f));
4643 child->SetBounds(gfx::Size(10, 10));
jaydasika8640f9f2015-11-10 01:34:364644 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144645
jaydasika8640f9f2015-11-10 01:34:364646 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064647 child2->SetPosition(gfx::PointF(2.f, 2.f));
4648 child2->SetBounds(gfx::Size(5, 5));
jaydasika8640f9f2015-11-10 01:34:364649 child2->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284650
[email protected]fb661802013-03-25 01:59:324651 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264652 gfx::Size viewport_size(100, 100);
danakje4fa7b72016-07-25 22:00:064653 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144654
danakj59931942016-07-26 22:11:294655 EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale());
4656 EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale());
4657 EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale());
[email protected]518ee582012-10-24 18:29:444658
enne637715732015-07-07 02:05:264659 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144660
danakje4fa7b72016-07-25 22:00:064661 // Verify root transforms
4662 gfx::Transform expected_root_transform;
4663 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4664 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4665 root->ScreenSpaceTransform());
4666 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4667 root->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144668
danakje4fa7b72016-07-25 22:00:064669 // Verify results of transformed root rects
4670 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
[email protected]94f206c12012-08-25 00:09:144671
danakje4fa7b72016-07-25 22:00:064672 gfx::RectF root_draw_rect =
4673 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4674 gfx::RectF root_screen_space_rect =
4675 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
[email protected]94f206c12012-08-25 00:09:144676
danakje4fa7b72016-07-25 22:00:064677 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4678 expected_root_draw_rect.Scale(device_scale_factor);
4679 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4680 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144681
jaydasika8640f9f2015-11-10 01:34:364682 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324683 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594684 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4685 expected_child_transform.Translate(child->position().x(),
4686 child->position().y());
[email protected]fb661802013-03-25 01:59:324687 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444688 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324689 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104690 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324691 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444692 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324693 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104694 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144695
jaydasika8640f9f2015-11-10 01:34:364696 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324697 // match.
danakjddaec912015-09-25 19:38:404698 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144699
[email protected]fb661802013-03-25 01:59:324700 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444701 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144702 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104703 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144704
jaydasika8640f9f2015-11-10 01:34:364705 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444706 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364707 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104708 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454709
danakjddaec912015-09-25 19:38:404710 gfx::RectF expected_child_draw_rect(child->position(),
4711 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324712 expected_child_draw_rect.Scale(device_scale_factor);
4713 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4714 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364715 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4716 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144717}
4718
enne637715732015-07-07 02:05:264719TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324720 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324721 gfx::Transform perspective_matrix;
4722 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094723
[email protected]fb661802013-03-25 01:59:324724 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054725 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094726
jaydasikabf1875a2016-06-28 03:39:594727 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064728 root->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094729
4730 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064731 page_scale->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094732
4733 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
danakje4fa7b72016-07-25 22:00:064734 parent->SetBounds(gfx::Size(100, 100));
jaydasika8640f9f2015-11-10 01:34:364735 parent->SetDrawsContent(true);
[email protected]9781afa2013-07-17 23:15:324736
enne637715732015-07-07 02:05:264737 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064738 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4739 perspective_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044740 perspective_surface->test_properties()->transform =
4741 perspective_matrix * scale_small_matrix;
enne637715732015-07-07 02:05:264742 perspective_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064743 perspective_surface->test_properties()->force_render_surface = true;
[email protected]1b30e8e2012-12-21 02:59:094744
enne637715732015-07-07 02:05:264745 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064746 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4747 scale_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044748 scale_surface->test_properties()->transform = scale_small_matrix;
enne637715732015-07-07 02:05:264749 scale_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064750 scale_surface->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:284751
[email protected]fb661802013-03-25 01:59:324752 float device_scale_factor = 2.5f;
4753 float page_scale_factor = 3.f;
sunxdc5d4fb42016-05-27 04:40:094754 root->layer_tree_impl()->SetViewportLayersFromIds(
4755 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4756 Layer::INVALID_ID);
jaydasika4340ea02016-06-06 19:44:264757 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094758 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264759 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackra283bed2016-10-31 14:49:424760 root, nullptr, nullptr);
[email protected]1b30e8e2012-12-21 02:59:094761
danakj59931942016-07-26 22:11:294762 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4763 parent->GetIdealContentsScale());
4764 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4765 perspective_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594766 // Ideal scale is the max 2d scale component of the combined transform up to
4767 // the nearest render target. Here this includes the layer transform as well
4768 // as the device and page scale factors.
4769 gfx::Transform transform = scale_small_matrix;
4770 transform.Scale(device_scale_factor * page_scale_factor,
4771 device_scale_factor * page_scale_factor);
4772 gfx::Vector2dF scales =
4773 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4774 float max_2d_scale = std::max(scales.x(), scales.y());
danakj59931942016-07-26 22:11:294775 EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594776
4777 // The ideal scale will draw 1:1 with its render target space along
4778 // the larger-scale axis.
4779 gfx::Vector2dF target_space_transform_scales =
4780 MathUtil::ComputeTransform2dScaleComponents(
4781 scale_surface->draw_properties().target_space_transform, 0.f);
4782 EXPECT_FLOAT_EQ(max_2d_scale,
4783 std::max(target_space_transform_scales.x(),
4784 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094785
enne637715732015-07-07 02:05:264786 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094787
[email protected]fb661802013-03-25 01:59:324788 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594789 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4790 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324791 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444792 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094793
[email protected]fb661802013-03-25 01:59:324794 // The scale for the perspective surface is not known, so it is rendered 1:1
4795 // with the screen, and then scaled during drawing.
4796 gfx::Transform expected_perspective_surface_draw_transform;
4797 expected_perspective_surface_draw_transform.Translate(
4798 device_scale_factor * page_scale_factor *
4799 perspective_surface->position().x(),
4800 device_scale_factor * page_scale_factor *
4801 perspective_surface->position().y());
4802 expected_perspective_surface_draw_transform.PreconcatTransform(
4803 perspective_matrix);
4804 expected_perspective_surface_draw_transform.PreconcatTransform(
4805 scale_small_matrix);
4806 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594807 expected_perspective_surface_layer_draw_transform.Scale(
4808 device_scale_factor * page_scale_factor,
4809 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324810 EXPECT_TRANSFORMATION_MATRIX_EQ(
4811 expected_perspective_surface_draw_transform,
4812 perspective_surface->render_surface()->draw_transform());
4813 EXPECT_TRANSFORMATION_MATRIX_EQ(
4814 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444815 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094816}
4817
enne637715732015-07-07 02:05:264818TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294819 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264820 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294821 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4822
4823 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264824 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294825 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4826
jaydasikabf1875a2016-06-28 03:39:594827 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294828 root->SetBounds(gfx::Size(100, 100));
4829
enne637715732015-07-07 02:05:264830 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064831 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044832 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364833 parent->SetDrawsContent(true);
[email protected]35a99a12013-05-09 23:52:294834
enne637715732015-07-07 02:05:264835 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064836 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4837 child_scale->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044838 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364839 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284840
[email protected]fb661802013-03-25 01:59:324841 float device_scale_factor = 2.5f;
4842 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214843
[email protected]989386c2013-07-18 21:37:234844 {
enne637715732015-07-07 02:05:264845 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackra283bed2016-10-31 14:49:424846 root, nullptr, nullptr);
[email protected]11ec92972012-11-10 03:06:214847
sohan.jyotie3bd6192014-10-13 07:13:594848 // The ideal scale is able to go below 1.
4849 float expected_ideal_scale =
4850 device_scale_factor * page_scale_factor * initial_parent_scale;
4851 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294852 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale());
[email protected]11ec92972012-11-10 03:06:214853
sohan.jyotie3bd6192014-10-13 07:13:594854 expected_ideal_scale = device_scale_factor * page_scale_factor *
4855 initial_parent_scale * initial_child_scale;
4856 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294857 EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale());
[email protected]989386c2013-07-18 21:37:234858 }
[email protected]11ec92972012-11-10 03:06:214859}
4860
enne637715732015-07-07 02:05:264861TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324862 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264863 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324864 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264865
[email protected]fb661802013-03-25 01:59:324866 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264867 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324868 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264869
jaydasikabf1875a2016-06-28 03:39:594870 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294871 root->SetBounds(gfx::Size(100, 100));
4872
enne637715732015-07-07 02:05:264873 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064874 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044875 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364876 parent->SetDrawsContent(true);
[email protected]6a9cff92012-11-08 11:53:264877
enne637715732015-07-07 02:05:264878 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064879 child_scale->SetBounds(gfx::Size(10, 10));
4880 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
jaydasika10d43fc2016-08-18 04:06:044881 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364882 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284883
danakje4fa7b72016-07-25 22:00:064884 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264885
danakj59931942016-07-26 22:11:294886 EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale());
danakje4fa7b72016-07-25 22:00:064887 // Animating layers compute ideal scale in the same way as when
4888 // they are static.
danakj59931942016-07-26 22:11:294889 EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale,
4890 child_scale->GetIdealContentsScale());
[email protected]6a9cff92012-11-08 11:53:264891}
4892
[email protected]989386c2013-07-18 21:37:234893TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594894 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064895 parent->SetBounds(gfx::Size(30, 30));
enneea850232015-07-27 16:43:124896 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064897 parent->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:204898 parent->test_properties()->sorting_context_id = 1;
[email protected]94f206c12012-08-25 00:09:144899
enneea850232015-07-27 16:43:124900 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064901 child->SetBounds(gfx::Size(10, 10));
4902 child->SetPosition(gfx::PointF(2.f, 2.f));
enneea850232015-07-27 16:43:124903 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064904 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:144905
[email protected]fb661802013-03-25 01:59:324906 // This layer should end up in the same surface as child, with the same draw
4907 // and screen space transforms.
enneea850232015-07-27 16:43:124908 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:064909 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
enneea850232015-07-27 16:43:124910 duplicate_child_non_owner->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144911
[email protected]fb661802013-03-25 01:59:324912 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124913 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144914
[email protected]fb661802013-03-25 01:59:324915 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004916 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124917 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144918
[email protected]fb661802013-03-25 01:59:324919 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594920 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324921 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104922 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324923 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444924 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144925
[email protected]fb661802013-03-25 01:59:324926 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594927 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324928 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444929 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144930
[email protected]fb661802013-03-25 01:59:324931 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594932 expected_screen_space_transform.Scale(device_scale_factor,
4933 device_scale_factor);
4934 expected_screen_space_transform.Translate(child->position().x(),
4935 child->position().y());
[email protected]fb661802013-03-25 01:59:324936 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104937 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144938
[email protected]fb661802013-03-25 01:59:324939 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444940 child->DrawTransform();
trchendba8b1502016-07-08 09:47:014941 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform,
ajumad9432e32015-11-30 19:43:444942 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324943 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104944 child->ScreenSpaceTransform(),
4945 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324946 EXPECT_EQ(child->drawable_content_rect(),
4947 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144948 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144949
[email protected]fb661802013-03-25 01:59:324950 gfx::Transform expected_render_surface_draw_transform;
4951 expected_render_surface_draw_transform.Translate(
4952 device_scale_factor * child->position().x(),
4953 device_scale_factor * child->position().y());
4954 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4955 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144956
[email protected]fb661802013-03-25 01:59:324957 gfx::Transform expected_surface_draw_transform;
4958 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4959 device_scale_factor * 2.f);
4960 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4961 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144962
[email protected]fb661802013-03-25 01:59:324963 gfx::Transform expected_surface_screen_space_transform;
4964 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4965 device_scale_factor * 2.f);
4966 EXPECT_TRANSFORMATION_MATRIX_EQ(
4967 expected_surface_screen_space_transform,
4968 child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474969}
4970
[email protected]989386c2013-07-18 21:37:234971TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324972 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
jaydasikabf1875a2016-06-28 03:39:594973 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064974 parent->SetBounds(gfx::Size(33, 31));
enneea850232015-07-27 16:43:124975 parent->SetDrawsContent(true);
[email protected]904e9132012-11-01 00:12:474976
enneea850232015-07-27 16:43:124977 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064978 child->SetBounds(gfx::Size(13, 11));
enneea850232015-07-27 16:43:124979 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064980 child->test_properties()->force_render_surface = true;
[email protected]904e9132012-11-01 00:12:474981
[email protected]873639e2013-07-24 19:56:314982 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124983 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474984
[email protected]fb661802013-03-25 01:59:324985 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004986 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124987 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474988
danakjf78fb272016-07-26 19:06:154989 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324990 child->render_surface()->draw_transform());
danakjf78fb272016-07-26 19:06:154991 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324992 child->render_surface()->draw_transform());
4993 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:154994 gfx::Transform(), child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144995}
4996
jaydasikadb41a582016-03-28 20:48:214997TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314998 scoped_refptr<Layer> root = Layer::Create();
4999 scoped_refptr<Layer> child = Layer::Create();
5000 scoped_refptr<Layer> grand_child = Layer::Create();
5001 scoped_refptr<Layer> mask_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145002
[email protected]fb661802013-03-25 01:59:325003 child->AddChild(grand_child.get());
5004 child->SetMaskLayer(mask_layer.get());
5005 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145006
ennea7b43c32015-06-18 20:01:335007 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285008
[email protected]fb661802013-03-25 01:59:325009 int nonexistent_id = -1;
khushalsagarb69ba9452017-01-27 22:20:075010 EXPECT_EQ(root.get(), host()->LayerById(root->id()));
5011 EXPECT_EQ(child.get(), host()->LayerById(child->id()));
5012 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
5013 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
5014 EXPECT_FALSE(host()->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145015}
5016
[email protected]989386c2013-07-18 21:37:235017TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
jaydasikabf1875a2016-06-28 03:39:595018 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:325019 LayerImpl* child = AddChild<LayerImpl>(root);
5020 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]498ec6e0e2012-11-30 18:24:575021
danakje4fa7b72016-07-25 22:00:065022 root->SetBounds(gfx::Size(100, 100));
5023 child->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:185024 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:065025 grand_child->SetBounds(gfx::Size(10, 10));
5026 grand_child->SetDrawsContent(true);
ajuma4711f4b12016-05-16 18:48:325027 ExecuteCalculateDrawProperties(root);
ennec1332992015-08-24 19:45:095028 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575029}
5030
[email protected]989386c2013-07-18 21:37:235031TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:165032 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565033 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:015034 FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider,
pimanc44437a22016-10-29 00:09:225035 &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:165036 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:485037 std::unique_ptr<LayerImpl> root =
5038 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065039 root->SetBounds(gfx::Size(100, 100));
[email protected]f90fc412013-03-30 20:13:165040 root->SetDrawsContent(true);
5041
danakj60bc3bc2016-04-09 00:24:485042 std::unique_ptr<LayerImpl> child =
5043 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065044 child->SetBounds(gfx::Size(50, 50));
[email protected]f90fc412013-03-30 20:13:165045 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:185046 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:165047
jaydasika9cb21c772016-05-10 22:37:085048 const int child_id = child->id();
jaydasika89f7b5a2016-06-22 02:08:395049 root->test_properties()->AddChild(std::move(child));
jaydasika9cb21c772016-05-10 22:37:085050 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595051 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
jaydasika4340ea02016-06-06 19:44:265052 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:275053
[email protected]f90fc412013-03-30 20:13:165054 // Add opacity animation.
loyso9556c732016-03-11 07:54:585055 scoped_refptr<AnimationTimeline> timeline =
5056 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5057 host_impl.animation_host()->AddAnimationTimeline(timeline);
vollickef2ae922016-06-29 17:54:275058 host_impl.pending_tree()->SetElementIdsForTesting();
loyso968163c92016-01-04 23:18:485059
vollickef2ae922016-06-29 17:54:275060 ElementId child_element_id =
5061 host_impl.pending_tree()->LayerById(child_id)->element_id();
5062
5063 AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0,
5064 0.0f, 1.0f, false);
[email protected]f90fc412013-03-30 20:13:165065
[email protected]c0ae06c12013-06-24 18:32:195066 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535067 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385068 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535069 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575070 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:165071
5072 // We should have one render surface and two layers. The child
5073 // layer should be included even though it is transparent.
5074 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055075 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:075076
5077 // If the root itself is hidden, the child should not be drawn even if it has
5078 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:185079 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:055080 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:075081 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:075082 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:385083 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:075084 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575085 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:075086
jaydasika0c2fd472016-03-24 01:26:055087 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:065088 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:055089 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075090 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:015091 EXPECT_FALSE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:405092
5093 // A layer should be drawn and it should contribute to drawn surface when
5094 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:185095 root_layer->test_properties()->opacity = 1.0f;
5096 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:055097 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:405098 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:405099 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:385100 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:405101 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575102 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:405103
jaydasika0c2fd472016-03-24 01:26:055104 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
5105 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:405106 node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:015107 EXPECT_TRUE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:405108 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:065109
5110 // But if the opacity of the layer remains 0 after activation, it should not
5111 // be drawn.
5112 host_impl.ActivateSyncTree();
danakj0da42ca62016-07-01 19:42:335113 LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id());
jaydasika8185d302016-04-14 15:20:065114 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
5115
5116 EffectTree& active_effect_tree =
5117 host_impl.active_tree()->property_trees()->effect_tree;
5118 EXPECT_TRUE(active_effect_tree.needs_update());
5119
5120 ExecuteCalculateDrawProperties(active_root);
5121
5122 node = active_effect_tree.Node(active_child->effect_tree_index());
trchendba8b1502016-07-08 09:47:015123 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:065124 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
5125 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:165126}
5127
danakj3f76ace2014-11-18 16:56:005128using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:265129class LCDTextTest : public LayerTreeHostCommonTestBase,
5130 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365131 public:
5132 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:225133 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
5134 host_impl_(LCDTextTestLayerTreeSettings(),
5135 &task_runner_provider_,
danakj59931942016-07-26 22:11:295136 &task_graph_runner_) {}
enneaf5bda32015-02-19 01:27:365137
loyso968163c92016-01-04 23:18:485138 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
5139
[email protected]fb661802013-03-25 01:59:325140 protected:
sunxd5a7a4032016-06-01 18:49:225141 LayerTreeSettings LCDTextTestLayerTreeSettings() {
danakj59931942016-07-26 22:11:295142 LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings();
sunxd5a7a4032016-06-01 18:49:225143
5144 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
5145 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
5146 settings.can_use_lcd_text = can_use_lcd_text_;
5147 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
5148 return settings;
5149 }
5150
dcheng93a52eb2014-12-23 02:14:235151 void SetUp() override {
loyso9556c732016-03-11 07:54:585152 timeline_ =
5153 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5154 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:485155
danakj60bc3bc2016-04-09 00:24:485156 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:365157 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:485158 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:365159 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:485160 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:365161 LayerImpl::Create(host_impl_.active_tree(), 3);
5162
5163 // Stash raw pointers to look at later.
5164 root_ = root_ptr.get();
5165 child_ = child_ptr.get();
5166 grand_child_ = grand_child_ptr.get();
5167
jaydasika89f7b5a2016-06-22 02:08:395168 child_->test_properties()->AddChild(std::move(grand_child_ptr));
5169 root_->test_properties()->AddChild(std::move(child_ptr));
jaydasikabf1875a2016-06-28 03:39:595170 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595171
vollickef2ae922016-06-29 17:54:275172 host_impl_.active_tree()->SetElementIdsForTesting();
5173
fmalita51b5e202014-11-18 20:11:505174 root_->SetContentsOpaque(true);
5175 child_->SetContentsOpaque(true);
5176 grand_child_->SetContentsOpaque(true);
5177
jaydasika3f930c12015-06-30 15:18:255178 root_->SetDrawsContent(true);
5179 child_->SetDrawsContent(true);
5180 grand_child_->SetDrawsContent(true);
5181
danakje4fa7b72016-07-25 22:00:065182 root_->SetBounds(gfx::Size(1, 1));
5183 child_->SetBounds(gfx::Size(1, 1));
5184 grand_child_->SetBounds(gfx::Size(1, 1));
5185
5186 child_->test_properties()->force_render_surface =
5187 std::tr1::get<2>(GetParam());
[email protected]fb661802013-03-25 01:59:325188 }
[email protected]10aabcc32012-12-13 09:18:595189
[email protected]fb661802013-03-25 01:59:325190 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005191 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365192
khushalsagarb64b360d2015-10-21 19:25:165193 FakeImplTaskRunnerProvider task_runner_provider_;
reveman34b7a1522015-03-23 20:27:475194 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365195 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485196 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365197
danakj59931942016-07-26 22:11:295198 LayerImpl* root_ = nullptr;
5199 LayerImpl* child_ = nullptr;
5200 LayerImpl* grand_child_ = nullptr;
[email protected]10aabcc32012-12-13 09:18:595201};
5202
[email protected]fb661802013-03-25 01:59:325203TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005204 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5205 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5206
[email protected]fb661802013-03-25 01:59:325207 // Case 1: Identity transform.
flackra283bed2016-10-31 14:49:425208 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225209 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5210 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5211 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595212
[email protected]fb661802013-03-25 01:59:325213 // Case 2: Integral translation.
5214 gfx::Transform integral_translation;
5215 integral_translation.Translate(1.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045216 child_->test_properties()->transform = integral_translation;
jaydasika3f930c12015-06-30 15:18:255217 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425218 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225219 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5220 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5221 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595222
[email protected]fb661802013-03-25 01:59:325223 // Case 3: Non-integral translation.
5224 gfx::Transform non_integral_translation;
5225 non_integral_translation.Translate(1.5, 2.5);
jaydasika10d43fc2016-08-18 04:06:045226 child_->test_properties()->transform = non_integral_translation;
jaydasika3f930c12015-06-30 15:18:255227 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425228 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225229 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5230 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5231 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595232
[email protected]fb661802013-03-25 01:59:325233 // Case 4: Rotation.
5234 gfx::Transform rotation;
5235 rotation.Rotate(10.0);
jaydasika10d43fc2016-08-18 04:06:045236 child_->test_properties()->transform = rotation;
jaydasika3f930c12015-06-30 15:18:255237 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425238 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225239 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5240 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5241 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595242
[email protected]fb661802013-03-25 01:59:325243 // Case 5: Scale.
5244 gfx::Transform scale;
5245 scale.Scale(2.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045246 child_->test_properties()->transform = scale;
jaydasika3f930c12015-06-30 15:18:255247 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425248 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225249 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5250 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5251 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595252
[email protected]fb661802013-03-25 01:59:325253 // Case 6: Skew.
5254 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105255 skew.Skew(10.0, 0.0);
jaydasika10d43fc2016-08-18 04:06:045256 child_->test_properties()->transform = skew;
jaydasika3f930c12015-06-30 15:18:255257 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425258 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225259 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5260 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5261 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595262
[email protected]fb661802013-03-25 01:59:325263 // Case 7: Translucent.
jaydasika10d43fc2016-08-18 04:06:045264 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255265 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185266 child_->test_properties()->opacity = 0.5f;
flackra283bed2016-10-31 14:49:425267 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225268 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5269 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5270 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595271
[email protected]fb661802013-03-25 01:59:325272 // Case 8: Sanity check: restore transform and opacity.
jaydasika10d43fc2016-08-18 04:06:045273 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255274 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185275 child_->test_properties()->opacity = 1.f;
flackra283bed2016-10-31 14:49:425276 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225277 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5278 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5279 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505280
5281 // Case 9: Non-opaque content.
5282 child_->SetContentsOpaque(false);
flackra283bed2016-10-31 14:49:425283 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225284 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5285 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5286 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505287
5288 // Case 10: Sanity check: restore content opaqueness.
5289 child_->SetContentsOpaque(true);
flackra283bed2016-10-31 14:49:425290 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225291 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5292 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5293 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595294}
5295
[email protected]fd9a3b6d2013-08-03 00:46:175296TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005297 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335298 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005299
[email protected]fb661802013-03-25 01:59:325300 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackra283bed2016-10-31 14:49:425301 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225302 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5303 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5304 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595305
[email protected]fb661802013-03-25 01:59:325306 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:185307 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:255308 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
vollickef2ae922016-06-29 17:54:275309
5310 SetElementIdsForTesting();
5311
5312 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5313 10.0, 0.9f, 0.1f, false);
flackra283bed2016-10-31 14:49:425314 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:335315 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:225316 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5317 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5318 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335319}
5320
5321TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5322 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5323 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5324
5325 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackra283bed2016-10-31 14:49:425326 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225327 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5328 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5329 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
vollickef2ae922016-06-29 17:54:275330 SetElementIdsForTesting();
fmalitafcd926a2015-05-13 20:19:335331
5332 // Mark contents non-opaque within the first animation frame.
5333 child_->SetContentsOpaque(false);
vollickef2ae922016-06-29 17:54:275334 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5335 10.0, 0.9f, 0.1f, false);
flackra283bed2016-10-31 14:49:425336 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:335337 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:225338 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5339 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5340 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595341}
5342
5343INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5344 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005345 testing::Combine(testing::Bool(),
5346 testing::Bool(),
5347 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595348
[email protected]989386c2013-07-18 21:37:235349TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165350 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565351 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225352 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195353 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195354
danakj60bc3bc2016-04-09 00:24:485355 std::unique_ptr<LayerImpl> root =
5356 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065357 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195358 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065359 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195360
danakj60bc3bc2016-04-09 00:24:485361 std::unique_ptr<LayerImpl> child =
5362 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065363 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195364 child->SetDrawsContent(true);
5365
danakj60bc3bc2016-04-09 00:24:485366 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195367 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065368 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195369 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355370 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195371
jaydasika89f7b5a2016-06-22 02:08:395372 child->test_properties()->AddChild(std::move(grand_child));
5373 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:595374 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195375
5376 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535377 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385378 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535379 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575380 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195381
5382 // We should have one render surface and two layers. The grand child has
5383 // hidden itself.
5384 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055385 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5386 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5387 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195388}
5389
[email protected]989386c2013-07-18 21:37:235390TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165391 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565392 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225393 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195394 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195395
danakj60bc3bc2016-04-09 00:24:485396 std::unique_ptr<LayerImpl> root =
5397 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065398 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195399 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095400 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195401
danakj60bc3bc2016-04-09 00:24:485402 std::unique_ptr<LayerImpl> child =
5403 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065404 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195405 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355406 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195407
danakj60bc3bc2016-04-09 00:24:485408 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195409 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065410 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195411 grand_child->SetDrawsContent(true);
5412
jaydasika89f7b5a2016-06-22 02:08:395413 child->test_properties()->AddChild(std::move(grand_child));
5414 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:595415 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195416
5417 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535418 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385419 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535420 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575421 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195422
5423 // We should have one render surface and one layers. The child has
5424 // hidden itself and the grand child.
5425 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095426 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5427 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195428}
5429
danakj60bc3bc2016-04-09 00:24:485430void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455431
[email protected]989386c2013-07-18 21:37:235432TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165433 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565434 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225435 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455436 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455437
danakj60bc3bc2016-04-09 00:24:485438 std::unique_ptr<LayerImpl> root =
5439 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065440 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305441 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095442 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455443
danakj60bc3bc2016-04-09 00:24:485444 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305445 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065446 copy_grand_parent->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305447 copy_grand_parent->SetDrawsContent(true);
5448 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455449
danakj60bc3bc2016-04-09 00:24:485450 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305451 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065452 copy_parent->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305453 copy_parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065454 copy_parent->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305455 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455456
danakj60bc3bc2016-04-09 00:24:485457 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305458 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065459 copy_request->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305460 copy_request->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065461 copy_request->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305462 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455463
danakj60bc3bc2016-04-09 00:24:485464 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305465 LayerImpl::Create(host_impl.pending_tree(), 5);
danakje4fa7b72016-07-25 22:00:065466 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305467 copy_child->SetDrawsContent(true);
5468 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455469
danakj60bc3bc2016-04-09 00:24:485470 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405471 LayerImpl::Create(host_impl.pending_tree(), 6);
danakje4fa7b72016-07-25 22:00:065472 copy_grand_child->SetBounds(gfx::Size(20, 20));
5473 copy_grand_child->SetDrawsContent(true);
jaydasika86654512016-01-27 17:05:075474 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5475
danakj60bc3bc2016-04-09 00:24:485476 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075477 LayerImpl::Create(host_impl.pending_tree(), 7);
danakje4fa7b72016-07-25 22:00:065478 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305479 copy_grand_parent_sibling_before->SetDrawsContent(true);
5480 LayerImpl* copy_grand_parent_sibling_before_layer =
5481 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535482
danakj60bc3bc2016-04-09 00:24:485483 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075484 LayerImpl::Create(host_impl.pending_tree(), 8);
danakje4fa7b72016-07-25 22:00:065485 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305486 copy_grand_parent_sibling_after->SetDrawsContent(true);
5487 LayerImpl* copy_grand_parent_sibling_after_layer =
5488 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535489
jaydasika89f7b5a2016-06-22 02:08:395490 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
5491 copy_request->test_properties()->AddChild(std::move(copy_child));
5492 copy_parent->test_properties()->AddChild(std::move(copy_request));
5493 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
5494 root->test_properties()->AddChild(
5495 std::move(copy_grand_parent_sibling_before));
5496 root->test_properties()->AddChild(std::move(copy_grand_parent));
5497 root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasikabf1875a2016-06-28 03:39:595498 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285499
[email protected]30fe19ff2013-07-04 00:54:455500 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075501 // hidden subtree on copy_layer. Also hide the copy grand child and its
5502 // subtree.
jaydasika5121caa82016-05-05 15:43:355503 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5504 copy_grand_parent_sibling_before_layer->test_properties()
5505 ->hide_layer_and_subtree = true;
5506 copy_grand_parent_sibling_after_layer->test_properties()
5507 ->hide_layer_and_subtree = true;
5508 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305509
ajumae6f541b2016-05-31 16:50:505510 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305511 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455512
weiliangc51fb255d2015-07-24 15:32:305513 LayerImplList render_surface_layer_list;
5514 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385515 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535516 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575517 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455518
jaydasika2411692c2016-03-23 01:56:095519 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025520 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5521 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5522 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535523
jaydasika86654512016-01-27 17:05:075524 // We should have four render surfaces, one for the root, one for the grand
5525 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455526 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075527 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095528 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075529 EXPECT_EQ(copy_grand_parent_layer->id(),
5530 render_surface_layer_list.at(1)->id());
5531 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5532 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455533
jaydasika86654512016-01-27 17:05:075534 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095535 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5536 EXPECT_EQ(root_layer->id(),
5537 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075538 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095539 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455540
[email protected]7392c7b2014-02-07 08:28:285541 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455542 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305543 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455544 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065545 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455546
5547 // The copy_layer's render surface should have two contributing layers.
5548 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5549 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235550 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305551 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235552 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075553
5554 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5555 // but the copy_layer and copy_child should be drawn for the copy request.
5556 // copy grand child should not be drawn as its hidden even in the copy
5557 // request.
ajumae4af47062016-05-24 23:59:045558 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095559 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075560 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015561 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075562 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015563 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075564 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015565 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075566 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015567 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075568 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015569 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075570
5571 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5572 // actually hidden.
5573 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455574}
5575
[email protected]989386c2013-07-18 21:37:235576TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165577 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565578 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225579 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455580 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455581
danakj60bc3bc2016-04-09 00:24:485582 std::unique_ptr<LayerImpl> root =
5583 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065584 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305585 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455586
danakj60bc3bc2016-04-09 00:24:485587 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305588 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:305589 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455590 copy_parent->SetMasksToBounds(true);
5591
danakj60bc3bc2016-04-09 00:24:485592 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305593 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065594 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305595 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065596 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:455597
danakj60bc3bc2016-04-09 00:24:485598 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305599 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065600 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305601 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455602
ajumae6f541b2016-05-31 16:50:505603 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305604 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455605
jaydasika89f7b5a2016-06-22 02:08:395606 copy_layer->test_properties()->AddChild(std::move(copy_child));
5607 copy_parent->test_properties()->AddChild(std::move(copy_layer));
5608 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305609
5610 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055611 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595612 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305613 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385614 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535615 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575616 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455617
xjze19f76402015-11-06 21:48:445618 // We should have two render surface, as the others are clipped out.
5619 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055620 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455621
xjze19f76402015-11-06 21:48:445622 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455623 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055624 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5625 EXPECT_EQ(root_layer->id(),
5626 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455627}
5628
weiliangcde7e0c32016-06-15 15:02:415629TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595630 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065631 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415632 root->SetDrawsContent(true);
5633 root->SetMasksToBounds(true);
5634
5635 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065636 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415637 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065638 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415639
5640 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065641 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5642 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415643 copy_child->SetDrawsContent(true);
5644
5645 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065646 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415647 copy_clip->SetMasksToBounds(true);
5648
5649 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065650 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5651 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415652 copy_clipped_child->SetDrawsContent(true);
5653
5654 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065655 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5656 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415657 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065658 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415659
5660 copy_layer->test_properties()->copy_requests.push_back(
5661 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5662
weiliangce22ce842016-07-04 23:31:535663 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415664 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535665 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415666
5667 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5668 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5669 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5670 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5671
5672 // Case 2: When the non root copy request layer is clipped.
5673 copy_layer->SetBounds(gfx::Size(50, 50));
5674 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535675 copy_layer->test_properties()->copy_requests.push_back(
5676 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415677 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5678
weiliangce22ce842016-07-04 23:31:535679 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415680 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535681 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415682
5683 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5684 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5685 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5686 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515687
5688 // Case 3: When there is device scale factor.
5689 float device_scale_factor = 2.f;
5690 copy_layer->test_properties()->copy_requests.push_back(
5691 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5692
5693 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5694 ExecuteCalculateDrawProperties(root, device_scale_factor);
5695 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5696
5697 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5698 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5699 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5700 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415701}
5702
[email protected]420fdf6e2013-08-26 20:36:385703TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5704 // Ensure that a transform between the layer and its render surface is not a
5705 // problem. Constructs the following layer tree.
5706 //
5707 // root (a render surface)
5708 // + render_surface
5709 // + clip_parent (scaled)
5710 // + intervening_clipping_layer
5711 // + clip_child
5712 //
5713 // The render surface should be resized correctly and the clip child should
5714 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595715 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315716 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5717 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285718 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315719 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285720 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315721 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5722 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565723 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485724 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315725 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565726 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385727
5728 intervening->SetMasksToBounds(true);
5729 clip_parent->SetMasksToBounds(true);
5730
[email protected]420fdf6e2013-08-26 20:36:385731 gfx::Transform scale_transform;
5732 scale_transform.Scale(2, 2);
5733
danakjf78fb272016-07-26 19:06:155734 root->SetBounds(gfx::Size(50, 50));
5735 render_surface->SetBounds(gfx::Size(10, 10));
5736 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:045737 clip_parent->test_properties()->transform = scale_transform;
danakjf78fb272016-07-26 19:06:155738 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5739 clip_parent->SetBounds(gfx::Size(10, 10));
5740 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5741 intervening->SetBounds(gfx::Size(5, 5));
5742 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5743 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315744 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385745
5746 ASSERT_TRUE(root->render_surface());
5747 ASSERT_TRUE(render_surface->render_surface());
5748
5749 // Ensure that we've inherited our clip parent's clip and weren't affected
5750 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145751 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5752 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5753 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385754
5755 // Ensure that the render surface reports a content rect that has been grown
5756 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145757 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5758 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385759
5760 // The above check implies the two below, but they nicely demonstrate that
5761 // we've grown, despite the intervening layer's clip.
5762 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5763 render_surface->render_surface()->content_rect()));
5764 ASSERT_FALSE(intervening->clip_rect().Contains(
5765 render_surface->render_surface()->content_rect()));
5766}
5767
5768TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5769 // Ensure that intervening render surfaces are not a problem in the basic
5770 // case. In the following tree, both render surfaces should be resized to
5771 // accomodate for the clip child, despite an intervening clip.
5772 //
5773 // root (a render surface)
5774 // + clip_parent (masks to bounds)
5775 // + render_surface1 (sets opacity)
5776 // + intervening (masks to bounds)
5777 // + render_surface2 (also sets opacity)
5778 // + clip_child
5779 //
jaydasikabf1875a2016-06-28 03:39:595780 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235781 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5782 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5783 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5784 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5785 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365786 render_surface1->SetDrawsContent(true);
5787 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235788 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385789
jaydasika1c0a27d42016-04-28 01:54:565790 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385791
5792 intervening->SetMasksToBounds(true);
5793 clip_parent->SetMasksToBounds(true);
5794
[email protected]420fdf6e2013-08-26 20:36:385795 gfx::Transform translation_transform;
5796 translation_transform.Translate(2, 2);
5797
danakjf78fb272016-07-26 19:06:155798 root->SetBounds(gfx::Size(50, 50));
5799 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5800 clip_parent->SetBounds(gfx::Size(40, 40));
5801 render_surface1->SetBounds(gfx::Size(10, 10));
5802 render_surface1->test_properties()->force_render_surface = true;
5803 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5804 intervening->SetBounds(gfx::Size(5, 5));
5805 render_surface2->SetBounds(gfx::Size(10, 10));
5806 render_surface2->test_properties()->force_render_surface = true;
5807 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5808 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235809 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385810
5811 EXPECT_TRUE(root->render_surface());
5812 EXPECT_TRUE(render_surface1->render_surface());
5813 EXPECT_TRUE(render_surface2->render_surface());
5814
5815 // Since the render surfaces could have expanded, they should not clip (their
5816 // bounds would no longer be reliable). We should resort to layer clipping
5817 // in this case.
jaydasika6f972de2016-04-07 16:16:145818 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5819 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385820 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145821 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5822 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385823 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5824
5825 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145826 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385827 EXPECT_TRUE(render_surface1->is_clipped());
5828
5829 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145830 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385831 EXPECT_TRUE(render_surface2->is_clipped());
5832
5833 // The content rects of both render surfaces should both have expanded to
5834 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145835 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5836 render_surface1->render_surface()->content_rect());
5837 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5838 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385839
5840 // The clip child should have inherited the clip parent's clip (projected to
5841 // the right space, of course), and should have the correctly sized visible
5842 // content rect.
jaydasika6f972de2016-04-07 16:16:145843 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5844 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385845 EXPECT_TRUE(clip_child->is_clipped());
5846}
5847
5848TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5849 // Ensure that intervening render surfaces are not a problem, even if there
5850 // is a scroll involved. Note, we do _not_ have to consider any other sort
5851 // of transform.
5852 //
5853 // root (a render surface)
5854 // + clip_parent (masks to bounds)
5855 // + render_surface1 (sets opacity)
5856 // + intervening (masks to bounds AND scrolls)
5857 // + render_surface2 (also sets opacity)
5858 // + clip_child
5859 //
jaydasikabf1875a2016-06-28 03:39:595860 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235861 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5862 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5863 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5864 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5865 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365866 render_surface1->SetDrawsContent(true);
5867 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235868 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385869
jaydasika1c0a27d42016-04-28 01:54:565870 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385871
5872 intervening->SetMasksToBounds(true);
5873 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235874 intervening->SetScrollClipLayer(clip_parent->id());
5875 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385876
5877 gfx::Transform translation_transform;
5878 translation_transform.Translate(2, 2);
5879
danakjf78fb272016-07-26 19:06:155880 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:045881 clip_parent->test_properties()->transform = translation_transform;
danakjf78fb272016-07-26 19:06:155882 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5883 clip_parent->SetBounds(gfx::Size(40, 40));
5884 render_surface1->SetBounds(gfx::Size(10, 10));
5885 render_surface1->test_properties()->force_render_surface = true;
5886 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5887 intervening->SetBounds(gfx::Size(5, 5));
5888 render_surface2->SetBounds(gfx::Size(10, 10));
5889 render_surface2->test_properties()->force_render_surface = true;
5890 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5891 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235892 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385893
5894 EXPECT_TRUE(root->render_surface());
5895 EXPECT_TRUE(render_surface1->render_surface());
5896 EXPECT_TRUE(render_surface2->render_surface());
5897
5898 // Since the render surfaces could have expanded, they should not clip (their
5899 // bounds would no longer be reliable). We should resort to layer clipping
5900 // in this case.
jaydasika6f972de2016-04-07 16:16:145901 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5902 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385903 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145904 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5905 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385906 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5907
5908 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145909 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385910 EXPECT_TRUE(render_surface1->is_clipped());
5911
5912 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145913 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385914 EXPECT_TRUE(render_surface2->is_clipped());
5915
5916 // The content rects of both render surfaces should both have expanded to
5917 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145918 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5919 render_surface1->render_surface()->content_rect());
5920 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
5921 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385922
5923 // The clip child should have inherited the clip parent's clip (projected to
5924 // the right space, of course), and should have the correctly sized visible
5925 // content rect.
jaydasika6f972de2016-04-07 16:16:145926 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
5927 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385928 EXPECT_TRUE(clip_child->is_clipped());
5929}
5930
5931TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5932 // Ensures that descendants of the clip child inherit the correct clip.
5933 //
5934 // root (a render surface)
5935 // + clip_parent (masks to bounds)
5936 // + intervening (masks to bounds)
5937 // + clip_child
5938 // + child
5939 //
jaydasikabf1875a2016-06-28 03:39:595940 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175941 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5942 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5943 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5944 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365945 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175946 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385947
jaydasika1c0a27d42016-04-28 01:54:565948 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155949 clip_parent->test_properties()->clip_children =
5950 base::MakeUnique<std::set<LayerImpl*>>();
5951 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385952
danakjf78fb272016-07-26 19:06:155953 root->SetBounds(gfx::Size(50, 50));
5954 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385955 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155956 intervening->SetBounds(gfx::Size(5, 5));
5957 intervening->SetMasksToBounds(true);
5958 clip_child->SetBounds(gfx::Size(60, 60));
5959 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385960
enne2d0d8e62015-08-18 18:29:175961 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385962
5963 EXPECT_TRUE(root->render_surface());
5964
5965 // Neither the clip child nor its descendant should have inherited the clip
5966 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145967 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385968 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145969 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385970 EXPECT_TRUE(child->is_clipped());
5971}
5972
5973TEST_F(LayerTreeHostCommonTest,
5974 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5975 // Ensures that non-descendant clip children in the tree do not affect
5976 // render surfaces.
5977 //
5978 // root (a render surface)
5979 // + clip_parent (masks to bounds)
5980 // + render_surface1
5981 // + clip_child
5982 // + render_surface2
5983 // + non_clip_child
5984 //
5985 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595986 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505987 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5988 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5989 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
enneb441cdd2015-07-28 22:47:505990 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
5991 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385992
jaydasika1c0a27d42016-04-28 01:54:565993 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155994 clip_parent->test_properties()->clip_children =
5995 base::MakeUnique<std::set<LayerImpl*>>();
5996 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385997
5998 clip_parent->SetMasksToBounds(true);
5999 render_surface1->SetMasksToBounds(true);
6000
danakjf78fb272016-07-26 19:06:156001 render_surface1->SetDrawsContent(true);
6002 clip_child->SetDrawsContent(true);
6003 render_surface2->SetDrawsContent(true);
6004 non_clip_child->SetDrawsContent(true);
6005
6006 root->SetBounds(gfx::Size(15, 15));
6007 clip_parent->SetBounds(gfx::Size(10, 10));
6008 render_surface1->SetPosition(gfx::PointF(5, 5));
6009 render_surface1->SetBounds(gfx::Size(5, 5));
6010 render_surface1->test_properties()->force_render_surface = true;
6011 render_surface2->SetBounds(gfx::Size(5, 5));
6012 render_surface2->test_properties()->force_render_surface = true;
6013 clip_child->SetPosition(gfx::PointF(-1, 1));
6014 clip_child->SetBounds(gfx::Size(10, 10));
6015 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:386016
enneb441cdd2015-07-28 22:47:506017 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386018
6019 EXPECT_TRUE(root->render_surface());
6020 EXPECT_TRUE(render_surface1->render_surface());
6021 EXPECT_TRUE(render_surface2->render_surface());
6022
jaydasika6f972de2016-04-07 16:16:146023 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386024 EXPECT_TRUE(render_surface1->is_clipped());
6025
6026 // The render surface should not clip (it has unclipped descendants), instead
6027 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:146028 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
6029 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386030 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6031
jaydasika0d98ba92015-11-17 05:17:286032 // That said, it should have grown to accomodate the unclipped descendant and
6033 // its own size.
jaydasika6f972de2016-04-07 16:16:146034 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
6035 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386036
6037 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:146038 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
6039 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386040 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:426041 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:386042
6043 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:146044 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
6045 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386046
6047 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:216048 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
6049 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:386050}
6051
weiliangc9ced1592015-11-17 19:04:376052TEST_F(LayerTreeHostCommonTest,
6053 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
6054 // Verifies that Render Surfaces are created at the edge of rendering context.
6055
jaydasikabf1875a2016-06-28 03:39:596056 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:266057 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
6058 LayerImpl* child2 = AddChild<LayerImpl>(child1);
6059 LayerImpl* child3 = AddChild<LayerImpl>(child2);
6060 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376061
weiliangc9ced1592015-11-17 19:04:376062 gfx::Size bounds(100, 100);
6063
danakjf78fb272016-07-26 19:06:156064 root->SetBounds(bounds);
6065 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:266066 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156067 child1->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:206068 child1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156069 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:266070 child2->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:206071 child2->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156072 child3->SetBounds(bounds);
6073 child3->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:206074 child3->test_properties()->sorting_context_id = 1;
jaydasika6ed869662016-09-21 14:29:596075 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
weiliangc9ced1592015-11-17 19:04:376076
6077 // Verify which render surfaces were created.
6078 EXPECT_TRUE(root->has_render_surface());
6079 EXPECT_FALSE(child1->has_render_surface());
6080 EXPECT_TRUE(child2->has_render_surface());
6081 EXPECT_FALSE(child3->has_render_surface());
6082}
6083
[email protected]45948712013-09-27 02:46:486084TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:166085 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:566086 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:226087 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:266088
danakj60bc3bc2016-04-09 00:24:486089 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:486090 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:486091 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:486092 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:486093 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:486094 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:486095 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:486096 LayerImpl::Create(host_impl.active_tree(), 12345678);
6097
[email protected]45948712013-09-27 02:46:486098 gfx::Size bounds(100, 100);
danakjf78fb272016-07-26 19:06:156099
6100 root->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:486101 root->SetDrawsContent(true);
6102
6103 // This layer structure normally forces render surface due to preserves3d
6104 // behavior.
danakjf78fb272016-07-26 19:06:156105 child1->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:486106 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156107 child1->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:206108 child1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156109 child2->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:486110 child2->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:206111 child2->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156112 child3->SetBounds(bounds);
6113 child3->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:206114 child3->test_properties()->sorting_context_id = 1;
[email protected]56fffdd2014-02-11 19:50:576115
jaydasika89f7b5a2016-06-22 02:08:396116 child2->test_properties()->AddChild(std::move(child3));
6117 child1->test_properties()->AddChild(std::move(child2));
6118 root->test_properties()->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:056119 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:596120 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
[email protected]45948712013-09-27 02:46:486121
6122 {
6123 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:056124 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:486125 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386126 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486127 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:576128 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486129
6130 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026131
6132 int count_represents_target_render_surface = 0;
6133 int count_represents_contributing_render_surface = 0;
6134 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516135 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6136 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026137 it != end; ++it) {
6138 if (it.represents_target_render_surface())
6139 count_represents_target_render_surface++;
6140 if (it.represents_contributing_render_surface())
6141 count_represents_contributing_render_surface++;
6142 if (it.represents_itself())
6143 count_represents_itself++;
6144 }
6145
6146 // Two render surfaces.
6147 EXPECT_EQ(2, count_represents_target_render_surface);
6148 // Second render surface contributes to root render surface.
6149 EXPECT_EQ(1, count_represents_contributing_render_surface);
6150 // All 4 layers represent itself.
6151 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486152 }
6153
6154 {
6155 LayerImplList render_surface_layer_list;
6156 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386157 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486158 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:576159 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486160
6161 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026162
6163 int count_represents_target_render_surface = 0;
6164 int count_represents_contributing_render_surface = 0;
6165 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516166 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6167 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026168 it != end; ++it) {
6169 if (it.represents_target_render_surface())
6170 count_represents_target_render_surface++;
6171 if (it.represents_contributing_render_surface())
6172 count_represents_contributing_render_surface++;
6173 if (it.represents_itself())
6174 count_represents_itself++;
6175 }
6176
6177 // Only root layer has a render surface.
6178 EXPECT_EQ(1, count_represents_target_render_surface);
6179 // No layer contributes a render surface to root render surface.
6180 EXPECT_EQ(0, count_represents_contributing_render_surface);
6181 // All 4 layers represent itself.
6182 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486183 }
6184}
6185
[email protected]a9aa60a82013-08-29 04:28:266186TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:596187 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:336188 LayerImpl* back_facing = AddChild<LayerImpl>(root);
trchen75204782016-11-03 01:05:426189
jaydasikae00c8a42016-01-28 20:18:336190 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
jaydasikae00c8a42016-01-28 20:18:336191 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
trchen75204782016-11-03 01:05:426192
6193 LayerImpl* flattener = AddChild<LayerImpl>(back_facing);
6194 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener);
jaydasikae00c8a42016-01-28 20:18:336195 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:156196
jaydasikae00c8a42016-01-28 20:18:336197 child1->SetDrawsContent(true);
6198 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266199
danakjf78fb272016-07-26 19:06:156200 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:156201 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:526202 back_facing->test_properties()->should_flatten_transform = false;
trchen75204782016-11-03 01:05:426203
danakjf78fb272016-07-26 19:06:156204 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156205 render_surface1->test_properties()->should_flatten_transform = false;
6206 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366207 render_surface1->test_properties()->double_sided = false;
trchen75204782016-11-03 01:05:426208 child1->SetBounds(gfx::Size(20, 20));
6209
6210 flattener->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156211 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156212 render_surface2->test_properties()->should_flatten_transform = false;
6213 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366214 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156215 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:266216
enne03b0e9a2015-06-19 00:08:026217 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266218
jaydasikae00c8a42016-01-28 20:18:336219 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6220 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026221 ->at(0)
6222 ->render_surface()
6223 ->layer_list()
6224 .size());
6225 EXPECT_EQ(1u, render_surface_layer_list_impl()
6226 ->at(1)
6227 ->render_surface()
6228 ->layer_list()
6229 .size());
[email protected]a9aa60a82013-08-29 04:28:266230
danakjf78fb272016-07-26 19:06:156231 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:266232 rotation_transform.RotateAboutXAxis(180.0);
6233
jaydasika10d43fc2016-08-18 04:06:046234 back_facing->test_properties()->transform = rotation_transform;
jaydasika5aa88b82015-11-10 01:48:036235 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266236
enne03b0e9a2015-06-19 00:08:026237 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266238
jaydasikae00c8a42016-01-28 20:18:336239 // render_surface1 is in the same 3d rendering context as back_facing and is
6240 // not double sided, so it should not be in RSLL. render_surface2 is also not
6241 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6242 // context.
6243 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6244 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026245 ->at(0)
6246 ->render_surface()
6247 ->layer_list()
6248 .size());
[email protected]a9aa60a82013-08-29 04:28:266249}
6250
ajumaaa0d3862015-11-09 22:24:466251TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:596252 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:466253 LayerImpl* child = AddChild<LayerImpl>(root);
6254 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:466255
danakjf78fb272016-07-26 19:06:156256 root->SetBounds(gfx::Size(50, 50));
6257 root->test_properties()->should_flatten_transform = false;
6258 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:366259 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156260 child->test_properties()->should_flatten_transform = false;
6261 grand_child->SetBounds(gfx::Size(20, 20));
6262 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:466263 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:156264 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:466265 ExecuteCalculateDrawProperties(root);
6266
6267 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6268 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6269 ->at(0)
6270 ->render_surface()
6271 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556272
6273 // As all layers have identity transform, we shouldn't check for backface
6274 // visibility.
6275 EXPECT_FALSE(root->should_check_backface_visibility());
6276 EXPECT_FALSE(child->should_check_backface_visibility());
6277 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6278 // As there are no 3d rendering contexts, all layers should use their local
6279 // transform for backface visibility.
6280 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6281 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6282 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6283
danakjf78fb272016-07-26 19:06:156284 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:466285 rotation_transform.RotateAboutXAxis(180.0);
6286
jaydasika10d43fc2016-08-18 04:06:046287 child->test_properties()->transform = rotation_transform;
wkormanf09921d2017-01-07 01:01:206288 child->test_properties()->sorting_context_id = 1;
6289 grand_child->test_properties()->sorting_context_id = 1;
ajumaaa0d3862015-11-09 22:24:466290 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6291
6292 ExecuteCalculateDrawProperties(root);
6293 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6294 EXPECT_EQ(0u, render_surface_layer_list_impl()
6295 ->at(0)
6296 ->render_surface()
6297 ->layer_list()
6298 .size());
jaydasika62bd3dd2016-02-04 18:52:556299
6300 // We should check for backface visibilty of child as it has a rotation
6301 // transform. We should also check for grand_child as it uses the backface
6302 // visibility of its parent.
6303 EXPECT_FALSE(root->should_check_backface_visibility());
6304 EXPECT_TRUE(child->should_check_backface_visibility());
6305 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6306 // child uses its local transform for backface visibility as it is the root of
6307 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6308 // the root, but it derives its backface visibility from its parent which uses
6309 // its local transform.
6310 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6311 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6312 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6313
6314 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366315 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556316 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6317
6318 ExecuteCalculateDrawProperties(root);
6319 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6320 EXPECT_EQ(0u, render_surface_layer_list_impl()
6321 ->at(0)
6322 ->render_surface()
6323 ->layer_list()
6324 .size());
6325
6326 // We should check the backface visibility of child as it has a rotation
6327 // transform and for grand_child as it is in a 3d rendering context and not
6328 // the root of it.
6329 EXPECT_FALSE(root->should_check_backface_visibility());
6330 EXPECT_TRUE(child->should_check_backface_visibility());
6331 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6332 // grand_child is in an existing 3d rendering context, so it should not use
6333 // local transform for backface visibility.
6334 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6335 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6336 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466337}
6338
sunxd59dd7da2016-05-19 20:07:476339TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:596340 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:476341 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6342 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6343 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6344
sunxd59dd7da2016-05-19 20:07:476345 gfx::Transform rotate_about_y;
6346 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:476347
danakjf78fb272016-07-26 19:06:156348 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:156349 root->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:206350 root->test_properties()->sorting_context_id = 1;
jaydasika10d43fc2016-08-18 04:06:046351 back_facing->test_properties()->transform = rotate_about_y;
danakjf78fb272016-07-26 19:06:156352 back_facing->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:156353 back_facing->test_properties()->should_flatten_transform = false;
wkormanf09921d2017-01-07 01:01:206354 back_facing->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156355 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156356 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476357 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156358 render_surface1->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:206359 render_surface1->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156360 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156361 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476362 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156363 render_surface2->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:206364 render_surface2->test_properties()->sorting_context_id = 1;
sunxd59dd7da2016-05-19 20:07:476365 ExecuteCalculateDrawProperties(root);
6366
6367 const EffectTree& tree =
6368 root->layer_tree_impl()->property_trees()->effect_tree;
6369 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016370 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476371 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016372 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476373
jaydasika09e16132016-08-24 21:39:346374 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6375 gfx::Transform(), back_facing->transform_tree_index(),
6376 root->layer_tree_impl());
6377 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6378 rotate_about_y, render_surface2->transform_tree_index(),
6379 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476380 ExecuteCalculateDrawProperties(root);
6381 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016382 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476383 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016384 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476385
jaydasika09e16132016-08-24 21:39:346386 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6387 rotate_about_y, render_surface1->transform_tree_index(),
6388 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476389 ExecuteCalculateDrawProperties(root);
6390 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016391 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476392 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016393 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476394}
6395
[email protected]995708c52013-10-17 20:52:596396TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6397 // Checks that the simple case (being clipped by a scroll parent that would
6398 // have been processed before you anyhow) results in the right clips.
6399 //
6400 // + root
6401 // + scroll_parent_border
6402 // | + scroll_parent_clip
6403 // | + scroll_parent
6404 // + scroll_child
6405 //
jaydasikabf1875a2016-06-28 03:39:596406 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:486407 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6408 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6409 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6410 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596411
enne085b48a2015-08-18 17:54:486412 scroll_parent->SetDrawsContent(true);
6413 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596414 scroll_parent_clip->SetMasksToBounds(true);
6415
jaydasika1c0a27d42016-04-28 01:54:566416 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156417 scroll_parent->test_properties()->scroll_children =
6418 base::MakeUnique<std::set<LayerImpl*>>();
6419 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596420
danakjf78fb272016-07-26 19:06:156421 root->SetBounds(gfx::Size(50, 50));
6422 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6423 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6424 scroll_parent->SetBounds(gfx::Size(50, 50));
6425 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:486426 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596427
6428 EXPECT_TRUE(root->render_surface());
6429
jaydasika6f972de2016-04-07 16:16:146430 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596431 EXPECT_TRUE(scroll_child->is_clipped());
6432}
6433
jaydasika8ccff3d2016-01-20 19:51:306434TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6435 // Tests the computation of draw transform for the scroll child when its
6436 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:596437 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:306438 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6439 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6440 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6441 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6442
6443 scroll_parent->SetDrawsContent(true);
6444 scroll_child->SetDrawsContent(true);
6445
jaydasika1c0a27d42016-04-28 01:54:566446 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156447 scroll_parent->test_properties()->scroll_children =
6448 base::MakeUnique<std::set<LayerImpl*>>();
6449 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:306450
danakjf78fb272016-07-26 19:06:156451 root->SetBounds(gfx::Size(50, 50));
6452 scroll_child_target->SetBounds(gfx::Size(50, 50));
6453 scroll_child_target->test_properties()->force_render_surface = true;
6454 scroll_child->SetBounds(gfx::Size(50, 50));
6455 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
6456 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:006457 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156458 scroll_parent_target->test_properties()->force_render_surface = true;
6459 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:306460
jaydasika2489a442016-01-29 02:26:006461 float device_scale_factor = 1.5f;
6462 LayerImplList render_surface_layer_list_impl;
jaydasikab4df4032016-09-13 18:38:496463 gfx::Size device_viewport_size =
6464 gfx::Size(root->bounds().width() * device_scale_factor,
6465 root->bounds().height() * device_scale_factor);
jaydasika2489a442016-01-29 02:26:006466 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasikab4df4032016-09-13 18:38:496467 root, device_viewport_size, gfx::Transform(),
6468 &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006469 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576470 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006471
weiliangc1da3fb892016-03-14 20:23:526472 EXPECT_EQ(scroll_child->effect_tree_index(),
6473 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006474 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6475 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6476 gfx::Transform scale;
6477 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:026478 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306479}
6480
jaydasika4de4c0832016-11-29 16:19:166481TEST_F(LayerTreeHostCommonTest, TargetBetweenScrollChildandScrollParentTarget) {
6482 LayerImpl* root = root_layer_for_testing();
6483 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6484 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6485 LayerImpl* child_of_scroll_child = AddChild<LayerImpl>(scroll_child);
6486 LayerImpl* intervening_target = AddChild<LayerImpl>(scroll_child_target);
6487 LayerImpl* clip = AddChild<LayerImpl>(intervening_target);
6488 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(clip);
6489 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6490
6491 scroll_parent->SetDrawsContent(true);
6492 child_of_scroll_child->SetDrawsContent(true);
6493
6494 scroll_child->test_properties()->scroll_parent = scroll_parent;
6495 scroll_parent->test_properties()->scroll_children =
6496 base::MakeUnique<std::set<LayerImpl*>>();
6497 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
6498
6499 root->SetBounds(gfx::Size(50, 50));
6500 scroll_child_target->SetBounds(gfx::Size(50, 50));
6501 scroll_child_target->SetMasksToBounds(true);
6502 scroll_child_target->test_properties()->force_render_surface = true;
6503 scroll_child->SetBounds(gfx::Size(50, 50));
6504 child_of_scroll_child->SetBounds(gfx::Size(50, 50));
6505 child_of_scroll_child->test_properties()->force_render_surface = true;
6506 intervening_target->SetBounds(gfx::Size(50, 50));
6507 intervening_target->test_properties()->force_render_surface = true;
6508 clip->SetBounds(gfx::Size(50, 50));
6509 clip->SetMasksToBounds(true);
6510 scroll_parent_target->SetBounds(gfx::Size(50, 50));
6511 scroll_parent_target->SetMasksToBounds(true);
6512 scroll_parent_target->test_properties()->force_render_surface = true;
6513 scroll_parent->SetBounds(gfx::Size(50, 50));
6514
6515 ExecuteCalculateDrawProperties(root);
6516 PropertyTrees* property_trees = root->layer_tree_impl()->property_trees();
6517 ClipNode* clip_node =
6518 property_trees->clip_tree.Node(child_of_scroll_child->clip_tree_index());
6519 ClipNode* parent_clip_node = property_trees->clip_tree.parent(clip_node);
6520 DCHECK_GT(parent_clip_node->target_transform_id,
6521 property_trees->transform_tree.TargetId(
6522 child_of_scroll_child->transform_tree_index()));
6523}
6524
[email protected]08bdf1b2014-04-16 23:23:296525TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:596526 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:196527 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:196528 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:156529
6530 root->SetBounds(gfx::Size(50, 50));
6531 root->SetDrawsContent(true);
wkormanf09921d2017-01-07 01:01:206532 root->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156533 parent->SetBounds(gfx::Size(30, 30));
6534 parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156535 parent->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:206536 parent->test_properties()->sorting_context_id = 1;
danakjf78fb272016-07-26 19:06:156537 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:196538 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156539 child->test_properties()->force_render_surface = true;
wkormanf09921d2017-01-07 01:01:206540 child->test_properties()->sorting_context_id = 1;
enneca33fed2015-07-27 18:22:196541 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296542
enneca33fed2015-07-27 18:22:196543 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296544
6545 gfx::Transform singular_transform;
6546 singular_transform.Scale3d(
6547 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6548
jaydasika10d43fc2016-08-18 04:06:046549 child->test_properties()->transform = singular_transform;
[email protected]08bdf1b2014-04-16 23:23:296550
sunxd71aea3e2016-04-01 23:48:056551 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196552 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296553
enneca33fed2015-07-27 18:22:196554 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296555
6556 // Ensure that the entire subtree under a layer with singular transform does
6557 // not get rendered.
jaydasika10d43fc2016-08-18 04:06:046558 parent->test_properties()->transform = singular_transform;
6559 child->test_properties()->transform = gfx::Transform();
[email protected]08bdf1b2014-04-16 23:23:296560
sunxd71aea3e2016-04-01 23:48:056561 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196562 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296563
enneca33fed2015-07-27 18:22:196564 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296565}
6566
[email protected]995708c52013-10-17 20:52:596567TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6568 // Checks that clipping by a scroll parent that follows you in paint order
6569 // still results in correct clipping.
6570 //
6571 // + root
[email protected]995708c52013-10-17 20:52:596572 // + scroll_parent_border
6573 // + scroll_parent_clip
6574 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026575 // + scroll_child
[email protected]995708c52013-10-17 20:52:596576 //
jaydasikabf1875a2016-06-28 03:39:596577 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026578 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6579 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6580 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6581 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596582
enne03b0e9a2015-06-19 00:08:026583 scroll_parent->SetDrawsContent(true);
6584 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596585
danakjf78fb272016-07-26 19:06:156586 root->SetBounds(gfx::Size(50, 50));
6587 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6588 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:596589 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156590 scroll_parent->SetBounds(gfx::Size(50, 50));
6591 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596592
jaydasika1c0a27d42016-04-28 01:54:566593 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156594 scroll_parent->test_properties()->scroll_children =
6595 base::MakeUnique<std::set<LayerImpl*>>();
6596 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596597
enne03b0e9a2015-06-19 00:08:026598 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596599
6600 EXPECT_TRUE(root->render_surface());
6601
jaydasika6f972de2016-04-07 16:16:146602 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596603 EXPECT_TRUE(scroll_child->is_clipped());
6604}
6605
6606TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6607 // Checks that clipping by a scroll parent and scroll grandparent that follow
6608 // you in paint order still results in correct clipping.
6609 //
6610 // + root
6611 // + scroll_child
6612 // + scroll_parent_border
6613 // | + scroll_parent_clip
6614 // | + scroll_parent
6615 // + scroll_grandparent_border
6616 // + scroll_grandparent_clip
6617 // + scroll_grandparent
6618 //
jaydasikabf1875a2016-06-28 03:39:596619 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026620 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6621 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6622 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6623 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6624 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6625 LayerImpl* scroll_grandparent_clip =
6626 AddChild<LayerImpl>(scroll_grandparent_border);
6627 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596628
enne03b0e9a2015-06-19 00:08:026629 scroll_parent->SetDrawsContent(true);
6630 scroll_grandparent->SetDrawsContent(true);
6631 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596632
6633 scroll_parent_clip->SetMasksToBounds(true);
6634 scroll_grandparent_clip->SetMasksToBounds(true);
6635
jaydasika1c0a27d42016-04-28 01:54:566636 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156637 scroll_parent->test_properties()->scroll_children =
6638 base::MakeUnique<std::set<LayerImpl*>>();
6639 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386640
jaydasika1c0a27d42016-04-28 01:54:566641 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156642 scroll_grandparent->test_properties()->scroll_children =
6643 base::MakeUnique<std::set<LayerImpl*>>();
6644 scroll_grandparent->test_properties()->scroll_children->insert(
6645 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596646
danakjf78fb272016-07-26 19:06:156647 root->SetBounds(gfx::Size(50, 50));
6648 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6649 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6650 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6651 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6652 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6653 scroll_parent->SetBounds(gfx::Size(50, 50));
6654 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596655
enne03b0e9a2015-06-19 00:08:026656 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596657
6658 EXPECT_TRUE(root->render_surface());
6659
jaydasika6f972de2016-04-07 16:16:146660 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596661 EXPECT_TRUE(scroll_child->is_clipped());
6662
6663 // Despite the fact that we visited the above layers out of order to get the
6664 // correct clip, the layer lists should be unaffected.
6665 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026666 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6667 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6668 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596669}
6670
6671TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6672 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226673 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596674 // + root
6675 // + scroll_child
6676 // + scroll_parent_border
6677 // + scroll_parent_clip
6678 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026679 // + render_surface2
[email protected]995708c52013-10-17 20:52:596680 // + scroll_grandparent_border
6681 // + scroll_grandparent_clip
6682 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026683 // + render_surface1
[email protected]995708c52013-10-17 20:52:596684 //
jaydasikabf1875a2016-06-28 03:39:596685 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026686 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596687
enne03b0e9a2015-06-19 00:08:026688 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6689 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596690
enne03b0e9a2015-06-19 00:08:026691 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6692 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6693 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6694 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6695 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6696 LayerImpl* scroll_grandparent_clip =
6697 AddChild<LayerImpl>(scroll_grandparent_border);
6698 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6699 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596700
enne03b0e9a2015-06-19 00:08:026701 scroll_parent->SetDrawsContent(true);
6702 render_surface1->SetDrawsContent(true);
6703 scroll_grandparent->SetDrawsContent(true);
6704 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596705
6706 scroll_parent_clip->SetMasksToBounds(true);
6707 scroll_grandparent_clip->SetMasksToBounds(true);
6708
jaydasika1c0a27d42016-04-28 01:54:566709 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156710 scroll_parent->test_properties()->scroll_children =
6711 base::MakeUnique<std::set<LayerImpl*>>();
6712 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386713
jaydasika1c0a27d42016-04-28 01:54:566714 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156715 scroll_grandparent->test_properties()->scroll_children =
6716 base::MakeUnique<std::set<LayerImpl*>>();
6717 scroll_grandparent->test_properties()->scroll_children->insert(
6718 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596719
danakjf78fb272016-07-26 19:06:156720 root->SetBounds(gfx::Size(50, 50));
6721 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6722 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6723 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6724 render_surface1->SetBounds(gfx::Size(50, 50));
6725 render_surface1->test_properties()->force_render_surface = true;
6726 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6727 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6728 scroll_parent->SetBounds(gfx::Size(50, 50));
6729 render_surface2->SetBounds(gfx::Size(50, 50));
6730 render_surface2->test_properties()->force_render_surface = true;
6731 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596732
enne03b0e9a2015-06-19 00:08:026733 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596734
6735 EXPECT_TRUE(root->render_surface());
6736
jaydasika6f972de2016-04-07 16:16:146737 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596738 EXPECT_TRUE(scroll_child->is_clipped());
6739
6740 // Despite the fact that we had to process the layers out of order to get the
6741 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026742 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6743 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6744 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6745 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6746 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6747 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6748 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596749}
6750
ajuma0b10f942015-03-21 07:45:536751TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6752 // Ensures that when we have a render surface between a fixed position layer
6753 // and its container, we compute the fixed position layer's draw transform
6754 // with respect to that intervening render surface, not with respect to its
6755 // container's render target.
6756 //
6757 // + root
6758 // + render_surface
6759 // + fixed
ajuma737b2702015-05-06 01:18:376760 // + child
ajuma0b10f942015-03-21 07:45:536761 //
jaydasikabf1875a2016-06-28 03:39:596762 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516763 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6764 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6765 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536766
jaydasika6b5a32bf2016-04-22 21:56:366767 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526768 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536769
6770 LayerPositionConstraint constraint;
6771 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526772 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536773
danakjf78fb272016-07-26 19:06:156774 root->SetBounds(gfx::Size(50, 50));
6775 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6776 render_surface->SetBounds(gfx::Size(50, 50));
6777 render_surface->SetDrawsContent(true);
6778 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6779 fixed->SetBounds(gfx::Size(50, 50));
6780 fixed->SetDrawsContent(true);
6781 child->SetPosition(gfx::PointF(1.f, 2.f));
6782 child->SetBounds(gfx::Size(50, 50));
6783 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516784 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536785
jaydasikabaede2d92016-07-20 00:34:326786 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516787 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326788 EffectTree& effect_tree =
6789 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156790
ajuma737b2702015-05-06 01:18:376791 gfx::Transform expected_fixed_draw_transform;
6792 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026793 EXPECT_TRANSFORMATION_MATRIX_EQ(
6794 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326795 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536796
ajuma737b2702015-05-06 01:18:376797 gfx::Transform expected_fixed_screen_space_transform;
6798 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026799 EXPECT_TRANSFORMATION_MATRIX_EQ(
6800 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326801 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376802
6803 gfx::Transform expected_child_draw_transform;
6804 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026805 EXPECT_TRANSFORMATION_MATRIX_EQ(
6806 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326807 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376808
6809 gfx::Transform expected_child_screen_space_transform;
6810 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026811 EXPECT_TRANSFORMATION_MATRIX_EQ(
6812 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326813 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536814}
6815
[email protected]d81752b2013-10-25 08:32:236816TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6817 // This test verifies that a scrolling layer that gets snapped to
6818 // integer coordinates doesn't move a fixed position child.
6819 //
6820 // + root
6821 // + container
6822 // + scroller
6823 // + fixed
6824 //
khushalsagarb64b360d2015-10-21 19:25:166825 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:566826 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:226827 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236828 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486829 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426830 LayerImpl::Create(host_impl.active_tree(), 1);
6831 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486832 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236833 LayerImpl::Create(host_impl.active_tree(), 2);
6834 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486835 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236836 LayerImpl::Create(host_impl.active_tree(), 3);
6837 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486838 std::unique_ptr<LayerImpl> fixed =
6839 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236840 LayerImpl* fixed_layer = fixed.get();
6841
jaydasikaca2605e2016-04-23 02:52:526842 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236843
6844 LayerPositionConstraint constraint;
6845 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526846 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236847
[email protected]adeda572014-01-31 00:49:476848 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236849
[email protected]d81752b2013-10-25 08:32:236850 gfx::Transform container_transform;
6851 container_transform.Translate3d(10.0, 20.0, 0.0);
6852 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6853
danakjf78fb272016-07-26 19:06:156854 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046855 container->test_properties()->transform = container_transform;
danakjf78fb272016-07-26 19:06:156856 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286857 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156858 scroller->SetBounds(gfx::Size(30, 30));
jaydasika0d98ba92015-11-17 05:17:286859 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156860 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286861 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156862
jaydasika89f7b5a2016-06-22 02:08:396863 scroller->test_properties()->AddChild(std::move(fixed));
6864 container->test_properties()->AddChild(std::move(scroller));
6865 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486866 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6867 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236868
6869 // Rounded to integers already.
6870 {
6871 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426872 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236873
6874 LayerImplList render_surface_layer_list;
6875 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386876 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:426877 root->layer_tree_impl()
6878 ->property_trees()
6879 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576880 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236881
6882 EXPECT_TRANSFORMATION_MATRIX_EQ(
6883 container_layer->draw_properties().screen_space_transform,
6884 fixed_layer->draw_properties().screen_space_transform);
6885 EXPECT_VECTOR_EQ(
6886 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6887 container_offset);
6888 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6889 .screen_space_transform.To2dTranslation(),
6890 container_offset - scroll_delta);
6891 }
6892
6893 // Scroll delta requiring rounding.
6894 {
6895 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426896 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236897
6898 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6899
6900 LayerImplList render_surface_layer_list;
6901 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386902 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576903 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236904
6905 EXPECT_TRANSFORMATION_MATRIX_EQ(
6906 container_layer->draw_properties().screen_space_transform,
6907 fixed_layer->draw_properties().screen_space_transform);
6908 EXPECT_VECTOR_EQ(
6909 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6910 container_offset);
6911 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6912 .screen_space_transform.To2dTranslation(),
6913 container_offset - rounded_scroll_delta);
6914 }
[email protected]cf15ad7b2014-04-02 03:59:266915
6916 // Scale is applied earlier in the tree.
6917 {
sunxdb7e79432016-03-09 21:13:426918 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266919 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286920 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:046921 container_layer->test_properties()->transform = scaled_container_transform;
danakj74af409e2016-07-01 00:41:486922
jaydasika0d98ba92015-11-17 05:17:286923 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266924
6925 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426926 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266927
6928 LayerImplList render_surface_layer_list;
6929 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386930 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576931 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266932
6933 EXPECT_TRANSFORMATION_MATRIX_EQ(
6934 container_layer->draw_properties().screen_space_transform,
6935 fixed_layer->draw_properties().screen_space_transform);
6936 EXPECT_VECTOR_EQ(
6937 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6938 container_offset);
6939
jaydasika10d43fc2016-08-18 04:06:046940 container_layer->test_properties()->transform = container_transform;
[email protected]cf15ad7b2014-04-02 03:59:266941 }
[email protected]d81752b2013-10-25 08:32:236942}
6943
miletus2c78036b2015-01-29 20:52:376944TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506945 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6946 // This test verifies that a scrolling layer whose screen space transform is
6947 // animating doesn't get snapped to integer coordinates.
6948 //
6949 // + root
6950 // + animated layer
6951 // + surface
6952 // + container
6953 // + scroller
6954 //
jaydasikabf1875a2016-06-28 03:39:596955 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506956 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6957 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6958 LayerImpl* container = AddChild<LayerImpl>(surface);
6959 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506960
ajuma5e8e40d2015-07-31 01:50:506961 gfx::Transform start_scale;
6962 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156963
6964 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046965 animated_layer->test_properties()->transform = start_scale;
danakjf78fb272016-07-26 19:06:156966 animated_layer->SetBounds(gfx::Size(50, 50));
6967 surface->SetBounds(gfx::Size(50, 50));
6968 surface->test_properties()->force_render_surface = true;
6969 container->SetBounds(gfx::Size(50, 50));
6970 scroller->SetBounds(gfx::Size(100, 100));
6971 scroller->SetScrollClipLayer(container->id());
6972 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506973
6974 gfx::Transform end_scale;
6975 end_scale.Scale(2.f, 2.f);
6976 TransformOperations start_operations;
6977 start_operations.AppendMatrix(start_scale);
6978 TransformOperations end_operations;
6979 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276980 SetElementIdsForTesting();
6981
6982 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6983 timeline_impl(), 1.0,
6984 start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:506985 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426986 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506987
6988 ExecuteCalculateDrawProperties(root);
6989
6990 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6991 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446992 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506993}
6994
sunxd8a9a60982016-07-29 18:46:566995TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6996 // This test verifies that a scrolling child of a scrolling layer doesn't get
6997 // snapped to integer coordinates.
6998 //
6999 // + root
7000 // + container
7001 // + scroller
7002 // + scroll_child
7003 //
7004 scoped_refptr<Layer> root = Layer::Create();
7005 scoped_refptr<Layer> container = Layer::Create();
7006 scoped_refptr<Layer> scroller = Layer::Create();
7007 scoped_refptr<Layer> scroll_child = Layer::Create();
7008 root->AddChild(container);
7009 root->AddChild(scroll_child);
7010 container->AddChild(scroller);
7011 host()->SetRootLayer(root);
7012
7013 scroller->SetScrollClipLayerId(container->id());
7014 scroll_child->SetScrollParent(scroller.get());
7015
7016 gfx::Transform rotate;
7017 rotate.RotateAboutYAxis(30);
7018 root->SetBounds(gfx::Size(50, 50));
7019 container->SetBounds(gfx::Size(50, 50));
7020 scroller->SetBounds(gfx::Size(100, 100));
7021 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7022 scroll_child->SetBounds(gfx::Size(10, 10));
7023 scroll_child->SetTransform(rotate);
7024
7025 ExecuteCalculateDrawProperties(root.get());
7026
7027 host()->host_impl()->CreatePendingTree();
7028 host()->CommitAndCreatePendingTree();
7029 host()->host_impl()->ActivateSyncTree();
7030 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7031
7032 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7033 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7034 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
7035 gfx::Vector2dF scroll_delta(5.f, 9.f);
7036 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7037
7038 ExecuteCalculateDrawProperties(root_impl);
7039
7040 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7041 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7042 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7043
7044 gfx::Transform expected_scroll_child_screen_space_transform;
7045 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
7046 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
7047 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
7048 scroll_child_impl->ScreenSpaceTransform());
7049}
7050
flackr2215b4e2016-09-21 20:16:017051TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
7052 scoped_refptr<Layer> root = Layer::Create();
7053 scoped_refptr<Layer> container = Layer::Create();
7054 scoped_refptr<Layer> scroller = Layer::Create();
7055 scoped_refptr<Layer> sticky_pos = Layer::Create();
7056 root->AddChild(container);
7057 container->AddChild(scroller);
7058 scroller->AddChild(sticky_pos);
7059 host()->SetRootLayer(root);
7060 scroller->SetScrollClipLayerId(container->id());
7061
7062 LayerStickyPositionConstraint sticky_position;
7063 sticky_position.is_sticky = true;
7064 sticky_position.is_anchored_top = true;
7065 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:427066 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
flackr2215b4e2016-09-21 20:16:017067 sticky_position.scroll_container_relative_sticky_box_rect =
7068 gfx::Rect(10, 20, 10, 10);
7069 sticky_position.scroll_container_relative_containing_block_rect =
7070 gfx::Rect(0, 0, 50, 50);
7071 sticky_pos->SetStickyPositionConstraint(sticky_position);
7072
7073 root->SetBounds(gfx::Size(100, 100));
7074 container->SetBounds(gfx::Size(100, 100));
7075 scroller->SetBounds(gfx::Size(1000, 1000));
7076 sticky_pos->SetBounds(gfx::Size(10, 10));
7077 sticky_pos->SetPosition(gfx::PointF(10, 20));
7078
7079 ExecuteCalculateDrawProperties(root.get());
7080 host()->host_impl()->CreatePendingTree();
7081 host()->CommitAndCreatePendingTree();
7082 host()->host_impl()->ActivateSyncTree();
7083 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7084
7085 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7086 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7087 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7088
7089 ExecuteCalculateDrawProperties(root_impl);
7090 EXPECT_VECTOR2DF_EQ(
7091 gfx::Vector2dF(10.f, 20.f),
7092 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7093
7094 // Scroll less than sticking point, sticky element should move with scroll as
7095 // we haven't gotten to the initial sticky item location yet.
7096 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7097 ExecuteCalculateDrawProperties(root_impl);
7098 EXPECT_VECTOR2DF_EQ(
7099 gfx::Vector2dF(5.f, 15.f),
7100 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7101
7102 // Scroll past the sticking point, the Y coordinate should now be clamped.
7103 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7104 ExecuteCalculateDrawProperties(root_impl);
7105 EXPECT_VECTOR2DF_EQ(
7106 gfx::Vector2dF(-5.f, 10.f),
7107 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7108 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
7109 ExecuteCalculateDrawProperties(root_impl);
7110 EXPECT_VECTOR2DF_EQ(
7111 gfx::Vector2dF(-5.f, 10.f),
7112 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7113
7114 // Scroll past the end of the sticky container (note: this element does not
7115 // have its own layer as it does not need to be composited).
7116 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
7117 ExecuteCalculateDrawProperties(root_impl);
7118 EXPECT_VECTOR2DF_EQ(
7119 gfx::Vector2dF(-5.f, -10.f),
7120 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7121}
7122
flackrd2ae03f2016-11-14 19:22:057123TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) {
7124 scoped_refptr<Layer> root = Layer::Create();
7125 scoped_refptr<Layer> container = Layer::Create();
7126 scoped_refptr<Layer> scroller = Layer::Create();
7127 scoped_refptr<Layer> sticky_pos = Layer::Create();
7128 root->AddChild(container);
7129 container->AddChild(scroller);
7130 root->AddChild(sticky_pos);
7131 sticky_pos->SetScrollParent(scroller.get());
7132 host()->SetRootLayer(root);
7133 scroller->SetScrollClipLayerId(container->id());
7134
7135 LayerStickyPositionConstraint sticky_position;
7136 sticky_position.is_sticky = true;
7137 sticky_position.is_anchored_top = true;
7138 sticky_position.top_offset = 10.0f;
7139 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
7140 sticky_position.scroll_container_relative_sticky_box_rect =
7141 gfx::Rect(10, 20, 10, 10);
7142 sticky_position.scroll_container_relative_containing_block_rect =
7143 gfx::Rect(0, 0, 50, 50);
7144 sticky_pos->SetStickyPositionConstraint(sticky_position);
7145
7146 root->SetBounds(gfx::Size(200, 200));
7147 container->SetBounds(gfx::Size(100, 100));
7148 container->SetPosition(gfx::PointF(50, 50));
7149 scroller->SetBounds(gfx::Size(1000, 1000));
7150 sticky_pos->SetBounds(gfx::Size(10, 10));
7151 sticky_pos->SetPosition(gfx::PointF(60, 70));
7152
7153 ExecuteCalculateDrawProperties(root.get());
7154 host()->host_impl()->CreatePendingTree();
7155 host()->CommitAndCreatePendingTree();
7156 host()->host_impl()->ActivateSyncTree();
7157 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7158
7159 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7160 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7161 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7162
7163 ExecuteCalculateDrawProperties(root_impl);
7164 EXPECT_VECTOR2DF_EQ(
7165 gfx::Vector2dF(60.f, 70.f),
7166 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7167
7168 // Scroll less than sticking point, sticky element should move with scroll as
7169 // we haven't gotten to the initial sticky item location yet.
7170 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7171 ExecuteCalculateDrawProperties(root_impl);
7172 EXPECT_VECTOR2DF_EQ(
7173 gfx::Vector2dF(55.f, 65.f),
7174 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7175
7176 // Scroll past the sticking point, the Y coordinate should now be clamped.
7177 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7178 ExecuteCalculateDrawProperties(root_impl);
7179 EXPECT_VECTOR2DF_EQ(
7180 gfx::Vector2dF(45.f, 60.f),
7181 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7182 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
7183 ExecuteCalculateDrawProperties(root_impl);
7184 EXPECT_VECTOR2DF_EQ(
7185 gfx::Vector2dF(45.f, 60.f),
7186 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7187
7188 // Scroll past the end of the sticky container (note: this element does not
7189 // have its own layer as it does not need to be composited).
7190 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
7191 ExecuteCalculateDrawProperties(root_impl);
7192 EXPECT_VECTOR2DF_EQ(
7193 gfx::Vector2dF(45.f, 40.f),
7194 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7195}
7196
flackrdc5dfbe2016-10-24 21:43:387197TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) {
7198 scoped_refptr<Layer> root = Layer::Create();
7199 scoped_refptr<Layer> container = Layer::Create();
7200 scoped_refptr<Layer> scroller = Layer::Create();
7201 scoped_refptr<Layer> sticky_pos = Layer::Create();
7202 root->AddChild(container);
7203 container->AddChild(scroller);
7204 scroller->AddChild(sticky_pos);
7205 host()->SetRootLayer(root);
7206 scroller->SetScrollClipLayerId(container->id());
7207
7208 LayerStickyPositionConstraint sticky_position;
7209 sticky_position.is_sticky = true;
7210 sticky_position.is_anchored_bottom = true;
7211 sticky_position.bottom_offset = 10.0f;
7212 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200);
7213 sticky_position.scroll_container_relative_sticky_box_rect =
7214 gfx::Rect(0, 200, 10, 10);
7215 sticky_position.scroll_container_relative_containing_block_rect =
7216 gfx::Rect(0, 0, 100, 500);
7217 sticky_pos->SetStickyPositionConstraint(sticky_position);
7218
7219 root->SetBounds(gfx::Size(100, 100));
7220 container->SetBounds(gfx::Size(100, 100));
7221 scroller->SetBounds(gfx::Size(100, 1000));
7222 sticky_pos->SetBounds(gfx::Size(10, 10));
7223 sticky_pos->SetPosition(gfx::PointF(0, 200));
7224
7225 ExecuteCalculateDrawProperties(root.get());
7226 host()->host_impl()->CreatePendingTree();
7227 host()->CommitAndCreatePendingTree();
7228 host()->host_impl()->ActivateSyncTree();
7229 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7230
7231 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7232 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7233 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7234
7235 ExecuteCalculateDrawProperties(root_impl);
7236 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f));
7237 ExecuteCalculateDrawProperties(root_impl);
7238 EXPECT_VECTOR2DF_EQ(
7239 gfx::Vector2dF(0.f, 80.f),
7240 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7241}
7242
flackr2215b4e2016-09-21 20:16:017243TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
7244 scoped_refptr<Layer> root = Layer::Create();
7245 scoped_refptr<Layer> container = Layer::Create();
7246 scoped_refptr<Layer> scroller = Layer::Create();
7247 scoped_refptr<Layer> sticky_pos = Layer::Create();
7248 root->AddChild(container);
7249 container->AddChild(scroller);
7250 scroller->AddChild(sticky_pos);
7251 host()->SetRootLayer(root);
7252 scroller->SetScrollClipLayerId(container->id());
7253
7254 LayerStickyPositionConstraint sticky_position;
7255 sticky_position.is_sticky = true;
7256 sticky_position.is_anchored_bottom = true;
7257 sticky_position.bottom_offset = 10.0f;
flackr68e1c292016-10-11 16:34:427258 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150);
flackr2215b4e2016-09-21 20:16:017259 sticky_position.scroll_container_relative_sticky_box_rect =
7260 gfx::Rect(0, 150, 10, 10);
7261 sticky_position.scroll_container_relative_containing_block_rect =
7262 gfx::Rect(0, 100, 50, 50);
7263 sticky_pos->SetStickyPositionConstraint(sticky_position);
7264
7265 root->SetBounds(gfx::Size(100, 100));
7266 container->SetBounds(gfx::Size(100, 100));
7267 scroller->SetBounds(gfx::Size(1000, 1000));
7268 sticky_pos->SetBounds(gfx::Size(10, 10));
7269 sticky_pos->SetPosition(gfx::PointF(0, 150));
7270
7271 ExecuteCalculateDrawProperties(root.get());
7272 host()->host_impl()->CreatePendingTree();
7273 host()->CommitAndCreatePendingTree();
7274 host()->host_impl()->ActivateSyncTree();
7275 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7276
7277 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7278 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7279 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7280
7281 // Initially the sticky element is moved up to the top of the container.
7282 ExecuteCalculateDrawProperties(root_impl);
7283 EXPECT_VECTOR2DF_EQ(
7284 gfx::Vector2dF(0.f, 100.f),
7285 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7286 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7287 ExecuteCalculateDrawProperties(root_impl);
7288 EXPECT_VECTOR2DF_EQ(
7289 gfx::Vector2dF(0.f, 95.f),
7290 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7291
7292 // Once we get past the top of the container it moves to be aligned 10px
7293 // up from the the bottom of the scroller.
7294 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7295 ExecuteCalculateDrawProperties(root_impl);
7296 EXPECT_VECTOR2DF_EQ(
7297 gfx::Vector2dF(0.f, 80.f),
7298 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7299 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7300 ExecuteCalculateDrawProperties(root_impl);
7301 EXPECT_VECTOR2DF_EQ(
7302 gfx::Vector2dF(0.f, 80.f),
7303 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7304
7305 // Once we scroll past its initial location, it sticks there.
7306 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
7307 ExecuteCalculateDrawProperties(root_impl);
7308 EXPECT_VECTOR2DF_EQ(
7309 gfx::Vector2dF(0.f, 0.f),
7310 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7311}
7312
flackra283bed2016-10-31 14:49:427313TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) {
flackre310f292016-10-12 21:09:287314 scoped_refptr<Layer> root = Layer::Create();
7315 scoped_refptr<Layer> scroller = Layer::Create();
7316 scoped_refptr<Layer> sticky_pos = Layer::Create();
7317 root->AddChild(scroller);
7318 scroller->AddChild(sticky_pos);
7319 host()->SetRootLayer(root);
7320 scroller->SetScrollClipLayerId(root->id());
khushalsagarb69ba9452017-01-27 22:20:077321 host()->RegisterViewportLayers(nullptr, root, scroller, nullptr);
flackre310f292016-10-12 21:09:287322
7323 LayerStickyPositionConstraint sticky_position;
7324 sticky_position.is_sticky = true;
7325 sticky_position.is_anchored_bottom = true;
7326 sticky_position.bottom_offset = 10.0f;
flackra283bed2016-10-31 14:49:427327 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70);
flackre310f292016-10-12 21:09:287328 sticky_position.scroll_container_relative_sticky_box_rect =
flackra283bed2016-10-31 14:49:427329 gfx::Rect(0, 70, 10, 10);
flackre310f292016-10-12 21:09:287330 sticky_position.scroll_container_relative_containing_block_rect =
flackra283bed2016-10-31 14:49:427331 gfx::Rect(0, 60, 100, 100);
flackre310f292016-10-12 21:09:287332 sticky_pos->SetStickyPositionConstraint(sticky_position);
7333
7334 root->SetBounds(gfx::Size(100, 100));
7335 scroller->SetBounds(gfx::Size(100, 1000));
7336 sticky_pos->SetBounds(gfx::Size(10, 10));
flackra283bed2016-10-31 14:49:427337 sticky_pos->SetPosition(gfx::PointF(0, 70));
flackre310f292016-10-12 21:09:287338
7339 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
flackra283bed2016-10-31 14:49:427340 scroller.get(), nullptr);
flackre310f292016-10-12 21:09:287341 host()->CommitAndCreateLayerImplTree();
7342 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7343 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7344 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id());
7345
7346 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
7347 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7348
7349 // Initially the sticky element is moved to the bottom of the container.
7350 EXPECT_VECTOR2DF_EQ(
flackra283bed2016-10-31 14:49:427351 gfx::Vector2dF(0.f, 70.f),
flackre310f292016-10-12 21:09:287352 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7353
flackra283bed2016-10-31 14:49:427354 // We start to hide the toolbar, but not far enough that the sticky element
7355 // should be moved up yet.
flackre310f292016-10-12 21:09:287356 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f));
flackra283bed2016-10-31 14:49:427357 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7358 nullptr);
flackre310f292016-10-12 21:09:287359 EXPECT_VECTOR2DF_EQ(
7360 gfx::Vector2dF(0.f, 70.f),
7361 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackra283bed2016-10-31 14:49:427362
7363 // On hiding more of the toolbar the sticky element starts to stick.
7364 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f));
7365 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7366 nullptr);
7367 EXPECT_VECTOR2DF_EQ(
7368 gfx::Vector2dF(0.f, 60.f),
7369 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7370
7371 // On hiding more the sticky element stops moving as it has reached its
7372 // limit.
7373 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f));
7374 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7375 nullptr);
7376 EXPECT_VECTOR2DF_EQ(
7377 gfx::Vector2dF(0.f, 60.f),
7378 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7379}
7380
7381TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) {
7382 scoped_refptr<Layer> root = Layer::Create();
7383 scoped_refptr<Layer> scroller = Layer::Create();
7384 scoped_refptr<Layer> outer_clip = Layer::Create();
7385 scoped_refptr<Layer> outer_viewport = Layer::Create();
7386 scoped_refptr<Layer> sticky_pos = Layer::Create();
7387 root->AddChild(scroller);
7388 scroller->AddChild(outer_clip);
7389 outer_clip->AddChild(outer_viewport);
7390 outer_viewport->AddChild(sticky_pos);
7391 host()->SetRootLayer(root);
7392 scroller->SetScrollClipLayerId(root->id());
7393 outer_viewport->SetScrollClipLayerId(outer_clip->id());
khushalsagarb69ba9452017-01-27 22:20:077394 host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport);
flackra283bed2016-10-31 14:49:427395
7396 LayerStickyPositionConstraint sticky_position;
7397 sticky_position.is_sticky = true;
7398 sticky_position.is_anchored_bottom = true;
7399 sticky_position.bottom_offset = 10.0f;
7400 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70);
7401 sticky_position.scroll_container_relative_sticky_box_rect =
7402 gfx::Rect(0, 70, 10, 10);
7403 sticky_position.scroll_container_relative_containing_block_rect =
7404 gfx::Rect(0, 60, 100, 100);
7405 sticky_pos->SetStickyPositionConstraint(sticky_position);
7406
7407 root->SetBounds(gfx::Size(100, 100));
7408 scroller->SetBounds(gfx::Size(100, 1000));
7409 outer_clip->SetBounds(gfx::Size(100, 100));
7410 sticky_pos->SetBounds(gfx::Size(10, 10));
7411 sticky_pos->SetPosition(gfx::PointF(0, 70));
7412
7413 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7414 scroller.get(), outer_viewport.get());
7415 host()->CommitAndCreateLayerImplTree();
7416 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7417 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7418 ASSERT_EQ(outer_viewport->id(),
7419 layer_tree_impl->OuterViewportScrollLayer()->id());
7420
7421 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
7422 LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer();
7423 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7424 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id());
7425
7426 // Initially the sticky element is moved to the bottom of the container.
7427 EXPECT_VECTOR2DF_EQ(
7428 gfx::Vector2dF(0.f, 70.f),
7429 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7430
7431 // We start to hide the toolbar, but not far enough that the sticky element
7432 // should be moved up yet.
7433 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f));
7434 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7435 outer_scroll);
7436 EXPECT_VECTOR2DF_EQ(
7437 gfx::Vector2dF(0.f, 70.f),
7438 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7439
7440 // On hiding more of the toolbar the sticky element starts to stick.
7441 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f));
7442 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7443 outer_scroll);
7444
7445 // On hiding more the sticky element stops moving as it has reached its
7446 // limit.
7447 EXPECT_VECTOR2DF_EQ(
7448 gfx::Vector2dF(0.f, 60.f),
7449 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7450
7451 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f));
7452 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7453 outer_scroll);
7454
7455 EXPECT_VECTOR2DF_EQ(
7456 gfx::Vector2dF(0.f, 60.f),
7457 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackre310f292016-10-12 21:09:287458}
7459
flackr2215b4e2016-09-21 20:16:017460TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
7461 scoped_refptr<Layer> root = Layer::Create();
7462 scoped_refptr<Layer> container = Layer::Create();
7463 scoped_refptr<Layer> scroller = Layer::Create();
7464 scoped_refptr<Layer> sticky_pos = Layer::Create();
7465 root->AddChild(container);
7466 container->AddChild(scroller);
7467 scroller->AddChild(sticky_pos);
7468 host()->SetRootLayer(root);
7469 scroller->SetScrollClipLayerId(container->id());
7470
7471 LayerStickyPositionConstraint sticky_position;
7472 sticky_position.is_sticky = true;
7473 sticky_position.is_anchored_left = true;
7474 sticky_position.is_anchored_right = true;
7475 sticky_position.left_offset = 10.f;
7476 sticky_position.right_offset = 10.f;
flackr68e1c292016-10-11 16:34:427477 sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0);
flackr2215b4e2016-09-21 20:16:017478 sticky_position.scroll_container_relative_sticky_box_rect =
7479 gfx::Rect(145, 0, 10, 10);
7480 sticky_position.scroll_container_relative_containing_block_rect =
7481 gfx::Rect(100, 0, 100, 100);
7482 sticky_pos->SetStickyPositionConstraint(sticky_position);
7483
7484 root->SetBounds(gfx::Size(100, 100));
7485 container->SetBounds(gfx::Size(100, 100));
7486 scroller->SetBounds(gfx::Size(1000, 1000));
7487 sticky_pos->SetBounds(gfx::Size(10, 10));
7488 sticky_pos->SetPosition(gfx::PointF(145, 0));
7489
7490 ExecuteCalculateDrawProperties(root.get());
7491 host()->host_impl()->CreatePendingTree();
7492 host()->CommitAndCreatePendingTree();
7493 host()->host_impl()->ActivateSyncTree();
7494 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7495
7496 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7497 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7498 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7499
7500 // Initially the sticky element is moved the leftmost side of the container.
7501 ExecuteCalculateDrawProperties(root_impl);
7502 EXPECT_VECTOR2DF_EQ(
7503 gfx::Vector2dF(100.f, 0.f),
7504 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7505 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
7506 ExecuteCalculateDrawProperties(root_impl);
7507 EXPECT_VECTOR2DF_EQ(
7508 gfx::Vector2dF(95.f, 0.f),
7509 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7510
7511 // Once we get past the left side of the container it moves to be aligned 10px
7512 // up from the the right of the scroller.
7513 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
7514 ExecuteCalculateDrawProperties(root_impl);
7515 EXPECT_VECTOR2DF_EQ(
7516 gfx::Vector2dF(80.f, 0.f),
7517 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7518 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
7519 ExecuteCalculateDrawProperties(root_impl);
7520 EXPECT_VECTOR2DF_EQ(
7521 gfx::Vector2dF(80.f, 0.f),
7522 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7523
7524 // When we get to the sticky element's original position we stop sticking
7525 // to the right.
7526 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
7527 ExecuteCalculateDrawProperties(root_impl);
7528 EXPECT_VECTOR2DF_EQ(
7529 gfx::Vector2dF(50.f, 0.f),
7530 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7531 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
7532 ExecuteCalculateDrawProperties(root_impl);
7533 EXPECT_VECTOR2DF_EQ(
7534 gfx::Vector2dF(40.f, 0.f),
7535 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7536
7537 // The element starts sticking to the left once we scroll far enough.
7538 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
7539 ExecuteCalculateDrawProperties(root_impl);
7540 EXPECT_VECTOR2DF_EQ(
7541 gfx::Vector2dF(10.f, 0.f),
7542 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7543 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
7544 ExecuteCalculateDrawProperties(root_impl);
7545 EXPECT_VECTOR2DF_EQ(
7546 gfx::Vector2dF(10.f, 0.f),
7547 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7548
7549 // Finally it stops sticking when it hits the right side of the container.
7550 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
7551 ExecuteCalculateDrawProperties(root_impl);
7552 EXPECT_VECTOR2DF_EQ(
7553 gfx::Vector2dF(0.f, 0.f),
7554 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7555 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
7556 ExecuteCalculateDrawProperties(root_impl);
7557 EXPECT_VECTOR2DF_EQ(
7558 gfx::Vector2dF(-5.f, 0.f),
7559 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7560}
7561
7562// This test ensures that the compositor sticky position code correctly accounts
7563// for the element having been given a position from the main thread sticky
7564// position code.
7565TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
7566 scoped_refptr<Layer> root = Layer::Create();
7567 scoped_refptr<Layer> container = Layer::Create();
7568 scoped_refptr<Layer> scroller = Layer::Create();
7569 scoped_refptr<Layer> sticky_pos = Layer::Create();
7570 root->AddChild(container);
7571 container->AddChild(scroller);
7572 scroller->AddChild(sticky_pos);
7573 host()->SetRootLayer(root);
7574 scroller->SetScrollClipLayerId(container->id());
7575
7576 LayerStickyPositionConstraint sticky_position;
7577 sticky_position.is_sticky = true;
7578 sticky_position.is_anchored_top = true;
7579 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:427580 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
flackr2215b4e2016-09-21 20:16:017581 sticky_position.scroll_container_relative_sticky_box_rect =
7582 gfx::Rect(10, 20, 10, 10);
7583 sticky_position.scroll_container_relative_containing_block_rect =
7584 gfx::Rect(0, 0, 50, 50);
7585 sticky_pos->SetStickyPositionConstraint(sticky_position);
7586
7587 root->SetBounds(gfx::Size(100, 100));
7588 container->SetBounds(gfx::Size(100, 100));
7589 scroller->SetBounds(gfx::Size(1000, 1000));
7590 sticky_pos->SetBounds(gfx::Size(10, 10));
7591 sticky_pos->SetPosition(gfx::PointF(10, 20));
7592
7593 ExecuteCalculateDrawProperties(root.get());
7594 host()->host_impl()->CreatePendingTree();
7595 host()->CommitAndCreatePendingTree();
7596 host()->host_impl()->ActivateSyncTree();
7597 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7598
7599 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7600 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7601 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7602
7603 ExecuteCalculateDrawProperties(root_impl);
7604 EXPECT_VECTOR2DF_EQ(
7605 gfx::Vector2dF(10.f, 20.f),
7606 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7607
7608 // Scroll less than sticking point, sticky element should move with scroll as
7609 // we haven't gotten to the initial sticky item location yet.
7610 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7611 ExecuteCalculateDrawProperties(root_impl);
7612 EXPECT_VECTOR2DF_EQ(
7613 gfx::Vector2dF(5.f, 15.f),
7614 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7615
7616 // Scroll past the sticking point, the Y coordinate should now be clamped.
7617 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7618 ExecuteCalculateDrawProperties(root_impl);
7619 EXPECT_VECTOR2DF_EQ(
7620 gfx::Vector2dF(-5.f, 10.f),
7621 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7622
7623 // Now the main thread commits the new position of the sticky element.
7624 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
7625 sticky_pos->SetPosition(gfx::PointF(10, 25));
7626 ExecuteCalculateDrawProperties(root.get());
7627 host()->host_impl()->CreatePendingTree();
7628 host()->CommitAndCreatePendingTree();
7629 host()->host_impl()->ActivateSyncTree();
7630 layer_tree_impl = host()->host_impl()->active_tree();
7631 root_impl = layer_tree_impl->LayerById(root->id());
7632 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7633 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7634
7635 // The element should still be where it was before. We reset the delta to
7636 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
7637 // thread.
7638 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7639 ExecuteCalculateDrawProperties(root_impl);
7640 EXPECT_VECTOR2DF_EQ(
7641 gfx::Vector2dF(-5.f, 10.f),
7642 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7643
7644 // And if we scroll a little further it remains there.
7645 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7646 ExecuteCalculateDrawProperties(root_impl);
7647 EXPECT_VECTOR2DF_EQ(
7648 gfx::Vector2dF(-5.f, 10.f),
7649 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7650}
7651
flackr68e1c292016-10-11 16:34:427652// This tests the main thread updates with a composited sticky container. In
7653// this case the position received from main is relative to the container but
7654// the constraint rects are relative to the ancestor scroller.
7655TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) {
7656 scoped_refptr<Layer> root = Layer::Create();
7657 scoped_refptr<Layer> container = Layer::Create();
7658 scoped_refptr<Layer> scroller = Layer::Create();
7659 scoped_refptr<Layer> sticky_container = Layer::Create();
7660 scoped_refptr<Layer> sticky_pos = Layer::Create();
7661 root->AddChild(container);
7662 container->AddChild(scroller);
7663 scroller->AddChild(sticky_container);
7664 sticky_container->AddChild(sticky_pos);
7665 host()->SetRootLayer(root);
7666 scroller->SetScrollClipLayerId(container->id());
7667
7668 LayerStickyPositionConstraint sticky_position;
7669 sticky_position.is_sticky = true;
7670 sticky_position.is_anchored_top = true;
7671 sticky_position.top_offset = 10.0f;
7672 // The sticky position layer is only offset by (0, 10) from its parent
7673 // layer, this position is used to determine the offset applied by the main
7674 // thread.
7675 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10);
7676 sticky_position.scroll_container_relative_sticky_box_rect =
7677 gfx::Rect(20, 30, 10, 10);
7678 sticky_position.scroll_container_relative_containing_block_rect =
7679 gfx::Rect(20, 20, 30, 30);
7680 sticky_pos->SetStickyPositionConstraint(sticky_position);
7681
7682 root->SetBounds(gfx::Size(100, 100));
7683 container->SetBounds(gfx::Size(100, 100));
7684 scroller->SetBounds(gfx::Size(1000, 1000));
7685 sticky_container->SetPosition(gfx::PointF(20, 20));
7686 sticky_container->SetBounds(gfx::Size(30, 30));
7687 sticky_pos->SetBounds(gfx::Size(10, 10));
7688 sticky_pos->SetPosition(gfx::PointF(0, 10));
7689
7690 ExecuteCalculateDrawProperties(root.get());
7691 host()->host_impl()->CreatePendingTree();
7692 host()->CommitAndCreatePendingTree();
7693 host()->host_impl()->ActivateSyncTree();
7694 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7695
7696 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7697 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7698 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7699
7700 ExecuteCalculateDrawProperties(root_impl);
7701 EXPECT_VECTOR2DF_EQ(
7702 gfx::Vector2dF(20.f, 30.f),
7703 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7704
7705 // Scroll less than sticking point, sticky element should move with scroll as
7706 // we haven't gotten to the initial sticky item location yet.
7707 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7708 ExecuteCalculateDrawProperties(root_impl);
7709 EXPECT_VECTOR2DF_EQ(
7710 gfx::Vector2dF(20.f, 25.f),
7711 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7712
7713 // Scroll past the sticking point, the Y coordinate should now be clamped.
7714 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7715 ExecuteCalculateDrawProperties(root_impl);
7716 EXPECT_VECTOR2DF_EQ(
7717 gfx::Vector2dF(20.f, 10.f),
7718 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7719
7720 // Now the main thread commits the new position of the sticky element.
7721 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25));
7722 sticky_pos->SetPosition(gfx::PointF(0, 15));
7723 ExecuteCalculateDrawProperties(root.get());
7724 host()->host_impl()->CreatePendingTree();
7725 host()->CommitAndCreatePendingTree();
7726 host()->host_impl()->ActivateSyncTree();
7727 layer_tree_impl = host()->host_impl()->active_tree();
7728 root_impl = layer_tree_impl->LayerById(root->id());
7729 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7730 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7731
7732 // The element should still be where it was before. We reset the delta to
7733 // (0, 0) because we have synced a scroll offset of (0, 25) from the main
7734 // thread.
7735 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7736 ExecuteCalculateDrawProperties(root_impl);
7737 EXPECT_VECTOR2DF_EQ(
7738 gfx::Vector2dF(20.f, 10.f),
7739 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7740
7741 // And if we scroll a little further it remains there.
7742 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7743 ExecuteCalculateDrawProperties(root_impl);
7744 EXPECT_VECTOR2DF_EQ(
7745 gfx::Vector2dF(20.f, 10.f),
7746 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7747
7748 // And hits the bottom of the container.
7749 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7750 ExecuteCalculateDrawProperties(root_impl);
7751 EXPECT_VECTOR2DF_EQ(
7752 gfx::Vector2dF(20.f, 5.f),
7753 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7754}
7755
flackr2215b4e2016-09-21 20:16:017756// A transform on a sticky element should not affect its sticky position.
7757TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7758 scoped_refptr<Layer> root = Layer::Create();
7759 scoped_refptr<Layer> container = Layer::Create();
7760 scoped_refptr<Layer> scroller = Layer::Create();
7761 scoped_refptr<Layer> sticky_pos = Layer::Create();
7762 root->AddChild(container);
7763 container->AddChild(scroller);
7764 scroller->AddChild(sticky_pos);
7765 host()->SetRootLayer(root);
7766 scroller->SetScrollClipLayerId(container->id());
7767 gfx::Transform t;
7768 t.Scale(2, 2);
7769 sticky_pos->SetTransform(t);
7770
7771 LayerStickyPositionConstraint sticky_position;
7772 sticky_position.is_sticky = true;
7773 sticky_position.is_anchored_top = true;
7774 sticky_position.top_offset = 0.0f;
flackr68e1c292016-10-11 16:34:427775 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20);
flackr2215b4e2016-09-21 20:16:017776 sticky_position.scroll_container_relative_sticky_box_rect =
7777 gfx::Rect(0, 20, 10, 10);
7778 sticky_position.scroll_container_relative_containing_block_rect =
7779 gfx::Rect(0, 0, 50, 50);
7780 sticky_pos->SetStickyPositionConstraint(sticky_position);
7781
7782 root->SetBounds(gfx::Size(100, 100));
7783 container->SetBounds(gfx::Size(100, 100));
7784 scroller->SetBounds(gfx::Size(1000, 1000));
7785 sticky_pos->SetBounds(gfx::Size(10, 10));
7786 sticky_pos->SetPosition(gfx::PointF(0, 20));
7787
7788 ExecuteCalculateDrawProperties(root.get());
7789 host()->host_impl()->CreatePendingTree();
7790 host()->CommitAndCreatePendingTree();
7791 host()->host_impl()->ActivateSyncTree();
7792 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7793
7794 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7795 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7796 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7797
7798 ExecuteCalculateDrawProperties(root_impl);
7799 EXPECT_VECTOR2DF_EQ(
7800 gfx::Vector2dF(0.f, 20.f),
7801 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7802
7803 // Scroll less than sticking point, sticky element should move with scroll as
7804 // we haven't gotten to the initial sticky item location yet.
7805 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7806 ExecuteCalculateDrawProperties(root_impl);
7807 EXPECT_VECTOR2DF_EQ(
7808 gfx::Vector2dF(0.f, 5.f),
7809 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7810
7811 // Scroll past the sticking point, the box is positioned at the scroller
7812 // edge.
7813 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7814 ExecuteCalculateDrawProperties(root_impl);
7815 EXPECT_VECTOR2DF_EQ(
7816 gfx::Vector2dF(0.f, 0.f),
7817 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7818 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7819 ExecuteCalculateDrawProperties(root_impl);
7820 EXPECT_VECTOR2DF_EQ(
7821 gfx::Vector2dF(0.f, 0.f),
7822 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7823
7824 // Scroll past the end of the sticky container.
7825 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7826 ExecuteCalculateDrawProperties(root_impl);
7827 EXPECT_VECTOR2DF_EQ(
7828 gfx::Vector2dF(0.f, -10.f),
7829 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7830}
7831
7832// Tests that a transform does not affect the sticking points. The sticky
7833// element will however move relative to the viewport due to its transform.
7834TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7835 scoped_refptr<Layer> root = Layer::Create();
7836 scoped_refptr<Layer> container = Layer::Create();
7837 scoped_refptr<Layer> scroller = Layer::Create();
7838 scoped_refptr<Layer> sticky_container = Layer::Create();
7839 scoped_refptr<Layer> sticky_pos = Layer::Create();
7840 root->AddChild(container);
7841 container->AddChild(scroller);
7842 scroller->AddChild(sticky_container);
7843 sticky_container->AddChild(sticky_pos);
7844 host()->SetRootLayer(root);
7845 scroller->SetScrollClipLayerId(container->id());
7846 gfx::Transform t;
7847 t.Scale(2, 2);
7848 sticky_container->SetTransform(t);
7849
7850 LayerStickyPositionConstraint sticky_position;
7851 sticky_position.is_sticky = true;
7852 sticky_position.is_anchored_top = true;
7853 sticky_position.top_offset = 0.0f;
flackr68e1c292016-10-11 16:34:427854 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20);
flackr2215b4e2016-09-21 20:16:017855 sticky_position.scroll_container_relative_sticky_box_rect =
7856 gfx::Rect(0, 20, 10, 10);
7857 sticky_position.scroll_container_relative_containing_block_rect =
7858 gfx::Rect(0, 0, 50, 50);
7859 sticky_pos->SetStickyPositionConstraint(sticky_position);
7860
7861 root->SetBounds(gfx::Size(100, 100));
7862 container->SetBounds(gfx::Size(100, 100));
7863 scroller->SetBounds(gfx::Size(1000, 1000));
7864 sticky_container->SetBounds(gfx::Size(50, 50));
7865 sticky_pos->SetBounds(gfx::Size(10, 10));
7866 sticky_pos->SetPosition(gfx::PointF(0, 20));
7867
7868 ExecuteCalculateDrawProperties(root.get());
7869 host()->host_impl()->CreatePendingTree();
7870 host()->CommitAndCreatePendingTree();
7871 host()->host_impl()->ActivateSyncTree();
7872 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7873
7874 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7875 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7876 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7877
7878 ExecuteCalculateDrawProperties(root_impl);
7879 EXPECT_VECTOR2DF_EQ(
7880 gfx::Vector2dF(0.f, 40.f),
7881 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7882
7883 // Scroll less than sticking point, sticky element should move with scroll as
7884 // we haven't gotten to the initial sticky item location yet.
7885 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7886 ExecuteCalculateDrawProperties(root_impl);
7887 EXPECT_VECTOR2DF_EQ(
7888 gfx::Vector2dF(0.f, 25.f),
7889 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7890
7891 // Scroll past the sticking point, the box is positioned at the scroller
7892 // edge but is also scaled by its container so it begins to move down.
7893 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7894 ExecuteCalculateDrawProperties(root_impl);
7895 EXPECT_VECTOR2DF_EQ(
7896 gfx::Vector2dF(0.f, 25.f),
7897 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7898 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7899 ExecuteCalculateDrawProperties(root_impl);
7900 EXPECT_VECTOR2DF_EQ(
7901 gfx::Vector2dF(0.f, 30.f),
7902 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7903
7904 // Scroll past the end of the sticky container.
7905 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7906 ExecuteCalculateDrawProperties(root_impl);
7907 EXPECT_VECTOR2DF_EQ(
7908 gfx::Vector2dF(0.f, 30.f),
7909 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7910}
7911
jaydasikaaf1582f2016-08-10 18:39:387912TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7913 scoped_refptr<Layer> root = Layer::Create();
7914 scoped_refptr<Layer> container = Layer::Create();
7915 scoped_refptr<Layer> scroller = Layer::Create();
7916 scoped_refptr<Layer> fixed_pos = Layer::Create();
7917
7918 scroller->SetIsContainerForFixedPositionLayers(true);
7919 root->AddChild(container);
7920 container->AddChild(scroller);
7921 scroller->AddChild(fixed_pos);
7922 host()->SetRootLayer(root);
7923
7924 LayerPositionConstraint fixed_position;
7925 fixed_position.set_is_fixed_position(true);
7926 scroller->SetScrollClipLayerId(container->id());
7927 fixed_pos->SetPositionConstraint(fixed_position);
7928
7929 root->SetBounds(gfx::Size(50, 50));
7930 container->SetBounds(gfx::Size(50, 50));
7931 scroller->SetBounds(gfx::Size(50, 50));
7932 fixed_pos->SetBounds(gfx::Size(50, 50));
7933
7934 gfx::Transform rotate;
7935 rotate.RotateAboutXAxis(20);
7936 container->SetTransform(rotate);
7937
7938 ExecuteCalculateDrawProperties(root.get());
khushalsagarb69ba9452017-01-27 22:20:077939 TransformTree& tree =
7940 root->layer_tree_host()->property_trees()->transform_tree;
jaydasikaaf1582f2016-08-10 18:39:387941 gfx::Transform transform;
7942 tree.ComputeTranslation(fixed_pos->transform_tree_index(),
7943 container->transform_tree_index(), &transform);
7944 EXPECT_TRUE(transform.IsIdentity());
7945}
7946
sunxd8a9a60982016-07-29 18:46:567947TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
7948 // This test verifies that a fixed pos child of a scrolling layer doesn't get
7949 // snapped to integer coordinates.
7950 //
7951 // + root
7952 // + container
7953 // + scroller
7954 // + fixed_pos
7955 //
7956 scoped_refptr<Layer> root = Layer::Create();
7957 scoped_refptr<Layer> container = Layer::Create();
7958 scoped_refptr<Layer> scroller = Layer::Create();
7959 scoped_refptr<Layer> fixed_pos = Layer::Create();
7960
7961 scroller->SetIsContainerForFixedPositionLayers(true);
7962
7963 root->AddChild(container);
7964 container->AddChild(scroller);
7965 scroller->AddChild(fixed_pos);
7966 host()->SetRootLayer(root);
7967
7968 LayerPositionConstraint fixed_position;
7969 fixed_position.set_is_fixed_position(true);
7970 scroller->SetScrollClipLayerId(container->id());
7971 fixed_pos->SetPositionConstraint(fixed_position);
7972
7973 root->SetBounds(gfx::Size(50, 50));
7974 container->SetBounds(gfx::Size(50, 50));
7975 scroller->SetBounds(gfx::Size(100, 100));
7976 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7977 fixed_pos->SetBounds(gfx::Size(10, 10));
7978
7979 ExecuteCalculateDrawProperties(root.get());
7980
7981 host()->host_impl()->CreatePendingTree();
7982 host()->CommitAndCreatePendingTree();
7983 host()->host_impl()->ActivateSyncTree();
7984 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7985
7986 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7987 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7988 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
7989 gfx::Vector2dF scroll_delta(5.f, 9.f);
7990 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7991
7992 ExecuteCalculateDrawProperties(root_impl);
7993
7994 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7995 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7996 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7997
7998 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
7999 10.3f);
8000 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
8001 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
8002}
8003
[email protected]1c3626e2014-04-09 17:49:228004class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
8005 public:
danakj60bc3bc2016-04-09 00:24:488006 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:228007 LayerTreeImpl* tree_impl,
8008 int id) {
danakj60bc3bc2016-04-09 00:24:488009 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:228010 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
8011 }
8012
dcheng716bedf2014-10-21 09:51:088013 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:228014
[email protected]1c3626e2014-04-09 17:49:228015 private:
8016 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
8017 int id)
[email protected]a57cb8b12014-06-13 18:15:378018 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:228019 SetDrawsContent(true);
8020 }
[email protected]1c3626e2014-04-09 17:49:228021};
8022
8023TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:168024 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568025 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018026 LayerTreeSettings settings = host()->GetSettings();
ajumab4a846f22015-08-24 19:13:448027 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:168028 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228029 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:488030 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:228031 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:488032 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:228033 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:488034 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:228035 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:488036 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:228037 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
8038
8039 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
8040 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
8041 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:098042 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:228043
danakjf78fb272016-07-26 19:06:158044 grand_parent->SetBounds(gfx::Size(1, 2));
8045 parent->SetBounds(gfx::Size(1, 2));
8046 child->SetBounds(gfx::Size(1, 2));
8047 grand_child->SetBounds(gfx::Size(1, 2));
8048
jaydasika89f7b5a2016-06-22 02:08:398049 child->test_properties()->AddChild(std::move(grand_child));
8050 parent->test_properties()->AddChild(std::move(child));
8051 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:598052 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:058053
jaydasika2411692c2016-03-23 01:56:098054 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228055
8056 // No layers have animations.
sunxdf468675e2016-06-30 23:56:188057 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8058 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8059 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8060 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228061
sunxdf468675e2016-06-30 23:56:188062 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8063 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8064 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8065 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038066
[email protected]1c3626e2014-04-09 17:49:228067 TransformOperations translation;
8068 translation.AppendTranslate(1.f, 2.f, 3.f);
8069
loyso968163c92016-01-04 23:18:488070 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:588071 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8072 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:488073
vollickef2ae922016-06-29 17:54:278074 host_impl.active_tree()->SetElementIdsForTesting();
loysodb006882016-09-14 00:31:518075
8076 scoped_refptr<AnimationPlayer> grand_parent_player =
8077 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
8078 timeline->AttachPlayer(grand_parent_player);
8079 grand_parent_player->AttachElement(grand_parent_raw->element_id());
8080
8081 scoped_refptr<AnimationPlayer> parent_player =
8082 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
8083 timeline->AttachPlayer(parent_player);
8084 parent_player->AttachElement(parent_raw->element_id());
8085
8086 scoped_refptr<AnimationPlayer> child_player =
8087 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
8088 timeline->AttachPlayer(child_player);
8089 child_player->AttachElement(child_raw->element_id());
8090
8091 scoped_refptr<AnimationPlayer> grand_child_player =
8092 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
8093 timeline->AttachPlayer(grand_child_player);
8094 grand_child_player->AttachElement(grand_child_raw->element_id());
8095
8096 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
8097 translation);
[email protected]1c3626e2014-04-09 17:49:228098
8099 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:188100 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8101 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8102 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8103 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228104
sunxdf468675e2016-06-30 23:56:188105 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8106 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8107 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8108 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038109
[email protected]1c3626e2014-04-09 17:49:228110 TransformOperations scale;
8111 scale.AppendScale(5.f, 4.f, 3.f);
8112
loysodb006882016-09-14 00:31:518113 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
8114 scale);
ajumacaaa9b32015-08-04 15:55:298115 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098116 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228117
8118 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:188119 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8120 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8121 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
8122 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228123
sunxdf468675e2016-06-30 23:56:188124 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8125 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8126 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
8127 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038128
loysodb006882016-09-14 00:31:518129 AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0,
8130 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:098131 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
8132 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228133
8134 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:188135 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
8136 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:228137 // We don't support combining animated scales from two nodes; 0.f means
8138 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:188139 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8140 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228141
sunxdf468675e2016-06-30 23:56:188142 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
8143 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
8144 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8145 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038146
loysodb006882016-09-14 00:31:518147 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
8148 scale);
ajumacaaa9b32015-08-04 15:55:298149 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098150 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228151
8152 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:188153 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
8154 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8155 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8156 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228157
sunxdf468675e2016-06-30 23:56:188158 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
8159 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8160 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8161 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038162
loysodb006882016-09-14 00:31:518163 grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
8164 parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
8165 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
[email protected]1c3626e2014-04-09 17:49:228166
8167 TransformOperations perspective;
8168 perspective.AppendPerspective(10.f);
8169
loysodb006882016-09-14 00:31:518170 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
8171 perspective);
ajumab4a846f22015-08-24 19:13:448172 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098173 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228174
8175 // |child| has a scale-affecting animation but computing the maximum of this
8176 // animation is not supported.
sunxdf468675e2016-06-30 23:56:188177 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8178 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8179 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8180 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228181
sunxdf468675e2016-06-30 23:56:188182 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8183 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8184 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8185 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038186
loysobb507792016-10-04 05:31:028187 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
8188
[email protected]1c3626e2014-04-09 17:49:228189 gfx::Transform scale_matrix;
8190 scale_matrix.Scale(1.f, 2.f);
jaydasika10d43fc2016-08-18 04:06:048191 grand_parent_raw->test_properties()->transform = scale_matrix;
8192 parent_raw->test_properties()->transform = scale_matrix;
jaydasika2411692c2016-03-23 01:56:098193 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:488194
loysodb006882016-09-14 00:31:518195 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
8196 scale);
jaydasika2411692c2016-03-23 01:56:098197 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228198
8199 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8200 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:188201 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8202 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
8203 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
8204 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228205
sunxdf468675e2016-06-30 23:56:188206 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8207 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
8208 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
8209 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038210
[email protected]1c3626e2014-04-09 17:49:228211 gfx::Transform perspective_matrix;
8212 perspective_matrix.ApplyPerspectiveDepth(2.f);
jaydasika10d43fc2016-08-18 04:06:048213 child_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:098214 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
8215 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228216
8217 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:188218 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8219 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
8220 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8221 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228222
sunxdf468675e2016-06-30 23:56:188223 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8224 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
8225 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8226 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038227
jaydasika10d43fc2016-08-18 04:06:048228 parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:098229 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
8230 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228231
8232 // |parent| and |child| have transforms that are neither translations nor
8233 // scales.
sunxdf468675e2016-06-30 23:56:188234 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8235 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8236 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8237 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228238
sunxdf468675e2016-06-30 23:56:188239 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8240 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8241 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8242 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038243
jaydasika10d43fc2016-08-18 04:06:048244 parent_raw->test_properties()->transform = gfx::Transform();
8245 child_raw->test_properties()->transform = gfx::Transform();
8246 grand_parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:098247 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:228248
jaydasika2411692c2016-03-23 01:56:098249 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:228250
8251 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:188252 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
8253 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
8254 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
8255 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:038256
sunxdf468675e2016-06-30 23:56:188257 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
8258 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
8259 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
8260 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:228261}
8262
danakj59931942016-07-26 22:11:298263static void GatherDrawnLayers(const LayerImplList* rsll,
[email protected]390bb1ff2014-05-09 17:14:408264 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:518265 for (LayerIterator it = LayerIterator::Begin(rsll),
8266 end = LayerIterator::End(rsll);
8267 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:408268 LayerImpl* layer = *it;
8269 if (it.represents_itself())
8270 drawn_layers->insert(layer);
8271
8272 if (!it.represents_contributing_render_surface())
8273 continue;
8274
ajuma1d4026a32016-06-14 13:18:508275 if (layer->render_surface()->MaskLayer())
8276 drawn_layers->insert(layer->render_surface()->MaskLayer());
[email protected]390bb1ff2014-05-09 17:14:408277 }
8278}
8279
8280TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:168281 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568282 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228283 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:408284
danakj60bc3bc2016-04-09 00:24:488285 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:408286 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:488287 std::unique_ptr<LayerImpl> parent =
8288 LayerImpl::Create(host_impl.active_tree(), 3);
8289 std::unique_ptr<LayerImpl> child =
8290 LayerImpl::Create(host_impl.active_tree(), 5);
8291 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:408292 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:488293 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:408294 LayerImpl::Create(host_impl.active_tree(), 9);
8295
8296 LayerImpl* grand_parent_raw = grand_parent.get();
8297 LayerImpl* parent_raw = parent.get();
8298 LayerImpl* child_raw = child.get();
8299 LayerImpl* grand_child1_raw = grand_child1.get();
8300 LayerImpl* grand_child2_raw = grand_child2.get();
8301
danakjf78fb272016-07-26 19:06:158302 grand_parent->SetBounds(gfx::Size(1, 2));
8303 parent->SetBounds(gfx::Size(1, 2));
8304 child->SetBounds(gfx::Size(1, 2));
8305 grand_child1->SetBounds(gfx::Size(1, 2));
8306 grand_child2->SetBounds(gfx::Size(1, 2));
8307
jaydasika89f7b5a2016-06-22 02:08:398308 child->test_properties()->AddChild(std::move(grand_child1));
8309 child->test_properties()->AddChild(std::move(grand_child2));
8310 parent->test_properties()->AddChild(std::move(child));
8311 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:598312 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:408313
[email protected]390bb1ff2014-05-09 17:14:408314 // Start with nothing being drawn.
8315 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408316
ajuma0adb5902016-04-28 16:32:388317 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8318 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8319 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8320 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8321 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408322
8323 std::set<LayerImpl*> expected;
8324 std::set<LayerImpl*> actual;
8325 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8326 EXPECT_EQ(expected, actual);
8327
8328 // If we force render surface, but none of the layers are in the layer list,
8329 // then this layer should not appear in RSLL.
ajuma35b24f62017-01-27 21:23:098330 grand_child1_raw->test_properties()->force_render_surface = true;
jaydasikaebf9e4ea2015-08-14 21:29:128331 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408332
8333 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408334
ajuma0adb5902016-04-28 16:32:388335 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8336 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8337 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8338 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8339 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408340
8341 expected.clear();
8342 actual.clear();
8343 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8344 EXPECT_EQ(expected, actual);
8345
8346 // However, if we say that this layer also draws content, it will appear in
8347 // RSLL.
8348 grand_child1_raw->SetDrawsContent(true);
8349
8350 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408351
ajuma0adb5902016-04-28 16:32:388352 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8353 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8354 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8355 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8356 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408357
8358 expected.clear();
8359 expected.insert(grand_child1_raw);
8360
8361 actual.clear();
8362 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8363 EXPECT_EQ(expected, actual);
8364
8365 // Now child is forced to have a render surface, and one if its children draws
8366 // content.
8367 grand_child1_raw->SetDrawsContent(false);
ajuma35b24f62017-01-27 21:23:098368 grand_child1_raw->test_properties()->force_render_surface = false;
jaydasikaebf9e4ea2015-08-14 21:29:128369 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
ajuma35b24f62017-01-27 21:23:098370 child_raw->test_properties()->force_render_surface = true;
[email protected]390bb1ff2014-05-09 17:14:408371 grand_child2_raw->SetDrawsContent(true);
8372
8373 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408374
ajuma0adb5902016-04-28 16:32:388375 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8376 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8377 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8378 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8379 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408380
8381 expected.clear();
8382 expected.insert(grand_child2_raw);
8383
8384 actual.clear();
8385 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8386 EXPECT_EQ(expected, actual);
8387
8388 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:508389 child_raw->test_properties()->SetMaskLayer(
8390 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:048391 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408392
8393 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408394
ajuma0adb5902016-04-28 16:32:388395 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8396 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8397 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508398 EXPECT_TRUE(child_raw->test_properties()
8399 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388400 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8401 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408402
8403 expected.clear();
8404 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508405 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408406
8407 expected.clear();
8408 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508409 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408410
8411 actual.clear();
8412 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8413 EXPECT_EQ(expected, actual);
8414
[email protected]390bb1ff2014-05-09 17:14:408415 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408416
ajuma0adb5902016-04-28 16:32:388417 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8418 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8419 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508420 EXPECT_TRUE(child_raw->test_properties()
8421 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388422 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8423 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408424
8425 expected.clear();
8426 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508427 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408428
8429 actual.clear();
8430 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8431 EXPECT_EQ(expected, actual);
8432
ajuma1d4026a32016-06-14 13:18:508433 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408434
8435 // With nothing drawing, we should have no layers.
8436 grand_child2_raw->SetDrawsContent(false);
8437
8438 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408439
ajuma0adb5902016-04-28 16:32:388440 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8441 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8442 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508443 EXPECT_FALSE(child_raw->test_properties()
8444 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388445 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8446 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408447
8448 expected.clear();
8449 actual.clear();
8450 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8451 EXPECT_EQ(expected, actual);
8452
8453 // Child itself draws means that we should have the child and the mask in the
8454 // list.
8455 child_raw->SetDrawsContent(true);
8456
8457 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408458
ajuma0adb5902016-04-28 16:32:388459 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8460 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8461 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508462 EXPECT_TRUE(child_raw->test_properties()
8463 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388464 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8465 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408466
8467 expected.clear();
8468 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:508469 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408470 actual.clear();
8471 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8472 EXPECT_EQ(expected, actual);
8473
ajuma1d4026a32016-06-14 13:18:508474 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:048475 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408476
8477 // Now everyone's a member!
8478 grand_parent_raw->SetDrawsContent(true);
8479 parent_raw->SetDrawsContent(true);
8480 child_raw->SetDrawsContent(true);
8481 grand_child1_raw->SetDrawsContent(true);
8482 grand_child2_raw->SetDrawsContent(true);
8483
8484 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408485
ajuma0adb5902016-04-28 16:32:388486 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8487 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
8488 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
8489 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8490 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408491
8492 expected.clear();
8493 expected.insert(grand_parent_raw);
8494 expected.insert(parent_raw);
8495 expected.insert(child_raw);
8496 expected.insert(grand_child1_raw);
8497 expected.insert(grand_child2_raw);
8498
8499 actual.clear();
8500 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8501 EXPECT_EQ(expected, actual);
8502}
[email protected]18e69652014-06-13 12:50:588503
8504TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:168505 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568506 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018507 LayerTreeSettings settings = host()->GetSettings();
enne637715732015-07-07 02:05:268508 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:168509 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228510 &task_graph_runner);
[email protected]18e69652014-06-13 12:50:588511
danakj60bc3bc2016-04-09 00:24:488512 std::unique_ptr<LayerImpl> root =
8513 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:588514 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:488515 std::unique_ptr<LayerImpl> child1 =
8516 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:588517 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:488518 std::unique_ptr<LayerImpl> child2 =
8519 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:588520 LayerImpl* child2_layer = child2.get();
8521
danakjf78fb272016-07-26 19:06:158522 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:588523 scale_transform_child1.Scale(2, 3);
8524 scale_transform_child2.Scale(4, 5);
8525
danakjf78fb272016-07-26 19:06:158526 root->SetBounds(gfx::Size(1, 1));
8527 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048528 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158529 child1_layer->SetBounds(gfx::Size(1, 1));
8530 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:588531
ajuma1d4026a32016-06-14 13:18:508532 child1_layer->test_properties()->SetMaskLayer(
8533 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:588534
danakjf78fb272016-07-26 19:06:158535 root->test_properties()->AddChild(std::move(child1));
8536 root->test_properties()->AddChild(std::move(child2));
8537 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8538 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:588539
8540 ExecuteCalculateDrawProperties(root_layer);
8541
8542 TransformOperations scale;
8543 scale.AppendScale(5.f, 8.f, 3.f);
8544
loyso9556c732016-03-11 07:54:588545 scoped_refptr<AnimationTimeline> timeline =
8546 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8547 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:488548
jaydasika10d43fc2016-08-18 04:06:048549 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158550 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:288551 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278552 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8553 1.0, TransformOperations(), scale);
8554
jaydasika2411692c2016-03-23 01:56:098555 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:588556 ExecuteCalculateDrawProperties(root_layer);
8557
enne637715732015-07-07 02:05:268558 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
8559 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:508560 EXPECT_FLOAT_EQ(
8561 3.f,
8562 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268563 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588564
sunxdf468675e2016-06-30 23:56:188565 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8566 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8567 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:588568
[email protected]18e69652014-06-13 12:50:588569 // Changing page-scale would affect ideal_contents_scale and
8570 // maximum_animation_contents_scale.
8571
8572 float page_scale_factor = 3.f;
8573 float device_scale_factor = 1.0f;
8574 std::vector<LayerImpl*> render_surface_layer_list;
8575 gfx::Size device_viewport_size =
8576 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8577 root_layer->bounds().height() * device_scale_factor);
8578 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388579 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:588580
8581 inputs.page_scale_factor = page_scale_factor;
8582 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:118583 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:578584 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:588585
enne637715732015-07-07 02:05:268586 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
8587 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588588 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268589 9.f,
ajuma1d4026a32016-06-14 13:18:508590 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268591 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588592
sunxdf468675e2016-06-30 23:56:188593 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8594 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8595 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:588596
[email protected]18e69652014-06-13 12:50:588597 // Changing device-scale would affect ideal_contents_scale and
8598 // maximum_animation_contents_scale.
8599
8600 device_scale_factor = 4.0f;
8601 inputs.device_scale_factor = device_scale_factor;
8602 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:098603 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:578604 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:588605
enne637715732015-07-07 02:05:268606 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
8607 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588608 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268609 36.f,
ajuma1d4026a32016-06-14 13:18:508610 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268611 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588612
sunxdf468675e2016-06-30 23:56:188613 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8614 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8615 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
8616}
8617
8618TEST_F(LayerTreeHostCommonTest, AnimationScales) {
8619 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188620 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018621 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188622 settings.layer_transforms_should_scale_layer_contents = true;
8623 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228624 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188625
8626 std::unique_ptr<LayerImpl> root =
8627 LayerImpl::Create(host_impl.active_tree(), 1);
8628 LayerImpl* root_layer = root.get();
8629 std::unique_ptr<LayerImpl> child1 =
8630 LayerImpl::Create(host_impl.active_tree(), 2);
8631 LayerImpl* child1_layer = child1.get();
8632 std::unique_ptr<LayerImpl> child2 =
8633 LayerImpl::Create(host_impl.active_tree(), 3);
8634 LayerImpl* child2_layer = child2.get();
8635
8636 root->test_properties()->AddChild(std::move(child1));
8637 child1_layer->test_properties()->AddChild(std::move(child2));
8638 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8639
8640 host_impl.active_tree()->SetElementIdsForTesting();
8641
danakjf78fb272016-07-26 19:06:158642 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:188643 scale_transform_child1.Scale(2, 3);
8644 scale_transform_child2.Scale(4, 5);
8645
danakjf78fb272016-07-26 19:06:158646 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048647 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158648 child1_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048649 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158650 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:188651
8652 TransformOperations scale;
8653 scale.AppendScale(5.f, 8.f, 3.f);
8654
8655 scoped_refptr<AnimationTimeline> timeline =
8656 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8657 host_impl.animation_host()->AddAnimationTimeline(timeline);
8658
8659 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8660 1.0, TransformOperations(), scale);
8661
sunxdf468675e2016-06-30 23:56:188662 // Correctly computes animation scale when rebuilding property trees.
8663 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8664 ExecuteCalculateDrawProperties(root_layer);
8665
8666 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8667 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8668 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
8669
8670 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8671 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
8672 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
8673
8674 // Correctly updates animation scale when layer property changes.
jaydasika10d43fc2016-08-18 04:06:048675 child1_layer->test_properties()->transform = gfx::Transform();
jaydasika09e16132016-08-24 21:39:348676 root_layer->layer_tree_impl()
8677 ->property_trees()
8678 ->transform_tree.OnTransformAnimated(gfx::Transform(),
8679 child1_layer->transform_tree_index(),
8680 root_layer->layer_tree_impl());
sunxdf468675e2016-06-30 23:56:188681 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
8682 ExecuteCalculateDrawProperties(root_layer);
8683 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
8684 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
8685
8686 // Do not update animation scale if already updated.
8687 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
8688 child2_layer->transform_tree_index(), 100.f, 100.f);
8689 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
8690 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
8691}
8692
8693TEST_F(LayerTreeHostCommonTest,
8694 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
8695 // Returns empty scale if layer_transforms_should_scale_layer_contents is
8696 // false.
8697 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188698 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018699 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188700 settings.layer_transforms_should_scale_layer_contents = false;
8701 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228702 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188703
8704 std::unique_ptr<LayerImpl> root =
8705 LayerImpl::Create(host_impl.active_tree(), 1);
8706 LayerImpl* root_layer = root.get();
8707 std::unique_ptr<LayerImpl> child =
8708 LayerImpl::Create(host_impl.active_tree(), 2);
8709 LayerImpl* child_layer = child.get();
8710
8711 root->test_properties()->AddChild(std::move(child));
8712 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8713
8714 host_impl.active_tree()->SetElementIdsForTesting();
8715
danakjf78fb272016-07-26 19:06:158716 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:188717 scale_transform_child.Scale(4, 5);
8718
danakjf78fb272016-07-26 19:06:158719 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048720 child_layer->test_properties()->transform = scale_transform_child;
danakjf78fb272016-07-26 19:06:158721 child_layer->SetBounds(gfx::Size(1, 1));
8722
sunxdf468675e2016-06-30 23:56:188723 TransformOperations scale;
8724 scale.AppendScale(5.f, 8.f, 3.f);
8725
8726 scoped_refptr<AnimationTimeline> timeline =
8727 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8728 host_impl.animation_host()->AddAnimationTimeline(timeline);
8729
8730 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
8731 1.0, TransformOperations(), scale);
8732
sunxdf468675e2016-06-30 23:56:188733 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8734 ExecuteCalculateDrawProperties(root_layer);
8735
8736 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8737 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
8738
8739 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8740 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:588741}
8742
danakjf6069db2014-09-13 00:46:478743TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598744 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148745 LayerImpl* clip = AddChild<LayerImpl>(root);
8746 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:478747
danakjf78fb272016-07-26 19:06:158748 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:148749 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158750 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:478751 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158752 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:148753 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158754 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:478755
8756 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:148757 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:148758 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakjf78fb272016-07-26 19:06:158759 root, device_viewport_size, gfx::Transform(),
ajuma0adb5902016-04-28 16:32:388760 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:478761 inputs.device_scale_factor = 2.f;
8762 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:298763 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:578764 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478765
8766 // Layers in the root render surface have their visible content rect clipped
8767 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148768 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478769
8770 // Layers drawing to a child render surface should still have their visible
8771 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148772 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478773}
8774
timav599f4359d2014-12-05 00:12:228775TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168776 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568777 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228778 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
timav599f4359d2014-12-05 00:12:228779
8780 // Set two layers: the root layer clips it's child,
8781 // the child draws its content.
8782
8783 gfx::Size root_size = gfx::Size(300, 500);
8784
8785 // Sublayer should be bigger than the root enlarged by bounds_delta.
8786 gfx::Size sublayer_size = gfx::Size(300, 1000);
8787
mdjones2ee41afd2016-10-27 16:50:208788 // Device viewport accomidated the root and the browser controls.
timav599f4359d2014-12-05 00:12:228789 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:228790
miletus8bd08a622015-06-16 18:44:528791 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:598792 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:228793 LayerImpl::Create(host_impl.active_tree(), 1));
8794
jaydasikabf1875a2016-06-28 03:39:598795 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:158796 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:228797 root->SetMasksToBounds(true);
8798
jaydasika89f7b5a2016-06-22 02:08:398799 root->test_properties()->AddChild(
8800 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:228801
jaydasikafc66cfb2016-06-10 04:34:228802 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:158803 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:228804 sublayer->SetDrawsContent(true);
8805
danakj74af409e2016-07-01 00:41:488806 host_impl.active_tree()->BuildPropertyTreesForTesting();
8807
timav599f4359d2014-12-05 00:12:228808 LayerImplList layer_impl_list;
8809 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388810 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:228811
sunxdb365de02016-04-28 20:32:578812 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438813 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228814
8815 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578816 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228817
8818 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8819 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438820 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228821}
8822
ajumadd2802e72015-06-30 20:28:298823TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318824 scoped_refptr<Layer> root = Layer::Create();
8825 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8826 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8827 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8828 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298829
8830 root->AddChild(inner_viewport_container_layer);
8831 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8832 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8833 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8834
8835 inner_viewport_scroll_layer->SetScrollClipLayerId(
8836 inner_viewport_container_layer->id());
8837 outer_viewport_scroll_layer->SetScrollClipLayerId(
8838 outer_viewport_container_layer->id());
8839
8840 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8841 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8842
8843 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:078844 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
8845 outer_viewport_scroll_layer);
ajumadd2802e72015-06-30 20:28:298846
loyso0940d412016-03-14 01:30:318847 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8848 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298849
8850 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8851 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8852
8853 LayerPositionConstraint fixed_to_right;
8854 fixed_to_right.set_is_fixed_position(true);
8855 fixed_to_right.set_is_fixed_to_right_edge(true);
8856
8857 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8858 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8859
jaydasika6ed869662016-09-21 14:29:598860 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298861
8862 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8863 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8864 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8865
8866 LayerPositionConstraint fixed_to_left;
8867 fixed_to_left.set_is_fixed_position(true);
8868 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8869
jaydasika6ed869662016-09-21 14:29:598870 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298871 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8872 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8873
8874 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8875
jaydasika6ed869662016-09-21 14:29:598876 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298877 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8878 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8879}
8880
vollick7d83b452015-02-24 20:18:068881TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
sunxd713aedbd2016-08-10 22:22:148882 host_impl()->CreatePendingTree();
8883 std::unique_ptr<LayerImpl> pending_root =
8884 LayerImpl::Create(host_impl()->pending_tree(), 1);
8885 LayerImpl* root = pending_root.get();
8886 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root));
8887 std::unique_ptr<LayerImpl> animated_ptr =
8888 LayerImpl::Create(host_impl()->pending_tree(), 2);
8889 LayerImpl* animated = animated_ptr.get();
8890 root->test_properties()->AddChild(std::move(animated_ptr));
vollick7d83b452015-02-24 20:18:068891
sunxd713aedbd2016-08-10 22:22:148892 animated->SetDrawsContent(true);
8893 host_impl()->pending_tree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278894
danakjf78fb272016-07-26 19:06:158895 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:068896 root->SetMasksToBounds(true);
sunxd713aedbd2016-08-10 22:22:148897 root->test_properties()->force_render_surface = true;
8898 animated->test_properties()->opacity = 0.f;
danakjf78fb272016-07-26 19:06:158899 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:068900
sunxd713aedbd2016-08-10 22:22:148901 AddOpacityTransitionToElementWithPlayer(
8902 animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false);
8903 animated->test_properties()->opacity_can_animate = true;
8904 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598905 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
vollick7d83b452015-02-24 20:18:068906
sunxd713aedbd2016-08-10 22:22:148907 EXPECT_FALSE(animated->visible_layer_rect().IsEmpty());
vollick7d83b452015-02-24 20:18:068908}
8909
ajumaa92fdc12015-03-31 22:47:418910TEST_F(LayerTreeHostCommonTest,
8911 VisibleContentRectForAnimatedLayerWithSingularTransform) {
sunxd713aedbd2016-08-10 22:22:148912 LayerImpl* root = root_layer_for_testing();
8913 LayerImpl* clip = AddChild<LayerImpl>(root);
8914 LayerImpl* animated = AddChild<LayerImpl>(clip);
8915 LayerImpl* surface = AddChild<LayerImpl>(animated);
8916 LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface);
ajumaa92fdc12015-03-31 22:47:418917
sunxd713aedbd2016-08-10 22:22:148918 SetElementIdsForTesting();
ajumaa92fdc12015-03-31 22:47:418919
sunxd713aedbd2016-08-10 22:22:148920 animated->SetDrawsContent(true);
8921 surface->SetDrawsContent(true);
8922 descendant_of_animation->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278923
ajumaa92fdc12015-03-31 22:47:418924 gfx::Transform uninvertible_matrix;
8925 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8926
danakjf78fb272016-07-26 19:06:158927 root->SetBounds(gfx::Size(100, 100));
8928 clip->SetBounds(gfx::Size(10, 10));
8929 clip->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:048930 animated->test_properties()->transform = uninvertible_matrix;
danakjf78fb272016-07-26 19:06:158931 animated->SetBounds(gfx::Size(120, 120));
8932 surface->SetBounds(gfx::Size(100, 100));
sunxd713aedbd2016-08-10 22:22:148933 surface->test_properties()->force_render_surface = true;
danakjf78fb272016-07-26 19:06:158934 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:418935
8936 TransformOperations start_transform_operations;
8937 start_transform_operations.AppendMatrix(uninvertible_matrix);
8938 TransformOperations end_transform_operations;
8939
sunxd713aedbd2016-08-10 22:22:148940 AddAnimatedTransformToElementWithPlayer(
8941 animated->element_id(), timeline_impl(), 10.0, start_transform_operations,
8942 end_transform_operations);
jaydasika6ed869662016-09-21 14:29:598943 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
ajumaa92fdc12015-03-31 22:47:418944
8945 // The animated layer has a singular transform and maps to a non-empty rect in
8946 // clipped target space, so is treated as fully visible.
sunxd713aedbd2016-08-10 22:22:148947 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418948
8949 // The singular transform on |animated| is flattened when inherited by
8950 // |surface|, and this happens to make it invertible.
sunxd713aedbd2016-08-10 22:22:148951 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect());
8952 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418953
8954 gfx::Transform zero_matrix;
8955 zero_matrix.Scale3d(0.f, 0.f, 0.f);
jaydasika09e16132016-08-24 21:39:348956 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
8957 zero_matrix, animated->transform_tree_index(), root->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:598958 // While computing visible rects by combining clips in screen space, we set
8959 // the entire layer as visible if the screen space transform is singular. This
8960 // is not always true when we combine clips in target space because if the
8961 // intersection of combined_clip in taret space with layer_rect projected to
8962 // target space is empty, we set it to an empty rect.
8963 bool skip_verify_visible_rect_calculations = true;
8964 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
8965 root, skip_verify_visible_rect_calculations);
ajumaa92fdc12015-03-31 22:47:418966
8967 // The animated layer maps to the empty rect in clipped target space, so is
8968 // treated as having an empty visible rect.
sunxd713aedbd2016-08-10 22:22:148969 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418970
jaydasika6ed869662016-09-21 14:29:598971 // The animated layer will be treated as fully visible when we combine clips
8972 // in screen space.
8973 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
8974 root->layer_tree_impl()->property_trees(), animated);
8975 EXPECT_EQ(gfx::Rect(120, 120), visible_rect);
8976
ajumaa92fdc12015-03-31 22:47:418977 // This time, flattening does not make |animated|'s transform invertible. This
8978 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348979 // |surface| and layers that draw into it as having empty visible rect.
sunxd713aedbd2016-08-10 22:22:148980 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect());
8981 EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418982}
8983
ajuma20384bf2016-07-22 13:26:158984// Verify that having animated opacity but current opacity 1 still creates
8985// a render surface.
8986TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
8987 LayerImpl* root = root_layer_for_testing();
8988 LayerImpl* child = AddChild<LayerImpl>(root);
8989 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:158990
danakjf78fb272016-07-26 19:06:158991 root->SetBounds(gfx::Size(50, 50));
8992 child->SetBounds(gfx::Size(50, 50));
8993 child->SetDrawsContent(true);
8994 grandchild->SetBounds(gfx::Size(50, 50));
8995 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:158996
8997 SetElementIdsForTesting();
8998 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
8999 10.0, 1.f, 0.2f, false);
9000 ExecuteCalculateDrawProperties(root);
9001
9002 EXPECT_EQ(1.f, child->Opacity());
9003 EXPECT_TRUE(root->has_render_surface());
9004 EXPECT_TRUE(child->has_render_surface());
9005 EXPECT_FALSE(grandchild->has_render_surface());
9006}
9007
enne92f2f6d92015-02-25 23:13:319008// Verify that having an animated filter (but no current filter, as these
9009// are mutually exclusive) correctly creates a render surface.
9010TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:599011 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:329012 LayerImpl* child = AddChild<LayerImpl>(root);
9013 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:319014
danakjf78fb272016-07-26 19:06:159015 root->SetBounds(gfx::Size(50, 50));
9016 child->SetBounds(gfx::Size(50, 50));
9017 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:319018
vollickef2ae922016-06-29 17:54:279019 SetElementIdsForTesting();
9020 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
9021 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:329022 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:319023
ennec1332992015-08-24 19:45:099024 EXPECT_TRUE(root->has_render_surface());
9025 EXPECT_TRUE(child->has_render_surface());
9026 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:319027
ajumacb2b74432016-07-21 19:11:159028 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
9029 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:319030
9031 EXPECT_FALSE(root->FilterIsAnimating());
9032 EXPECT_TRUE(child->FilterIsAnimating());
9033 EXPECT_FALSE(grandchild->FilterIsAnimating());
9034}
9035
ajuma315a4782015-07-24 21:16:349036// Verify that having a filter animation with a delayed start time creates a
9037// render surface.
9038TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:599039 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:329040 LayerImpl* child = AddChild<LayerImpl>(root);
9041 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:349042
danakjf78fb272016-07-26 19:06:159043 root->SetBounds(gfx::Size(50, 50));
9044 child->SetBounds(gfx::Size(50, 50));
9045 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:349046
vollickef2ae922016-06-29 17:54:279047 SetElementIdsForTesting();
9048
danakj60bc3bc2016-04-09 00:24:489049 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:349050 KeyframedFilterAnimationCurve::Create());
9051 FilterOperations start_filters;
9052 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
9053 FilterOperations end_filters;
9054 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
9055 curve->AddKeyframe(
9056 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
9057 curve->AddKeyframe(FilterKeyframe::Create(
9058 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:489059 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:309060 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:559061 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:349062 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:349063
vollickef2ae922016-06-29 17:54:279064 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
9065 std::move(animation));
ajuma4711f4b12016-05-16 18:48:329066 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:349067
ennec1332992015-08-24 19:45:099068 EXPECT_TRUE(root->has_render_surface());
9069 EXPECT_TRUE(child->has_render_surface());
9070 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:349071
ajumacb2b74432016-07-21 19:11:159072 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
9073 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:349074
9075 EXPECT_FALSE(root->FilterIsAnimating());
9076 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
9077 EXPECT_FALSE(child->FilterIsAnimating());
9078 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
9079 EXPECT_FALSE(grandchild->FilterIsAnimating());
9080 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
9081}
9082
vollick0120eb22015-03-02 03:07:349083// Ensures that the property tree code accounts for offsets between fixed
9084// position layers and their respective containers.
9085TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:599086 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149087 LayerImpl* child = AddChild<LayerImpl>(root);
9088 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:349089
danakjf78fb272016-07-26 19:06:159090 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:349091 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:529092 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:159093 child->SetPosition(gfx::PointF(1000, 1000));
9094 child->SetBounds(gfx::Size(50, 50));
9095 grandchild->SetPosition(gfx::PointF(-1000, -1000));
9096 grandchild->SetBounds(gfx::Size(50, 50));
9097 grandchild->SetDrawsContent(true);
9098
vollick0120eb22015-03-02 03:07:349099 LayerPositionConstraint constraint;
9100 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:529101 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:349102
jaydasika6f972de2016-04-07 16:16:149103 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:349104
jaydasika6f972de2016-04-07 16:16:149105 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:349106}
9107
ajuma0178b522015-07-02 21:08:419108// Ensures that the property tree code accounts for offsets between fixed
9109// position containers and their transform tree parents, when a fixed position
9110// layer's container is its layer tree parent, but this parent doesn't have its
9111// own transform tree node.
9112TEST_F(LayerTreeHostCommonTest,
9113 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:599114 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149115 LayerImpl* child = AddChild<LayerImpl>(root);
9116 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:419117
danakjf78fb272016-07-26 19:06:159118 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:419119 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159120 root->test_properties()->is_container_for_fixed_position_layers = true;
9121 child->SetPosition(gfx::PointF(1000, 1000));
9122 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:529123 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:159124 grandchild->SetPosition(gfx::PointF(-1000, -1000));
9125 grandchild->SetBounds(gfx::Size(50, 50));
9126 grandchild->SetDrawsContent(true);
9127
ajuma0178b522015-07-02 21:08:419128 LayerPositionConstraint constraint;
9129 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:529130 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:419131
jaydasika6f972de2016-04-07 16:16:149132 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:419133
jaydasika6f972de2016-04-07 16:16:149134 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:419135}
9136
vollick8c824742015-03-20 22:21:089137TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:599138 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149139 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
9140 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:089141 gfx::Transform translate_z;
9142 translate_z.Translate3d(0, 0, 10);
9143
danakjf78fb272016-07-26 19:06:159144 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:529145 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:089146
danakjf78fb272016-07-26 19:06:159147 frame_clip->SetPosition(gfx::PointF(500, 100));
9148 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:089149 frame_clip->SetMasksToBounds(true);
9150
danakjf78fb272016-07-26 19:06:159151 fixed->SetBounds(gfx::Size(1000, 1000));
9152 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:089153
9154 LayerPositionConstraint constraint;
9155 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:529156 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:089157
jaydasika6f972de2016-04-07 16:16:149158 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:089159
9160 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:149161 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:089162}
9163
vollick06ca3e832015-03-31 19:37:129164TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:599165 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149166 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
9167 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
9168 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
9169
danakjf78fb272016-07-26 19:06:159170 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:149171 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159172 root->test_properties()->is_container_for_fixed_position_layers = true;
9173 frame_clip->SetPosition(gfx::PointF(500, 100));
9174 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:149175 frame_clip->SetMasksToBounds(true);
9176 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159177 scroller->SetBounds(gfx::Size(1000, 1000));
jaydasika6f972de2016-04-07 16:16:149178 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
9179 scroller->SetScrollClipLayer(frame_clip->id());
9180 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159181 fixed->SetPosition(gfx::PointF(100, 100));
9182 fixed->SetBounds(gfx::Size(50, 50));
9183 fixed->SetMasksToBounds(true);
9184 fixed->SetDrawsContent(true);
9185 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:129186
9187 LayerPositionConstraint constraint;
9188 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:529189 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:129190
jaydasika6f972de2016-04-07 16:16:149191 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:129192
9193 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:149194 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:129195}
9196
vollick5057e1e2015-04-17 19:12:329197TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:329198 gfx::Transform translate;
9199 gfx::Transform rotate;
9200
9201 translate.Translate(10, 10);
9202 rotate.Rotate(45);
9203
loyso0940d412016-03-14 01:30:319204 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:159205 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:329206 root->SetIsContainerForFixedPositionLayers(true);
9207
ennea7b43c32015-06-18 20:01:339208 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:329209
jaydasika6ed869662016-09-21 14:29:599210 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ennea7b43c32015-06-18 20:01:339211 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:329212
9213 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:339214 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:329215
9216 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:339217 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:329218}
9219
ajumab0e0c1c2015-04-23 00:29:239220TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:599221 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149222 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:239223
ajumab0e0c1c2015-04-23 00:29:239224 gfx::Transform scale_matrix;
9225 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:239226
danakjf78fb272016-07-26 19:06:159227 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:149228 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:049229 child->test_properties()->transform = scale_matrix;
danakjf78fb272016-07-26 19:06:159230 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149231 child->SetDrawsContent(true);
9232
9233 ExecuteCalculateDrawProperties(root);
9234 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:239235
jaydasika38be7a822016-04-21 16:07:069236 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:239237
jaydasika6f972de2016-04-07 16:16:149238 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9239 ExecuteCalculateDrawProperties(root);
9240 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:239241}
9242
ajumaf09db8962015-04-24 21:55:349243TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:599244 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149245 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
9246 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:349247
ajumaf09db8962015-04-24 21:55:349248 gfx::Transform scale;
9249 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:159250
9251 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:049252 scroll_child->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159253 scroll_child->SetBounds(gfx::Size(40, 40));
9254 scroll_child->SetDrawsContent(true);
9255 scroll_parent->SetBounds(gfx::Size(30, 30));
9256 scroll_parent->SetDrawsContent(true);
9257
9258 scroll_child->test_properties()->scroll_parent = scroll_parent;
9259 scroll_parent->test_properties()->scroll_children =
9260 base::MakeUnique<std::set<LayerImpl*>>();
9261 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:349262
jaydasika6f972de2016-04-07 16:16:149263 ExecuteCalculateDrawProperties(root);
9264 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:349265
9266 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:149267 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
9268 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9269 ExecuteCalculateDrawProperties(root);
9270 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:349271}
9272
danakj60bc3bc2016-04-09 00:24:489273static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:129274
sunxded58688e2016-01-11 21:01:029275TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
9276 // If the layer has a node in effect_tree, the return value of
9277 // num_copy_requests_in_target_subtree() must be equal to the actual number
9278 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
9279 // to be the value of its nearest ancestor that owns an effect node and
9280 // greater than or equal to the actual number of copy requests in the
9281 // sub-layer_tree.
9282
loyso0940d412016-03-14 01:30:319283 scoped_refptr<Layer> root = Layer::Create();
9284 scoped_refptr<Layer> child1 = Layer::Create();
9285 scoped_refptr<Layer> child2 = Layer::Create();
9286 scoped_refptr<Layer> grandchild = Layer::Create();
9287 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:029288
9289 root->AddChild(child1);
9290 root->AddChild(child2);
9291 child1->AddChild(grandchild);
9292 grandchild->AddChild(greatgrandchild);
9293 host()->SetRootLayer(root);
9294
9295 child1->RequestCopyOfOutput(
9296 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
9297 greatgrandchild->RequestCopyOfOutput(
9298 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
9299 child2->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:599300 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029301
9302 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
9303 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
9304 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
9305 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
9306 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
9307}
9308
vollick2175fae82015-04-27 21:18:129309TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:319310 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:329311 FakeContentLayerClient client;
9312 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:129313 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:319314 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:129315 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:319316 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:259317 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:319318 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:159319
9320 root->SetBounds(gfx::Size(100, 100));
9321 child->SetBounds(gfx::Size(10, 10));
9322 grandchild->SetBounds(gfx::Size(10, 10));
9323 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129324
9325 root->AddChild(child);
9326 child->AddChild(grandchild);
9327 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:339328 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:079329 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279330
vollick2175fae82015-04-27 21:18:129331 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599332 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149333 const LayerList* update_list = GetUpdateLayerList();
9334 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129335
9336 // Now we will reset the visible rect from property trees for the grandchild,
9337 // and we will configure |child| in several ways that should force the subtree
9338 // to be skipped. The visible content rect for |grandchild| should, therefore,
9339 // remain empty.
vollick2175fae82015-04-27 21:18:129340 gfx::Transform singular;
9341 singular.matrix().set(0, 0, 0);
9342
9343 child->SetTransform(singular);
jaydasika6ed869662016-09-21 14:29:599344 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149345 update_list = GetUpdateLayerList();
9346 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
danakjf78fb272016-07-26 19:06:159347 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:129348
9349 child->SetHideLayerAndSubtree(true);
jaydasika6ed869662016-09-21 14:29:599350 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149351 update_list = GetUpdateLayerList();
9352 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129353 child->SetHideLayerAndSubtree(false);
9354
ajuma315a4782015-07-24 21:16:349355 gfx::Transform zero_z_scale;
9356 zero_z_scale.Scale3d(1, 1, 0);
9357 child->SetTransform(zero_z_scale);
9358
9359 // Add a transform animation with a start delay. Now, even though |child| has
9360 // a singular transform, the subtree should still get processed.
9361 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:489362 std::unique_ptr<Animation> animation = Animation::Create(
9363 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:309364 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:559365 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:349366 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:279367 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
9368 std::move(animation));
jaydasika6ed869662016-09-21 14:29:599369 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149370 update_list = GetUpdateLayerList();
9371 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:349372
vollickef2ae922016-06-29 17:54:279373 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
9374 animation_id);
danakjf78fb272016-07-26 19:06:159375 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:129376 child->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:599377 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149378 update_list = GetUpdateLayerList();
9379 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129380
9381 // Now, even though child has zero opacity, we will configure |grandchild| and
9382 // |greatgrandchild| in several ways that should force the subtree to be
9383 // processed anyhow.
jaydasika86654512016-01-27 17:05:079384 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:129385 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
jaydasika6ed869662016-09-21 14:29:599386 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149387 update_list = GetUpdateLayerList();
9388 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:349389
9390 // Add an opacity animation with a start delay.
9391 animation_id = 1;
9392 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:489393 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:309394 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559395 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:349396 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:279397 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
9398 std::move(animation));
jaydasika6ed869662016-09-21 14:29:599399 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149400 update_list = GetUpdateLayerList();
9401 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129402}
9403
sunxd71aea3e2016-04-01 23:48:059404TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:169405 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:569406 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:229407 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
vollick2175fae82015-04-27 21:18:129408
danakj60bc3bc2016-04-09 00:24:489409 std::unique_ptr<LayerImpl> root =
9410 LayerImpl::Create(host_impl.active_tree(), 1);
9411 std::unique_ptr<LayerImpl> child =
9412 LayerImpl::Create(host_impl.active_tree(), 2);
9413 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:129414 LayerImpl::Create(host_impl.active_tree(), 3);
9415
danakj60bc3bc2016-04-09 00:24:489416 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:259417 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:129418
danakjf78fb272016-07-26 19:06:159419 root->SetBounds(gfx::Size(100, 100));
9420 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129421 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159422 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129423 grandchild->SetDrawsContent(true);
9424 greatgrandchild->SetDrawsContent(true);
9425
jaydasika2411692c2016-03-23 01:56:099426 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:129427 LayerImpl* child_ptr = child.get();
9428 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:129429
jaydasika89f7b5a2016-06-22 02:08:399430 child->test_properties()->AddChild(std::move(grandchild));
9431 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:599432 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:129433
vollickef2ae922016-06-29 17:54:279434 host_impl.active_tree()->SetElementIdsForTesting();
9435
vollick2175fae82015-04-27 21:18:129436 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599437 // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059438 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129439
9440 // Now we will reset the visible rect from property trees for the grandchild,
9441 // and we will configure |child| in several ways that should force the subtree
9442 // to be skipped. The visible content rect for |grandchild| should, therefore,
9443 // remain empty.
weiliangcc97575c2016-03-03 18:34:279444 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:059445
vollick2175fae82015-04-27 21:18:129446 gfx::Transform singular;
9447 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:059448 // This line is used to make the results of skipping and not skipping layers
9449 // different.
9450 singular.matrix().set(0, 1, 1);
9451
9452 gfx::Transform rotate;
9453 rotate.Rotate(90);
9454
9455 gfx::Transform rotate_back_and_translate;
9456 rotate_back_and_translate.RotateAboutYAxis(180);
9457 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:129458
jaydasika10d43fc2016-08-18 04:06:049459 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059460 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599461 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279462 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049463 child_ptr->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129464
jaydasika5121caa82016-05-05 15:43:359465 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika6ed869662016-09-21 14:29:599466 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279467 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359468 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129469
jaydasikab5bc1a22016-08-24 02:59:059470 child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated(
9471 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:599472 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279473 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:189474 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:129475
jaydasika10d43fc2016-08-18 04:06:049476 root_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059477 // Force transform tree to have a node for child, so that ancestor's
9478 // invertible transform can be tested.
jaydasika10d43fc2016-08-18 04:06:049479 child_ptr->test_properties()->transform = rotate;
sunxd71aea3e2016-04-01 23:48:059480 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599481 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059482 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049483 root_ptr->test_properties()->transform = gfx::Transform();
9484 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:059485
jaydasikaab317e02016-06-01 00:53:189486 root_ptr->test_properties()->opacity = 0.f;
9487 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:059488 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599489 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059490 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:189491 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:059492
jaydasikaab317e02016-06-01 00:53:189493 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:129494 // Now, even though child has zero opacity, we will configure |grandchild| and
9495 // |greatgrandchild| in several ways that should force the subtree to be
9496 // processed anyhow.
ajumae6f541b2016-05-31 16:50:509497 grandchild_ptr->test_properties()->copy_requests.push_back(
9498 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:099499 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599500 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279501 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:509502
9503 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:189504 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:059505
9506 // A double sided render surface with backface visible should not be skipped
9507 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
ajuma35b24f62017-01-27 21:23:099508 child_ptr->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:369509 child_ptr->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049510 child_ptr->test_properties()->transform = rotate_back_and_translate;
sunxd71aea3e2016-04-01 23:48:059511 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599512 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059513 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049514 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:059515
danakj60bc3bc2016-04-09 00:24:489516 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059517 KeyframedTransformAnimationCurve::Create());
9518 TransformOperations start;
9519 start.AppendTranslate(1.f, 2.f, 3.f);
9520 gfx::Transform transform;
9521 transform.Scale3d(1.0, 2.0, 3.0);
9522 TransformOperations operation;
9523 operation.AppendMatrix(transform);
9524 curve->AddKeyframe(
9525 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9526 curve->AddKeyframe(TransformKeyframe::Create(
9527 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:489528 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:059529 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9530 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089531 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
9532 player.get());
loysobb507792016-10-04 05:31:029533 player->AddAnimation(std::move(transform_animation));
sunxd71aea3e2016-04-01 23:48:059534 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9535 child_ptr->SetScrollClipLayer(root_ptr->id());
jaydasika10d43fc2016-08-18 04:06:049536 root_ptr->test_properties()->transform = singular;
9537 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059538 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599539 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:279540 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:059541
loyso6d6356e2016-11-02 23:41:089542 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
9543 player.get());
sunxd71aea3e2016-04-01 23:48:059544}
9545
jaydasikaf187b06b2016-04-11 23:30:279546TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:599547 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:279548 LayerImpl* child = AddChild<LayerImpl>(root);
9549 LayerImpl* grand_child = AddChild<LayerImpl>(child);
9550
vollickef2ae922016-06-29 17:54:279551 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:279552
9553 gfx::Transform singular;
9554 singular.matrix().set(0, 0, 0);
9555 singular.matrix().set(0, 1, 1);
9556
danakjf78fb272016-07-26 19:06:159557 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:049558 child->test_properties()->transform = singular;
danakjf78fb272016-07-26 19:06:159559 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:279560 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159561 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:279562 grand_child->SetDrawsContent(true);
9563
danakj25c52c32016-04-12 21:51:089564 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:279565 KeyframedTransformAnimationCurve::Create());
9566 TransformOperations start;
9567 start.AppendTranslate(1.f, 2.f, 3.f);
9568 gfx::Transform transform;
9569 transform.Scale3d(1.0, 2.0, 3.0);
9570 TransformOperations operation;
9571 operation.AppendMatrix(transform);
9572 curve->AddKeyframe(
9573 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9574 curve->AddKeyframe(TransformKeyframe::Create(
9575 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:089576 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:279577 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9578 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089579 host_impl()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279580 grand_child->element_id(), player.get());
loysobb507792016-10-04 05:31:029581 player->AddAnimation(std::move(transform_animation));
jaydasikaf187b06b2016-04-11 23:30:279582
9583 ExecuteCalculateDrawProperties(root);
9584 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
9585 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
9586
loyso6d6356e2016-11-02 23:41:089587 host_impl()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279588 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:279589}
9590
sunxd71aea3e2016-04-01 23:48:059591TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
9592 FakeImplTaskRunnerProvider task_runner_provider;
sunxd71aea3e2016-04-01 23:48:059593 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:229594 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
sunxd71aea3e2016-04-01 23:48:059595
sunxd71aea3e2016-04-01 23:48:059596 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:489597 std::unique_ptr<LayerImpl> root =
9598 LayerImpl::Create(host_impl.pending_tree(), 1);
9599 std::unique_ptr<LayerImpl> child =
9600 LayerImpl::Create(host_impl.pending_tree(), 2);
9601 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:059602 LayerImpl::Create(host_impl.pending_tree(), 3);
9603
danakj60bc3bc2016-04-09 00:24:489604 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:059605 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
9606
danakjf78fb272016-07-26 19:06:159607 root->SetBounds(gfx::Size(100, 100));
9608 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:059609 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159610 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:059611 grandchild->SetDrawsContent(true);
9612 greatgrandchild->SetDrawsContent(true);
9613
sunxd71aea3e2016-04-01 23:48:059614 LayerImpl* root_ptr = root.get();
9615 LayerImpl* grandchild_ptr = grandchild.get();
9616
jaydasika89f7b5a2016-06-22 02:08:399617 child->test_properties()->AddChild(std::move(grandchild));
9618 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:059619
jaydasikabf1875a2016-06-28 03:39:599620 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:279621 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:059622
9623 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599624 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059625 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9626
danakj60bc3bc2016-04-09 00:24:489627 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059628 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:499629 std::unique_ptr<TimingFunction> func =
9630 CubicBezierTimingFunction::CreatePreset(
9631 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:059632 curve->AddKeyframe(
9633 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9634 curve->AddKeyframe(
9635 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489636 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059637 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9638 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089639 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
9640 player.get());
loysobb507792016-10-04 05:31:029641 player->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189642 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059643 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9644 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599645 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059646 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9647
loyso6d6356e2016-11-02 23:41:089648 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
9649 player.get());
vollick2175fae82015-04-27 21:18:129650}
9651
9652TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:599653 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149654 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129655
danakjf78fb272016-07-26 19:06:159656 root->SetBounds(gfx::Size(100, 100));
9657 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149658 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129659
jaydasika6f972de2016-04-07 16:16:149660 ExecuteCalculateDrawProperties(root);
9661 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279662 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129663
jaydasika5121caa82016-05-05 15:43:359664 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149665 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9666 ExecuteCalculateDrawProperties(root);
9667 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359668 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129669
9670 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149671 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9672 ExecuteCalculateDrawProperties(root);
9673 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129674 child->SetBounds(gfx::Size(10, 10));
9675
9676 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369677 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129678 rotate.RotateAboutXAxis(180.f);
jaydasika10d43fc2016-08-18 04:06:049679 child->test_properties()->transform = rotate;
jaydasika6f972de2016-04-07 16:16:149680 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9681 ExecuteCalculateDrawProperties(root);
9682 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369683 child->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049684 child->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129685
jaydasikaab317e02016-06-01 00:53:189686 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149687 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9688 ExecuteCalculateDrawProperties(root);
9689 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129690}
9691
jaydasika3d10aa62015-05-06 17:50:449692TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9693 // Ensure that the treewalk in LayerTreeHostCommom::
9694 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319695 scoped_refptr<Layer> root = Layer::Create();
9696 scoped_refptr<Layer> parent = Layer::Create();
9697 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449698
danakjf78fb272016-07-26 19:06:159699 root->SetBounds(gfx::Size(100, 100));
9700 parent->SetBounds(gfx::Size(100, 100));
9701 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:449702 child->SetClipParent(root.get());
9703
danakjf78fb272016-07-26 19:06:159704 root->AddChild(parent);
9705 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:339706 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449707
jaydasika3d10aa62015-05-06 17:50:449708 child->RequestCopyOfOutput(
9709 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029710
jaydasika6ed869662016-09-21 14:29:599711 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029712 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9713
9714 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika6ed869662016-09-21 14:29:599715 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029716 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449717}
9718
vollick692444f2015-05-20 15:39:149719TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:159720 scoped_refptr<Layer> root = Layer::Create();
9721 root->SetBounds(gfx::Size(800, 800));
9722
vollick692444f2015-05-20 15:39:149723 gfx::Transform translate_z;
9724 translate_z.Translate3d(0, 0, 10);
9725
loyso0940d412016-03-14 01:30:319726 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:159727 child->SetTransform(translate_z);
9728 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:149729
9730 root->AddChild(child);
9731
ennea7b43c32015-06-18 20:01:339732 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149733
jaydasika6ed869662016-09-21 14:29:599734 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149735 EXPECT_NE(-1, child->transform_tree_index());
9736
9737 child->RemoveFromParent();
9738
jaydasika6ed869662016-09-21 14:29:599739 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149740 EXPECT_EQ(-1, child->transform_tree_index());
9741}
9742
jaydasika67d7989e2015-08-06 21:55:349743TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9744 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:599745 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349746 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9747 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9748 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9749 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9750
jaydasika67d7989e2015-08-06 21:55:349751 // This transform should be a significant one so that a transform node is
9752 // formed for it.
9753 gfx::Transform transform1;
9754 transform1.RotateAboutYAxis(45);
9755 transform1.RotateAboutXAxis(30);
9756 // This transform should be a 3d transform as we want the render surface
9757 // to flatten the transform
9758 gfx::Transform transform2;
9759 transform2.Translate3d(10, 10, 10);
9760
danakjf78fb272016-07-26 19:06:159761 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049762 significant_transform->test_properties()->transform = transform1;
danakjf78fb272016-07-26 19:06:159763 significant_transform->SetBounds(gfx::Size(30, 30));
9764 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349765 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159766 layer_clips_subtree->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049767 render_surface->test_properties()->transform = transform2;
danakjf78fb272016-07-26 19:06:159768 render_surface->SetBounds(gfx::Size(30, 30));
9769 render_surface->test_properties()->force_render_surface = true;
9770 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349771 test_layer->SetDrawsContent(true);
9772
jaydasika5237db02016-09-20 01:34:309773 float device_scale_factor = 1.f;
9774 float page_scale_factor = 1.f;
9775 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:289776 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:429777 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika5237db02016-09-20 01:34:309778 // Visible rects computed by combining clips in target space and root space
9779 // don't match because of rotation transforms. So, we skip
9780 // verify_visible_rect_calculations.
9781 bool skip_verify_visible_rect_calculations = true;
9782 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:289783 page_scale_layer, inner_viewport_scroll_layer,
flackra283bed2016-10-31 14:49:429784 outer_viewport_scroll_layer,
jaydasika5237db02016-09-20 01:34:309785 skip_verify_visible_rect_calculations);
jaydasika67d7989e2015-08-06 21:55:349786
ajumae4af47062016-05-24 23:59:049787 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:349788 root->layer_tree_impl()->property_trees()->transform_tree;
9789 TransformNode* transform_node =
9790 transform_tree.Node(significant_transform->transform_tree_index());
wkormana4c2d8682017-01-05 01:16:379791 EXPECT_EQ(transform_node->owning_layer_id, significant_transform->id());
jaydasika67d7989e2015-08-06 21:55:349792
weiliangcc154ce22015-12-09 03:39:269793 EXPECT_TRUE(root->has_render_surface());
9794 EXPECT_FALSE(significant_transform->has_render_surface());
9795 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9796 EXPECT_TRUE(render_surface->has_render_surface());
9797 EXPECT_FALSE(test_layer->has_render_surface());
9798
ajumae4af47062016-05-24 23:59:049799 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:349800 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma259f1e72016-10-24 16:25:389801 EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE);
weiliangcd15784432016-06-07 17:57:339802 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect());
jaydasika5237db02016-09-20 01:34:309803
9804 // Also test the visible rects computed by combining clips in root space.
9805 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
9806 root->layer_tree_impl()->property_trees(), test_layer);
9807 EXPECT_EQ(gfx::Rect(30, 20), visible_rect);
jaydasika67d7989e2015-08-06 21:55:349808}
9809
9810TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9811 // Ensure that when parent clip node's transform is an ancestor of current
9812 // clip node's target, clip is 'projected' from parent space to current
9813 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:599814 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349815 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9816 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9817 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9818
jaydasika67d7989e2015-08-06 21:55:349819 gfx::Transform transform;
9820 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:159821
9822 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049823 clip_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159824 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349825 clip_layer->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049826 target_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159827 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349828 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159829 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349830 test_layer->SetDrawsContent(true);
9831
jaydasika67d7989e2015-08-06 21:55:349832 ExecuteCalculateDrawProperties(root);
9833
weiliangcc97575c2016-03-03 18:34:279834 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349835}
9836
jaydasika7d5c1ed2015-08-14 14:27:029837TEST_F(LayerTreeHostCommonTest,
9838 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9839 // Ensure clip rect is calculated correctly when render surface has unclipped
9840 // descendants.
jaydasikabf1875a2016-06-28 03:39:599841 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:029842 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9843 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9844 LayerImpl* render_surface =
9845 AddChild<LayerImpl>(between_clip_parent_and_child);
9846 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9847
weiliangcbb2e8642016-03-04 00:24:429848 gfx::Transform translate;
9849 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029850
danakjf78fb272016-07-26 19:06:159851 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049852 clip_parent->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159853 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:429854 clip_parent->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049855 between_clip_parent_and_child->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159856 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
9857 render_surface->SetBounds(gfx::Size(30, 30));
9858 render_surface->test_properties()->force_render_surface = true;
9859 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:029860 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159861
jaydasika1c0a27d42016-04-28 01:54:569862 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159863 clip_parent->test_properties()->clip_children =
9864 base::MakeUnique<std::set<LayerImpl*>>();
9865 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:029866
9867 ExecuteCalculateDrawProperties(root);
9868
weiliangcbb2e8642016-03-04 00:24:429869 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259870 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569871 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9872 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029873}
9874
jaydasika571dd2cf2015-09-25 20:55:429875TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089876 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9877 // Ensure that the visible layer rect of a descendant of a surface with
9878 // unclipped descendants is computed correctly, when the surface doesn't apply
9879 // a clip.
jaydasikabf1875a2016-06-28 03:39:599880 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:089881 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9882 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9883 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9884 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9885
danakjf78fb272016-07-26 19:06:159886 root->SetBounds(gfx::Size(30, 10));
9887 clip_parent->SetBounds(gfx::Size(30, 30));
9888 render_surface->SetBounds(gfx::Size(10, 15));
9889 render_surface->test_properties()->force_render_surface = true;
9890 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:089891 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159892 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:089893 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159894
jaydasika1c0a27d42016-04-28 01:54:569895 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159896 clip_parent->test_properties()->clip_children =
9897 base::MakeUnique<std::set<LayerImpl*>>();
9898 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:089899
9900 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:189901 EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect());
ajuma01734dd02015-10-07 01:22:089902}
9903
9904TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429905 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:599906 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429907 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9908 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9909 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9910 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9911 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9912
danakjf78fb272016-07-26 19:06:159913 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429914 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159915 clip_parent->SetBounds(gfx::Size(30, 30));
9916 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429917 render_surface->SetMasksToBounds(true);
9918 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159919 render_surface->test_properties()->force_render_surface = true;
9920 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429921 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159922 clip_child->SetBounds(gfx::Size(50, 50));
9923 clip_child->SetDrawsContent(true);
9924 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429925 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429926
danakjf78fb272016-07-26 19:06:159927 clip_child->test_properties()->clip_parent = clip_parent;
9928 clip_parent->test_properties()->clip_children =
9929 base::MakeUnique<std::set<LayerImpl*>>();
9930 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:429931
9932 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569933 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9934 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429935 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9936 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9937}
9938
ajumae2b7a5c2015-09-30 21:41:429939TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:599940 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:429941 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9942 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9943 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9944
danakjf78fb272016-07-26 19:06:159945 root->SetBounds(gfx::Size(50, 50));
9946 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429947 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159948 render_surface->SetBounds(gfx::Size(30, 30));
9949 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:429950 render_surface->SetMasksToBounds(true);
9951 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159952 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429953 clip_child->SetDrawsContent(true);
9954
jaydasika1c0a27d42016-04-28 01:54:569955 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159956 clip_parent->test_properties()->clip_children =
9957 base::MakeUnique<std::set<LayerImpl*>>();
9958 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:429959
9960 ExecuteCalculateDrawProperties(root);
9961
9962 // The clip child should inherit its clip parent's clipping state, not its
9963 // tree parent's clipping state.
9964 EXPECT_FALSE(clip_parent->is_clipped());
9965 EXPECT_TRUE(render_surface->is_clipped());
9966 EXPECT_FALSE(clip_child->is_clipped());
9967}
9968
jaydasika77a4a072015-10-20 21:47:279969TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9970 // Tests the value of render surface content rect when we have multiple types
9971 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9972 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:599973 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279974 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9975 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9976 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9977 LayerImpl* unclipped_desc_surface2 =
9978 AddChild<LayerImpl>(unclipped_desc_surface);
9979 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9980 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9981
danakjf78fb272016-07-26 19:06:159982 root->SetBounds(gfx::Size(80, 80));
9983 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:279984 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159985 unclipped_surface->SetDrawsContent(true);
9986 unclipped_surface->test_properties()->force_render_surface = true;
9987 clip_parent->SetBounds(gfx::Size(50, 50));
9988 clip_parent->SetMasksToBounds(true);
9989 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279990 unclipped_desc_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159991 unclipped_desc_surface->SetDrawsContent(true);
9992 unclipped_desc_surface->test_properties()->force_render_surface = true;
9993 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
9994 unclipped_desc_surface2->SetDrawsContent(true);
9995 unclipped_desc_surface2->test_properties()->force_render_surface = true;
9996 clip_child->SetBounds(gfx::Size(100, 100));
9997 clipped_surface->SetBounds(gfx::Size(70, 70));
9998 clipped_surface->SetDrawsContent(true);
9999 clipped_surface->test_properties()->force_render_surface = true;
10000
10001 clip_child->test_properties()->clip_parent = clip_parent;
10002 clip_parent->test_properties()->clip_children =
10003 base::MakeUnique<std::set<LayerImpl*>>();
10004 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:2710005
10006 ExecuteCalculateDrawProperties(root);
10007 EXPECT_EQ(gfx::Rect(50, 50),
10008 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:5610009 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:2710010 unclipped_desc_surface->render_surface()->content_rect());
10011 EXPECT_EQ(gfx::Rect(50, 50),
10012 unclipped_desc_surface2->render_surface()->content_rect());
10013 EXPECT_EQ(gfx::Rect(50, 50),
10014 clipped_surface->render_surface()->content_rect());
10015}
10016
10017TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
10018 // Tests the value of render surface content rect when we have a layer that
10019 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:5910020 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:2710021 LayerImpl* surface = AddChildToRoot<LayerImpl>();
10022 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
10023 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
10024 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
10025 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
10026
jaydasika77a4a072015-10-20 21:47:2710027 gfx::Transform translate;
10028 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:1510029
jaydasika778cb272016-08-15 19:00:5410030 gfx::Transform rotate;
10031 rotate.RotateAboutXAxis(10);
10032
danakjf78fb272016-07-26 19:06:1510033 root->SetBounds(gfx::Size(100, 100));
10034 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:2710035 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510036 surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:0410037 surface->test_properties()->transform = rotate;
danakjf78fb272016-07-26 19:06:1510038 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:2710039 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510040 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:0410041 unclipped_desc_surface->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:1510042 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
10043 unclipped_desc_surface->SetDrawsContent(true);
10044 unclipped_desc_surface->test_properties()->force_render_surface = true;
10045 clip_child->SetBounds(gfx::Size(100, 100));
10046 clip_child->SetDrawsContent(true);
10047
10048 clip_child->test_properties()->clip_parent = clip_parent;
10049 clip_parent->test_properties()->clip_children =
10050 base::MakeUnique<std::set<LayerImpl*>>();
10051 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:2710052
10053 ExecuteCalculateDrawProperties(root);
10054
10055 EXPECT_EQ(gfx::Rect(10, 10),
10056 unclipped_desc_surface->render_surface()->content_rect());
10057}
10058
jaydasika2c8c2872015-10-21 23:28:2110059TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:5910060 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:2110061 LayerImpl* surface = AddChildToRoot<LayerImpl>();
10062 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
10063 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
10064 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
10065 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
10066
jaydasika2c8c2872015-10-21 23:28:2110067
jaydasika2c8c2872015-10-21 23:28:2110068 gfx::Transform scale;
10069 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:1510070
10071 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:0410072 surface->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:1510073 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:2110074 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510075 surface->test_properties()->force_render_surface = true;
10076 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:2110077 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510078 clip_parent->SetBounds(gfx::Size(50, 50));
10079 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
10080 unclipped_desc_surface->SetDrawsContent(true);
10081 unclipped_desc_surface->test_properties()->force_render_surface = true;
10082 clip_child->SetBounds(gfx::Size(100, 100));
10083 clip_child->SetDrawsContent(true);
10084
10085 clip_child->test_properties()->clip_parent = clip_parent;
10086 clip_parent->test_properties()->clip_children =
10087 base::MakeUnique<std::set<LayerImpl*>>();
10088 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:2110089
10090 ExecuteCalculateDrawProperties(root);
10091
10092 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
10093}
10094
jaydasika60f85862015-10-01 20:36:1410095TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:5910096 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:1410097 LayerImpl* render_surface = AddChild<LayerImpl>(root);
10098 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
10099
jaydasika86654512016-01-27 17:05:0710100 gfx::Transform translation;
10101 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:1410102
danakjf78fb272016-07-26 19:06:1510103 root->SetBounds(gfx::Size(30, 30));
10104 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:1410105 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510106 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:0410107 test_layer->test_properties()->transform = translation;
danakjf78fb272016-07-26 19:06:1510108 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:1410109 test_layer->SetDrawsContent(true);
dtapuskaee0b6982016-01-29 15:14:4810110 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
danakjf78fb272016-07-26 19:06:1510111 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:1410112
10113 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:0210114 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
10115 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:1410116}
10117
jaydasikab874eddc2016-11-02 22:34:2810118TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) {
10119 LayerImpl* root = root_layer_for_testing();
10120 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
10121 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
10122 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
10123 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
10124
10125 root->SetBounds(gfx::Size(100, 100));
10126 clip_layer->SetBounds(gfx::Size(20, 20));
10127 clip_layer->SetMasksToBounds(true);
10128 clip_parent->SetBounds(gfx::Size(50, 50));
10129 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
10130 unclipped_desc_surface->SetDrawsContent(true);
10131 unclipped_desc_surface->test_properties()->force_render_surface = true;
10132 clip_child->SetBounds(gfx::Size(100, 100));
10133 clip_child->SetDrawsContent(true);
10134
10135 clip_child->test_properties()->clip_parent = clip_parent;
10136 clip_parent->test_properties()->clip_children =
10137 base::MakeUnique<std::set<LayerImpl*>>();
10138 clip_parent->test_properties()->clip_children->insert(clip_child);
10139
10140 float device_scale_factor = 1.f;
10141 ExecuteCalculateDrawProperties(root, device_scale_factor);
10142 EXPECT_EQ(gfx::Rect(20, 20), clip_child->clip_rect());
10143 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
10144
10145 device_scale_factor = 2.f;
10146 ExecuteCalculateDrawProperties(root, device_scale_factor);
10147 EXPECT_EQ(gfx::Rect(40, 40), clip_child->clip_rect());
10148 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
10149}
10150
jaydasikae4910fa22015-10-09 00:52:0910151TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:5910152 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:0910153 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
10154 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
10155 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
10156
danakjf78fb272016-07-26 19:06:1510157 root->SetBounds(gfx::Size(30, 30));
10158 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:0910159 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510160 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:0910161 render_surface->SetMasksToBounds(true);
10162 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:1510163 render_surface->test_properties()->force_render_surface = true;
10164 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:0910165 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:0910166
danakjf78fb272016-07-26 19:06:1510167 clip_child->test_properties()->clip_parent = clip_parent;
10168 clip_parent->test_properties()->clip_children =
10169 base::MakeUnique<std::set<LayerImpl*>>();
10170 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:0910171
10172 ExecuteCalculateDrawProperties(root);
jaydasikab4df4032016-09-13 18:38:4910173 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
jaydasikae4910fa22015-10-09 00:52:0910174}
10175
jaydasika571dd2cf2015-09-25 20:55:4210176TEST_F(LayerTreeHostCommonTest,
10177 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:5910178 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:4210179 LayerImpl* render_surface = AddChild<LayerImpl>(root);
10180 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:1510181
10182 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:4210183 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:3610184 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:1510185 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:4210186 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:3610187 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:1510188 render_surface->test_properties()->force_render_surface = true;
10189 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:4210190 test_layer->SetMasksToBounds(true);
10191 test_layer->SetDrawsContent(true);
10192 ExecuteCalculateDrawProperties(root);
10193
10194 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
10195 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
10196 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
10197}
10198
jaydasikab5504ca2015-12-18 23:41:5510199TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
10200 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:5910201 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:5510202 LayerImpl* hidden = AddChild<LayerImpl>(root);
10203 LayerImpl* test = AddChild<LayerImpl>(hidden);
10204
danakjf78fb272016-07-26 19:06:1510205 root->SetBounds(gfx::Size(30, 30));
10206 hidden->SetBounds(gfx::Size(30, 30));
10207 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:3510208 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:1510209 test->SetBounds(gfx::Size(30, 30));
10210 test->test_properties()->force_render_surface = true;
10211
jaydasikab5504ca2015-12-18 23:41:5510212 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:0710213 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:5510214
jaydasika5121caa82016-05-05 15:43:3510215 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:5510216 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
10217 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:0710218 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:5510219}
10220
jaydasikac0137282015-10-01 15:50:3010221TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:5910222 LayerImpl* root = root_layer_for_testing();
jaydasikac0137282015-10-01 15:50:3010223 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
10224 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
10225 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
10226
danakjf78fb272016-07-26 19:06:1510227 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:3010228 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:1510229 render_surface1->SetPosition(gfx::PointF(10, 10));
10230 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:3010231 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:1510232 render_surface1->test_properties()->force_render_surface = true;
10233 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:3010234 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:1510235 render_surface2->test_properties()->force_render_surface = true;
10236 clip_child->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:3010237
danakjf78fb272016-07-26 19:06:1510238 clip_child->test_properties()->clip_parent = root;
10239 root->test_properties()->clip_children =
10240 base::MakeUnique<std::set<LayerImpl*>>();
10241 root->test_properties()->clip_children->insert(clip_child);
10242
jaydasikac0137282015-10-01 15:50:3010243 ExecuteCalculateDrawProperties(root);
10244
10245 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:3710246 // A clip node is created for every render surface and for layers that have
10247 // local clip. So, here it should be craeted for every layer.
10248 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:3010249}
10250
ajumadb6216f2c2016-06-07 21:44:0510251TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
10252 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:5910253 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:0910254 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:5010255 child->test_properties()->SetMaskLayer(
10256 LayerImpl::Create(root->layer_tree_impl(), 100));
10257 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:0910258
jaydasika224bca02015-12-18 02:37:0910259 gfx::Transform transform;
10260 transform.Translate(10, 10);
10261
danakjf78fb272016-07-26 19:06:1510262 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:0910263 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:0410264 child->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:1510265 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:0910266 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:1510267 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:0910268 ExecuteCalculateDrawProperties(root);
10269
ajumadb6216f2c2016-06-07 21:44:0510270 // The render surface created for the mask has no contributing content, so the
10271 // mask isn't a drawn RSLL member. This means it has an empty visible rect,
10272 // but its screen space transform can still be computed correctly on-demand.
ajuma1d4026a32016-06-14 13:18:5010273 EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member());
10274 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
10275 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:0510276
10277 // Make the child's render surface have contributing content.
10278 child->SetDrawsContent(true);
10279 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
10280 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:5010281 EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member());
10282 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
10283 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:0510284
jaydasika224bca02015-12-18 02:37:0910285 transform.Translate(10, 10);
jaydasika10d43fc2016-08-18 04:06:0410286 child->test_properties()->transform = transform;
jaydasika224bca02015-12-18 02:37:0910287 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
10288 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:5010289 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
10290 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:0510291}
10292
jaydasikaf62311f2016-04-20 14:38:4510293TEST_F(LayerTreeHostCommonTest,
10294 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:5910295 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:4510296 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
10297 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
10298 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
10299 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:4510300
10301 gfx::Transform scale;
10302 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:1510303
10304 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:0410305 render_surface1->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:1510306 render_surface1->SetBounds(gfx::Size(30, 30));
10307 render_surface1->test_properties()->force_render_surface = true;
10308 between_targets->SetBounds(gfx::Size(30, 30));
10309 render_surface2->SetBounds(gfx::Size(30, 30));
10310 render_surface2->test_properties()->force_render_surface = true;
10311 test_layer->SetBounds(gfx::Size(30, 30));
10312 test_layer->SetDrawsContent(true);
10313
jaydasikab433552b2016-10-26 18:49:4410314 // We want layer between the two targets to create a clip node and effect
jaydasikaf62311f2016-04-20 14:38:4510315 // node but it shouldn't create a render surface.
10316 between_targets->SetMasksToBounds(true);
jaydasikab433552b2016-10-26 18:49:4410317 between_targets->test_properties()->opacity = 0.5f;
jaydasikaf62311f2016-04-20 14:38:4510318
10319 ExecuteCalculateDrawProperties(root);
10320
jaydasikab433552b2016-10-26 18:49:4410321 EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree;
10322 EffectNode* node = tree.Node(render_surface1->effect_tree_index());
jaydasika6be761602016-07-18 20:11:4310323 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:4510324
jaydasikab433552b2016-10-26 18:49:4410325 node = tree.Node(between_targets->effect_tree_index());
jaydasika6be761602016-07-18 20:11:4310326 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:4510327
jaydasikab433552b2016-10-26 18:49:4410328 node = tree.Node(render_surface2->effect_tree_index());
jaydasika6be761602016-07-18 20:11:4310329 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:4510330
10331 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
10332}
10333
jaydasika3c5633d2016-08-25 00:39:2210334TEST_F(LayerTreeHostCommonTest, NoisyTransform) {
10335 LayerImpl* root = root_layer_for_testing();
10336 LayerImpl* render_surface = AddChild<LayerImpl>(root);
10337 LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface);
10338 LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface);
10339 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip);
10340
10341 scroll_child->test_properties()->scroll_parent = scroll_parent;
10342 scroll_parent->test_properties()->scroll_children =
10343 base::MakeUnique<std::set<LayerImpl*>>();
10344 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
10345 scroll_parent->SetScrollClipLayer(scroll_clip->id());
10346
10347 scroll_parent->SetDrawsContent(true);
10348 scroll_child->SetDrawsContent(true);
10349 render_surface->test_properties()->force_render_surface = true;
10350
10351 // A noisy transform that's invertible.
10352 gfx::Transform transform;
10353 transform.matrix().setDouble(0, 0, 6.12323e-17);
10354 transform.matrix().setDouble(0, 2, 1);
10355 transform.matrix().setDouble(2, 2, 6.12323e-17);
10356 transform.matrix().setDouble(2, 0, -1);
10357
10358 scroll_child->test_properties()->transform = transform;
10359 render_surface->test_properties()->transform = transform;
10360
10361 root->SetBounds(gfx::Size(30, 30));
10362 scroll_child->SetBounds(gfx::Size(30, 30));
10363 scroll_parent->SetBounds(gfx::Size(30, 30));
10364 ExecuteCalculateDrawProperties(root);
10365
10366 gfx::Transform expected;
10367 expected.matrix().setDouble(0, 0, 3.749395e-33);
10368 expected.matrix().setDouble(0, 2, 6.12323e-17);
10369 expected.matrix().setDouble(2, 0, -1);
10370 expected.matrix().setDouble(2, 2, 6.12323e-17);
10371 EXPECT_TRANSFORMATION_MATRIX_EQ(expected,
10372 scroll_child->ScreenSpaceTransform());
10373}
10374
jaydasika5160e672015-10-15 15:25:1410375TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:5910376 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:1410377 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:0510378 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:1410379
sunxd71aea3e2016-04-01 23:48:0510380 child->SetDrawsContent(true);
10381 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:1410382
10383 gfx::Transform large_transform;
10384 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
10385 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
10386 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
10387 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
10388
danakjf78fb272016-07-26 19:06:1510389 root->SetBounds(gfx::Size(30, 30));
10390 render_surface1->SetBounds(gfx::Size(30, 30));
10391 render_surface1->test_properties()->force_render_surface = true;
10392
sunxd71aea3e2016-04-01 23:48:0510393 // TODO(sunxd): we make child have no render surface, because if the
10394 // child has one, the large transform applied to child will result in NaNs in
10395 // the draw_transform of the render_surface, thus make draw property updates
10396 // skip the child layer. We need further investigation into this to know
10397 // what exactly happens here.
jaydasika10d43fc2016-08-18 04:06:0410398 child->test_properties()->transform = large_transform;
danakjf78fb272016-07-26 19:06:1510399 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:1410400
10401 ExecuteCalculateDrawProperties(root);
10402
jaydasika5160e672015-10-15 15:25:1410403 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:0510404 render_surface1->render_surface()->DrawableContentRect());
10405
10406 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
10407 std::isnan(child->DrawTransform().matrix().get(0, 0));
10408 EXPECT_TRUE(is_inf_or_nan);
10409
10410 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
10411 std::isnan(child->DrawTransform().matrix().get(1, 1));
10412 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:1410413
danakj59931942016-07-26 22:11:2910414 // The root layer should be in the RenderSurfaceLayerListImpl.
10415 const auto* rsll = render_surface_layer_list_impl();
10416 EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end());
jaydasika5160e672015-10-15 15:25:1410417}
10418
jaydasika8d6efe2e2016-05-17 15:37:2110419TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:2110420 scoped_refptr<Layer> root = Layer::Create();
10421 scoped_refptr<LayerWithForcedDrawsContent> child =
10422 make_scoped_refptr(new LayerWithForcedDrawsContent());
10423 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:2110424 host()->SetRootLayer(root);
10425
danakjf78fb272016-07-26 19:06:1510426 root->SetBounds(gfx::Size(100, 100));
10427 child->SetBounds(gfx::Size(20, 20));
jaydasika6ed869662016-09-21 14:29:5910428 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110429
10430 // Changing the opacity from 1 to non-1 value should trigger rebuild of
10431 // property trees as a new effect node will be created.
10432 child->SetOpacity(0.5f);
10433 PropertyTrees* property_trees = host()->property_trees();
10434 EXPECT_TRUE(property_trees->needs_rebuild);
10435
jaydasika6ed869662016-09-21 14:29:5910436 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
wkormanc2d1f652017-01-11 22:45:3210437 EXPECT_NE(property_trees->layer_id_to_effect_node_index.find(child->id()),
10438 property_trees->layer_id_to_effect_node_index.end());
jaydasika8d6efe2e2016-05-17 15:37:2110439
10440 // child already has an effect node. Changing its opacity shouldn't trigger
10441 // a property trees rebuild.
10442 child->SetOpacity(0.8f);
10443 property_trees = host()->property_trees();
10444 EXPECT_FALSE(property_trees->needs_rebuild);
10445
jaydasika6ed869662016-09-21 14:29:5910446 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
wkormanc2d1f652017-01-11 22:45:3210447 EXPECT_NE(property_trees->layer_id_to_effect_node_index.find(child->id()),
10448 property_trees->layer_id_to_effect_node_index.end());
jaydasika8d6efe2e2016-05-17 15:37:2110449
10450 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
10451 // property trees as the effect node may no longer be needed.
10452 child->SetOpacity(1.f);
10453 property_trees = host()->property_trees();
10454 EXPECT_TRUE(property_trees->needs_rebuild);
10455
jaydasika6ed869662016-09-21 14:29:5910456 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
wkormanc2d1f652017-01-11 22:45:3210457 EXPECT_EQ(property_trees->layer_id_to_effect_node_index.find(child->id()),
10458 property_trees->layer_id_to_effect_node_index.end());
jaydasika8d6efe2e2016-05-17 15:37:2110459}
10460
jaydasika9cb21c772016-05-10 22:37:0810461TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:0810462 scoped_refptr<Layer> root = Layer::Create();
10463 scoped_refptr<LayerWithForcedDrawsContent> animated =
10464 make_scoped_refptr(new LayerWithForcedDrawsContent());
10465 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:0810466 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:0710467 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:2710468
danakjf78fb272016-07-26 19:06:1510469 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:0810470 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:1510471 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:0810472 animated->SetOpacity(0.f);
10473
10474 scoped_refptr<AnimationPlayer> player =
10475 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
10476 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:2710477
10478 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:0810479
10480 int animation_id = 0;
10481 std::unique_ptr<Animation> animation = Animation::Create(
10482 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
10483 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:5510484 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:0810485 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
10486 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:2710487 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
10488 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:0810489
jaydasika6ed869662016-09-21 14:29:5910490 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika9cb21c772016-05-10 22:37:0810491
khushalsagarb69ba9452017-01-27 22:20:0710492 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree;
jaydasika9cb21c772016-05-10 22:37:0810493 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110494 EXPECT_FALSE(node->is_currently_animating_opacity);
10495 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810496
10497 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:5810498 host()->AnimateLayers(
jaydasika9cb21c772016-05-10 22:37:0810499 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
10500 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110501 EXPECT_TRUE(node->is_currently_animating_opacity);
10502 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810503
10504 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
10505 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110506 EXPECT_FALSE(node->is_currently_animating_opacity);
10507 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810508}
10509
jaydasika6c3404e92016-05-19 02:40:3610510TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:3610511 scoped_refptr<Layer> root = Layer::Create();
10512 scoped_refptr<LayerWithForcedDrawsContent> animated =
10513 make_scoped_refptr(new LayerWithForcedDrawsContent());
10514 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:3610515 host()->SetRootLayer(root);
khushalsagarb69ba9452017-01-27 22:20:0710516 host()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:2710517
danakjf78fb272016-07-26 19:06:1510518 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:3610519 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:1510520 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:3610521
10522 scoped_refptr<AnimationPlayer> player =
10523 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
10524 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:2710525 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:3610526
10527 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
10528 KeyframedTransformAnimationCurve::Create());
10529 TransformOperations start;
10530 start.AppendTranslate(1.f, 2.f, 3.f);
10531 gfx::Transform transform;
10532 transform.Scale3d(1.0, 2.0, 3.0);
10533 TransformOperations operation;
10534 operation.AppendMatrix(transform);
10535 curve->AddKeyframe(
10536 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
10537 curve->AddKeyframe(TransformKeyframe::Create(
10538 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
10539 std::unique_ptr<Animation> animation(
10540 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
10541 animation->set_fill_mode(Animation::FillMode::NONE);
10542 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
10543 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:2710544 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
10545 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:3610546
jaydasika6ed869662016-09-21 14:29:5910547 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika6c3404e92016-05-19 02:40:3610548
khushalsagarb69ba9452017-01-27 22:20:0710549 TransformTree& tree =
10550 root->layer_tree_host()->property_trees()->transform_tree;
jaydasika6c3404e92016-05-19 02:40:3610551 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110552 EXPECT_FALSE(node->is_currently_animating);
10553 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610554
10555 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:5810556 host()->AnimateLayers(
jaydasika6c3404e92016-05-19 02:40:3610557 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
10558 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110559 EXPECT_TRUE(node->is_currently_animating);
10560 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610561
10562 player->AbortAnimations(TargetProperty::TRANSFORM,
10563 false /*needs_completion*/);
10564 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110565 EXPECT_FALSE(node->is_currently_animating);
10566 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610567}
10568
sunxdea1df782016-01-28 00:12:3310569TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
10570 // Test the behavior of scroll tree builder
10571 // Topology:
sunxdcfccd1b32016-02-11 00:54:2010572 // +root1(1)[inner_viewport_container_layer]
10573 // +-page_scale_layer
10574 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
10575 // scrollable, inner_viewport_scroll_layer]
10576 // +------child6(6)[kScrollbarScrolling]
10577 // +--------grand_child10(10)[kScrollbarScrolling]
10578 // +----parent3(3)
10579 // +------child7(7)[scrollable]
10580 // +------child8(8)[scroll_parent=7]
10581 // +--------grand_child11(11)[scrollable]
10582 // +----parent4(4)
10583 // +------child9(9)
10584 // +--------grand_child12(12)
10585 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:3310586 //
10587 // Expected scroll tree topology:
10588 // +property_tree_root---owner:-1
10589 // +--root---owner:1, id:1
10590 // +----node---owner:2, id:2
10591 // +------node---owner:6, id:3
10592 // +----node---owner:7, id:4
10593 // +------node---owner:11, id:5
10594 // +----node---owner:5, id:6
10595 //
10596 // Extra check:
10597 // scroll_tree_index() of:
10598 // grand_child10:3
10599 // parent3:1
10600 // child8:4
10601 // parent4:1
10602 // child9:1
10603 // grand_child12:1
loyso0940d412016-03-14 01:30:3110604 scoped_refptr<Layer> root1 = Layer::Create();
10605 scoped_refptr<Layer> page_scale_layer = Layer::Create();
10606 scoped_refptr<Layer> parent2 = Layer::Create();
10607 scoped_refptr<Layer> parent3 = Layer::Create();
10608 scoped_refptr<Layer> parent4 = Layer::Create();
10609 scoped_refptr<Layer> parent5 = Layer::Create();
10610 scoped_refptr<Layer> child6 = Layer::Create();
10611 scoped_refptr<Layer> child7 = Layer::Create();
10612 scoped_refptr<Layer> child8 = Layer::Create();
10613 scoped_refptr<Layer> child9 = Layer::Create();
10614 scoped_refptr<Layer> grand_child10 = Layer::Create();
10615 scoped_refptr<Layer> grand_child11 = Layer::Create();
10616 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:3310617
sunxdcfccd1b32016-02-11 00:54:2010618 root1->AddChild(page_scale_layer);
10619 page_scale_layer->AddChild(parent2);
10620 page_scale_layer->AddChild(parent3);
10621 page_scale_layer->AddChild(parent4);
10622 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310623 parent2->AddChild(child6);
10624 parent3->AddChild(child7);
10625 parent3->AddChild(child8);
10626 parent4->AddChild(child9);
10627 child6->AddChild(grand_child10);
10628 child8->AddChild(grand_child11);
10629 child9->AddChild(grand_child12);
10630 host()->SetRootLayer(root1);
10631
10632 parent2->AddMainThreadScrollingReasons(
10633 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:4810634 parent2->AddMainThreadScrollingReasons(
10635 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310636 parent2->SetScrollClipLayerId(root1->id());
10637 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810638 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310639 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810640 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310641
sunxdcfccd1b32016-02-11 00:54:2010642 child7->SetScrollClipLayerId(parent3->id());
10643
sunxdea1df782016-01-28 00:12:3310644 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:2010645 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:3310646
10647 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010648 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310649
khushalsagarb69ba9452017-01-27 22:20:0710650 host()->RegisterViewportLayers(nullptr, page_scale_layer, parent2, nullptr);
jaydasika6ed869662016-09-21 14:29:5910651 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get());
sunxdea1df782016-01-28 00:12:3310652
sunxdea1df782016-01-28 00:12:3310653 const int kRootPropertyTreeNodeId = 0;
10654
10655 // Property tree root
ajumae4af47062016-05-24 23:59:0410656 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010657 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010658 property_trees.is_main_thread = true;
10659 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410660 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310661 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10662 property_tree_root->id = kRootPropertyTreeNodeId;
ajumaf884cfb2017-01-16 22:27:5210663 property_tree_root->parent_id = ScrollTree::kInvalidNodeId;
10664 property_tree_root->owning_layer_id = Layer::INVALID_ID;
trchendba8b1502016-07-08 09:47:0110665 property_tree_root->scrollable = false;
10666 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810667 MainThreadScrollingReason::kNotScrollingOnMain;
trchendba8b1502016-07-08 09:47:0110668 property_tree_root->contains_non_fast_scrollable_region = false;
10669 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310670
10671 // The node owned by root1
10672 ScrollNode scroll_root1;
10673 scroll_root1.id = 1;
wkormana4c2d8682017-01-05 01:16:3710674 scroll_root1.owning_layer_id = root1->id();
trchendba8b1502016-07-08 09:47:0110675 scroll_root1.user_scrollable_horizontal = true;
10676 scroll_root1.user_scrollable_vertical = true;
10677 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310678 expected_scroll_tree.Insert(scroll_root1, 0);
10679
10680 // The node owned by parent2
10681 ScrollNode scroll_parent2;
10682 scroll_parent2.id = 2;
wkormana4c2d8682017-01-05 01:16:3710683 scroll_parent2.owning_layer_id = parent2->id();
trchendba8b1502016-07-08 09:47:0110684 scroll_parent2.scrollable = true;
10685 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810686 parent2->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110687 scroll_parent2.scroll_clip_layer_bounds = root1->bounds();
10688 scroll_parent2.bounds = parent2->bounds();
10689 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
pdrabe15522017-02-24 19:15:5610690 scroll_parent2.scrolls_inner_viewport = true;
trchendba8b1502016-07-08 09:47:0110691 scroll_parent2.user_scrollable_horizontal = true;
10692 scroll_parent2.user_scrollable_vertical = true;
10693 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310694 expected_scroll_tree.Insert(scroll_parent2, 1);
10695
10696 // The node owned by child6
10697 ScrollNode scroll_child6;
10698 scroll_child6.id = 3;
wkormana4c2d8682017-01-05 01:16:3710699 scroll_child6.owning_layer_id = child6->id();
trchendba8b1502016-07-08 09:47:0110700 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810701 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110702 scroll_child6.should_flatten = true;
10703 scroll_child6.user_scrollable_horizontal = true;
10704 scroll_child6.user_scrollable_vertical = true;
10705 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310706 expected_scroll_tree.Insert(scroll_child6, 2);
10707
10708 // The node owned by child7, child7 also owns a transform node
10709 ScrollNode scroll_child7;
10710 scroll_child7.id = 4;
wkormana4c2d8682017-01-05 01:16:3710711 scroll_child7.owning_layer_id = child7->id();
trchendba8b1502016-07-08 09:47:0110712 scroll_child7.scrollable = true;
10713 scroll_child7.scroll_clip_layer_bounds = parent3->bounds();
10714 scroll_child7.bounds = child7->bounds();
10715 scroll_child7.user_scrollable_horizontal = true;
10716 scroll_child7.user_scrollable_vertical = true;
10717 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310718 expected_scroll_tree.Insert(scroll_child7, 1);
10719
10720 // The node owned by grand_child11, grand_child11 also owns a transform node
10721 ScrollNode scroll_grand_child11;
10722 scroll_grand_child11.id = 5;
wkormana4c2d8682017-01-05 01:16:3710723 scroll_grand_child11.owning_layer_id = grand_child11->id();
trchendba8b1502016-07-08 09:47:0110724 scroll_grand_child11.scrollable = true;
10725 scroll_grand_child11.user_scrollable_horizontal = true;
10726 scroll_grand_child11.user_scrollable_vertical = true;
10727 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310728 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10729
10730 // The node owned by parent5
10731 ScrollNode scroll_parent5;
10732 scroll_parent5.id = 8;
wkormana4c2d8682017-01-05 01:16:3710733 scroll_parent5.owning_layer_id = parent5->id();
trchendba8b1502016-07-08 09:47:0110734 scroll_parent5.contains_non_fast_scrollable_region = true;
10735 scroll_parent5.bounds = gfx::Size(10, 10);
10736 scroll_parent5.should_flatten = true;
10737 scroll_parent5.user_scrollable_horizontal = true;
10738 scroll_parent5.user_scrollable_vertical = true;
10739 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310740 expected_scroll_tree.Insert(scroll_parent5, 1);
10741
sunxdc044b11a2016-03-16 16:23:2010742 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10743 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10744 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10745 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310746 expected_scroll_tree.set_needs_update(false);
10747
10748 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10749
10750 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010751 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310752 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10753 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10754 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10755 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10756 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10757 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10758}
10759
[email protected]ba565742012-11-10 09:29:4810760} // namespace
10761} // namespace cc