blob: e6c829f260ff55d90ba01c111dc14bd0065c0773 [file] [log] [blame]
ajumae2b7a5c2015-09-30 21:41:421// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_common.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj6496cba2014-10-16 01:31:089#include <algorithm>
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]995708c52013-10-17 20:52:5911#include <set>
vmpstra370ef52015-11-18 10:41:2812#include <vector>
[email protected]995708c52013-10-17 20:52:5913
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
loyso968163c92016-01-04 23:18:4815#include "cc/animation/animation_host.h"
16#include "cc/animation/animation_id_provider.h"
sunxd71aea3e2016-04-01 23:48:0517#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3418#include "cc/animation/keyframed_animation_curve.h"
[email protected]1c3626e2014-04-09 17:49:2219#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5220#include "cc/base/math_util.h"
sunxd29f17bf422016-02-03 02:47:4821#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5924#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5225#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4026#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2827#include "cc/layers/render_surface_impl.h"
jaydasika69c77aa2016-07-14 22:48:4828#include "cc/layers/texture_layer_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4529#include "cc/output/copy_output_request.h"
30#include "cc/output/copy_output_result.h"
khushalsagar37694212016-01-15 20:46:4831#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
32#include "cc/proto/gfx_conversions.h"
[email protected]101441ce2012-10-16 01:45:0333#include "cc/test/animation_test_common.h"
danakj1120f4c2016-09-15 02:05:3234#include "cc/test/fake_compositor_frame_sink.h"
vollick2175fae82015-04-27 21:18:1235#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1636#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2837#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4538#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5939#include "cc/test/fake_picture_layer.h"
40#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0341#include "cc/test/geometry_test_utils.h"
danakj59931942016-07-26 22:11:2942#include "cc/test/layer_test_common.h"
reveman34b7a1522015-03-23 20:27:4743#include "cc/test/test_task_graph_runner.h"
trchendba8b1502016-07-08 09:47:0144#include "cc/trees/clip_node.h"
ennef6903532015-08-18 05:10:1545#include "cc/trees/draw_property_utils.h"
trchendba8b1502016-07-08 09:47:0146#include "cc/trees/effect_node.h"
[email protected]556fd292013-03-18 08:03:0447#include "cc/trees/layer_tree_impl.h"
danakj59931942016-07-26 22:11:2948#include "cc/trees/property_tree_builder.h"
trchendba8b1502016-07-08 09:47:0149#include "cc/trees/scroll_node.h"
[email protected]556fd292013-03-18 08:03:0450#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1651#include "cc/trees/task_runner_provider.h"
trchendba8b1502016-07-08 09:47:0152#include "cc/trees/transform_node.h"
[email protected]7f0c53db2012-10-02 00:23:1853#include "testing/gtest/include/gtest/gtest.h"
jbroman1c44d5b52016-06-06 21:19:3054#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2055#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3756#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0057#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1458
[email protected]ba565742012-11-10 09:29:4859namespace cc {
[email protected]94f206c12012-08-25 00:09:1460namespace {
61
danakj59931942016-07-26 22:11:2962class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings {
63 public:
64 VerifyTreeCalcsLayerTreeSettings() {
jaydasika853306a2016-07-29 19:28:3465 verify_clip_tree_calculations = true;
danakj59931942016-07-26 22:11:2966 }
67};
68
69class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest {
70 public:
71 LayerTreeHostCommonTestBase()
72 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {}
73 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings)
74 : LayerTestCommon::LayerImplTest(settings) {}
75
76 static void SetScrollOffsetDelta(LayerImpl* layer_impl,
77 const gfx::Vector2dF& delta) {
78 if (layer_impl->layer_tree_impl()
79 ->property_trees()
80 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(),
81 delta))
vollickc9696912016-09-16 16:02:4782 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(layer_impl->id());
danakj59931942016-07-26 22:11:2983 }
84
85 static float GetMaximumAnimationScale(LayerImpl* layer_impl) {
86 return layer_impl->layer_tree_impl()
87 ->property_trees()
88 ->GetAnimationScales(layer_impl->transform_tree_index(),
89 layer_impl->layer_tree_impl())
90 .maximum_animation_scale;
91 }
92
93 static float GetStartingAnimationScale(LayerImpl* layer_impl) {
94 return layer_impl->layer_tree_impl()
95 ->property_trees()
96 ->GetAnimationScales(layer_impl->transform_tree_index(),
97 layer_impl->layer_tree_impl())
98 .starting_animation_scale;
99 }
100
101 void ExecuteCalculateDrawProperties(Layer* root_layer,
102 float device_scale_factor,
103 float page_scale_factor,
flackre310f292016-10-12 21:09:28104 Layer* page_scale_layer,
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) {
khushalsagar86928f92016-08-17 21:49:05191 DCHECK(root_layer->GetLayerTree());
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 =
khushalsagar86928f92016-08-17 21:49:05197 root_layer->GetLayerTree()->page_scale_layer();
danakj59931942016-07-26 22:11:29198 Layer* inner_viewport_scroll_layer =
khushalsagar86928f92016-08-17 21:49:05199 root_layer->GetLayerTree()->inner_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29200 Layer* outer_viewport_scroll_layer =
khushalsagar86928f92016-08-17 21:49:05201 root_layer->GetLayerTree()->outer_viewport_scroll_layer();
danakj59931942016-07-26 22:11:29202 const Layer* overscroll_elasticity_layer =
khushalsagar86928f92016-08-17 21:49:05203 root_layer->GetLayerTree()->overscroll_elasticity_layer();
danakj59931942016-07-26 22:11:29204 gfx::Vector2dF elastic_overscroll =
khushalsagar86928f92016-08-17 21:49:05205 root_layer->GetLayerTree()->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 =
khushalsagar86928f92016-08-17 21:49:05212 root_layer->GetLayerTree()->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(
jaydasikab433552b2016-10-26 18:49:44222 root_layer->GetLayerTree(), 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));
awoloszyne83f28c2014-12-22 15:40:00566 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09567 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59568 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
[email protected]657b24c2013-03-06 09:01:20569
jaydasikaa534a472016-03-31 01:12:16570 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28571 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42572 nullptr, nullptr);
danakjf78fb272016-07-26 19:06:15573 gfx::Transform expected_transform;
[email protected]fb661802013-03-25 01:59:32574 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33575 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16576 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33577 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16578 page_scale * kDeviceScale));
579 expected_transform.Scale(page_scale * kDeviceScale,
580 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32581 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44582 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32583 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10584 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20585
[email protected]fb661802013-03-25 01:59:32586 gfx::Transform arbitrary_translate;
587 const float kTranslateX = 10.6f;
588 const float kTranslateY = 20.6f;
589 arbitrary_translate.Translate(kTranslateX, kTranslateY);
jaydasika10d43fc2016-08-18 04:06:04590 scroll_layer->test_properties()->transform = arbitrary_translate;
jaydasika2411692c2016-03-23 01:56:09591 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16592 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28593 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42594 nullptr, nullptr);
[email protected]fb661802013-03-25 01:59:32595 expected_transform.MakeIdentity();
596 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16597 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
598 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33599 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16600 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
601 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33602 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16603 expected_transform.Scale(page_scale * kDeviceScale,
604 page_scale * kDeviceScale);
605 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
606 sublayer->DrawTransform());
607
608 // Test that page scale is updated even when we don't rebuild property trees.
609 page_scale = 1.888f;
610 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
jaydasikaf419bf72016-06-15 10:21:21611 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(),
612 Layer::INVALID_ID, Layer::INVALID_ID);
jaydasikaa534a472016-03-31 01:12:16613 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
614 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
615 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
flackre310f292016-10-12 21:09:28616 scroll_layer->test_properties()->parent,
flackra283bed2016-10-31 14:49:42617 nullptr, nullptr);
jaydasikaa534a472016-03-31 01:12:16618
619 expected_transform.MakeIdentity();
620 expected_transform.Translate(
621 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
622 sub_layer_screen_position.x() * page_scale *
623 kDeviceScale),
624 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
625 sub_layer_screen_position.y() * page_scale *
626 kDeviceScale));
627 expected_transform.Scale(page_scale * kDeviceScale,
628 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32629 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44630 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20631}
632
[email protected]989386c2013-07-18 21:37:23633TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
jaydasikabf1875a2016-06-28 03:39:59634 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51635 LayerImpl* parent = AddChild<LayerImpl>(root);
636 LayerImpl* child = AddChild<LayerImpl>(parent);
637 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28638
[email protected]fb661802013-03-25 01:59:32639 // One-time setup of root layer
danakje4fa7b72016-07-25 22:00:06640 root->SetBounds(gfx::Size(1, 2));
enne826452722015-08-18 22:22:31641
jaydasikabaede2d92016-07-20 00:34:32642 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51643 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32644 EffectTree& effect_tree =
645 host_impl()->active_tree()->property_trees()->effect_tree;
[email protected]ecc12622012-10-30 20:45:42646
[email protected]fb661802013-03-25 01:59:32647 // Case 1: parent's anchor point should not affect child or grand_child.
danakje4fa7b72016-07-25 22:00:06648 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
649 parent->SetBounds(gfx::Size(10, 12));
650 child->SetBounds(gfx::Size(16, 18));
651 grand_child->SetBounds(gfx::Size(76, 78));
sunxdfd920f3f2016-04-05 16:17:51652 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31653
654 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15655 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32656 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31657 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15658 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32659 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
660 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15661 gfx::Transform(), draw_property_utils::DrawTransform(
662 grand_child, transform_tree, effect_tree));
jaydasikabaede2d92016-07-20 00:34:32663 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15664 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32665 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14666
[email protected]fb661802013-03-25 01:59:32667 // Case 2: parent's position affects child and grand_child.
668 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05669 parent_position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06670 parent->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51671 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
672 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31673 EXPECT_TRANSFORMATION_MATRIX_EQ(
674 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32675 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31676 EXPECT_TRANSFORMATION_MATRIX_EQ(
677 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32678 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
679 EXPECT_TRANSFORMATION_MATRIX_EQ(
680 parent_position_transform, draw_property_utils::DrawTransform(
681 grand_child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31682 EXPECT_TRANSFORMATION_MATRIX_EQ(
683 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32684 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14685
[email protected]fb661802013-03-25 01:59:32686 // Case 3: parent's local transform affects child and grandchild
687 gfx::Transform parent_layer_transform;
688 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
689 gfx::Transform parent_translation_to_anchor;
690 parent_translation_to_anchor.Translate(2.5, 3.0);
691 gfx::Transform parent_composite_transform =
692 parent_translation_to_anchor * parent_layer_transform *
693 Inverse(parent_translation_to_anchor);
jaydasika10d43fc2016-08-18 04:06:04694 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06695 parent->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51696 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
697 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31698 EXPECT_TRANSFORMATION_MATRIX_EQ(
699 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32700 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31701 EXPECT_TRANSFORMATION_MATRIX_EQ(
702 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32703 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
enne826452722015-08-18 22:22:31704 EXPECT_TRANSFORMATION_MATRIX_EQ(
705 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32706 draw_property_utils::DrawTransform(grand_child, transform_tree,
707 effect_tree));
enne826452722015-08-18 22:22:31708 EXPECT_TRANSFORMATION_MATRIX_EQ(
709 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32710 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14711}
712
[email protected]989386c2013-07-18 21:37:23713TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:59714 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28715 LayerImpl* parent = AddChildToRoot<LayerImpl>();
716 LayerImpl* child = AddChild<LayerImpl>(parent);
717 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]94f206c12012-08-25 00:09:14718
[email protected]fb661802013-03-25 01:59:32719 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05720 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32721 gfx::Transform parent_translation_to_anchor;
722 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44723
[email protected]fb661802013-03-25 01:59:32724 gfx::Transform parent_composite_transform =
725 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39726 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32727 gfx::Vector2dF parent_composite_scale =
728 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
729 1.f);
730 gfx::Transform surface_sublayer_transform;
731 surface_sublayer_transform.Scale(parent_composite_scale.x(),
732 parent_composite_scale.y());
733 gfx::Transform surface_sublayer_composite_transform =
734 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14735
danakje4fa7b72016-07-25 22:00:06736 root->SetBounds(gfx::Size(1, 2));
jaydasika10d43fc2016-08-18 04:06:04737 parent->test_properties()->transform = parent_layer_transform;
danakje4fa7b72016-07-25 22:00:06738 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
739 parent->SetBounds(gfx::Size(100, 120));
740 child->SetBounds(gfx::Size(16, 18));
741 child->test_properties()->force_render_surface = true;
742 grand_child->SetBounds(gfx::Size(8, 10));
743 grand_child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28744 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14745
[email protected]fb661802013-03-25 01:59:32746 // Render surface should have been created now.
747 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25748 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14749
[email protected]fb661802013-03-25 01:59:32750 // The child layer's draw transform should refer to its new render surface.
751 // The screen-space transform, however, should still refer to the root.
752 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44753 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32754 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10755 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14756
[email protected]fb661802013-03-25 01:59:32757 // Because the grand_child is the only drawable content, the child's render
758 // surface will tighten its bounds to the grand_child. The scale at which the
759 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25760 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
761 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14762
[email protected]fb661802013-03-25 01:59:32763 // The screen space is the same as the target since the child surface draws
764 // into the root.
765 EXPECT_TRANSFORMATION_MATRIX_EQ(
766 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25767 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14768}
769
ajuma51d73f72015-10-19 19:43:58770TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:59771 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:58772 LayerImpl* parent = AddChildToRoot<LayerImpl>();
773 LayerImpl* child = AddChild<LayerImpl>(parent);
774 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma51d73f72015-10-19 19:43:58775
776 gfx::Transform parent_transform;
777 parent_transform.Translate(10.0, 10.0);
778
779 gfx::Transform child_transform;
780 child_transform.Rotate(45.0);
781
danakje4fa7b72016-07-25 22:00:06782 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:04783 parent->test_properties()->transform = parent_transform;
danakje4fa7b72016-07-25 22:00:06784 parent->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:04785 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:06786 child->SetBounds(gfx::Size(10, 10));
787 child->test_properties()->force_render_surface = true;
788 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
789 grand_child->SetBounds(gfx::Size(20, 20));
790 grand_child->SetDrawsContent(true);
ajuma51d73f72015-10-19 19:43:58791
792 gfx::Transform expected_grand_child_screen_space_transform;
793 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
794 expected_grand_child_screen_space_transform.Rotate(45.0);
795 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
796
797 // First compute draw properties with separate surfaces enabled.
798 ExecuteCalculateDrawProperties(root);
799
800 // The grand child's draw transform should be its offset wrt the child.
801 gfx::Transform expected_grand_child_draw_transform;
802 expected_grand_child_draw_transform.Translate(2.0, 2.0);
803 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44804 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58805 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10806 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58807
808 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
809
810 // With separate surfaces disabled, the grand child's draw transform should be
811 // the same as its screen space transform.
812 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44813 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58814 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10815 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58816}
817
[email protected]989386c2013-07-18 21:37:23818TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32819 // This test creates a more complex tree and verifies it all at once. This
820 // covers the following cases:
821 // - layers that are described w.r.t. a render surface: should have draw
822 // transforms described w.r.t. that surface
823 // - A render surface described w.r.t. an ancestor render surface: should
824 // have a draw transform described w.r.t. that ancestor surface
[email protected]fb661802013-03-25 01:59:32825 // - Sanity check on recursion: verify transforms of layers described w.r.t.
826 // a render surface that is described w.r.t. an ancestor render surface.
827 // - verifying that each layer has a reference to the correct render surface
828 // and render target values.
829
jaydasikabf1875a2016-06-28 03:39:59830 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28831 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36832 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28833 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36834 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28835 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36836 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28837 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36838 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28839 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36840 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28841 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36842 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28843 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36844 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28845 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
846 grand_child_of_rs1->SetDrawsContent(true);
847 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
848 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32849
[email protected]fb661802013-03-25 01:59:32850 // In combination with descendant draws content, opacity != 1 forces the layer
851 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18852 render_surface1->test_properties()->opacity = 0.5f;
853 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32854
[email protected]fb661802013-03-25 01:59:32855 // All layers in the tree are initialized with an anchor at .25 and a size of
wangxianzhu932d7f12016-09-30 05:47:00856 // (10,10). Matrix "A" is the composite layer transform used in all layers.
[email protected]fb661802013-03-25 01:59:32857 gfx::Transform translation_to_anchor;
858 translation_to_anchor.Translate(2.5, 0.0);
859 gfx::Transform layer_transform;
860 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32861
862 gfx::Transform A =
863 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32864
865 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39866 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32867 gfx::Transform surface1_sublayer_transform;
868 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
869 surface1_parent_transform_scale.y());
870
871 // SS1 = transform given to the subtree of render_surface1
872 gfx::Transform SS1 = surface1_sublayer_transform;
873 // S1 = transform to move from render_surface1 pixels to the layer space of
874 // the owning layer
875 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
876
877 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39878 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32879 gfx::Transform surface2_sublayer_transform;
880 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
881 surface2_parent_transform_scale.y());
882
883 // SS2 = transform given to the subtree of render_surface2
884 gfx::Transform SS2 = surface2_sublayer_transform;
885 // S2 = transform to move from render_surface2 pixels to the layer space of
886 // the owning layer
887 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
888
danakje4fa7b72016-07-25 22:00:06889 root->SetBounds(gfx::Size(1, 2));
890 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04891 parent->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06892 parent->SetBounds(gfx::Size(10, 10));
893 render_surface1->test_properties()->transform_origin =
894 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04895 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06896 render_surface1->SetBounds(gfx::Size(10, 10));
897 render_surface1->test_properties()->force_render_surface = true;
898 render_surface2->test_properties()->transform_origin =
899 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04900 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06901 render_surface2->SetBounds(gfx::Size(10, 10));
902 render_surface2->test_properties()->force_render_surface = true;
903 child_of_root->test_properties()->transform_origin =
904 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04905 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06906 child_of_root->SetBounds(gfx::Size(10, 10));
907 child_of_rs1->test_properties()->transform_origin =
908 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04909 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06910 child_of_rs1->SetBounds(gfx::Size(10, 10));
911 child_of_rs2->test_properties()->transform_origin =
912 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04913 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06914 child_of_rs2->SetBounds(gfx::Size(10, 10));
915 grand_child_of_root->test_properties()->transform_origin =
916 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04917 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06918 grand_child_of_root->SetBounds(gfx::Size(10, 10));
919 grand_child_of_rs1->test_properties()->transform_origin =
920 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04921 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06922 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
923 grand_child_of_rs2->test_properties()->transform_origin =
924 gfx::Point3F(2.5f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:04925 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:06926 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:32927
enne25dea3f2015-07-27 16:44:28928 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32929
930 // Only layers that are associated with render surfaces should have an actual
931 // RenderSurface() value.
932 ASSERT_TRUE(root->render_surface());
933 ASSERT_FALSE(child_of_root->render_surface());
934 ASSERT_FALSE(grand_child_of_root->render_surface());
935
936 ASSERT_TRUE(render_surface1->render_surface());
937 ASSERT_FALSE(child_of_rs1->render_surface());
938 ASSERT_FALSE(grand_child_of_rs1->render_surface());
939
940 ASSERT_TRUE(render_surface2->render_surface());
941 ASSERT_FALSE(child_of_rs2->render_surface());
942 ASSERT_FALSE(grand_child_of_rs2->render_surface());
943
944 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25945 EXPECT_EQ(root->render_surface(), parent->render_target());
946 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
947 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32948
weiliangc189c1a12016-04-11 16:16:25949 EXPECT_EQ(render_surface1->render_surface(),
950 render_surface1->render_target());
951 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
952 EXPECT_EQ(render_surface1->render_surface(),
953 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32954
weiliangc189c1a12016-04-11 16:16:25955 EXPECT_EQ(render_surface2->render_surface(),
956 render_surface2->render_target());
957 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
958 EXPECT_EQ(render_surface2->render_surface(),
959 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32960
961 // Verify layer draw transforms note that draw transforms are described with
962 // respect to the nearest ancestor render surface but screen space transforms
963 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44964 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
965 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39966 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44967 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32968
ajumad9432e32015-11-30 19:43:44969 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
970 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39971 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44972 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32973
ajumad9432e32015-11-30 19:43:44974 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
975 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39976 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44977 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32978
979 // Verify layer screen-space transforms
980 //
ajumab6aa1c62015-12-01 21:01:10981 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
982 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
983 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
984 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32985
[email protected]baf64d062014-02-16 22:10:39986 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10987 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39988 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10989 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39990 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10991 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32992
[email protected]baf64d062014-02-16 22:10:39993 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10994 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39995 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10996 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39997 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10998 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32999
1000 // Verify render surface transforms.
1001 //
1002 // Draw transform of render surface 1 is described with respect to root.
1003 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391004 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321005 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391006 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321007 // Draw transform of render surface 2 is described with respect to render
1008 // surface 1.
1009 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391010 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321011 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391012 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321013 render_surface2->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321014
1015 // Sanity check. If these fail there is probably a bug in the test itself. It
1016 // is expected that we correctly set up transforms so that the y-component of
1017 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:101018 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:261019 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101020 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321021 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101022 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321023
[email protected]803f6b52013-09-12 00:51:261024 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101025 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
1026 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321027 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101028 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321029
[email protected]803f6b52013-09-12 00:51:261030 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:101031 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
1032 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321033 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101034 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321035}
1036
[email protected]989386c2013-07-18 21:37:231037TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321038 // For layers that flatten their subtree, there should be an orthographic
1039 // projection (for x and y values) in the middle of the transform sequence.
1040 // Note that the way the code is currently implemented, it is not expected to
1041 // use a canonical orthographic projection.
1042
jaydasikabf1875a2016-06-28 03:39:591043 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:281044 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:361045 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:281046 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1047 grand_child->SetDrawsContent(true);
1048 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1049 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321050
1051 gfx::Transform rotation_about_y_axis;
1052 rotation_about_y_axis.RotateAboutYAxis(30.0);
1053
danakje4fa7b72016-07-25 22:00:061054 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041055 child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061056 child->SetBounds(gfx::Size(10, 10));
1057 child->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041058 grand_child->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061059 grand_child->SetBounds(gfx::Size(10, 10));
1060 great_grand_child->SetBounds(gfx::Size(10, 10));
[email protected]d600df7d2013-08-03 02:34:281061
[email protected]fb661802013-03-25 01:59:321062 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521063 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
1064 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
1065 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
1066 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:321067
1068 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1069 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1070 gfx::Transform expected_grand_child_draw_transform =
1071 rotation_about_y_axis; // draws onto child's render surface
1072 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1073 flattened_rotation_about_y.FlattenTo2d();
1074 gfx::Transform expected_grand_child_screen_space_transform =
1075 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081076 gfx::Transform expected_great_grand_child_draw_transform =
1077 flattened_rotation_about_y;
1078 gfx::Transform expected_great_grand_child_screen_space_transform =
1079 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321080
enne25dea3f2015-07-27 16:44:281081 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321082
1083 // The child's draw transform should have been taken by its surface.
1084 ASSERT_TRUE(child->render_surface());
1085 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1086 child->render_surface()->draw_transform());
1087 EXPECT_TRANSFORMATION_MATRIX_EQ(
1088 expected_child_screen_space_transform,
1089 child->render_surface()->screen_space_transform());
danakje4fa7b72016-07-25 22:00:061090 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321091 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101092 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321093 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441094 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321095 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101096 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081097 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441098 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081099 EXPECT_TRANSFORMATION_MATRIX_EQ(
1100 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101101 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321102}
1103
ajumadbd92cb2015-07-16 13:47:061104TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasikabf1875a2016-06-28 03:39:591105 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:141106 LayerImpl* child = AddChild<LayerImpl>(root);
1107 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061108
1109 gfx::Transform child_transform;
1110 child_transform.Translate(50.0, 50.0);
1111 child_transform.RotateAboutZAxis(30.0);
1112
1113 gfx::Transform grand_child_transform;
1114 grand_child_transform.RotateAboutYAxis(90.0);
1115
danakje4fa7b72016-07-25 22:00:061116 root->SetBounds(gfx::Size(200, 200));
jaydasika10d43fc2016-08-18 04:06:041117 child->test_properties()->transform = child_transform;
danakje4fa7b72016-07-25 22:00:061118 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:041119 grand_child->test_properties()->transform = grand_child_transform;
danakje4fa7b72016-07-25 22:00:061120 grand_child->SetBounds(gfx::Size(100, 100));
jaydasikaca2605e2016-04-23 02:52:521121 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141122 grand_child->SetDrawsContent(true);
jaydasika6ed869662016-09-21 14:29:591123 float device_scale_factor = 1.f;
1124 float page_scale_factor = 1.f;
1125 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:281126 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:421127 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika6ed869662016-09-21 14:29:591128 // Visible rects computed by combining clips in target space and root space
1129 // don't match because of rotation transforms. So, we skip
1130 // verify_visible_rect_calculations.
1131 bool skip_verify_visible_rect_calculations = true;
1132 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:281133 page_scale_layer, inner_viewport_scroll_layer,
flackra283bed2016-10-31 14:49:421134 outer_viewport_scroll_layer,
jaydasika6ed869662016-09-21 14:29:591135 skip_verify_visible_rect_calculations);
ajumadbd92cb2015-07-16 13:47:061136
1137 // Mapping grand_child's bounds to target space produces a non-empty rect
1138 // that is fully contained within the target's bounds, so grand_child should
1139 // be considered fully visible.
1140 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141141 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061142}
1143
[email protected]989386c2013-07-18 21:37:231144TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321145 // A layer that is empty in one axis, but not the other, was accidentally
1146 // skipping a necessary translation. Without that translation, the coordinate
1147 // space of the layer's draw transform is incorrect.
1148 //
1149 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1150 // but if that layer becomes a render surface, then its draw transform is
1151 // implicitly inherited by the rest of the subtree, which then is positioned
1152 // incorrectly as a result.
1153
jaydasikabf1875a2016-06-28 03:39:591154 LayerImpl* root = root_layer_for_testing();
ennec1332992015-08-24 19:45:091155 LayerImpl* child = AddChild<LayerImpl>(root);
1156 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1157 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321158
danakje4fa7b72016-07-25 22:00:061159 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:321160 // The child height is zero, but has non-zero width that should be accounted
1161 // for while computing draw transforms.
danakje4fa7b72016-07-25 22:00:061162 child->SetBounds(gfx::Size(10, 0));
1163 child->test_properties()->force_render_surface = true;
1164 grand_child->SetBounds(gfx::Size(10, 10));
ennec1332992015-08-24 19:45:091165 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321166
ennec1332992015-08-24 19:45:091167 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321168 // This is the real test, the rest are sanity checks.
danakje4fa7b72016-07-25 22:00:061169 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:321170 child->render_surface()->draw_transform());
danakje4fa7b72016-07-25 22:00:061171 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1172 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441173 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321174}
1175
jaydasika9bbee9b2016-01-13 00:36:481176TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
jaydasikabf1875a2016-06-28 03:39:591177 LayerImpl* root = root_layer_for_testing();
jaydasika9bbee9b2016-01-13 00:36:481178 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1179 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1180 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1181
jaydasika9bbee9b2016-01-13 00:36:481182 gfx::Transform translate;
1183 translate.Translate3d(5, 5, 5);
danakje4fa7b72016-07-25 22:00:061184
1185 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041186 render_surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061187 render_surface->SetBounds(gfx::Size(100, 100));
1188 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:041189 child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061190 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041191 grand_child->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:061192 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika9bbee9b2016-01-13 00:36:481193 grand_child->SetDrawsContent(true);
1194
1195 // render_surface will have a sublayer scale because of device scale factor.
1196 float device_scale_factor = 2.0f;
1197 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481198 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381199 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481200 inputs.device_scale_factor = device_scale_factor;
1201 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571202 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481203
1204 // Between grand_child and render_surface, we translate by (10, 10) and scale
1205 // by a factor of 2.
1206 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1207 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1208 expected_translation);
1209}
1210
[email protected]989386c2013-07-18 21:37:231211TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321212 // Transformations applied at the root of the tree should be forwarded
1213 // to child layers instead of applied to the root RenderSurface.
jaydasikabf1875a2016-06-28 03:39:591214 LayerImpl* root = root_layer_for_testing();
enned3f61fb02015-08-18 22:54:391215 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061216
1217 root->SetDrawsContent(true);
jaydasikab874eddc2016-11-02 22:34:281218 root->SetBounds(gfx::Size(100, 100));
enned3f61fb02015-08-18 22:54:391219 child->SetDrawsContent(true);
enned3f61fb02015-08-18 22:54:391220 child->SetScrollClipLayer(root->id());
jaydasikab874eddc2016-11-02 22:34:281221 child->SetBounds(gfx::Size(100, 100));
1222 child->SetMasksToBounds(true);
[email protected]f224cc92013-06-06 23:23:321223
[email protected]f224cc92013-06-06 23:23:321224 gfx::Transform translate;
1225 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231226 {
enned3f61fb02015-08-18 22:54:391227 LayerImplList render_surface_layer_list_impl;
1228 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381229 root, root->bounds(), translate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321230 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571231 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021232 EXPECT_TRANSFORMATION_MATRIX_EQ(
1233 translate, root->draw_properties().target_space_transform);
1234 EXPECT_TRANSFORMATION_MATRIX_EQ(
1235 translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151236 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021237 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281238 EXPECT_TRANSFORMATION_MATRIX_EQ(translate, child->ScreenSpaceTransform());
1239 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231240 }
[email protected]f224cc92013-06-06 23:23:321241
1242 gfx::Transform scale;
1243 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231244 {
enned3f61fb02015-08-18 22:54:391245 LayerImplList render_surface_layer_list_impl;
1246 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381247 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321248 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571249 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021250 EXPECT_TRANSFORMATION_MATRIX_EQ(
1251 scale, root->draw_properties().target_space_transform);
1252 EXPECT_TRANSFORMATION_MATRIX_EQ(
1253 scale, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151254 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021255 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281256 EXPECT_TRANSFORMATION_MATRIX_EQ(scale, child->ScreenSpaceTransform());
1257 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231258 }
[email protected]f224cc92013-06-06 23:23:321259
1260 gfx::Transform rotate;
1261 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231262 {
enned3f61fb02015-08-18 22:54:391263 LayerImplList render_surface_layer_list_impl;
1264 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381265 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321266 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571267 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021268 EXPECT_TRANSFORMATION_MATRIX_EQ(
1269 rotate, root->draw_properties().target_space_transform);
1270 EXPECT_TRANSFORMATION_MATRIX_EQ(
1271 rotate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151272 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021273 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281274 EXPECT_TRANSFORMATION_MATRIX_EQ(rotate, child->ScreenSpaceTransform());
1275 EXPECT_EQ(gfx::Rect(-4, 0, 104, 104), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231276 }
[email protected]f224cc92013-06-06 23:23:321277
1278 gfx::Transform composite;
1279 composite.ConcatTransform(translate);
1280 composite.ConcatTransform(scale);
1281 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231282 {
enned3f61fb02015-08-18 22:54:391283 LayerImplList render_surface_layer_list_impl;
1284 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381285 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321286 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571287 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021288 EXPECT_TRANSFORMATION_MATRIX_EQ(
1289 composite, root->draw_properties().target_space_transform);
1290 EXPECT_TRANSFORMATION_MATRIX_EQ(
1291 composite, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151292 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021293 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281294 EXPECT_TRANSFORMATION_MATRIX_EQ(composite, child->ScreenSpaceTransform());
1295 EXPECT_EQ(gfx::Rect(89, 103, 208, 208), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231296 }
[email protected]f224cc92013-06-06 23:23:321297
[email protected]9781afa2013-07-17 23:15:321298 // Verify it composes correctly with device scale.
1299 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231300
1301 {
enned3f61fb02015-08-18 22:54:391302 LayerImplList render_surface_layer_list_impl;
1303 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381304 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531305 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321306 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571307 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231308 gfx::Transform device_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101309 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
weiliangcc3517722016-06-28 22:52:021310 EXPECT_TRANSFORMATION_MATRIX_EQ(
1311 device_scaled_translate,
1312 root->draw_properties().target_space_transform);
1313 EXPECT_TRANSFORMATION_MATRIX_EQ(
1314 device_scaled_translate,
1315 child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151316 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021317 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281318 EXPECT_TRANSFORMATION_MATRIX_EQ(device_scaled_translate,
1319 child->ScreenSpaceTransform());
1320 EXPECT_EQ(gfx::Rect(50, 50, 150, 150), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231321 }
[email protected]9781afa2013-07-17 23:15:321322
1323 // Verify it composes correctly with page scale.
1324 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231325
1326 {
enned3f61fb02015-08-18 22:54:391327 LayerImplList render_surface_layer_list_impl;
1328 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381329 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531330 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391331 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321332 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571333 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231334 gfx::Transform page_scaled_translate = translate;
jaydasika18ea2722016-10-27 23:47:101335 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
weiliangcc3517722016-06-28 22:52:021336 EXPECT_TRANSFORMATION_MATRIX_EQ(
1337 page_scaled_translate, root->draw_properties().target_space_transform);
1338 EXPECT_TRANSFORMATION_MATRIX_EQ(
1339 page_scaled_translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151340 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021341 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281342 EXPECT_TRANSFORMATION_MATRIX_EQ(page_scaled_translate,
1343 child->ScreenSpaceTransform());
1344 EXPECT_EQ(gfx::Rect(50, 50, 200, 200), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231345 }
[email protected]9781afa2013-07-17 23:15:321346
[email protected]f224cc92013-06-06 23:23:321347 // Verify that it composes correctly with transforms directly on root layer.
jaydasika10d43fc2016-08-18 04:06:041348 root->test_properties()->transform = composite;
[email protected]989386c2013-07-18 21:37:231349
1350 {
enned3f61fb02015-08-18 22:54:391351 LayerImplList render_surface_layer_list_impl;
1352 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381353 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391354 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571355 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231356 gfx::Transform compositeSquared = composite;
1357 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261358 EXPECT_TRANSFORMATION_MATRIX_EQ(
1359 compositeSquared, root->draw_properties().target_space_transform);
1360 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391361 compositeSquared, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151362 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021363 root->render_surface()->draw_transform());
jaydasikab874eddc2016-11-02 22:34:281364 EXPECT_TRANSFORMATION_MATRIX_EQ(compositeSquared,
1365 child->ScreenSpaceTransform());
1366 EXPECT_EQ(gfx::Rect(254, 316, 428, 428), child->clip_rect());
[email protected]989386c2013-07-18 21:37:231367 }
[email protected]f224cc92013-06-06 23:23:321368}
1369
[email protected]989386c2013-07-18 21:37:231370TEST_F(LayerTreeHostCommonTest,
1371 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
danakje4fa7b72016-07-25 22:00:061372 LayerImpl* root = root_layer_for_testing();
enneea850232015-07-27 16:43:121373 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1374 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
danakje4fa7b72016-07-25 22:00:061375
1376 root->SetBounds(gfx::Size(10, 10));
1377 root->SetMasksToBounds(true);
1378 render_surface1->SetBounds(gfx::Size(10, 10));
1379 render_surface1->test_properties()->force_render_surface = true;
enneea850232015-07-27 16:43:121380 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061381 child->SetPosition(gfx::PointF(30.f, 30.f));
1382 child->SetBounds(gfx::Size(10, 10));
1383 ExecuteCalculateDrawProperties(root);
[email protected]d600df7d2013-08-03 02:34:281384
danakje4fa7b72016-07-25 22:00:061385 // The child layer's content is entirely outside the root's clip rect, so
[email protected]fb661802013-03-25 01:59:321386 // the intermediate render surface should not be listed here, even if it was
1387 // forced to be created. Render surfaces without children or visible content
1388 // are unexpected at draw time (e.g. we might try to create a content texture
1389 // of size 0).
danakje4fa7b72016-07-25 22:00:061390 ASSERT_TRUE(root->render_surface());
enneea850232015-07-27 16:43:121391 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321392}
1393
[email protected]989386c2013-07-18 21:37:231394TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
danakje4fa7b72016-07-25 22:00:061395 LayerImpl* root = root_layer_for_testing();
1396 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
enne03b0e9a2015-06-19 00:08:021397 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
[email protected]d600df7d2013-08-03 02:34:281398
danakje4fa7b72016-07-25 22:00:061399 render_surface1->SetBounds(gfx::Size(10, 10));
1400 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181401 render_surface1->test_properties()->opacity = 0.f;
danakje4fa7b72016-07-25 22:00:061402 child->SetBounds(gfx::Size(10, 10));
1403 child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321404
enne03b0e9a2015-06-19 00:08:021405 LayerImplList render_surface_layer_list;
1406 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061407 root, root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531408 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571409 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321410
1411 // Since the layer is transparent, render_surface1->render_surface() should
1412 // not have gotten added anywhere. Also, the drawable content rect should not
1413 // have been extended by the children.
danakje4fa7b72016-07-25 22:00:061414 ASSERT_TRUE(root->render_surface());
1415 EXPECT_EQ(0U, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:321416 EXPECT_EQ(1U, render_surface_layer_list.size());
danakje4fa7b72016-07-25 22:00:061417 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
1418 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321419}
1420
hendrikwc266f7b2015-08-21 23:41:341421TEST_F(LayerTreeHostCommonTest,
1422 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
danakje4fa7b72016-07-25 22:00:061423 LayerImpl* root = root_layer_for_testing();
1424 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
hendrikwc266f7b2015-08-21 23:41:341425 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
hendrikwc266f7b2015-08-21 23:41:341426
danakje4fa7b72016-07-25 22:00:061427 root->SetBounds(gfx::Size(10, 10));
1428 render_surface1->SetBounds(gfx::Size(10, 10));
1429 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181430 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071431 render_surface1->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341432 FilterOperations filters;
1433 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
ajuma50bce7e2016-06-24 20:56:041434 render_surface1->test_properties()->background_filters = filters;
danakje4fa7b72016-07-25 22:00:061435 child->SetBounds(gfx::Size(10, 10));
1436 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341437
jaydasika369c24b2016-04-06 23:44:161438 {
1439 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161440 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061441 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161442 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571443 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161444 EXPECT_EQ(2U, render_surface_layer_list.size());
1445 }
hendrikwc266f7b2015-08-21 23:41:341446 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161447 // shouldn't be skipped and should be drawn.
danakje4fa7b72016-07-25 22:00:061448 ASSERT_TRUE(root->render_surface());
1449 EXPECT_EQ(1U, root->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361450 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
danakje4fa7b72016-07-25 22:00:061451 root->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161452 EffectTree& effect_tree =
danakje4fa7b72016-07-25 22:00:061453 root->layer_tree_impl()->property_trees()->effect_tree;
jaydasika369c24b2016-04-06 23:44:161454 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011455 EXPECT_TRUE(node->is_drawn);
jaydasika369c24b2016-04-06 23:44:161456
danakje4fa7b72016-07-25 22:00:061457 // When root is transparent, the layer should not be drawn.
jaydasika898b2f12016-08-20 04:22:091458 effect_tree.OnOpacityAnimated(0.f, root->effect_tree_index(),
1459 root->layer_tree_impl());
1460 effect_tree.OnOpacityAnimated(1.f, render_surface1->effect_tree_index(),
1461 root->layer_tree_impl());
jaydasika8185d302016-04-14 15:20:061462 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161463 {
1464 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161465 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061466 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161467 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571468 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161469 }
1470
1471 node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011472 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:061473 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341474}
1475
senorblanco38858c52016-01-20 23:15:001476TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
jaydasikabf1875a2016-06-28 03:39:591477 LayerImpl* root = root_layer_for_testing();
senorblanco38858c52016-01-20 23:15:001478 LayerImpl* parent = AddChild<LayerImpl>(root);
1479 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1480 LayerImpl* child2 = AddChild<LayerImpl>(parent);
senorblanco38858c52016-01-20 23:15:001481
senorblanco38858c52016-01-20 23:15:001482 gfx::Transform scale_matrix;
1483 scale_matrix.Scale(2.0f, 2.0f);
danakje4fa7b72016-07-25 22:00:061484
1485 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041486 parent->test_properties()->transform = scale_matrix;
senorblanco38858c52016-01-20 23:15:001487 FilterOperations filters;
1488 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
ajumacb2b74432016-07-21 19:11:151489 parent->test_properties()->filters = filters;
danakje4fa7b72016-07-25 22:00:061490 parent->test_properties()->force_render_surface = true;
1491 child1->SetBounds(gfx::Size(25, 25));
1492 child1->SetDrawsContent(true);
1493 child1->test_properties()->force_render_surface = true;
1494 child2->SetPosition(gfx::PointF(25, 25));
1495 child2->SetBounds(gfx::Size(25, 25));
1496 child2->SetDrawsContent(true);
1497 child2->test_properties()->force_render_surface = true;
senorblanco38858c52016-01-20 23:15:001498
1499 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001500 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381501 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001502 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571503 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001504
1505 ASSERT_TRUE(parent->render_surface());
1506 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1507 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman1c44d5b52016-06-06 21:19:301508
1509 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1510 // blur (-30,-30 110x110), and then scaled by the scale matrix
1511 // (-60,-60 220x220).
1512 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
senorblanco38858c52016-01-20 23:15:001513 parent->render_surface()->DrawableContentRect());
1514}
1515
jbroman1c44d5b52016-06-06 21:19:301516TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
jaydasikabf1875a2016-06-28 03:39:591517 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301518 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061519
1520 root->SetBounds(gfx::Size(100, 100));
1521 child->SetBounds(gfx::Size(25, 25));
jbroman1c44d5b52016-06-06 21:19:301522 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061523 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301524 FilterOperations filters;
1525 filters.Append(FilterOperation::CreateReferenceFilter(
1526 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151527 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301528 ExecuteCalculateDrawProperties(root);
1529
1530 // The render surface's size should be unaffected by the offset image filter;
1531 // it need only have a drawable content rect large enough to contain the
1532 // contents (at the new offset).
1533 ASSERT_TRUE(child->render_surface());
1534 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1535 child->render_surface()->DrawableContentRect());
1536}
1537
1538TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1539 const float device_scale_factor = 2.0f;
1540
jaydasikabf1875a2016-06-28 03:39:591541 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301542 LayerImpl* child = AddChild<LayerImpl>(root);
jbroman1c44d5b52016-06-06 21:19:301543
danakje4fa7b72016-07-25 22:00:061544 root->SetBounds(gfx::Size(100, 100));
1545 child->SetBounds(gfx::Size(25, 25));
1546 child->SetDrawsContent(true);
1547 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301548
1549 FilterOperations filters;
1550 filters.Append(FilterOperation::CreateReferenceFilter(
1551 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151552 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301553
1554 ExecuteCalculateDrawProperties(root, device_scale_factor);
1555
1556 // The render surface's size should be unaffected by the offset image filter;
1557 // it need only have a drawable content rect large enough to contain the
1558 // contents (at the new offset). All coordinates should be scaled by 2,
1559 // corresponding to the device scale factor.
1560 ASSERT_TRUE(child->render_surface());
1561 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1562 child->render_surface()->DrawableContentRect());
1563}
1564
rosca948d29d2014-11-09 10:25:131565TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
danakje4fa7b72016-07-25 22:00:061566 LayerImpl* root = root_layer_for_testing();
1567 LayerImpl* child = AddChild<LayerImpl>(root);
1568
1569 root->SetBounds(gfx::Size(10, 10));
1570 child->SetBounds(gfx::Size(10, 10));
enned5f4ddd2015-08-18 16:50:061571 child->SetDrawsContent(true);
ajuma4c14b252016-07-26 20:10:591572 child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode;
jaydasikaab317e02016-06-01 00:53:181573 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061574 child->test_properties()->force_render_surface = true;
1575 ExecuteCalculateDrawProperties(root);
rosca948d29d2014-11-09 10:25:131576
1577 // Since the child layer has a blend mode other than normal, it should get
1578 // its own render surface. Also, layer's draw_properties should contain the
1579 // default blend mode, since the render surface becomes responsible for
1580 // applying the blend mode.
1581 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291582 EXPECT_EQ(1.0f, child->draw_opacity());
1583 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261584 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131585}
1586
jaydasikafbdb86e2016-01-21 18:57:511587TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
jaydasikabf1875a2016-06-28 03:39:591588 LayerImpl* root = root_layer_for_testing();
jaydasikafbdb86e2016-01-21 18:57:511589 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1590 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1591 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1592
danakje4fa7b72016-07-25 22:00:061593 root->SetBounds(gfx::Size(10, 10));
1594 surface1->SetBounds(gfx::Size(10, 10));
jaydasikafbdb86e2016-01-21 18:57:511595 surface1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181596 surface1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061597 surface1->test_properties()->force_render_surface = true;
1598 not_surface->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:181599 not_surface->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061600 surface2->SetBounds(gfx::Size(10, 10));
1601 surface2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181602 surface2->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061603 surface2->test_properties()->force_render_surface = true;
jaydasikafbdb86e2016-01-21 18:57:511604 ExecuteCalculateDrawProperties(root);
1605
1606 ASSERT_TRUE(surface1->render_surface());
1607 ASSERT_FALSE(not_surface->render_surface());
1608 ASSERT_TRUE(surface2->render_surface());
1609 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1610 // surface2's draw opacity should include the opacity of not-surface and
1611 // itself, but not the opacity of surface1.
1612 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1613}
1614
ajuma51d73f72015-10-19 19:43:581615TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1616 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1617 // the product of all ancestor layer opacties and the layer's own opacity.
1618 // (Rendering will still be incorrect in situations where we really do need
1619 // surfaces to apply opacity, such as when we have overlapping layers with an
1620 // ancestor whose opacity is <1.)
jaydasikabf1875a2016-06-28 03:39:591621 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581622 LayerImpl* parent = AddChild<LayerImpl>(root);
1623 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1624 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1625 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1626 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1627 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1628
danakje4fa7b72016-07-25 22:00:061629 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581630 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061631 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581632 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061633 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581634 child1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181635 child1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061636 child1->test_properties()->force_render_surface = true;
1637 child2->SetBounds(gfx::Size(100, 100));
1638 child2->SetDrawsContent(true);
1639 grand_child->SetBounds(gfx::Size(100, 100));
1640 grand_child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181641 grand_child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061642 grand_child->test_properties()->force_render_surface = true;
1643 leaf_node1->SetBounds(gfx::Size(100, 100));
1644 leaf_node1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181645 leaf_node1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061646 leaf_node2->SetBounds(gfx::Size(100, 100));
1647 leaf_node2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181648 leaf_node2->test_properties()->opacity = 0.5f;
ajuma51d73f72015-10-19 19:43:581649
1650 // With surfaces enabled, each layer's draw opacity is the product of layer
1651 // opacities on the path from the layer to its render target, not including
1652 // the opacity of the layer that owns the target surface (since that opacity
1653 // is applied by the surface).
1654 ExecuteCalculateDrawProperties(root);
1655 EXPECT_EQ(1.f, root->draw_opacity());
1656 EXPECT_EQ(1.f, parent->draw_opacity());
1657 EXPECT_EQ(1.f, child1->draw_opacity());
1658 EXPECT_EQ(1.f, child2->draw_opacity());
1659 EXPECT_EQ(1.f, grand_child->draw_opacity());
1660 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1661 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1662
1663 // With surfaces disabled, each layer's draw opacity is the product of layer
1664 // opacities on the path from the layer to the root.
1665 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1666 EXPECT_EQ(1.f, root->draw_opacity());
1667 EXPECT_EQ(1.f, parent->draw_opacity());
1668 EXPECT_EQ(0.5f, child1->draw_opacity());
1669 EXPECT_EQ(1.f, child2->draw_opacity());
1670 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1671 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1672 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1673}
1674
[email protected]989386c2013-07-18 21:37:231675TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
danakje4fa7b72016-07-25 22:00:061676 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:261677 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1678 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261679
danakje4fa7b72016-07-25 22:00:061680 root->SetBounds(gfx::Size(10, 10));
1681 render_surface1->SetBounds(gfx::Size(10, 10));
jaydasika6b5a32bf2016-04-22 21:56:361682 render_surface1->test_properties()->force_render_surface = true;
danakje4fa7b72016-07-25 22:00:061683 child->SetBounds(gfx::Size(10, 10));
1684 child->SetDrawsContent(true);
weiliangceffae0462015-12-08 23:17:261685
[email protected]989386c2013-07-18 21:37:231686 {
jaydasika6ed869662016-09-21 14:29:591687 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:321688
[email protected]989386c2013-07-18 21:37:231689 // The root layer always creates a render surface
danakje4fa7b72016-07-25 22:00:061690 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091691 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231692 }
[email protected]fb661802013-03-25 01:59:321693
[email protected]989386c2013-07-18 21:37:231694 {
jaydasika6b5a32bf2016-04-22 21:56:361695 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261696 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:591697 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
danakje4fa7b72016-07-25 22:00:061698 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091699 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231700 }
[email protected]fb661802013-03-25 01:59:321701}
1702
ajuma246190a2015-03-11 20:56:031703TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1704 // Render surfaces act as a flattening point for their subtree, so should
1705 // always flatten the target-to-screen space transform seen by descendants.
jaydasikabf1875a2016-06-28 03:39:591706 LayerImpl* root = root_layer_for_testing();
enne1a79c5542015-08-18 19:43:571707 LayerImpl* parent = AddChild<LayerImpl>(root);
1708 LayerImpl* child = AddChild<LayerImpl>(parent);
1709 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1710
ajuma246190a2015-03-11 20:56:031711 gfx::Transform rotation_about_y_axis;
1712 rotation_about_y_axis.RotateAboutYAxis(30.0);
ajuma246190a2015-03-11 20:56:031713
danakje4fa7b72016-07-25 22:00:061714 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:041715 parent->test_properties()->transform = rotation_about_y_axis;
danakje4fa7b72016-07-25 22:00:061716 parent->SetBounds(gfx::Size(10, 10));
1717 parent->test_properties()->force_render_surface = true;
1718 child->SetBounds(gfx::Size(10, 10));
1719 child->SetDrawsContent(true);
1720 grand_child->SetBounds(gfx::Size(10, 10));
1721 grand_child->SetDrawsContent(true);
jaydasikaca2605e2016-04-23 02:52:521722 grand_child->test_properties()->should_flatten_transform = false;
enne1a79c5542015-08-18 19:43:571723 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031724
1725 EXPECT_TRUE(parent->render_surface());
1726 EXPECT_FALSE(child->render_surface());
1727 EXPECT_FALSE(grand_child->render_surface());
1728
danakje4fa7b72016-07-25 22:00:061729 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1730 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441731 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031732
1733 // The screen-space transform inherited by |child| and |grand_child| should
1734 // have been flattened at their render target. In particular, the fact that
1735 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
danakje4fa7b72016-07-25 22:00:061736 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1737 flattened_rotation_about_y.FlattenTo2d();
ajuma246190a2015-03-11 20:56:031738 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101739 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031740 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101741 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031742}
1743
[email protected]989386c2013-07-18 21:37:231744TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321745 // The entire subtree of layers that are outside the clip rect should be
1746 // culled away, and should not affect the render_surface_layer_list.
1747 //
1748 // The test tree is set up as follows:
1749 // - all layers except the leaf_nodes are forced to be a new render surface
1750 // that have something to draw.
1751 // - parent is a large container layer.
danakje4fa7b72016-07-25 22:00:061752 // - child has MasksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321753 // - grand_child is positioned outside of the child's bounds
1754 // - great_grand_child is also kept outside child's bounds.
1755 //
1756 // In this configuration, grand_child and great_grand_child are completely
1757 // outside the clip rect, and they should never get scheduled on the list of
1758 // render surfaces.
[email protected]fb661802013-03-25 01:59:321759
danakje4fa7b72016-07-25 22:00:061760 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571761 LayerImpl* child = AddChildToRoot<LayerImpl>();
1762 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1763 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281764
danakje4fa7b72016-07-25 22:00:061765 // leaf_node1 ensures that root and child are kept on the
[email protected]fb661802013-03-25 01:59:321766 // render_surface_layer_list, even though grand_child and great_grand_child
1767 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571768 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
weiliangcfb3d5eaa2015-07-28 23:54:571769 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
[email protected]fb661802013-03-25 01:59:321770
danakje4fa7b72016-07-25 22:00:061771 root->SetBounds(gfx::Size(500, 500));
1772 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321773 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061774 child->test_properties()->force_render_surface = true;
1775 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1776 grand_child->SetBounds(gfx::Size(10, 10));
1777 great_grand_child->SetBounds(gfx::Size(10, 10));
1778 leaf_node1->SetBounds(gfx::Size(500, 500));
1779 leaf_node1->SetDrawsContent(true);
1780 leaf_node1->SetBounds(gfx::Size(20, 20));
1781 leaf_node2->SetDrawsContent(true);
1782 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321783
weiliangcfb3d5eaa2015-07-28 23:54:571784 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061785 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
weiliangcfb3d5eaa2015-07-28 23:54:571786 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321787}
1788
[email protected]989386c2013-07-18 21:37:231789TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321790 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571791 // of the surface.
[email protected]fb661802013-03-25 01:59:321792
1793 // The test tree is set up as follows:
danakje4fa7b72016-07-25 22:00:061794 // - root is a container layer that masksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321795 // - child is a render surface, which has a clip rect set to the bounds of
danakje4fa7b72016-07-25 22:00:061796 // the root.
[email protected]fb661802013-03-25 01:59:321797 // - grand_child is a render surface, and the only visible content in child.
danakje4fa7b72016-07-25 22:00:061798 // It is positioned outside of the clip rect from root.
[email protected]fb661802013-03-25 01:59:321799
1800 // In this configuration, grand_child should be outside the clipped
1801 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571802 // render_surface_layer_list.
1803
danakje4fa7b72016-07-25 22:00:061804 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571805 LayerImpl* child = AddChildToRoot<LayerImpl>();
1806 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1807 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
[email protected]fb661802013-03-25 01:59:321808
danakje4fa7b72016-07-25 22:00:061809 root->SetMasksToBounds(true);
1810 root->SetBounds(gfx::Size(100, 100));
1811 child->SetBounds(gfx::Size(20, 20));
1812 child->test_properties()->force_render_surface = true;
1813 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1814 grand_child->SetBounds(gfx::Size(10, 10));
1815 grand_child->test_properties()->force_render_surface = true;
1816 leaf_node->SetBounds(gfx::Size(10, 10));
1817 leaf_node->SetDrawsContent(true);
1818 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321819
weiliangcfb3d5eaa2015-07-28 23:54:571820 // We should cull child and grand_child from the
1821 // render_surface_layer_list.
1822 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061823 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321824}
1825
ajumae2b7a5c2015-09-30 21:41:421826TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1827 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321828 // - the layer clips its subtree, e.g. masks to bounds,
1829 // - the layer is clipped by an ancestor that contributes to the same
1830 // render target,
1831 // - a surface is clipped by an ancestor that contributes to the same
1832 // render target.
1833 //
1834 // In particular, for a layer that owns a render surface:
1835 // - the render surface inherits any clip from ancestors, and does NOT
1836 // pass that clipped status to the layer itself.
1837 // - but if the layer itself masks to bounds, it is considered clipped
1838 // and propagates the clip to the subtree.
1839
jaydasikabf1875a2016-06-28 03:39:591840 LayerImpl* root = root_layer_for_testing();
enne76bf8982015-08-18 17:55:331841 LayerImpl* parent = AddChild<LayerImpl>(root);
1842 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1843 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1844 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1845 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
enne76bf8982015-08-18 17:55:331846 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
enne76bf8982015-08-18 17:55:331847
danakje4fa7b72016-07-25 22:00:061848 root->SetBounds(gfx::Size(100, 100));
1849 parent->SetBounds(gfx::Size(100, 100));
1850 parent->SetDrawsContent(true);
1851 child1->SetBounds(gfx::Size(100, 100));
1852 child1->SetDrawsContent(true);
1853 child2->SetBounds(gfx::Size(100, 100));
1854 child2->SetDrawsContent(true);
1855 child2->test_properties()->force_render_surface = true;
1856 grand_child->SetBounds(gfx::Size(100, 100));
1857 grand_child->SetDrawsContent(true);
1858 leaf_node1->SetBounds(gfx::Size(100, 100));
1859 leaf_node1->SetDrawsContent(true);
1860 leaf_node2->SetBounds(gfx::Size(100, 100));
1861 leaf_node2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331862
1863 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521864 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331865
weiliangce3f09a612016-03-16 17:02:521866 ASSERT_TRUE(root->render_surface());
1867 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331868
weiliangce3f09a612016-03-16 17:02:521869 EXPECT_FALSE(root->is_clipped());
1870 EXPECT_TRUE(root->render_surface()->is_clipped());
1871 EXPECT_FALSE(parent->is_clipped());
1872 EXPECT_FALSE(child1->is_clipped());
1873 EXPECT_FALSE(child2->is_clipped());
1874 EXPECT_FALSE(child2->render_surface()->is_clipped());
1875 EXPECT_FALSE(grand_child->is_clipped());
1876 EXPECT_FALSE(leaf_node1->is_clipped());
1877 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331878
danakje4fa7b72016-07-25 22:00:061879 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
enne76bf8982015-08-18 17:55:331880 // surface are clipped. But layers that contribute to child2's surface are
1881 // not clipped explicitly because child2's surface already accounts for
1882 // that clip.
weiliangce3f09a612016-03-16 17:02:521883 parent->SetMasksToBounds(true);
1884 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331885
weiliangce3f09a612016-03-16 17:02:521886 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331887
weiliangce3f09a612016-03-16 17:02:521888 ASSERT_TRUE(root->render_surface());
1889 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331890
weiliangce3f09a612016-03-16 17:02:521891 EXPECT_FALSE(root->is_clipped());
1892 EXPECT_TRUE(root->render_surface()->is_clipped());
1893 EXPECT_TRUE(parent->is_clipped());
1894 EXPECT_TRUE(child1->is_clipped());
1895 EXPECT_FALSE(child2->is_clipped());
1896 EXPECT_TRUE(child2->render_surface()->is_clipped());
1897 EXPECT_TRUE(grand_child->is_clipped());
1898 EXPECT_TRUE(leaf_node1->is_clipped());
1899 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331900
weiliangce3f09a612016-03-16 17:02:521901 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331902
danakje4fa7b72016-07-25 22:00:061903 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
enne76bf8982015-08-18 17:55:331904 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521905 child2->SetMasksToBounds(true);
1906 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331907
weiliangce3f09a612016-03-16 17:02:521908 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331909
weiliangce3f09a612016-03-16 17:02:521910 ASSERT_TRUE(root->render_surface());
1911 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331912
weiliangce3f09a612016-03-16 17:02:521913 EXPECT_FALSE(root->is_clipped());
1914 EXPECT_TRUE(root->render_surface()->is_clipped());
1915 EXPECT_FALSE(parent->is_clipped());
1916 EXPECT_FALSE(child1->is_clipped());
1917 EXPECT_TRUE(child2->is_clipped());
1918 EXPECT_FALSE(child2->render_surface()->is_clipped());
1919 EXPECT_FALSE(grand_child->is_clipped());
1920 EXPECT_FALSE(leaf_node1->is_clipped());
1921 EXPECT_TRUE(leaf_node2->is_clipped());
1922}
1923
1924TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1925 // Tests that when as long as layer is clipped, it's clip rect is set to
1926 // correct value.
jaydasikabf1875a2016-06-28 03:39:591927 LayerImpl* root = root_layer_for_testing();
weiliangce3f09a612016-03-16 17:02:521928 LayerImpl* parent = AddChild<LayerImpl>(root);
1929 LayerImpl* child = AddChild<LayerImpl>(parent);
1930
danakje4fa7b72016-07-25 22:00:061931 root->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521932 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061933 parent->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521934 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061935 child->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521936 child->SetDrawsContent(true);
weiliangce3f09a612016-03-16 17:02:521937 child->SetMasksToBounds(true);
1938
1939 ExecuteCalculateDrawProperties(root);
1940
1941 EXPECT_FALSE(root->is_clipped());
1942 EXPECT_FALSE(parent->is_clipped());
1943 EXPECT_TRUE(child->is_clipped());
1944 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1945
1946 parent->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061947 child->SetPosition(gfx::PointF(100.f, 100.f));
weiliangce3f09a612016-03-16 17:02:521948 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1949
1950 ExecuteCalculateDrawProperties(root);
1951
1952 EXPECT_FALSE(root->is_clipped());
1953 EXPECT_TRUE(parent->is_clipped());
1954 EXPECT_TRUE(child->is_clipped());
1955 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321956}
1957
ajuma51d73f72015-10-19 19:43:581958TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1959 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1960 // when a layer or its ancestor has a clip; in particular, if a layer
1961 // is_clipped, so is its entire subtree (since there are no render surfaces
1962 // that can reset is_clipped).
jaydasikabf1875a2016-06-28 03:39:591963 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581964 LayerImpl* parent = AddChild<LayerImpl>(root);
1965 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1966 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1967 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1968 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1969 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1970
danakje4fa7b72016-07-25 22:00:061971 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581972 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061973 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581974 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061975 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581976 child1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061977 child1->test_properties()->force_render_surface = true;
1978 child2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581979 child2->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061980 grand_child->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581981 grand_child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061982 grand_child->test_properties()->force_render_surface = true;
1983 leaf_node1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581984 leaf_node1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061985 leaf_node2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581986 leaf_node2->SetDrawsContent(true);
1987
ajuma51d73f72015-10-19 19:43:581988 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1989 // or without surfaces.
1990 ExecuteCalculateDrawProperties(root);
1991 EXPECT_FALSE(root->is_clipped());
1992 EXPECT_FALSE(parent->is_clipped());
1993 EXPECT_FALSE(child1->is_clipped());
1994 EXPECT_FALSE(child2->is_clipped());
1995 EXPECT_FALSE(grand_child->is_clipped());
1996 EXPECT_FALSE(leaf_node1->is_clipped());
1997 EXPECT_FALSE(leaf_node2->is_clipped());
1998
1999 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2000 EXPECT_FALSE(root->is_clipped());
2001 EXPECT_FALSE(parent->is_clipped());
2002 EXPECT_FALSE(child1->is_clipped());
2003 EXPECT_FALSE(child2->is_clipped());
2004 EXPECT_FALSE(grand_child->is_clipped());
2005 EXPECT_FALSE(leaf_node1->is_clipped());
2006 EXPECT_FALSE(leaf_node2->is_clipped());
2007
2008 // Case 2: The root is clipped. With surfaces, this only persists until the
2009 // next render surface. Without surfaces, the entire tree is clipped.
2010 root->SetMasksToBounds(true);
2011 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2012 ExecuteCalculateDrawProperties(root);
2013 EXPECT_TRUE(root->is_clipped());
2014 EXPECT_TRUE(parent->is_clipped());
2015 EXPECT_FALSE(child1->is_clipped());
2016 EXPECT_TRUE(child2->is_clipped());
2017 EXPECT_FALSE(grand_child->is_clipped());
2018 EXPECT_FALSE(leaf_node1->is_clipped());
2019 EXPECT_TRUE(leaf_node2->is_clipped());
2020
2021 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2022 EXPECT_TRUE(root->is_clipped());
2023 EXPECT_TRUE(parent->is_clipped());
2024 EXPECT_TRUE(child1->is_clipped());
2025 EXPECT_TRUE(child2->is_clipped());
2026 EXPECT_TRUE(grand_child->is_clipped());
2027 EXPECT_TRUE(leaf_node1->is_clipped());
2028 EXPECT_TRUE(leaf_node2->is_clipped());
2029
2030 root->SetMasksToBounds(false);
2031
2032 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2033 // until the next render surface. Without surfaces, parent's entire subtree is
2034 // clipped.
2035 parent->SetMasksToBounds(true);
2036 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2037 ExecuteCalculateDrawProperties(root);
2038 EXPECT_FALSE(root->is_clipped());
2039 EXPECT_TRUE(parent->is_clipped());
2040 EXPECT_FALSE(child1->is_clipped());
2041 EXPECT_TRUE(child2->is_clipped());
2042 EXPECT_FALSE(grand_child->is_clipped());
2043 EXPECT_FALSE(leaf_node1->is_clipped());
2044 EXPECT_TRUE(leaf_node2->is_clipped());
2045
2046 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2047 EXPECT_FALSE(root->is_clipped());
2048 EXPECT_TRUE(parent->is_clipped());
2049 EXPECT_TRUE(child1->is_clipped());
2050 EXPECT_TRUE(child2->is_clipped());
2051 EXPECT_TRUE(grand_child->is_clipped());
2052 EXPECT_TRUE(leaf_node1->is_clipped());
2053 EXPECT_TRUE(leaf_node2->is_clipped());
2054
2055 parent->SetMasksToBounds(false);
2056
2057 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2058 // has no non-surface children. Without surfaces, child1's entire subtree is
2059 // clipped.
2060 child1->SetMasksToBounds(true);
2061 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2062 ExecuteCalculateDrawProperties(root);
2063 EXPECT_FALSE(root->is_clipped());
2064 EXPECT_FALSE(parent->is_clipped());
2065 EXPECT_TRUE(child1->is_clipped());
2066 EXPECT_FALSE(child2->is_clipped());
2067 EXPECT_FALSE(grand_child->is_clipped());
2068 EXPECT_FALSE(leaf_node1->is_clipped());
2069 EXPECT_FALSE(leaf_node2->is_clipped());
2070
2071 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2072 EXPECT_FALSE(root->is_clipped());
2073 EXPECT_FALSE(parent->is_clipped());
2074 EXPECT_TRUE(child1->is_clipped());
2075 EXPECT_FALSE(child2->is_clipped());
2076 EXPECT_TRUE(grand_child->is_clipped());
2077 EXPECT_TRUE(leaf_node1->is_clipped());
2078 EXPECT_FALSE(leaf_node2->is_clipped());
2079
2080 child1->SetMasksToBounds(false);
2081
2082 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2083 // surfaces is the same.
2084 leaf_node1->SetMasksToBounds(true);
2085 leaf_node2->SetMasksToBounds(true);
2086 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2087 ExecuteCalculateDrawProperties(root);
2088 EXPECT_FALSE(root->is_clipped());
2089 EXPECT_FALSE(parent->is_clipped());
2090 EXPECT_FALSE(child1->is_clipped());
2091 EXPECT_FALSE(child2->is_clipped());
2092 EXPECT_FALSE(grand_child->is_clipped());
2093 EXPECT_TRUE(leaf_node1->is_clipped());
2094 EXPECT_TRUE(leaf_node2->is_clipped());
2095
2096 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2097 EXPECT_FALSE(root->is_clipped());
2098 EXPECT_FALSE(parent->is_clipped());
2099 EXPECT_FALSE(child1->is_clipped());
2100 EXPECT_FALSE(child2->is_clipped());
2101 EXPECT_FALSE(grand_child->is_clipped());
2102 EXPECT_TRUE(leaf_node1->is_clipped());
2103 EXPECT_TRUE(leaf_node2->is_clipped());
2104}
2105
[email protected]fd9a3b6d2013-08-03 00:46:172106TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322107 // Verify that layers get the appropriate DrawableContentRect when their
danakje4fa7b72016-07-25 22:00:062108 // parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322109 //
2110 // grand_child1 - completely inside the region; DrawableContentRect should
2111 // be the layer rect expressed in target space.
danakje4fa7b72016-07-25 22:00:062112 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
[email protected]fb661802013-03-25 01:59:322113 // will be the intersection of layer bounds and the mask region.
danakje4fa7b72016-07-25 22:00:062114 // grand_child3 - partially clipped and MasksToBounds; the
[email protected]fb661802013-03-25 01:59:322115 // DrawableContentRect will still be the intersection of layer bounds and
2116 // the mask region.
2117 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2118 // be empty.
[email protected]fb661802013-03-25 01:59:322119
jaydasikabf1875a2016-06-28 03:39:592120 LayerImpl* parent = root_layer_for_testing();
enne07405c772015-08-18 17:56:452121 LayerImpl* child = AddChild<LayerImpl>(parent);
2122 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2123 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2124 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2125 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322126
danakje4fa7b72016-07-25 22:00:062127 parent->SetBounds(gfx::Size(500, 500));
[email protected]fb661802013-03-25 01:59:322128 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062129 child->SetBounds(gfx::Size(20, 20));
2130 child->test_properties()->force_render_surface = true;
2131 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2132 grand_child1->SetBounds(gfx::Size(10, 10));
2133 grand_child1->SetDrawsContent(true);
2134 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2135 grand_child2->SetBounds(gfx::Size(10, 10));
2136 grand_child2->SetDrawsContent(true);
2137 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
[email protected]fb661802013-03-25 01:59:322138 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062139 grand_child3->SetBounds(gfx::Size(10, 10));
2140 grand_child3->SetDrawsContent(true);
2141 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2142 grand_child4->SetBounds(gfx::Size(10, 10));
2143 grand_child4->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452144 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322145
hush6b614212014-12-04 22:37:322146 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2147 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2148 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322149 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2150}
2151
[email protected]989386c2013-07-18 21:37:232152TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322153 // Verify that render surfaces (and their layers) get the appropriate
danakje4fa7b72016-07-25 22:00:062154 // clip rects when their parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322155 //
2156 // Layers that own render surfaces (at least for now) do not inherit any
2157 // clipping; instead the surface will enforce the clip for the entire subtree.
2158 // They may still have a clip rect of their own layer bounds, however, if
danakje4fa7b72016-07-25 22:00:062159 // MasksToBounds was true.
jaydasikabf1875a2016-06-28 03:39:592160 LayerImpl* parent = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:572161 LayerImpl* child = AddChildToRoot<LayerImpl>();
2162 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2163 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2164 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2165 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:062166 // The leaf nodes ensure that these grand_children become render surfaces for
[email protected]fb661802013-03-25 01:59:322167 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572168 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
weiliangcfb3d5eaa2015-07-28 23:54:572169 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
weiliangcfb3d5eaa2015-07-28 23:54:572170 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
weiliangcfb3d5eaa2015-07-28 23:54:572171 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
[email protected]fb661802013-03-25 01:59:322172
danakje4fa7b72016-07-25 22:00:062173 parent->SetBounds(gfx::Size(500, 500));
2174 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:322175 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062176 child->test_properties()->force_render_surface = true;
2177 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2178 grand_child1->SetBounds(gfx::Size(10, 10));
2179 grand_child1->test_properties()->force_render_surface = true;
2180 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2181 grand_child2->SetBounds(gfx::Size(10, 10));
2182 grand_child2->test_properties()->force_render_surface = true;
2183 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
2184 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322185 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062186 grand_child3->test_properties()->force_render_surface = true;
2187 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2188 grand_child4->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322189 grand_child4->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062190 grand_child4->test_properties()->force_render_surface = true;
2191 leaf_node1->SetBounds(gfx::Size(10, 10));
2192 leaf_node1->SetDrawsContent(true);
2193 leaf_node2->SetBounds(gfx::Size(10, 10));
2194 leaf_node2->SetDrawsContent(true);
2195 leaf_node3->SetBounds(gfx::Size(10, 10));
2196 leaf_node3->SetDrawsContent(true);
2197 leaf_node4->SetBounds(gfx::Size(10, 10));
2198 leaf_node4->SetDrawsContent(true);
weiliangcfb3d5eaa2015-07-28 23:54:572199 ExecuteCalculateDrawProperties(parent);
2200
[email protected]fb661802013-03-25 01:59:322201 ASSERT_TRUE(grand_child1->render_surface());
2202 ASSERT_TRUE(grand_child2->render_surface());
2203 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322204
2205 // Surfaces are clipped by their parent, but un-affected by the owning layer's
danakje4fa7b72016-07-25 22:00:062206 // MasksToBounds.
hush6b614212014-12-04 22:37:322207 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2208 grand_child1->render_surface()->clip_rect());
2209 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2210 grand_child2->render_surface()->clip_rect());
2211 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2212 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322213}
2214
ajuma51d73f72015-10-19 19:43:582215TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2216 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2217 // intersection of all ancestor clips in screen space; in particular, if a
2218 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2219 // subtree (since there are no render surfaces that can reset the clip_rect).
jaydasikabf1875a2016-06-28 03:39:592220 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582221 LayerImpl* parent = AddChild<LayerImpl>(root);
2222 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2223 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2224 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2225 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2226 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2227
danakje4fa7b72016-07-25 22:00:062228 root->SetBounds(gfx::Size(100, 100));
2229 parent->SetPosition(gfx::PointF(2.f, 2.f));
2230 parent->SetBounds(gfx::Size(400, 400));
2231 child1->SetPosition(gfx::PointF(4.f, 4.f));
2232 child1->SetBounds(gfx::Size(800, 800));
2233 child2->SetPosition(gfx::PointF(3.f, 3.f));
2234 child2->SetBounds(gfx::Size(800, 800));
2235 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2236 grand_child->SetBounds(gfx::Size(1500, 1500));
2237 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
2238 leaf_node1->SetBounds(gfx::Size(2000, 2000));
2239 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
2240 leaf_node2->SetBounds(gfx::Size(2000, 2000));
2241
ajuma51d73f72015-10-19 19:43:582242 root->SetDrawsContent(true);
2243 parent->SetDrawsContent(true);
2244 child1->SetDrawsContent(true);
2245 child2->SetDrawsContent(true);
2246 grand_child->SetDrawsContent(true);
2247 leaf_node1->SetDrawsContent(true);
2248 leaf_node2->SetDrawsContent(true);
2249
danakje4fa7b72016-07-25 22:00:062250 root->test_properties()->force_render_surface = true;
2251 child1->test_properties()->force_render_surface = true;
2252 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582253
2254 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2255 // bounds in target space. The only thing that changes when surfaces are
2256 // disabled is that target space is always screen space.
2257 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262258 EXPECT_TRUE(root->has_render_surface());
2259 EXPECT_FALSE(parent->has_render_surface());
2260 EXPECT_TRUE(child1->has_render_surface());
2261 EXPECT_FALSE(child2->has_render_surface());
2262 EXPECT_TRUE(grand_child->has_render_surface());
2263 EXPECT_FALSE(leaf_node1->has_render_surface());
2264 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422265 EXPECT_FALSE(root->is_clipped());
2266 EXPECT_FALSE(parent->is_clipped());
2267 EXPECT_FALSE(child1->is_clipped());
2268 EXPECT_FALSE(child2->is_clipped());
2269 EXPECT_FALSE(grand_child->is_clipped());
2270 EXPECT_FALSE(leaf_node1->is_clipped());
2271 EXPECT_FALSE(leaf_node2->is_clipped());
2272 EXPECT_TRUE(root->render_surface()->is_clipped());
2273 EXPECT_FALSE(child1->render_surface()->is_clipped());
2274 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2275 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582276
2277 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422278 EXPECT_FALSE(root->is_clipped());
2279 EXPECT_FALSE(parent->is_clipped());
2280 EXPECT_FALSE(child1->is_clipped());
2281 EXPECT_FALSE(child2->is_clipped());
2282 EXPECT_FALSE(grand_child->is_clipped());
2283 EXPECT_FALSE(leaf_node1->is_clipped());
2284 EXPECT_FALSE(leaf_node2->is_clipped());
2285 EXPECT_TRUE(root->render_surface()->is_clipped());
2286 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582287
2288 // Case 2: The root is clipped. In this case, layers that draw into the root
2289 // render surface are clipped by the root's bounds.
2290 root->SetMasksToBounds(true);
2291 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362292 root->test_properties()->force_render_surface = true;
2293 child1->test_properties()->force_render_surface = true;
2294 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582295 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262296 EXPECT_TRUE(root->has_render_surface());
2297 EXPECT_FALSE(parent->has_render_surface());
2298 EXPECT_TRUE(child1->has_render_surface());
2299 EXPECT_FALSE(child2->has_render_surface());
2300 EXPECT_TRUE(grand_child->has_render_surface());
2301 EXPECT_FALSE(leaf_node1->has_render_surface());
2302 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422303 EXPECT_TRUE(root->is_clipped());
2304 EXPECT_TRUE(parent->is_clipped());
2305 EXPECT_FALSE(child1->is_clipped());
2306 EXPECT_TRUE(child1->render_surface()->is_clipped());
2307 EXPECT_TRUE(child2->is_clipped());
2308 EXPECT_FALSE(grand_child->is_clipped());
2309 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2310 EXPECT_FALSE(leaf_node1->is_clipped());
2311 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582312 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2313 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422314 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582315 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582316 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2317
2318 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422319 EXPECT_TRUE(root->is_clipped());
2320 EXPECT_TRUE(parent->is_clipped());
2321 EXPECT_TRUE(child1->is_clipped());
2322 EXPECT_TRUE(child2->is_clipped());
2323 EXPECT_TRUE(grand_child->is_clipped());
2324 EXPECT_TRUE(leaf_node1->is_clipped());
2325 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582326 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2327 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2328 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2329 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2330 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2331 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2332 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2333
2334 root->SetMasksToBounds(false);
2335
2336 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2337 // parent clip rect only contributes to the subtree rooted at child2, since
2338 // the subtree rooted at child1 renders into a separate surface. Similarly,
2339 // child1's clip rect doesn't contribute to its descendants, since its only
2340 // child is a render surface. However, without surfaces, these clip rects
2341 // contribute to all descendants.
2342 parent->SetMasksToBounds(true);
2343 child1->SetMasksToBounds(true);
2344 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362345 root->test_properties()->force_render_surface = true;
2346 child1->test_properties()->force_render_surface = true;
2347 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582348 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262349 EXPECT_TRUE(root->has_render_surface());
2350 EXPECT_FALSE(parent->has_render_surface());
2351 EXPECT_TRUE(child1->has_render_surface());
2352 EXPECT_FALSE(child2->has_render_surface());
2353 EXPECT_TRUE(grand_child->has_render_surface());
2354 EXPECT_FALSE(leaf_node1->has_render_surface());
2355 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422356 EXPECT_FALSE(root->is_clipped());
2357 EXPECT_TRUE(root->render_surface()->is_clipped());
2358 EXPECT_TRUE(parent->is_clipped());
2359 EXPECT_TRUE(child1->is_clipped());
2360 EXPECT_TRUE(child2->is_clipped());
2361 EXPECT_FALSE(grand_child->is_clipped());
2362 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2363 EXPECT_FALSE(leaf_node1->is_clipped());
2364 EXPECT_TRUE(leaf_node2->is_clipped());
2365 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582366 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2367 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2368 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422369 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582370 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2371
2372 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422373 EXPECT_FALSE(root->is_clipped());
2374 EXPECT_TRUE(root->render_surface()->is_clipped());
2375 EXPECT_TRUE(parent->is_clipped());
2376 EXPECT_TRUE(child1->is_clipped());
2377 EXPECT_TRUE(child2->is_clipped());
2378 EXPECT_TRUE(grand_child->is_clipped());
2379 EXPECT_TRUE(leaf_node1->is_clipped());
2380 EXPECT_TRUE(leaf_node2->is_clipped());
2381 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582382 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2383 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2384 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2385 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2386 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2387 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2388}
2389
jaydasika8d0064f2016-06-02 23:34:542390TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
jaydasikabf1875a2016-06-28 03:39:592391 LayerImpl* root = root_layer_for_testing();
jaydasika8d0064f2016-06-02 23:34:542392 LayerImpl* parent = AddChild<LayerImpl>(root);
2393 LayerImpl* child = AddChild<LayerImpl>(parent);
2394 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2395 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2396
danakje4fa7b72016-07-25 22:00:062397 root->SetBounds(gfx::Size(100, 100));
2398 parent->SetPosition(gfx::PointF(2.f, 2.f));
2399 parent->SetBounds(gfx::Size(400, 400));
2400 parent->SetMasksToBounds(true);
2401 child->SetPosition(gfx::PointF(4.f, 4.f));
2402 child->SetBounds(gfx::Size(800, 800));
2403 child->SetMasksToBounds(true);
2404 child->test_properties()->force_render_surface = true;
2405 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2406 grand_child->SetBounds(gfx::Size(1500, 1500));
2407 grand_child->test_properties()->force_render_surface = true;
2408 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2409 leaf_node->SetBounds(gfx::Size(2000, 2000));
2410
jaydasika8d0064f2016-06-02 23:34:542411 root->SetDrawsContent(true);
2412 parent->SetDrawsContent(true);
2413 child->SetDrawsContent(true);
2414 grand_child->SetDrawsContent(true);
2415 leaf_node->SetDrawsContent(true);
2416
jaydasika8d0064f2016-06-02 23:34:542417 host_impl()->set_resourceless_software_draw_for_testing();
2418 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2419 gfx::PointF test_point(90.f, 90.f);
2420 LayerImpl* result_layer =
2421 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2422 ASSERT_TRUE(result_layer);
2423 EXPECT_EQ(leaf_node, result_layer);
2424}
2425
ajuma51d73f72015-10-19 19:43:582426TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2427 // Tests that draw properties are computed correctly when we disable and then
2428 // re-enable separate surfaces.
jaydasikabf1875a2016-06-28 03:39:592429 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582430 LayerImpl* parent = AddChild<LayerImpl>(root);
2431 LayerImpl* child = AddChild<LayerImpl>(parent);
2432 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2433 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2434
danakje4fa7b72016-07-25 22:00:062435 root->SetBounds(gfx::Size(100, 100));
2436 parent->SetPosition(gfx::PointF(2.f, 2.f));
2437 parent->SetBounds(gfx::Size(400, 400));
2438 parent->SetMasksToBounds(true);
2439 child->SetPosition(gfx::PointF(4.f, 4.f));
2440 child->SetBounds(gfx::Size(800, 800));
2441 child->SetMasksToBounds(true);
2442 child->test_properties()->force_render_surface = true;
2443 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2444 grand_child->SetBounds(gfx::Size(1500, 1500));
2445 grand_child->test_properties()->force_render_surface = true;
2446 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2447 leaf_node->SetBounds(gfx::Size(2000, 2000));
2448
ajuma51d73f72015-10-19 19:43:582449 root->SetDrawsContent(true);
2450 parent->SetDrawsContent(true);
2451 child->SetDrawsContent(true);
2452 grand_child->SetDrawsContent(true);
2453 leaf_node->SetDrawsContent(true);
2454
ajuma51d73f72015-10-19 19:43:582455 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2456 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2457
2458 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2459 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2460
2461 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422462 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252463 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582464 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2466 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582467
2468 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422469 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582470 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2471 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022472 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces,
2473 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582474
2475 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422476 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252477 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582478 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022479 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2480 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582481}
2482
[email protected]989386c2013-07-18 21:37:232483TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
danakje4fa7b72016-07-25 22:00:062484 LayerImpl* root = root_layer_for_testing();
enneab0fee42015-07-07 17:36:422485 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2486 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2487 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2488 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2489 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2490 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2491 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2492 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322493
danakje4fa7b72016-07-25 22:00:062494 root->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362495 render_surface1->SetDrawsContent(true);
2496 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422497 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362498 render_surface2->SetDrawsContent(true);
2499 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422500 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362501 child_of_root->SetDrawsContent(true);
2502 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322503
2504 gfx::Transform layer_transform;
2505 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322506
jaydasika10d43fc2016-08-18 04:06:042507 root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062508 root->SetPosition(gfx::PointF(2.5f, 0.f));
2509 root->SetBounds(gfx::Size(10, 10));
2510 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042511 render_surface1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062512 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2513 render_surface1->SetBounds(gfx::Size(10, 10));
2514 render_surface1->test_properties()->transform_origin =
2515 gfx::Point3F(0.25f, 0.f, 0.f);
2516 render_surface1->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042517 render_surface2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062518 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2519 render_surface2->SetBounds(gfx::Size(10, 10));
2520 render_surface2->test_properties()->transform_origin =
2521 gfx::Point3F(0.25f, 0.f, 0.f);
2522 render_surface2->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:042523 child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062524 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2525 child_of_root->SetBounds(gfx::Size(10, 10));
2526 child_of_root->test_properties()->transform_origin =
2527 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042528 child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062529 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2530 child_of_rs1->SetBounds(gfx::Size(10, 10));
2531 child_of_rs1->test_properties()->transform_origin =
2532 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042533 child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062534 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2535 child_of_rs2->SetBounds(gfx::Size(10, 10));
2536 child_of_rs2->test_properties()->transform_origin =
2537 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042538 grand_child_of_root->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062539 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2540 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2541 grand_child_of_root->test_properties()->transform_origin =
2542 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042543 grand_child_of_rs1->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062544 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2545 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2546 grand_child_of_rs1->test_properties()->transform_origin =
2547 gfx::Point3F(0.25f, 0.f, 0.f);
jaydasika10d43fc2016-08-18 04:06:042548 grand_child_of_rs2->test_properties()->transform = layer_transform;
danakje4fa7b72016-07-25 22:00:062549 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2550 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2551 grand_child_of_rs2->test_properties()->transform_origin =
2552 gfx::Point3F(0.25f, 0.f, 0.f);
[email protected]fb661802013-03-25 01:59:322553
danakje4fa7b72016-07-25 22:00:062554 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:272555 SetElementIdsForTesting();
jaydasika9cb21c772016-05-10 22:37:082556
loyso9556c732016-03-11 07:54:582557 // Put an animated opacity on the render surface.
vollickef2ae922016-06-29 17:54:272558 AddOpacityTransitionToElementWithPlayer(
2559 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322560
loyso9556c732016-03-11 07:54:582561 // Also put an animated opacity on a layer without descendants.
vollickef2ae922016-06-29 17:54:272562 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2563 timeline_impl(), 10.0, 1.f, 0.f,
2564 false);
[email protected]fb661802013-03-25 01:59:322565
loyso9556c732016-03-11 07:54:582566 // Put a transform animation on the render surface.
vollickef2ae922016-06-29 17:54:272567 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2568 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322569
loyso9556c732016-03-11 07:54:582570 // Also put transform animations on grand_child_of_root, and
2571 // grand_child_of_rs2
vollickef2ae922016-06-29 17:54:272572 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2573 timeline_impl(), 10.0, 30, 0);
2574 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2575 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322576
danakje4fa7b72016-07-25 22:00:062577 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2578 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322579
2580 // Only layers that are associated with render surfaces should have an actual
2581 // RenderSurface() value.
danakje4fa7b72016-07-25 22:00:062582 ASSERT_TRUE(root->render_surface());
[email protected]fb661802013-03-25 01:59:322583 ASSERT_FALSE(child_of_root->render_surface());
2584 ASSERT_FALSE(grand_child_of_root->render_surface());
2585
2586 ASSERT_TRUE(render_surface1->render_surface());
2587 ASSERT_FALSE(child_of_rs1->render_surface());
2588 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2589
2590 ASSERT_TRUE(render_surface2->render_surface());
2591 ASSERT_FALSE(child_of_rs2->render_surface());
2592 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2593
2594 // Verify all render target accessors
danakje4fa7b72016-07-25 22:00:062595 EXPECT_EQ(root->render_surface(), root->render_target());
2596 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
2597 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322598
weiliangc189c1a12016-04-11 16:16:252599 EXPECT_EQ(render_surface1->render_surface(),
2600 render_surface1->render_target());
2601 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2602 EXPECT_EQ(render_surface1->render_surface(),
2603 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322604
weiliangc189c1a12016-04-11 16:16:252605 EXPECT_EQ(render_surface2->render_surface(),
2606 render_surface2->render_target());
2607 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2608 EXPECT_EQ(render_surface2->render_surface(),
2609 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322610
[email protected]fb661802013-03-25 01:59:322611 // Verify screen_space_transform_is_animating values
danakje4fa7b72016-07-25 22:00:062612 EXPECT_FALSE(root->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322613 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2614 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2615 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322616 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2617 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2618 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322619 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2620 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2621
2622 // Sanity check. If these fail there is probably a bug in the test itself.
2623 // It is expected that we correctly set up transforms so that the y-component
2624 // of the screen-space transform encodes the "depth" of the layer in the tree.
danakje4fa7b72016-07-25 22:00:062625 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262626 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102627 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322628 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102629 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322630
[email protected]803f6b52013-09-12 00:51:262631 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102632 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2633 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322634 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102635 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322636
[email protected]803f6b52013-09-12 00:51:262637 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102638 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2639 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322640 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102641 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322642}
2643
ajuma9384b9c22015-09-17 20:35:032644TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
danakje4fa7b72016-07-25 22:00:062645 LayerImpl* root = root_layer_for_testing();
ajuma9384b9c22015-09-17 20:35:032646 LayerImpl* child = AddChildToRoot<LayerImpl>();
2647 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2648
ajuma9384b9c22015-09-17 20:35:032649 gfx::Transform large_transform;
2650 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2651
danakje4fa7b72016-07-25 22:00:062652 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042653 child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062654 child->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:042655 grand_child->test_properties()->transform = large_transform;
danakje4fa7b72016-07-25 22:00:062656 grand_child->SetBounds(gfx::Size(10, 10));
2657 grand_child->SetDrawsContent(true);
2658 ExecuteCalculateDrawProperties(root);
ajuma9384b9c22015-09-17 20:35:032659
2660 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2661}
2662
ajuma315a4782015-07-24 21:16:342663TEST_F(LayerTreeHostCommonTest,
2664 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
danakje4fa7b72016-07-25 22:00:062665 LayerImpl* root = root_layer_for_testing();
2666 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma315a4782015-07-24 21:16:342667 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2668 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2669
danakje4fa7b72016-07-25 22:00:062670 root->SetDrawsContent(true);
ajuma315a4782015-07-24 21:16:342671 child->SetDrawsContent(true);
2672 grand_child->SetDrawsContent(true);
2673 great_grand_child->SetDrawsContent(true);
2674
danakje4fa7b72016-07-25 22:00:062675 root->SetBounds(gfx::Size(10, 10));
2676 child->SetBounds(gfx::Size(10, 10));
2677 grand_child->SetBounds(gfx::Size(10, 10));
2678 great_grand_child->SetBounds(gfx::Size(10, 10));
ajuma315a4782015-07-24 21:16:342679
vollickef2ae922016-06-29 17:54:272680 SetElementIdsForTesting();
2681
ajuma315a4782015-07-24 21:16:342682 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482683 std::unique_ptr<Animation> animation = Animation::Create(
2684 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302685 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552686 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342687 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:272688 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2689 std::move(animation));
danakje4fa7b72016-07-25 22:00:062690 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:342691
danakje4fa7b72016-07-25 22:00:062692 EXPECT_FALSE(root->screen_space_transform_is_animating());
ajuma315a4782015-07-24 21:16:342693 EXPECT_FALSE(child->screen_space_transform_is_animating());
2694
2695 EXPECT_FALSE(grand_child->TransformIsAnimating());
2696 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2697 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2698 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2699}
2700
weiliangc6da32862016-04-20 16:40:112701TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2702 // Test visible layer rect and drawable content rect are calculated correctly
2703 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322704
[email protected]2c7c6702013-03-26 03:14:052705 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322706 gfx::Transform layer_to_surface_transform;
2707
2708 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232709 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112710 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2711 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2712 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2713 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2714 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2715 EXPECT_EQ(expected_drawable_content_rect,
2716 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322717
2718 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052719 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112720 expected_visible_layer_rect = gfx::Rect();
2721 expected_drawable_content_rect = gfx::Rect();
2722 drawing_layer = TestVisibleRectAndDrawableContentRect(
2723 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2724 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2725 EXPECT_EQ(expected_drawable_content_rect,
2726 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322727
2728 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052729 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112730 expected_visible_layer_rect = gfx::Rect(20, 20);
2731 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2732 drawing_layer = TestVisibleRectAndDrawableContentRect(
2733 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2734 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2735 EXPECT_EQ(expected_drawable_content_rect,
2736 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322737}
2738
weiliangc6da32862016-04-20 16:40:112739TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2740 // Test visible layer rect and drawable content rect are calculated correctly
2741 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322742
[email protected]2c7c6702013-03-26 03:14:052743 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2744 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322745 gfx::Transform layer_to_surface_transform;
2746
2747 // Case 1: Layer is contained within the surface.
2748 layer_to_surface_transform.MakeIdentity();
2749 layer_to_surface_transform.Translate(50.0, 50.0);
2750 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112751 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2752 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2753 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2754 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2755 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2756 EXPECT_EQ(expected_drawable_content_rect,
2757 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322758
2759 // Case 2: Layer is outside the surface rect.
2760 layer_to_surface_transform.MakeIdentity();
2761 layer_to_surface_transform.Translate(-50.0, 0.0);
2762 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112763 expected_visible_layer_rect = gfx::Rect();
2764 expected_drawable_content_rect = gfx::Rect();
2765 drawing_layer = TestVisibleRectAndDrawableContentRect(
2766 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2767 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2768 EXPECT_EQ(expected_drawable_content_rect,
2769 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322770
2771 // Case 3: The layer is rotated about its top-left corner. In surface space,
2772 // the layer is oriented diagonally, with the left half outside of the render
2773 // surface. In this case, the g should still be the entire layer
2774 // (remember the g is computed in layer space); both the top-left
2775 // and bottom-right corners of the layer are still visible.
2776 layer_to_surface_transform.MakeIdentity();
2777 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112778 expected_visible_layer_rect = gfx::Rect(30, 30);
2779 expected_drawable_content_rect = gfx::Rect(22, 43);
2780 drawing_layer = TestVisibleRectAndDrawableContentRect(
2781 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2782 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2783 EXPECT_EQ(expected_drawable_content_rect,
2784 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322785
2786 // Case 4: The layer is rotated about its top-left corner, and translated
2787 // upwards. In surface space, the layer is oriented diagonally, with only the
2788 // top corner of the surface overlapping the layer. In layer space, the render
2789 // surface overlaps the right side of the layer. The g should be
2790 // the layer's right half.
2791 layer_to_surface_transform.MakeIdentity();
2792 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2793 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112794 // Right half of layer bounds.
2795 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2796 expected_drawable_content_rect = gfx::Rect(22, 22);
2797 drawing_layer = TestVisibleRectAndDrawableContentRect(
2798 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2799 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2800 EXPECT_EQ(expected_drawable_content_rect,
2801 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322802}
2803
weiliangc6da32862016-04-20 16:40:112804TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2805 // Test visible layer rect and drawable content rect are calculated correctly
2806 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322807
[email protected]2c7c6702013-03-26 03:14:052808 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2809 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322810 gfx::Transform layer_to_surface_transform;
2811
2812 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2813 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112814 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322815 layer_to_surface_transform.MakeIdentity();
2816 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112817 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2818 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2819 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2820 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2821 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2822 EXPECT_EQ(expected_drawable_content_rect,
2823 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322824
2825 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2826 // degrees, but shifted to the side so only the right-half the layer would be
2827 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112828 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262829 SkMScalar half_width_of_rotated_layer =
2830 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322831 layer_to_surface_transform.MakeIdentity();
2832 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232833 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2834 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112835 // Tight half of the layer.
2836 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2837 expected_drawable_content_rect = gfx::Rect(36, 100);
2838 drawing_layer = TestVisibleRectAndDrawableContentRect(
2839 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2840 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2841 EXPECT_EQ(expected_drawable_content_rect,
2842 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322843}
2844
weiliangc6da32862016-04-20 16:40:112845TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2846 // Test visible layer rect and drawable content rect are calculated correctly
2847 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322848
[email protected]2c7c6702013-03-26 03:14:052849 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2850 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322851 gfx::Transform layer_to_surface_transform;
2852
2853 // Case 1: Even though the layer is twice as large as the surface, due to
2854 // perspective foreshortening, the layer will fit fully in the surface when
2855 // its translated more than the perspective amount.
2856 layer_to_surface_transform.MakeIdentity();
2857
2858 // The following sequence of transforms applies the perspective about the
2859 // center of the surface.
2860 layer_to_surface_transform.Translate(50.0, 50.0);
2861 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2862 layer_to_surface_transform.Translate(-50.0, -50.0);
2863
2864 // This translate places the layer in front of the surface's projection plane.
2865 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2866
weiliangc6da32862016-04-20 16:40:112867 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2868 // offset by layer position.
2869 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2870 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2871 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2872 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2873 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2874 EXPECT_EQ(expected_drawable_content_rect,
2875 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322876
2877 // Case 2: same projection as before, except that the layer is also translated
2878 // to the side, so that only the right half of the layer should be visible.
2879 //
2880 // Explanation of expected result: The perspective ratio is (z distance
2881 // between layer and camera origin) / (z distance between projection plane and
2882 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112883 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322884 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112885 // -25 == -100 in the layer's units.
2886 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2887 // Visible layer rect is moved by 100, and drawable content rect is in target
2888 // space and is moved by 25.
2889 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2890 expected_drawable_content_rect = gfx::Rect(13, 38);
2891 drawing_layer = TestVisibleRectAndDrawableContentRect(
2892 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2893 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2894 EXPECT_EQ(expected_drawable_content_rect,
2895 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322896}
2897
weiliangc6da32862016-04-20 16:40:112898TEST_F(LayerTreeHostCommonDrawRectsTest,
2899 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322900 // There is currently no explicit concept of an orthographic projection plane
2901 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2902 // are technically behind the surface in an orthographic world should not be
2903 // clipped when they are flattened to the surface.
2904
[email protected]2c7c6702013-03-26 03:14:052905 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2906 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322907 gfx::Transform layer_to_surface_transform;
2908
2909 // This sequence of transforms effectively rotates the layer about the y-axis
2910 // at the center of the layer.
2911 layer_to_surface_transform.MakeIdentity();
2912 layer_to_surface_transform.Translate(50.0, 0.0);
2913 layer_to_surface_transform.RotateAboutYAxis(45.0);
2914 layer_to_surface_transform.Translate(-50.0, 0.0);
2915
weiliangc6da32862016-04-20 16:40:112916 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2917 // space.
2918 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2919 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2920 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2921 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2922 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2923 EXPECT_EQ(expected_drawable_content_rect,
2924 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322925}
2926
weiliangc6da32862016-04-20 16:40:112927TEST_F(LayerTreeHostCommonDrawRectsTest,
2928 DrawRectsFor3dPerspectiveWhenClippedByW) {
2929 // Test visible layer rect and drawable content rect are calculated correctly
2930 // when projecting a surface onto a layer, but the layer is partially behind
2931 // the camera (not just behind the projection plane). In this case, the
2932 // cartesian coordinates may seem to be valid, but actually they are not. The
2933 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2934 // coordinates before converting to cartesian coordinates. The drawable
2935 // content rect would be entire surface rect because layer is rotated at the
2936 // camera position.
[email protected]fb661802013-03-25 01:59:322937
weiliangc6da32862016-04-20 16:40:112938 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2939 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322940 gfx::Transform layer_to_surface_transform;
2941
2942 // The layer is positioned so that the right half of the layer should be in
2943 // front of the camera, while the other half is behind the surface's
2944 // projection plane. The following sequence of transforms applies the
2945 // perspective and rotation about the center of the layer.
2946 layer_to_surface_transform.MakeIdentity();
2947 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112948 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2949 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2950 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322951
2952 // Sanity check that this transform does indeed cause w < 0 when applying the
2953 // transform, otherwise this code is not testing the intended scenario.
2954 bool clipped;
2955 MathUtil::MapQuad(layer_to_surface_transform,
2956 gfx::QuadF(gfx::RectF(layer_content_rect)),
2957 &clipped);
2958 ASSERT_TRUE(clipped);
2959
weiliangc6da32862016-04-20 16:40:112960 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2961 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2962 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2963 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2964 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2965 EXPECT_EQ(expected_drawable_content_rect,
2966 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322967}
2968
weiliangc6da32862016-04-20 16:40:112969TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322970 // To determine visible rect in layer space, there needs to be an
2971 // un-projection from surface space to layer space. When the original
2972 // transform was a perspective projection that was clipped, it returns a rect
2973 // that encloses the clipped bounds. Un-projecting this new rect may require
2974 // clipping again.
2975
2976 // This sequence of transforms causes one corner of the layer to protrude
2977 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:112978 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
2979 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322980 gfx::Transform layer_to_surface_transform;
2981 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:112982 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:322983 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2984 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2985 layer_to_surface_transform.RotateAboutYAxis(45.0);
2986 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:112987 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:322988
2989 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2990 // code is not testing the intended scenario.
2991 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442992 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2993 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322994 MathUtil::ProjectQuad(
2995 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2996 ASSERT_TRUE(clipped);
2997
2998 // Only the corner of the layer is not visible on the surface because of being
2999 // clipped. But, the net result of rounding visible region to an axis-aligned
3000 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:113001 gfx::Rect expected_visible_layer_rect = layer_content_rect;
3002 gfx::Rect expected_drawable_content_rect = target_surface_rect;
3003 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3004 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3005 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3006 EXPECT_EQ(expected_drawable_content_rect,
3007 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323008}
3009
miletus9d3da522015-06-05 19:45:073010TEST_F(LayerTreeHostCommonTest,
3011 VisibleRectsForPositionedRootLayerClippedByViewport) {
jaydasikabf1875a2016-06-28 03:39:593012 LayerImpl* root = root_layer_for_testing();
miletus9d3da522015-06-05 19:45:073013
danakje4fa7b72016-07-25 22:00:063014 root->SetPosition(gfx::PointF(60, 70));
3015 root->SetBounds(gfx::Size(100, 100));
3016 root->SetDrawsContent(true);
enne6c281f6e2015-08-18 23:23:003017 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:073018
danakj5e6ff6d2015-09-05 04:43:443019 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:073020 root->render_surface()->DrawableContentRect());
3021 // In target space, not clipped.
3022 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3023 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:443024 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:073025}
3026
[email protected]989386c2013-07-18 21:37:233027TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
jaydasikabf1875a2016-06-28 03:39:593028 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173029 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173030 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173031 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063032
3033 root->SetBounds(gfx::Size(100, 100));
3034 child1_layer->SetBounds(gfx::Size(50, 50));
3035 child1_layer->SetDrawsContent(true);
3036 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
3037 child2_layer->SetBounds(gfx::Size(50, 50));
3038 child2_layer->SetDrawsContent(true);
3039 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
3040 child3_layer->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173041 child3_layer->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173042 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323043
danakj5e6ff6d2015-09-05 04:43:443044 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323045 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323046
danakj64767d902015-06-19 00:10:433047 // Layers that do not draw content should have empty visible_layer_rects.
3048 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323049
danakj64767d902015-06-19 00:10:433050 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173051 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3052 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3053 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323054
3055 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173056 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3057 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3058 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323059}
3060
[email protected]989386c2013-07-18 21:37:233061TEST_F(LayerTreeHostCommonTest,
3062 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
jaydasikabf1875a2016-06-28 03:39:593063 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173064 LayerImpl* child = AddChildToRoot<LayerImpl>();
3065 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173066 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173067 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:283068
danakje4fa7b72016-07-25 22:00:063069 root->SetBounds(gfx::Size(100, 100));
3070 child->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323071 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063072 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
3073 grand_child1->SetBounds(gfx::Size(50, 50));
3074 grand_child1->SetDrawsContent(true);
3075 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
3076 grand_child2->SetBounds(gfx::Size(50, 50));
3077 grand_child2->SetDrawsContent(true);
3078 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
3079 grand_child3->SetBounds(gfx::Size(50, 50));
3080 grand_child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173081 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323082
danakj5e6ff6d2015-09-05 04:43:443083 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323084 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323085
3086 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433087 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3088 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323089
3090 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433091 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3092 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3093 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323094
3095 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323096 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3097 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323098 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3099}
3100
ajuma27442dd2015-03-30 19:19:483101TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasikabf1875a2016-06-28 03:39:593102 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:143103 LayerImpl* child = AddChild<LayerImpl>(root);
3104 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483105
ajuma27442dd2015-03-30 19:19:483106 gfx::Transform child_scale_matrix;
3107 child_scale_matrix.Scale(0.25f, 0.25f);
3108 gfx::Transform grand_child_scale_matrix;
3109 grand_child_scale_matrix.Scale(0.246f, 0.246f);
ajuma27442dd2015-03-30 19:19:483110
danakje4fa7b72016-07-25 22:00:063111 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043112 child->test_properties()->transform = child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063113 child->SetBounds(gfx::Size(10, 10));
ajuma27442dd2015-03-30 19:19:483114 child->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:043115 grand_child->test_properties()->transform = grand_child_scale_matrix;
danakje4fa7b72016-07-25 22:00:063116 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:143117 grand_child->SetDrawsContent(true);
3118 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483119
weiliangcd15784432016-06-07 17:57:333120 // The visible rect is expanded to integer coordinates.
3121 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483122}
3123
[email protected]989386c2013-07-18 21:37:233124TEST_F(LayerTreeHostCommonTest,
3125 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593126 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173127 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3128 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173129 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173130 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
danakje4fa7b72016-07-25 22:00:063131
3132 root->SetBounds(gfx::Size(100, 100));
3133 render_surface->SetBounds(gfx::Size(3, 4));
3134 render_surface->test_properties()->force_render_surface = true;
3135 child1->SetPosition(gfx::PointF(5.f, 5.f));
3136 child1->SetBounds(gfx::Size(50, 50));
3137 child1->SetDrawsContent(true);
3138 child2->SetPosition(gfx::PointF(75.f, 75.f));
3139 child2->SetBounds(gfx::Size(50, 50));
3140 child2->SetDrawsContent(true);
3141 child3->SetPosition(gfx::PointF(125.f, 125.f));
3142 child3->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173143 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173144 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323145
weiliangc0dece732015-07-27 19:06:173146 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323147
danakj5e6ff6d2015-09-05 04:43:443148 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323149 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323150
3151 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433152 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173153 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323154
3155 // An unclipped surface grows its DrawableContentRect to include all drawable
3156 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443157 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173158 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323159
3160 // All layers that draw content into the unclipped surface are also unclipped.
jaydasika94bebdd2016-09-16 22:11:183161 // Only the viewport clip should apply
danakj64767d902015-06-19 00:10:433162 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183163 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3164 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323165
hush6b614212014-12-04 22:37:323166 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3167 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3168 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323169}
3170
[email protected]989386c2013-07-18 21:37:233171TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583172 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:593173 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:583174 LayerImpl* parent = AddChild<LayerImpl>(root);
3175 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3176 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3177 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3178 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3179 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3180 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3181
danakje4fa7b72016-07-25 22:00:063182 root->SetBounds(gfx::Size(100, 100));
3183 parent->SetPosition(gfx::PointF(2.f, 2.f));
3184 parent->SetBounds(gfx::Size(400, 400));
3185 child1->SetPosition(gfx::PointF(4.f, 4.f));
3186 child1->SetBounds(gfx::Size(800, 800));
3187 child1->test_properties()->force_render_surface = true;
3188 child2->SetPosition(gfx::PointF(3.f, 3.f));
3189 child2->SetBounds(gfx::Size(800, 800));
3190 child2->test_properties()->force_render_surface = true;
3191 grand_child1->SetPosition(gfx::PointF(8.f, 8.f));
3192 grand_child1->SetBounds(gfx::Size(1500, 1500));
3193 grand_child2->SetPosition(gfx::PointF(7.f, 7.f));
3194 grand_child2->SetBounds(gfx::Size(1500, 1500));
3195 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
3196 leaf_node1->SetBounds(gfx::Size(2000, 2000));
3197 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
3198 leaf_node2->SetBounds(gfx::Size(2000, 2000));
3199
ajuma51d73f72015-10-19 19:43:583200 root->SetDrawsContent(true);
3201 parent->SetDrawsContent(true);
3202 child1->SetDrawsContent(true);
3203 child2->SetDrawsContent(true);
3204 grand_child1->SetDrawsContent(true);
3205 grand_child2->SetDrawsContent(true);
3206 leaf_node1->SetDrawsContent(true);
3207 leaf_node2->SetDrawsContent(true);
3208
jaydasika94bebdd2016-09-16 22:11:183209 // Case 1: No layers clip. Visible rects are clipped by the viewport.
ajuma51d73f72015-10-19 19:43:583210 // Each layer's drawable content rect is its bounds in target space; the only
3211 // thing that changes with surfaces disabled is that target space is always
3212 // screen space.
weiliangcc154ce22015-12-09 03:39:263213 root->SetHasRenderSurface(true);
3214 child1->SetHasRenderSurface(true);
3215 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583216 ExecuteCalculateDrawProperties(root);
3217 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3218 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183219 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3220 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3221 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3222 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3223 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3224 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583225
3226 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3227 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3228 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3229 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3230 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3231 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3232 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3233 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3234
3235 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3236 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3237 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3238 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3239 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3240 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3241 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3242 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3243 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3244
3245 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3246 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3247 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3248 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3249 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3250 grand_child1->drawable_content_rect());
3251 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3252 grand_child2->drawable_content_rect());
3253 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3254 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3255
3256 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3257 // all visible layer rects are clipped by the intersection of all ancestor
3258 // clips, whether or not surfaces are disabled. However, drawable content
3259 // rects are clipped only until the next render surface is reached, so
3260 // descendants of parent have their drawable content rects clipped only when
3261 // surfaces are disabled.
3262 parent->SetMasksToBounds(true);
3263 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3264 ExecuteCalculateDrawProperties(root);
3265 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3266 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3267 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3268 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3269 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3270 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3271 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3272 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3273
3274 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3275 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3276 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3277 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3278 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3279 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3280 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3281 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3282
3283 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3284 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3285 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3286 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3287 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3288 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3289 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3290 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3291 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3292
3293 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3294 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3295 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3296 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3297 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3298 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3299 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3300 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3301
3302 parent->SetMasksToBounds(false);
3303
3304 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
jaydasika526eae0a2016-09-02 01:47:593305 // layers have their visible rects clipped by them; Similarly, descendants of
3306 // these layers have their drawable content rects clipped by them.
ajuma51d73f72015-10-19 19:43:583307 child1->SetMasksToBounds(true);
3308 grand_child2->SetMasksToBounds(true);
3309 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3310 ExecuteCalculateDrawProperties(root);
3311 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3312 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593313 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183314 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593315 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3316 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3317 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3318 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
ajuma51d73f72015-10-19 19:43:583319
3320 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3321 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3322 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3323 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3324 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3325 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3326 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3327 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3328
3329 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3330 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3331 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3332 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3333 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3334 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3335 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3336 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3337 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3338
3339 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3340 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3341 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3342 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3343 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3344 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3345 grand_child2->drawable_content_rect());
3346 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3347 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3348}
3349
3350TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023351 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
jaydasikabf1875a2016-06-28 03:39:593352 LayerImpl* root = root_layer_for_testing();
enne6c281f6e2015-08-18 23:23:003353 LayerImpl* child1 = AddChild<LayerImpl>(root);
3354 LayerImpl* child2 = AddChild<LayerImpl>(root);
3355 LayerImpl* child3 = AddChild<LayerImpl>(root);
hush887bb542014-12-02 22:49:023356
danakje4fa7b72016-07-25 22:00:063357 root->SetBounds(gfx::Size(100, 100));
3358 child1->SetPosition(gfx::PointF(5.f, 5.f));
3359 child1->SetBounds(gfx::Size(50, 50));
3360 child1->SetDrawsContent(true);
3361 child2->SetPosition(gfx::PointF(75.f, 75.f));
3362 child2->SetBounds(gfx::Size(50, 50));
3363 child2->SetDrawsContent(true);
3364 child3->SetPosition(gfx::PointF(125.f, 125.f));
3365 child3->SetBounds(gfx::Size(50, 50));
3366 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023367
enne6c281f6e2015-08-18 23:23:003368 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023369 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003370 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383371 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023372
sunxdb365de02016-04-28 20:32:573373 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023374 ASSERT_TRUE(root->render_surface());
3375 EXPECT_FALSE(root->is_clipped());
3376
3377 gfx::Rect empty;
3378 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3379 EXPECT_TRUE(root->render_surface()->is_clipped());
3380
3381 // Visible content rect calculation will check if the target surface is
3382 // clipped or not. An empty clip rect does not indicate the render surface
3383 // is unclipped.
danakj64767d902015-06-19 00:10:433384 EXPECT_EQ(empty, child1->visible_layer_rect());
3385 EXPECT_EQ(empty, child2->visible_layer_rect());
3386 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023387}
3388
3389TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233390 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
jaydasikabf1875a2016-06-28 03:39:593391 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173392 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063393
3394 root->SetBounds(gfx::Size(100, 100));
3395 child->SetPosition(gfx::PointF(5.f, 5.f));
3396 child->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173397 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283398
[email protected]630ddad2013-08-16 03:01:323399 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473400 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323401 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473402
jaydasika10d43fc2016-08-18 04:06:043403 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173404 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473405
danakj64767d902015-06-19 00:10:433406 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473407 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323408
[email protected]08bdf1b2014-04-16 23:23:293409 // Case 2: a matrix with flattened z, uninvertible and not visible according
3410 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323411 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263412 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323413 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3414
jaydasika10d43fc2016-08-18 04:06:043415 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173416 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323417
danakj64767d902015-06-19 00:10:433418 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293419 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323420
[email protected]08bdf1b2014-04-16 23:23:293421 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323422 uninvertible_matrix.MakeIdentity();
3423 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263424 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323425 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3426
jaydasika10d43fc2016-08-18 04:06:043427 child->test_properties()->transform = uninvertible_matrix;
weiliangc0dece732015-07-27 19:06:173428 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323429
danakj64767d902015-06-19 00:10:433430 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293431 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473432}
3433
[email protected]989386c2013-07-18 21:37:233434TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563435 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
jaydasikabf1875a2016-06-28 03:39:593436 LayerImpl* root = root_layer_for_testing();
ajumaae0dc2d2015-08-05 21:55:563437 LayerImpl* child = AddChildToRoot<LayerImpl>();
3438 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaae0dc2d2015-08-05 21:55:563439
ajumaae0dc2d2015-08-05 21:55:563440 gfx::Transform perspective;
3441 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3442
3443 gfx::Transform rotation;
3444 rotation.RotateAboutYAxis(45.0);
3445
danakje4fa7b72016-07-25 22:00:063446 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:043447 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063448 child->SetPosition(gfx::PointF(10.f, 10.f));
3449 child->SetBounds(gfx::Size(100, 100));
3450 child->SetDrawsContent(true);
3451 child->Set3dSortingContextId(1);
3452 child->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:043453 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063454 grand_child->SetBounds(gfx::Size(100, 100));
3455 grand_child->SetDrawsContent(true);
3456 grand_child->Set3dSortingContextId(1);
3457 grand_child->test_properties()->should_flatten_transform = false;
ajumaae0dc2d2015-08-05 21:55:563458 ExecuteCalculateDrawProperties(root);
3459
3460 // Though all layers have invertible transforms, matrix multiplication using
3461 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053462 EXPECT_FALSE(root->layer_tree_impl()
3463 ->property_trees()
3464 ->transform_tree.Node(grand_child->transform_tree_index())
trchendba8b1502016-07-08 09:47:013465 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563466
sunxd71aea3e2016-04-01 23:48:053467 // CalcDrawProps skips a subtree when a layer's screen space transform is
3468 // uninvertible
3469 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563470}
3471
jaydasika69c77aa2016-07-14 22:48:483472TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) {
3473 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika69c77aa2016-07-14 22:48:483474 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323475 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3476 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223477 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483478
3479 std::unique_ptr<LayerImpl> root =
3480 LayerImpl::Create(host_impl.active_tree(), 1);
3481 std::unique_ptr<LayerImpl> child =
3482 LayerImpl::Create(host_impl.active_tree(), 2);
3483 std::unique_ptr<TextureLayerImpl> surface =
3484 TextureLayerImpl::Create(host_impl.active_tree(), 3);
3485 std::unique_ptr<TextureLayerImpl> surface_child =
3486 TextureLayerImpl::Create(host_impl.active_tree(), 4);
3487 std::unique_ptr<TextureLayerImpl> surface_sibling =
3488 TextureLayerImpl::Create(host_impl.active_tree(), 5);
3489 std::unique_ptr<TextureLayerImpl> surface_child_mask =
3490 TextureLayerImpl::Create(host_impl.active_tree(), 6);
3491
3492 surface->SetDrawsContent(true);
3493 surface_child->SetDrawsContent(true);
3494 surface_sibling->SetDrawsContent(true);
3495 surface_child_mask->SetDrawsContent(true);
3496 surface->SetContentsOpaque(true);
3497 surface_child->SetContentsOpaque(true);
3498 surface_sibling->SetContentsOpaque(true);
3499 surface_child_mask->SetContentsOpaque(true);
3500
jaydasika69c77aa2016-07-14 22:48:483501 gfx::Transform translate;
3502 translate.Translate(20.f, 20.f);
3503
danakje4fa7b72016-07-25 22:00:063504 root->SetBounds(gfx::Size(1000, 1000));
3505 child->SetBounds(gfx::Size(300, 300));
jaydasika10d43fc2016-08-18 04:06:043506 surface->test_properties()->transform = translate;
danakje4fa7b72016-07-25 22:00:063507 surface->SetBounds(gfx::Size(300, 300));
3508 surface->test_properties()->force_render_surface = true;
3509 surface_child->SetBounds(gfx::Size(300, 300));
3510 surface_child->test_properties()->force_render_surface = true;
3511 surface_sibling->SetBounds(gfx::Size(200, 200));
jaydasika69c77aa2016-07-14 22:48:483512
3513 LayerImpl* surface_ptr = surface.get();
3514 LayerImpl* surface_child_ptr = surface_child.get();
3515 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3516
3517 host_impl.SetViewportSize(root->bounds());
3518
3519 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3520 surface->test_properties()->AddChild(std::move(surface_child));
3521 child->test_properties()->AddChild(std::move(surface));
3522 child->test_properties()->AddChild(std::move(surface_sibling));
3523 root->test_properties()->AddChild(std::move(child));
3524 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3525 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323526 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika69c77aa2016-07-14 22:48:483527 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3528 bool update_lcd_text = false;
3529 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3530
3531 EXPECT_TRANSFORMATION_MATRIX_EQ(
3532 surface_ptr->render_surface()->draw_transform(), translate);
3533 // surface_sibling draws into the root render surface and occludes
3534 // surface_child's contents.
3535 Occlusion actual_occlusion =
3536 surface_child_ptr->render_surface()->occlusion_in_content_space();
3537 Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()),
3538 SimpleEnclosedRegion(gfx::Rect(200, 200)));
3539 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3540
3541 // Mask layer should have the same occlusion.
3542 actual_occlusion =
3543 surface_child_mask_ptr->draw_properties().occlusion_in_content_space;
3544 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3545}
3546
jaydasika2a1718b2016-10-26 22:58:023547TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) {
3548 FakeImplTaskRunnerProvider task_runner_provider;
jaydasika2a1718b2016-10-26 22:58:023549 TestTaskGraphRunner task_graph_runner;
3550 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3551 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223552 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika2a1718b2016-10-26 22:58:023553
3554 std::unique_ptr<LayerImpl> root =
3555 LayerImpl::Create(host_impl.active_tree(), 1);
3556 std::unique_ptr<TextureLayerImpl> child =
3557 TextureLayerImpl::Create(host_impl.active_tree(), 2);
3558
3559 LayerImpl* child_ptr = child.get();
3560
3561 root->SetBounds(gfx::Size(100, 100));
3562 child->SetBounds(gfx::Size(100, 100));
3563 child->SetDrawsContent(true);
3564 gfx::Transform fractional_translate;
3565 fractional_translate.Translate(10.5f, 20.3f);
3566 child->test_properties()->transform = fractional_translate;
3567
3568 host_impl.SetViewportSize(root->bounds());
3569
3570 root->test_properties()->AddChild(std::move(child));
3571 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3572 host_impl.SetVisible(true);
3573 host_impl.InitializeRenderer(compositor_frame_sink.get());
3574 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3575 bool update_lcd_text = false;
3576 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3577
3578 EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate);
3579 fractional_translate.RoundTranslationComponents();
3580 EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(),
3581 fractional_translate);
3582 gfx::RectF layer_bounds_in_screen_space =
3583 MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(),
3584 gfx::RectF(gfx::SizeF(child_ptr->bounds())));
3585 EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f));
3586}
3587
ajumaae0dc2d2015-08-05 21:55:563588TEST_F(LayerTreeHostCommonTest,
3589 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163590 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563591 TestTaskGraphRunner task_graph_runner;
danakj1120f4c2016-09-15 02:05:323592 std::unique_ptr<CompositorFrameSink> compositor_frame_sink =
3593 FakeCompositorFrameSink::Create3d();
pimanc44437a22016-10-29 00:09:223594 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483595
danakj60bc3bc2016-04-09 00:24:483596 std::unique_ptr<LayerImpl> root =
3597 LayerImpl::Create(host_impl.active_tree(), 1);
3598 std::unique_ptr<LayerImpl> child =
3599 LayerImpl::Create(host_impl.active_tree(), 2);
3600 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563601 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483602 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563603 LayerImpl::Create(host_impl.active_tree(), 4);
ajumaae0dc2d2015-08-05 21:55:563604
ajumaae0dc2d2015-08-05 21:55:563605 gfx::Transform perspective;
3606 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3607
3608 gfx::Transform rotation;
3609 rotation.RotateAboutYAxis(45.0);
3610
danakje4fa7b72016-07-25 22:00:063611 root->SetBounds(gfx::Size(1000, 1000));
jaydasika10d43fc2016-08-18 04:06:043612 child->test_properties()->transform = perspective;
danakje4fa7b72016-07-25 22:00:063613 child->SetPosition(gfx::PointF(10.f, 10.f));
3614 child->SetBounds(gfx::Size(300, 300));
3615 child->test_properties()->should_flatten_transform = false;
3616 child->Set3dSortingContextId(1);
jaydasika10d43fc2016-08-18 04:06:043617 grand_child->test_properties()->transform = rotation;
danakje4fa7b72016-07-25 22:00:063618 grand_child->SetBounds(gfx::Size(200, 200));
3619 grand_child->test_properties()->should_flatten_transform = false;
3620 grand_child->Set3dSortingContextId(1);
3621 occluding_child->SetBounds(gfx::Size(200, 200));
3622 occluding_child->test_properties()->should_flatten_transform = false;
3623
3624 child->SetDrawsContent(true);
3625 grand_child->SetDrawsContent(true);
3626 occluding_child->SetDrawsContent(true);
3627 occluding_child->SetContentsOpaque(true);
ajumaae0dc2d2015-08-05 21:55:563628
3629 host_impl.SetViewportSize(root->bounds());
3630
jaydasika89f7b5a2016-06-22 02:08:393631 child->test_properties()->AddChild(std::move(grand_child));
3632 root->test_properties()->AddChild(std::move(child));
3633 root->test_properties()->AddChild(std::move(occluding_child));
jaydasikabf1875a2016-06-28 03:39:593634 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
sievers71c62dd52015-10-07 01:44:393635 host_impl.SetVisible(true);
danakj1120f4c2016-09-15 02:05:323636 host_impl.InitializeRenderer(compositor_frame_sink.get());
jaydasika4340ea02016-06-06 19:44:263637 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563638 bool update_lcd_text = false;
3639 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3640
jaydasikafc66cfb2016-06-10 04:34:223641 LayerImpl* grand_child_ptr = host_impl.active_tree()
jaydasikabf1875a2016-06-28 03:39:593642 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:223643 ->test_properties()
3644 ->children[0]
3645 ->test_properties()
3646 ->children[0];
ajumaae0dc2d2015-08-05 21:55:563647
3648 // Though all layers have invertible transforms, matrix multiplication using
3649 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053650 EXPECT_FALSE(
3651 host_impl.active_tree()
3652 ->property_trees()
3653 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
trchendba8b1502016-07-08 09:47:013654 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563655
sunxd71aea3e2016-04-01 23:48:053656 // Since |grand_child| has an uninvertible screen space transform, it is
3657 // skipped so
3658 // that we are not computing its occlusion_in_content_space.
3659 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563660 EXPECT_EQ(
3661 layer_bounds,
3662 grand_child_ptr->draw_properties()
3663 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3664}
3665
3666TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233667 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593668 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173669 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3670 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173671 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173672 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283673
danakje4fa7b72016-07-25 22:00:063674 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323675 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063676 render_surface->SetBounds(gfx::Size(3, 4));
3677 render_surface->test_properties()->force_render_surface = true;
3678 child1->SetPosition(gfx::PointF(5.f, 5.f));
3679 child1->SetBounds(gfx::Size(50, 50));
3680 child1->SetDrawsContent(true);
3681 child2->SetPosition(gfx::PointF(75.f, 75.f));
3682 child2->SetBounds(gfx::Size(50, 50));
3683 child2->SetDrawsContent(true);
3684 child3->SetPosition(gfx::PointF(125.f, 125.f));
3685 child3->SetBounds(gfx::Size(50, 50));
3686 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173687 ExecuteCalculateDrawProperties(root);
3688
3689 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323690
danakj5e6ff6d2015-09-05 04:43:443691 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323692 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323693
3694 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433695 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173696 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323697
3698 // A clipped surface grows its DrawableContentRect to include all drawable
3699 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443700 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173701 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323702
3703 // All layers that draw content into the surface have their visible content
3704 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433705 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3706 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3707 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323708
3709 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323710 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3711 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3712 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323713}
3714
[email protected]989386c2013-07-18 21:37:233715TEST_F(LayerTreeHostCommonTest,
3716 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323717 // Check that clipping does not propagate down surfaces.
jaydasikabf1875a2016-06-28 03:39:593718 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173719 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3720 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3721 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173722 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173723 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283724
danakje4fa7b72016-07-25 22:00:063725 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323726 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063727 render_surface1->SetBounds(gfx::Size(3, 4));
3728 render_surface1->test_properties()->force_render_surface = true;
3729 render_surface2->SetBounds(gfx::Size(7, 13));
3730 render_surface2->test_properties()->force_render_surface = true;
3731 child1->SetPosition(gfx::PointF(5.f, 5.f));
3732 child1->SetBounds(gfx::Size(50, 50));
3733 child1->SetDrawsContent(true);
3734 child2->SetPosition(gfx::PointF(75.f, 75.f));
3735 child2->SetBounds(gfx::Size(50, 50));
3736 child2->SetDrawsContent(true);
3737 child3->SetPosition(gfx::PointF(125.f, 125.f));
3738 child3->SetBounds(gfx::Size(50, 50));
3739 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173740 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323741
3742 ASSERT_TRUE(render_surface1->render_surface());
3743 ASSERT_TRUE(render_surface2->render_surface());
3744
danakj5e6ff6d2015-09-05 04:43:443745 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323746 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323747
3748 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433749 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3750 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3751 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323752
3753 // A clipped surface grows its DrawableContentRect to include all drawable
3754 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443755 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323756 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323757
3758 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3759 // is only implicitly clipped by render_surface1's content rect. So,
3760 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443761 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323762 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323763
jaydasika94bebdd2016-09-16 22:11:183764 // All layers that draw content into render_surface2 think they are unclipped
3765 // by the surface. So, only the viewport clip applies.
danakj64767d902015-06-19 00:10:433766 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:183767 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3768 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323769
3770 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323771 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3772 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3773 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323774}
3775
[email protected]989386c2013-07-18 21:37:233776TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463777 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593778 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463779 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3780 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3781 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3782 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
jaydasika27d0f2e2015-10-16 23:52:463783
danakje4fa7b72016-07-25 22:00:063784 root->SetBounds(gfx::Size(100, 100));
3785 render_surface1->SetBounds(gfx::Size(100, 100));
3786 render_surface1->test_properties()->force_render_surface = true;
3787 child1->SetBounds(gfx::Size(500, 500));
3788 child1->SetDrawsContent(true);
3789 child2->SetBounds(gfx::Size(700, 700));
3790 child2->SetDrawsContent(true);
3791 render_surface2->SetBounds(gfx::Size(1000, 1000));
3792 render_surface2->test_properties()->force_render_surface = true;
3793 render_surface2->SetDrawsContent(true);
jaydasika27d0f2e2015-10-16 23:52:463794
3795 child1->SetMasksToBounds(true);
3796 child2->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463797 ExecuteCalculateDrawProperties(root);
jaydasika526eae0a2016-09-02 01:47:593798 EXPECT_EQ(gfx::Rect(100, 100), child1->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463799 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3800}
3801
3802TEST_F(LayerTreeHostCommonTest,
3803 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593804 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463805 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3806 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3807 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3808 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3809
danakje4fa7b72016-07-25 22:00:063810 root->SetBounds(gfx::Size(100, 100));
3811
3812 clip_parent->SetBounds(gfx::Size(50, 50));
3813 clip_parent->SetMasksToBounds(true);
3814 clip_parent->test_properties()->clip_children =
3815 base::MakeUnique<std::set<LayerImpl*>>();
3816 clip_parent->test_properties()->clip_children->insert(clip_child);
3817
3818 render_surface1->SetBounds(gfx::Size(20, 20));
3819 render_surface1->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463820 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063821 render_surface1->test_properties()->force_render_surface = true;
3822
3823 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika27d0f2e2015-10-16 23:52:463824 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563825 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika27d0f2e2015-10-16 23:52:463826
danakje4fa7b72016-07-25 22:00:063827 render_surface2->SetBounds(gfx::Size(60, 60));
3828 render_surface2->SetDrawsContent(true);
3829 render_surface2->test_properties()->force_render_surface = true;
jaydasika27d0f2e2015-10-16 23:52:463830
3831 ExecuteCalculateDrawProperties(root);
3832 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3833 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3834 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3835}
3836
jaydasika1f5312d2015-10-21 21:34:323837TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
jaydasikabf1875a2016-06-28 03:39:593838 LayerImpl* root = root_layer_for_testing();
jaydasika1f5312d2015-10-21 21:34:323839 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3840 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3841 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3842 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3843
danakje4fa7b72016-07-25 22:00:063844 root->SetBounds(gfx::Size(100, 100));
3845
3846 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
3847 clip_parent->SetBounds(gfx::Size(50, 50));
3848 clip_parent->test_properties()->clip_children =
3849 base::MakeUnique<std::set<LayerImpl*>>();
3850 clip_parent->test_properties()->clip_children->insert(clip_child);
3851
3852 render_surface1->SetBounds(gfx::Size(20, 20));
jaydasika1f5312d2015-10-21 21:34:323853 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063854 render_surface1->test_properties()->force_render_surface = true;
3855
3856 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika1f5312d2015-10-21 21:34:323857 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563858 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika1f5312d2015-10-21 21:34:323859
danakje4fa7b72016-07-25 22:00:063860 render_surface2->SetBounds(gfx::Size(60, 60));
3861 render_surface2->SetDrawsContent(true);
3862 render_surface2->test_properties()->force_render_surface = true;
3863
jaydasika1f5312d2015-10-21 21:34:323864 clip_parent->SetMasksToBounds(true);
3865 render_surface1->SetMasksToBounds(true);
3866
3867 ExecuteCalculateDrawProperties(root);
3868 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3869}
3870
jaydasika77a4a072015-10-20 21:47:273871TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3872 // Test that only drawn layers contribute to render surface content rect.
jaydasikabf1875a2016-06-28 03:39:593873 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:273874 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3875 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3876
danakje4fa7b72016-07-25 22:00:063877 root->SetBounds(gfx::Size(200, 200));
3878 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:273879 surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063880 surface->test_properties()->force_render_surface = true;
3881 test_layer->SetBounds(gfx::Size(150, 150));
jaydasika77a4a072015-10-20 21:47:273882
3883 ExecuteCalculateDrawProperties(root);
3884 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3885
3886 test_layer->SetDrawsContent(true);
3887 ExecuteCalculateDrawProperties(root);
3888 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3889}
3890
jaydasika27d0f2e2015-10-16 23:52:463891TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3892 // Tests visible rects computation when we have unclipped_surface->
3893 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3894 // of surface_with_unclipped_descendants doesn't propagate to the
3895 // clipped_surface below it.
jaydasikabf1875a2016-06-28 03:39:593896 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463897 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3898 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3899 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3900 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3901 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3902
danakje4fa7b72016-07-25 22:00:063903 root->SetBounds(gfx::Size(100, 100));
jaydasika27d0f2e2015-10-16 23:52:463904
danakje4fa7b72016-07-25 22:00:063905 unclipped_surface->SetBounds(gfx::Size(30, 30));
3906 unclipped_surface->SetDrawsContent(true);
3907 unclipped_surface->test_properties()->force_render_surface = true;
3908
3909 clip_parent->SetBounds(gfx::Size(50, 50));
3910 clip_parent->test_properties()->clip_children =
3911 base::MakeUnique<std::set<LayerImpl*>>();
3912 clip_parent->test_properties()->clip_children->insert(clip_child);
3913
3914 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
3915 unclipped_desc_surface->SetDrawsContent(true);
3916 unclipped_desc_surface->test_properties()->force_render_surface = true;
3917
3918 clip_child->SetBounds(gfx::Size(60, 60));
3919 clip_child->test_properties()->clip_parent = clip_parent;
3920
3921 clipped_surface->SetBounds(gfx::Size(60, 60));
3922 clipped_surface->SetDrawsContent(true);
3923 clipped_surface->test_properties()->force_render_surface = true;
3924
jaydasika27d0f2e2015-10-16 23:52:463925 clip_parent->SetMasksToBounds(true);
3926
3927 ExecuteCalculateDrawProperties(root);
3928 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3929 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3930 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3931}
3932
3933TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3934 // Tests visible rects computation when we have unclipped_surface->
3935 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3936 // of root propagate to the clipped_surface.
jaydasikabf1875a2016-06-28 03:39:593937 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463938 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3939 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3940 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3941 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3942 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3943
danakje4fa7b72016-07-25 22:00:063944 root->SetBounds(gfx::Size(10, 10));
jaydasika27d0f2e2015-10-16 23:52:463945
danakje4fa7b72016-07-25 22:00:063946 unclipped_surface->SetBounds(gfx::Size(50, 50));
3947 unclipped_surface->SetDrawsContent(true);
3948 unclipped_surface->test_properties()->force_render_surface = true;
3949
3950 clip_parent->SetBounds(gfx::Size(50, 50));
3951 clip_parent->test_properties()->clip_children =
3952 base::MakeUnique<std::set<LayerImpl*>>();
3953 clip_parent->test_properties()->clip_children->insert(clip_child);
3954
3955 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
3956 unclipped_desc_surface->SetDrawsContent(true);
3957 unclipped_desc_surface->test_properties()->force_render_surface = true;
3958
3959 clip_child->SetBounds(gfx::Size(100, 100));
3960 clip_child->test_properties()->clip_parent = clip_parent;
3961
3962 clipped_surface->SetBounds(gfx::Size(50, 50));
3963 clipped_surface->SetDrawsContent(true);
3964 clipped_surface->test_properties()->force_render_surface = true;
3965
jaydasika27d0f2e2015-10-16 23:52:463966 clip_parent->SetMasksToBounds(true);
3967 unclipped_desc_surface->SetMasksToBounds(true);
3968
3969 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:183970 EXPECT_EQ(gfx::Rect(10, 10), unclipped_surface->visible_layer_rect());
jaydasika526eae0a2016-09-02 01:47:593971 EXPECT_EQ(gfx::Rect(10, 10), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463972 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3973}
3974
3975TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233976 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323977 // Layers that have non-axis aligned bounds (due to transforms) have an
3978 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593979 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173980 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3981 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283982
[email protected]fb661802013-03-25 01:59:323983 gfx::Transform child_rotation;
3984 child_rotation.Rotate(45.0);
[email protected]fb661802013-03-25 01:59:323985
danakje4fa7b72016-07-25 22:00:063986 root->SetBounds(gfx::Size(100, 100));
3987 render_surface->SetBounds(gfx::Size(3, 4));
3988 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:043989 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:063990 child1->SetPosition(gfx::PointF(25.f, 25.f));
3991 child1->SetBounds(gfx::Size(50, 50));
3992 child1->SetDrawsContent(true);
3993 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173994 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323995
weiliangc0dece732015-07-27 19:06:173996 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323997
danakj5e6ff6d2015-09-05 04:43:443998 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323999 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324000
4001 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:434002 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:174003 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324004
4005 // The unclipped surface grows its DrawableContentRect to include all drawable
4006 // regions of the subtree.
4007 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4008 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:264009 gfx::Rect(50 - diagonal_radius,
4010 50 - diagonal_radius,
4011 diagonal_radius * 2,
4012 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444013 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174014 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324015
4016 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434017 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324018 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324019}
4020
[email protected]989386c2013-07-18 21:37:234021TEST_F(LayerTreeHostCommonTest,
4022 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324023 // Layers that have non-axis aligned bounds (due to transforms) have an
4024 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:594025 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174026 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4027 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:284028
[email protected]fb661802013-03-25 01:59:324029 gfx::Transform child_rotation;
4030 child_rotation.Rotate(45.0);
[email protected]a2566412014-06-05 03:14:204031
danakje4fa7b72016-07-25 22:00:064032 root->SetBounds(gfx::Size(50, 50));
[email protected]fb661802013-03-25 01:59:324033 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064034 render_surface->SetBounds(gfx::Size(3, 4));
4035 render_surface->test_properties()->force_render_surface = true;
4036 child1->SetPosition(gfx::PointF(25.f, 25.f));
4037 child1->SetBounds(gfx::Size(50, 50));
4038 child1->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:044039 child1->test_properties()->transform = child_rotation;
danakje4fa7b72016-07-25 22:00:064040 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:174041 ExecuteCalculateDrawProperties(root);
4042
4043 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324044
4045 // The clipped surface clamps the DrawableContentRect that encloses the
4046 // rotated layer.
4047 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264048 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4049 50 - diagonal_radius,
4050 diagonal_radius * 2,
4051 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444052 gfx::RectF expected_surface_drawable_content(
4053 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324054 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174055 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324056
4057 // On the clipped surface, only a quarter of the child1 is visible, but when
4058 // rotating it back to child1's content space, the actual enclosing rect ends
4059 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:334060 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324061
4062 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324063 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324064}
4065
[email protected]989386c2013-07-18 21:37:234066TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594067 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174068 FakePictureLayerImpl* render_surface1 =
4069 AddChildToRoot<FakePictureLayerImpl>();
weiliangc0dece732015-07-27 19:06:174070 FakePictureLayerImpl* render_surface2 =
4071 AddChild<FakePictureLayerImpl>(render_surface1);
weiliangc0dece732015-07-27 19:06:174072 FakePictureLayerImpl* child1 =
4073 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174074 FakePictureLayerImpl* child2 =
4075 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174076 FakePictureLayerImpl* child3 =
4077 AddChild<FakePictureLayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:284078
danakje4fa7b72016-07-25 22:00:064079 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324080 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064081 render_surface1->SetBounds(gfx::Size(3, 4));
4082 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
4083 render_surface1->SetDrawsContent(true);
4084 render_surface1->test_properties()->force_render_surface = true;
4085 render_surface2->SetBounds(gfx::Size(7, 13));
4086 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
4087 render_surface2->SetDrawsContent(true);
4088 render_surface2->test_properties()->force_render_surface = true;
4089 child1->SetBounds(gfx::Size(50, 50));
4090 child1->SetPosition(gfx::PointF(5.f, 5.f));
4091 child1->SetDrawsContent(true);
4092 child2->SetBounds(gfx::Size(50, 50));
4093 child2->SetPosition(gfx::PointF(75.f, 75.f));
4094 child2->SetDrawsContent(true);
4095 child3->SetBounds(gfx::Size(50, 50));
4096 child3->SetPosition(gfx::PointF(125.f, 125.f));
4097 child3->SetDrawsContent(true);
4098 float device_scale_factor = 2.f;
weiliangc0dece732015-07-27 19:06:174099 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324100
4101 ASSERT_TRUE(render_surface1->render_surface());
4102 ASSERT_TRUE(render_surface2->render_surface());
4103
4104 // drawable_content_rects for all layers and surfaces are scaled by
4105 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444106 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324107 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444108 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324109 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324110
4111 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4112 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444113 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324114 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324115
hush6b614212014-12-04 22:37:324116 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4117 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4118 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324119
4120 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434121 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324122
sohan.jyotie3bd6192014-10-13 07:13:594123 // All layer visible content rects are not expressed in content space of each
4124 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434125 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4126 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4127 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
jaydasika94bebdd2016-09-16 22:11:184128 EXPECT_EQ(gfx::Rect(0, 0, 15, 15), child2->visible_layer_rect());
4129 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324130}
4131
[email protected]989386c2013-07-18 21:37:234132TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324133 // Verify the behavior of back-face culling when there are no preserve-3d
4134 // layers. Note that 3d transforms still apply in this case, but they are
4135 // "flattened" to each parent layer according to current W3C spec.
4136
danakje4fa7b72016-07-25 22:00:064137 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324138 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4139 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4140 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4141 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4142 LayerImpl* front_facing_child_of_front_facing_surface =
4143 AddChild<LayerImpl>(front_facing_surface);
4144 LayerImpl* back_facing_child_of_front_facing_surface =
4145 AddChild<LayerImpl>(front_facing_surface);
4146 LayerImpl* front_facing_child_of_back_facing_surface =
4147 AddChild<LayerImpl>(back_facing_surface);
4148 LayerImpl* back_facing_child_of_back_facing_surface =
4149 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284150
[email protected]fb661802013-03-25 01:59:324151 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324152 front_facing_child->test_properties()->double_sided = false;
4153 back_facing_child->test_properties()->double_sided = false;
4154 front_facing_surface->test_properties()->double_sided = false;
4155 back_facing_surface->test_properties()->double_sided = false;
4156 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4157 false;
4158 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4159 false;
4160 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4161 false;
4162 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4163 false;
4164
4165 // Everything draws content.
4166 front_facing_child->SetDrawsContent(true);
4167 back_facing_child->SetDrawsContent(true);
4168 front_facing_surface->SetDrawsContent(true);
4169 back_facing_surface->SetDrawsContent(true);
4170 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4171 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4172 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4173 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324174
4175 gfx::Transform backface_matrix;
4176 backface_matrix.Translate(50.0, 50.0);
4177 backface_matrix.RotateAboutYAxis(180.0);
4178 backface_matrix.Translate(-50.0, -50.0);
4179
danakje4fa7b72016-07-25 22:00:064180 root->SetBounds(gfx::Size(100, 100));
4181 front_facing_child->SetBounds(gfx::Size(100, 100));
4182 back_facing_child->SetBounds(gfx::Size(100, 100));
4183 front_facing_surface->SetBounds(gfx::Size(100, 100));
4184 back_facing_surface->SetBounds(gfx::Size(100, 100));
4185 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4186 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4187 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4188 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324189
danakje4fa7b72016-07-25 22:00:064190 front_facing_surface->test_properties()->force_render_surface = true;
4191 back_facing_surface->test_properties()->force_render_surface = true;
[email protected]fb661802013-03-25 01:59:324192
jaydasika10d43fc2016-08-18 04:06:044193 back_facing_child->test_properties()->transform = backface_matrix;
4194 back_facing_surface->test_properties()->transform = backface_matrix;
4195 back_facing_child_of_front_facing_surface->test_properties()->transform =
4196 backface_matrix;
4197 back_facing_child_of_back_facing_surface->test_properties()->transform =
4198 backface_matrix;
danakje4fa7b72016-07-25 22:00:064199
4200 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
4201 // spec, these layers should blindly use their own local transforms to
4202 // determine back-face culling.
jaydasika6ed869662016-09-21 14:29:594203 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324204
4205 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094206 EXPECT_FALSE(front_facing_child->has_render_surface());
4207 EXPECT_FALSE(back_facing_child->has_render_surface());
4208 EXPECT_TRUE(front_facing_surface->has_render_surface());
4209 EXPECT_TRUE(back_facing_surface->has_render_surface());
4210 EXPECT_FALSE(
4211 front_facing_child_of_front_facing_surface->has_render_surface());
4212 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4213 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4214 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324215
trchen75204782016-11-03 01:05:424216 EXPECT_EQ(3u, update_layer_list_impl()->size());
ajuma4711f4b12016-05-16 18:48:324217 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4218 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4219 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534220 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324221}
4222
[email protected]989386c2013-07-18 21:37:234223TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324224 // Verify the behavior of back-face culling when preserves-3d transform style
4225 // is used.
4226
danakje4fa7b72016-07-25 22:00:064227 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:264228 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4229 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4230 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4231 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4232 LayerImpl* front_facing_child_of_front_facing_surface =
4233 AddChild<LayerImpl>(front_facing_surface);
4234 LayerImpl* back_facing_child_of_front_facing_surface =
4235 AddChild<LayerImpl>(front_facing_surface);
4236 LayerImpl* front_facing_child_of_back_facing_surface =
4237 AddChild<LayerImpl>(back_facing_surface);
4238 LayerImpl* back_facing_child_of_back_facing_surface =
4239 AddChild<LayerImpl>(back_facing_surface);
4240 // Opacity will not force creation of render surfaces in this case because of
4241 // the preserve-3d transform style. Instead, an example of when a surface
wangxianzhu932d7f12016-09-30 05:47:004242 // would be created with preserve-3d is when there is a mask layer.
4243 LayerImpl* dummy_mask_layer1 = AddMaskLayer<LayerImpl>(front_facing_surface);
4244 LayerImpl* dummy_mask_layer2 = AddMaskLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284245
[email protected]fb661802013-03-25 01:59:324246 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364247 front_facing_child->test_properties()->double_sided = false;
4248 back_facing_child->test_properties()->double_sided = false;
4249 front_facing_surface->test_properties()->double_sided = false;
4250 back_facing_surface->test_properties()->double_sided = false;
4251 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4252 false;
4253 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4254 false;
4255 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4256 false;
4257 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4258 false;
[email protected]fb661802013-03-25 01:59:324259
weiliangcc154ce22015-12-09 03:39:264260 // Everything draws content.
4261 front_facing_child->SetDrawsContent(true);
4262 back_facing_child->SetDrawsContent(true);
4263 front_facing_surface->SetDrawsContent(true);
4264 back_facing_surface->SetDrawsContent(true);
4265 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4266 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4267 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4268 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
wangxianzhu932d7f12016-09-30 05:47:004269 dummy_mask_layer1->SetDrawsContent(true);
4270 dummy_mask_layer2->SetDrawsContent(true);
weiliangcc154ce22015-12-09 03:39:264271
[email protected]fb661802013-03-25 01:59:324272 gfx::Transform backface_matrix;
4273 backface_matrix.Translate(50.0, 50.0);
4274 backface_matrix.RotateAboutYAxis(180.0);
4275 backface_matrix.Translate(-50.0, -50.0);
4276
danakje4fa7b72016-07-25 22:00:064277 root->SetBounds(gfx::Size(100, 100));
4278 front_facing_child->SetBounds(gfx::Size(100, 100));
4279 back_facing_child->SetBounds(gfx::Size(100, 100));
4280 front_facing_surface->SetBounds(gfx::Size(100, 100));
4281 back_facing_surface->SetBounds(gfx::Size(100, 100));
4282 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4283 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4284 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4285 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4286
jaydasika10d43fc2016-08-18 04:06:044287 back_facing_child->test_properties()->transform = backface_matrix;
4288 back_facing_surface->test_properties()->transform = backface_matrix;
4289 back_facing_child_of_front_facing_surface->test_properties()->transform =
4290 backface_matrix;
4291 back_facing_child_of_back_facing_surface->test_properties()->transform =
4292 backface_matrix;
danakje4fa7b72016-07-25 22:00:064293
[email protected]fb661802013-03-25 01:59:324294 // Each surface creates its own new 3d rendering context (as defined by W3C
4295 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4296 // rendering context should use the transform with respect to that context.
4297 // This 3d rendering context occurs when (a) parent's transform style is flat
4298 // and (b) the layer's transform style is preserve-3d.
danakje4fa7b72016-07-25 22:00:064299 front_facing_surface->test_properties()->should_flatten_transform = false;
4300 front_facing_surface->Set3dSortingContextId(1);
4301 back_facing_surface->test_properties()->should_flatten_transform = false;
4302 back_facing_surface->Set3dSortingContextId(1);
4303 front_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4304 back_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4305 front_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
4306 back_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
[email protected]fb661802013-03-25 01:59:324307
jaydasika6ed869662016-09-21 14:29:594308 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324309
awoloszyne83f28c2014-12-22 15:40:004310 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094311 EXPECT_FALSE(front_facing_child->has_render_surface());
4312 EXPECT_FALSE(back_facing_child->has_render_surface());
4313 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094314 // We expect that a has_render_surface was created but not used.
4315 EXPECT_TRUE(back_facing_surface->has_render_surface());
4316 EXPECT_FALSE(
4317 front_facing_child_of_front_facing_surface->has_render_surface());
4318 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4319 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4320 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324321
weiliangcc154ce22015-12-09 03:39:264322 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324323
weiliangcc154ce22015-12-09 03:39:264324 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4325 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4326 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534327 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324328}
4329
[email protected]989386c2013-07-18 21:37:234330TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324331 // Verify that layers are appropriately culled when their back face is showing
4332 // and they are not double sided, while animations are going on.
4333 //
ajuma4711f4b12016-05-16 18:48:324334 // Even layers that are animating get culled if their back face is showing and
4335 // they are not double sided.
danakje4fa7b72016-07-25 22:00:064336 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324337 LayerImpl* child = AddChildToRoot<LayerImpl>();
4338 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4339 LayerImpl* child_of_animating_surface =
4340 AddChild<LayerImpl>(animating_surface);
4341 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4342 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284343
[email protected]fb661802013-03-25 01:59:324344 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324345 child->test_properties()->double_sided = false;
4346 child2->test_properties()->double_sided = false;
4347 animating_surface->test_properties()->double_sided = false;
4348 child_of_animating_surface->test_properties()->double_sided = false;
4349 animating_child->test_properties()->double_sided = false;
4350
4351 // Everything draws content.
4352 child->SetDrawsContent(true);
4353 child2->SetDrawsContent(true);
4354 animating_surface->SetDrawsContent(true);
4355 child_of_animating_surface->SetDrawsContent(true);
4356 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324357
4358 gfx::Transform backface_matrix;
4359 backface_matrix.Translate(50.0, 50.0);
4360 backface_matrix.RotateAboutYAxis(180.0);
4361 backface_matrix.Translate(-50.0, -50.0);
4362
vollickef2ae922016-06-29 17:54:274363 SetElementIdsForTesting();
4364
loyso9556c732016-03-11 07:54:584365 // Animate the transform on the render surface.
vollickef2ae922016-06-29 17:54:274366 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
4367 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584368 // This is just an animating layer, not a surface.
vollickef2ae922016-06-29 17:54:274369 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
4370 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324371
danakje4fa7b72016-07-25 22:00:064372 root->SetBounds(gfx::Size(100, 100));
4373 child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044374 child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064375 animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044376 animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064377 animating_surface->test_properties()->force_render_surface = true;
4378 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044379 child_of_animating_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064380 animating_child->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044381 animating_child->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064382 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324383
jaydasika6ed869662016-09-21 14:29:594384 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324385
ennec1332992015-08-24 19:45:094386 EXPECT_FALSE(child->has_render_surface());
4387 EXPECT_TRUE(animating_surface->has_render_surface());
4388 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4389 EXPECT_FALSE(animating_child->has_render_surface());
4390 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324391
ajuma4711f4b12016-05-16 18:48:324392 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534393
ajuma4711f4b12016-05-16 18:48:324394 // The back facing layers are culled from the layer list, and have an empty
4395 // visible rect.
4396 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4397 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4398 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4399 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4400 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324401
ajuma4711f4b12016-05-16 18:48:324402 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324403}
4404
[email protected]989386c2013-07-18 21:37:234405TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324406 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4407 // Verify the behavior of back-face culling for a render surface that is
4408 // created when it flattens its subtree, and its parent has preserves-3d.
4409
danakje4fa7b72016-07-25 22:00:064410 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324411 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4412 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4413 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4414 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284415
[email protected]fb661802013-03-25 01:59:324416 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324417 front_facing_surface->test_properties()->double_sided = false;
4418 back_facing_surface->test_properties()->double_sided = false;
4419
4420 // Everything draws content.
4421 front_facing_surface->SetDrawsContent(true);
4422 back_facing_surface->SetDrawsContent(true);
4423 child1->SetDrawsContent(true);
4424 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324425
4426 gfx::Transform backface_matrix;
4427 backface_matrix.Translate(50.0, 50.0);
4428 backface_matrix.RotateAboutYAxis(180.0);
4429 backface_matrix.Translate(-50.0, -50.0);
4430
danakje4fa7b72016-07-25 22:00:064431 root->SetBounds(gfx::Size(100, 100));
4432 front_facing_surface->SetBounds(gfx::Size(100, 100));
4433 front_facing_surface->test_properties()->force_render_surface = true;
4434 back_facing_surface->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044435 back_facing_surface->test_properties()->transform = backface_matrix;
danakje4fa7b72016-07-25 22:00:064436 back_facing_surface->test_properties()->force_render_surface = true;
4437 child1->SetBounds(gfx::Size(100, 100));
4438 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324439
[email protected]a9d4d4f2014-06-19 06:49:284440 front_facing_surface->Set3dSortingContextId(1);
4441 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574442
jaydasika6ed869662016-09-21 14:29:594443 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
[email protected]fb661802013-03-25 01:59:324444
awoloszyne83f28c2014-12-22 15:40:004445 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094446 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004447
4448 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094449 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094450 EXPECT_FALSE(child1->has_render_surface());
4451 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324452
ajuma4711f4b12016-05-16 18:48:324453 EXPECT_EQ(2u, update_layer_list_impl()->size());
4454 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4455 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324456}
4457
enne637715732015-07-07 02:05:264458TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324459 // Verify draw and screen space transforms of layers not in a surface.
danakje4fa7b72016-07-25 22:00:064460 LayerImpl* root = root_layer_for_testing();
4461 root->SetBounds(gfx::Size(100, 100));
4462 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144463
enne637715732015-07-07 02:05:264464 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064465 child->SetPosition(gfx::PointF(2.f, 2.f));
4466 child->SetBounds(gfx::Size(10, 10));
jaydasika8640f9f2015-11-10 01:34:364467 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144468
jaydasika8640f9f2015-11-10 01:34:364469 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064470 child2->SetPosition(gfx::PointF(2.f, 2.f));
4471 child2->SetBounds(gfx::Size(5, 5));
jaydasika8640f9f2015-11-10 01:34:364472 child2->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284473
[email protected]fb661802013-03-25 01:59:324474 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264475 gfx::Size viewport_size(100, 100);
danakje4fa7b72016-07-25 22:00:064476 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144477
danakj59931942016-07-26 22:11:294478 EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale());
4479 EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale());
4480 EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale());
[email protected]518ee582012-10-24 18:29:444481
enne637715732015-07-07 02:05:264482 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144483
danakje4fa7b72016-07-25 22:00:064484 // Verify root transforms
4485 gfx::Transform expected_root_transform;
4486 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4487 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4488 root->ScreenSpaceTransform());
4489 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4490 root->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144491
danakje4fa7b72016-07-25 22:00:064492 // Verify results of transformed root rects
4493 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
[email protected]94f206c12012-08-25 00:09:144494
danakje4fa7b72016-07-25 22:00:064495 gfx::RectF root_draw_rect =
4496 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4497 gfx::RectF root_screen_space_rect =
4498 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
[email protected]94f206c12012-08-25 00:09:144499
danakje4fa7b72016-07-25 22:00:064500 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4501 expected_root_draw_rect.Scale(device_scale_factor);
4502 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4503 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144504
jaydasika8640f9f2015-11-10 01:34:364505 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324506 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594507 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4508 expected_child_transform.Translate(child->position().x(),
4509 child->position().y());
[email protected]fb661802013-03-25 01:59:324510 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444511 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324512 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104513 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324514 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444515 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324516 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104517 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144518
jaydasika8640f9f2015-11-10 01:34:364519 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324520 // match.
danakjddaec912015-09-25 19:38:404521 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144522
[email protected]fb661802013-03-25 01:59:324523 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444524 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144525 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104526 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144527
jaydasika8640f9f2015-11-10 01:34:364528 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444529 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364530 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104531 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454532
danakjddaec912015-09-25 19:38:404533 gfx::RectF expected_child_draw_rect(child->position(),
4534 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324535 expected_child_draw_rect.Scale(device_scale_factor);
4536 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4537 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364538 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4539 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144540}
4541
enne637715732015-07-07 02:05:264542TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324543 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324544 gfx::Transform perspective_matrix;
4545 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094546
[email protected]fb661802013-03-25 01:59:324547 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054548 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094549
jaydasikabf1875a2016-06-28 03:39:594550 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064551 root->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094552
4553 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064554 page_scale->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094555
4556 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
danakje4fa7b72016-07-25 22:00:064557 parent->SetBounds(gfx::Size(100, 100));
jaydasika8640f9f2015-11-10 01:34:364558 parent->SetDrawsContent(true);
[email protected]9781afa2013-07-17 23:15:324559
enne637715732015-07-07 02:05:264560 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064561 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4562 perspective_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044563 perspective_surface->test_properties()->transform =
4564 perspective_matrix * scale_small_matrix;
enne637715732015-07-07 02:05:264565 perspective_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064566 perspective_surface->test_properties()->force_render_surface = true;
[email protected]1b30e8e2012-12-21 02:59:094567
enne637715732015-07-07 02:05:264568 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064569 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4570 scale_surface->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044571 scale_surface->test_properties()->transform = scale_small_matrix;
enne637715732015-07-07 02:05:264572 scale_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064573 scale_surface->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:284574
[email protected]fb661802013-03-25 01:59:324575 float device_scale_factor = 2.5f;
4576 float page_scale_factor = 3.f;
sunxdc5d4fb42016-05-27 04:40:094577 root->layer_tree_impl()->SetViewportLayersFromIds(
4578 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4579 Layer::INVALID_ID);
jaydasika4340ea02016-06-06 19:44:264580 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094581 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264582 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackra283bed2016-10-31 14:49:424583 root, nullptr, nullptr);
[email protected]1b30e8e2012-12-21 02:59:094584
danakj59931942016-07-26 22:11:294585 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4586 parent->GetIdealContentsScale());
4587 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4588 perspective_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594589 // Ideal scale is the max 2d scale component of the combined transform up to
4590 // the nearest render target. Here this includes the layer transform as well
4591 // as the device and page scale factors.
4592 gfx::Transform transform = scale_small_matrix;
4593 transform.Scale(device_scale_factor * page_scale_factor,
4594 device_scale_factor * page_scale_factor);
4595 gfx::Vector2dF scales =
4596 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4597 float max_2d_scale = std::max(scales.x(), scales.y());
danakj59931942016-07-26 22:11:294598 EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594599
4600 // The ideal scale will draw 1:1 with its render target space along
4601 // the larger-scale axis.
4602 gfx::Vector2dF target_space_transform_scales =
4603 MathUtil::ComputeTransform2dScaleComponents(
4604 scale_surface->draw_properties().target_space_transform, 0.f);
4605 EXPECT_FLOAT_EQ(max_2d_scale,
4606 std::max(target_space_transform_scales.x(),
4607 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094608
enne637715732015-07-07 02:05:264609 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094610
[email protected]fb661802013-03-25 01:59:324611 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594612 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4613 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324614 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444615 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094616
[email protected]fb661802013-03-25 01:59:324617 // The scale for the perspective surface is not known, so it is rendered 1:1
4618 // with the screen, and then scaled during drawing.
4619 gfx::Transform expected_perspective_surface_draw_transform;
4620 expected_perspective_surface_draw_transform.Translate(
4621 device_scale_factor * page_scale_factor *
4622 perspective_surface->position().x(),
4623 device_scale_factor * page_scale_factor *
4624 perspective_surface->position().y());
4625 expected_perspective_surface_draw_transform.PreconcatTransform(
4626 perspective_matrix);
4627 expected_perspective_surface_draw_transform.PreconcatTransform(
4628 scale_small_matrix);
4629 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594630 expected_perspective_surface_layer_draw_transform.Scale(
4631 device_scale_factor * page_scale_factor,
4632 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324633 EXPECT_TRANSFORMATION_MATRIX_EQ(
4634 expected_perspective_surface_draw_transform,
4635 perspective_surface->render_surface()->draw_transform());
4636 EXPECT_TRANSFORMATION_MATRIX_EQ(
4637 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444638 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094639}
4640
enne637715732015-07-07 02:05:264641TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294642 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264643 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294644 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4645
4646 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264647 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294648 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4649
jaydasikabf1875a2016-06-28 03:39:594650 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294651 root->SetBounds(gfx::Size(100, 100));
4652
enne637715732015-07-07 02:05:264653 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064654 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044655 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364656 parent->SetDrawsContent(true);
[email protected]35a99a12013-05-09 23:52:294657
enne637715732015-07-07 02:05:264658 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064659 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4660 child_scale->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:044661 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364662 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284663
[email protected]fb661802013-03-25 01:59:324664 float device_scale_factor = 2.5f;
4665 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214666
[email protected]989386c2013-07-18 21:37:234667 {
enne637715732015-07-07 02:05:264668 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackra283bed2016-10-31 14:49:424669 root, nullptr, nullptr);
[email protected]11ec92972012-11-10 03:06:214670
sohan.jyotie3bd6192014-10-13 07:13:594671 // The ideal scale is able to go below 1.
4672 float expected_ideal_scale =
4673 device_scale_factor * page_scale_factor * initial_parent_scale;
4674 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294675 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale());
[email protected]11ec92972012-11-10 03:06:214676
sohan.jyotie3bd6192014-10-13 07:13:594677 expected_ideal_scale = device_scale_factor * page_scale_factor *
4678 initial_parent_scale * initial_child_scale;
4679 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294680 EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale());
[email protected]989386c2013-07-18 21:37:234681 }
[email protected]11ec92972012-11-10 03:06:214682}
4683
enne637715732015-07-07 02:05:264684TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324685 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264686 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324687 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264688
[email protected]fb661802013-03-25 01:59:324689 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264690 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324691 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264692
jaydasikabf1875a2016-06-28 03:39:594693 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294694 root->SetBounds(gfx::Size(100, 100));
4695
enne637715732015-07-07 02:05:264696 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064697 parent->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:044698 parent->test_properties()->transform = parent_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364699 parent->SetDrawsContent(true);
[email protected]6a9cff92012-11-08 11:53:264700
enne637715732015-07-07 02:05:264701 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064702 child_scale->SetBounds(gfx::Size(10, 10));
4703 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
jaydasika10d43fc2016-08-18 04:06:044704 child_scale->test_properties()->transform = child_scale_matrix;
jaydasika8640f9f2015-11-10 01:34:364705 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284706
danakje4fa7b72016-07-25 22:00:064707 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264708
danakj59931942016-07-26 22:11:294709 EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale());
danakje4fa7b72016-07-25 22:00:064710 // Animating layers compute ideal scale in the same way as when
4711 // they are static.
danakj59931942016-07-26 22:11:294712 EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale,
4713 child_scale->GetIdealContentsScale());
[email protected]6a9cff92012-11-08 11:53:264714}
4715
[email protected]989386c2013-07-18 21:37:234716TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594717 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064718 parent->SetBounds(gfx::Size(30, 30));
enneea850232015-07-27 16:43:124719 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064720 parent->Set3dSortingContextId(1);
4721 parent->test_properties()->should_flatten_transform = false;
[email protected]94f206c12012-08-25 00:09:144722
enneea850232015-07-27 16:43:124723 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064724 child->SetBounds(gfx::Size(10, 10));
4725 child->SetPosition(gfx::PointF(2.f, 2.f));
enneea850232015-07-27 16:43:124726 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064727 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:144728
[email protected]fb661802013-03-25 01:59:324729 // This layer should end up in the same surface as child, with the same draw
4730 // and screen space transforms.
enneea850232015-07-27 16:43:124731 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:064732 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
enneea850232015-07-27 16:43:124733 duplicate_child_non_owner->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144734
[email protected]fb661802013-03-25 01:59:324735 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124736 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144737
[email protected]fb661802013-03-25 01:59:324738 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004739 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124740 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144741
[email protected]fb661802013-03-25 01:59:324742 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594743 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324744 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104745 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324746 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444747 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144748
[email protected]fb661802013-03-25 01:59:324749 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594750 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324751 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444752 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144753
[email protected]fb661802013-03-25 01:59:324754 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594755 expected_screen_space_transform.Scale(device_scale_factor,
4756 device_scale_factor);
4757 expected_screen_space_transform.Translate(child->position().x(),
4758 child->position().y());
[email protected]fb661802013-03-25 01:59:324759 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104760 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144761
[email protected]fb661802013-03-25 01:59:324762 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444763 child->DrawTransform();
trchendba8b1502016-07-08 09:47:014764 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform,
ajumad9432e32015-11-30 19:43:444765 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324766 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104767 child->ScreenSpaceTransform(),
4768 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324769 EXPECT_EQ(child->drawable_content_rect(),
4770 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144771 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144772
[email protected]fb661802013-03-25 01:59:324773 gfx::Transform expected_render_surface_draw_transform;
4774 expected_render_surface_draw_transform.Translate(
4775 device_scale_factor * child->position().x(),
4776 device_scale_factor * child->position().y());
4777 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4778 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144779
[email protected]fb661802013-03-25 01:59:324780 gfx::Transform expected_surface_draw_transform;
4781 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4782 device_scale_factor * 2.f);
4783 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4784 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144785
[email protected]fb661802013-03-25 01:59:324786 gfx::Transform expected_surface_screen_space_transform;
4787 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4788 device_scale_factor * 2.f);
4789 EXPECT_TRANSFORMATION_MATRIX_EQ(
4790 expected_surface_screen_space_transform,
4791 child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474792}
4793
[email protected]989386c2013-07-18 21:37:234794TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324795 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
jaydasikabf1875a2016-06-28 03:39:594796 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064797 parent->SetBounds(gfx::Size(33, 31));
enneea850232015-07-27 16:43:124798 parent->SetDrawsContent(true);
[email protected]904e9132012-11-01 00:12:474799
enneea850232015-07-27 16:43:124800 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064801 child->SetBounds(gfx::Size(13, 11));
enneea850232015-07-27 16:43:124802 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064803 child->test_properties()->force_render_surface = true;
[email protected]904e9132012-11-01 00:12:474804
[email protected]873639e2013-07-24 19:56:314805 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124806 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474807
[email protected]fb661802013-03-25 01:59:324808 // We should have two render surfaces. The root's render surface and child's
wangxianzhu932d7f12016-09-30 05:47:004809 // render surface (it needs one because of force_render_surface).
enneea850232015-07-27 16:43:124810 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474811
danakjf78fb272016-07-26 19:06:154812 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324813 child->render_surface()->draw_transform());
danakjf78fb272016-07-26 19:06:154814 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324815 child->render_surface()->draw_transform());
4816 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:154817 gfx::Transform(), child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144818}
4819
jaydasikadb41a582016-03-28 20:48:214820TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314821 scoped_refptr<Layer> root = Layer::Create();
4822 scoped_refptr<Layer> child = Layer::Create();
4823 scoped_refptr<Layer> grand_child = Layer::Create();
4824 scoped_refptr<Layer> mask_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:144825
[email protected]fb661802013-03-25 01:59:324826 child->AddChild(grand_child.get());
4827 child->SetMaskLayer(mask_layer.get());
4828 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144829
ennea7b43c32015-06-18 20:01:334830 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284831
[email protected]fb661802013-03-25 01:59:324832 int nonexistent_id = -1;
xingliu95d9e6b62016-08-18 03:53:084833 LayerTree* layer_tree = host()->GetLayerTree();
4834 EXPECT_EQ(root.get(), layer_tree->LayerById(root->id()));
4835 EXPECT_EQ(child.get(), layer_tree->LayerById(child->id()));
4836 EXPECT_EQ(grand_child.get(), layer_tree->LayerById(grand_child->id()));
4837 EXPECT_EQ(mask_layer.get(), layer_tree->LayerById(mask_layer->id()));
xingliu95d9e6b62016-08-18 03:53:084838 EXPECT_FALSE(layer_tree->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144839}
4840
[email protected]989386c2013-07-18 21:37:234841TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
jaydasikabf1875a2016-06-28 03:39:594842 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324843 LayerImpl* child = AddChild<LayerImpl>(root);
4844 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]498ec6e0e2012-11-30 18:24:574845
danakje4fa7b72016-07-25 22:00:064846 root->SetBounds(gfx::Size(100, 100));
4847 child->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:184848 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:064849 grand_child->SetBounds(gfx::Size(10, 10));
4850 grand_child->SetDrawsContent(true);
ajuma4711f4b12016-05-16 18:48:324851 ExecuteCalculateDrawProperties(root);
ennec1332992015-08-24 19:45:094852 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:574853}
4854
[email protected]989386c2013-07-18 21:37:234855TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164856 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:564857 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:014858 FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider,
pimanc44437a22016-10-29 00:09:224859 &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:164860 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:484861 std::unique_ptr<LayerImpl> root =
4862 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064863 root->SetBounds(gfx::Size(100, 100));
[email protected]f90fc412013-03-30 20:13:164864 root->SetDrawsContent(true);
4865
danakj60bc3bc2016-04-09 00:24:484866 std::unique_ptr<LayerImpl> child =
4867 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064868 child->SetBounds(gfx::Size(50, 50));
[email protected]f90fc412013-03-30 20:13:164869 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:184870 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:164871
jaydasika9cb21c772016-05-10 22:37:084872 const int child_id = child->id();
jaydasika89f7b5a2016-06-22 02:08:394873 root->test_properties()->AddChild(std::move(child));
jaydasika9cb21c772016-05-10 22:37:084874 root->SetHasRenderSurface(true);
4875 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594876 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
jaydasika4340ea02016-06-06 19:44:264877 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:274878
[email protected]f90fc412013-03-30 20:13:164879 // Add opacity animation.
loyso9556c732016-03-11 07:54:584880 scoped_refptr<AnimationTimeline> timeline =
4881 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4882 host_impl.animation_host()->AddAnimationTimeline(timeline);
vollickef2ae922016-06-29 17:54:274883 host_impl.pending_tree()->SetElementIdsForTesting();
loyso968163c92016-01-04 23:18:484884
vollickef2ae922016-06-29 17:54:274885 ElementId child_element_id =
4886 host_impl.pending_tree()->LayerById(child_id)->element_id();
4887
4888 AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0,
4889 0.0f, 1.0f, false);
[email protected]f90fc412013-03-30 20:13:164890
[email protected]c0ae06c12013-06-24 18:32:194891 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534892 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:384893 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534894 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574895 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:164896
4897 // We should have one render surface and two layers. The child
4898 // layer should be included even though it is transparent.
4899 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:054900 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:074901
4902 // If the root itself is hidden, the child should not be drawn even if it has
4903 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:184904 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054905 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:074906 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:074907 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:384908 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:074909 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574910 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:074911
jaydasika0c2fd472016-03-24 01:26:054912 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:064913 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:054914 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:074915 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014916 EXPECT_FALSE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404917
4918 // A layer should be drawn and it should contribute to drawn surface when
4919 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:184920 root_layer->test_properties()->opacity = 1.0f;
4921 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054922 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:404923 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:404924 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:384925 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:404926 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574927 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:404928
jaydasika0c2fd472016-03-24 01:26:054929 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
4930 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:404931 node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014932 EXPECT_TRUE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404933 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:064934
4935 // But if the opacity of the layer remains 0 after activation, it should not
4936 // be drawn.
4937 host_impl.ActivateSyncTree();
danakj0da42ca62016-07-01 19:42:334938 LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id());
jaydasika8185d302016-04-14 15:20:064939 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
4940
4941 EffectTree& active_effect_tree =
4942 host_impl.active_tree()->property_trees()->effect_tree;
4943 EXPECT_TRUE(active_effect_tree.needs_update());
4944
4945 ExecuteCalculateDrawProperties(active_root);
4946
4947 node = active_effect_tree.Node(active_child->effect_tree_index());
trchendba8b1502016-07-08 09:47:014948 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:064949 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
4950 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:164951}
4952
danakj3f76ace2014-11-18 16:56:004953using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:264954class LCDTextTest : public LayerTreeHostCommonTestBase,
4955 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:364956 public:
4957 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:224958 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
4959 host_impl_(LCDTextTestLayerTreeSettings(),
4960 &task_runner_provider_,
danakj59931942016-07-26 22:11:294961 &task_graph_runner_) {}
enneaf5bda32015-02-19 01:27:364962
loyso968163c92016-01-04 23:18:484963 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
4964
[email protected]fb661802013-03-25 01:59:324965 protected:
sunxd5a7a4032016-06-01 18:49:224966 LayerTreeSettings LCDTextTestLayerTreeSettings() {
danakj59931942016-07-26 22:11:294967 LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings();
sunxd5a7a4032016-06-01 18:49:224968
4969 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4970 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4971 settings.can_use_lcd_text = can_use_lcd_text_;
4972 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
4973 return settings;
4974 }
4975
dcheng93a52eb2014-12-23 02:14:234976 void SetUp() override {
loyso9556c732016-03-11 07:54:584977 timeline_ =
4978 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4979 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:484980
danakj60bc3bc2016-04-09 00:24:484981 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:364982 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:484983 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:364984 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:484985 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:364986 LayerImpl::Create(host_impl_.active_tree(), 3);
4987
4988 // Stash raw pointers to look at later.
4989 root_ = root_ptr.get();
4990 child_ = child_ptr.get();
4991 grand_child_ = grand_child_ptr.get();
4992
jaydasika89f7b5a2016-06-22 02:08:394993 child_->test_properties()->AddChild(std::move(grand_child_ptr));
4994 root_->test_properties()->AddChild(std::move(child_ptr));
jaydasikabf1875a2016-06-28 03:39:594995 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:594996
vollickef2ae922016-06-29 17:54:274997 host_impl_.active_tree()->SetElementIdsForTesting();
4998
fmalita51b5e202014-11-18 20:11:504999 root_->SetContentsOpaque(true);
5000 child_->SetContentsOpaque(true);
5001 grand_child_->SetContentsOpaque(true);
5002
jaydasika3f930c12015-06-30 15:18:255003 root_->SetDrawsContent(true);
5004 child_->SetDrawsContent(true);
5005 grand_child_->SetDrawsContent(true);
5006
danakje4fa7b72016-07-25 22:00:065007 root_->SetBounds(gfx::Size(1, 1));
5008 child_->SetBounds(gfx::Size(1, 1));
5009 grand_child_->SetBounds(gfx::Size(1, 1));
5010
5011 child_->test_properties()->force_render_surface =
5012 std::tr1::get<2>(GetParam());
[email protected]fb661802013-03-25 01:59:325013 }
[email protected]10aabcc32012-12-13 09:18:595014
[email protected]fb661802013-03-25 01:59:325015 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005016 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365017
khushalsagarb64b360d2015-10-21 19:25:165018 FakeImplTaskRunnerProvider task_runner_provider_;
reveman34b7a1522015-03-23 20:27:475019 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365020 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485021 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365022
danakj59931942016-07-26 22:11:295023 LayerImpl* root_ = nullptr;
5024 LayerImpl* child_ = nullptr;
5025 LayerImpl* grand_child_ = nullptr;
[email protected]10aabcc32012-12-13 09:18:595026};
5027
[email protected]fb661802013-03-25 01:59:325028TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005029 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5030 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5031
[email protected]fb661802013-03-25 01:59:325032 // Case 1: Identity transform.
flackra283bed2016-10-31 14:49:425033 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225034 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5035 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5036 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595037
[email protected]fb661802013-03-25 01:59:325038 // Case 2: Integral translation.
5039 gfx::Transform integral_translation;
5040 integral_translation.Translate(1.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045041 child_->test_properties()->transform = integral_translation;
jaydasika3f930c12015-06-30 15:18:255042 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425043 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225044 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5045 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5046 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595047
[email protected]fb661802013-03-25 01:59:325048 // Case 3: Non-integral translation.
5049 gfx::Transform non_integral_translation;
5050 non_integral_translation.Translate(1.5, 2.5);
jaydasika10d43fc2016-08-18 04:06:045051 child_->test_properties()->transform = non_integral_translation;
jaydasika3f930c12015-06-30 15:18:255052 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425053 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225054 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5055 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5056 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595057
[email protected]fb661802013-03-25 01:59:325058 // Case 4: Rotation.
5059 gfx::Transform rotation;
5060 rotation.Rotate(10.0);
jaydasika10d43fc2016-08-18 04:06:045061 child_->test_properties()->transform = rotation;
jaydasika3f930c12015-06-30 15:18:255062 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425063 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225064 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5065 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5066 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595067
[email protected]fb661802013-03-25 01:59:325068 // Case 5: Scale.
5069 gfx::Transform scale;
5070 scale.Scale(2.0, 2.0);
jaydasika10d43fc2016-08-18 04:06:045071 child_->test_properties()->transform = scale;
jaydasika3f930c12015-06-30 15:18:255072 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425073 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225074 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5075 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5076 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595077
[email protected]fb661802013-03-25 01:59:325078 // Case 6: Skew.
5079 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105080 skew.Skew(10.0, 0.0);
jaydasika10d43fc2016-08-18 04:06:045081 child_->test_properties()->transform = skew;
jaydasika3f930c12015-06-30 15:18:255082 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
flackra283bed2016-10-31 14:49:425083 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225084 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5085 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5086 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595087
[email protected]fb661802013-03-25 01:59:325088 // Case 7: Translucent.
jaydasika10d43fc2016-08-18 04:06:045089 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255090 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185091 child_->test_properties()->opacity = 0.5f;
flackra283bed2016-10-31 14:49:425092 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225093 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5094 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5095 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595096
[email protected]fb661802013-03-25 01:59:325097 // Case 8: Sanity check: restore transform and opacity.
jaydasika10d43fc2016-08-18 04:06:045098 child_->test_properties()->transform = gfx::Transform();
jaydasika3f930c12015-06-30 15:18:255099 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185100 child_->test_properties()->opacity = 1.f;
flackra283bed2016-10-31 14:49:425101 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225102 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5103 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5104 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505105
5106 // Case 9: Non-opaque content.
5107 child_->SetContentsOpaque(false);
flackra283bed2016-10-31 14:49:425108 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225109 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5110 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5111 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505112
5113 // Case 10: Sanity check: restore content opaqueness.
5114 child_->SetContentsOpaque(true);
flackra283bed2016-10-31 14:49:425115 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225116 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5117 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5118 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595119}
5120
[email protected]fd9a3b6d2013-08-03 00:46:175121TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005122 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335123 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005124
[email protected]fb661802013-03-25 01:59:325125 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackra283bed2016-10-31 14:49:425126 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225127 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5128 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5129 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595130
[email protected]fb661802013-03-25 01:59:325131 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:185132 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:255133 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
vollickef2ae922016-06-29 17:54:275134
5135 SetElementIdsForTesting();
5136
5137 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5138 10.0, 0.9f, 0.1f, false);
flackra283bed2016-10-31 14:49:425139 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:335140 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:225141 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5142 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5143 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335144}
5145
5146TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5147 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5148 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5149
5150 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
flackra283bed2016-10-31 14:49:425151 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
sunxd5a7a4032016-06-01 18:49:225152 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5153 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5154 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
vollickef2ae922016-06-29 17:54:275155 SetElementIdsForTesting();
fmalitafcd926a2015-05-13 20:19:335156
5157 // Mark contents non-opaque within the first animation frame.
5158 child_->SetContentsOpaque(false);
vollickef2ae922016-06-29 17:54:275159 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5160 10.0, 0.9f, 0.1f, false);
flackra283bed2016-10-31 14:49:425161 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr);
fmalitafcd926a2015-05-13 20:19:335162 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:225163 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5164 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5165 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595166}
5167
5168INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5169 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005170 testing::Combine(testing::Bool(),
5171 testing::Bool(),
5172 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595173
[email protected]989386c2013-07-18 21:37:235174TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165175 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565176 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225177 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195178 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195179
danakj60bc3bc2016-04-09 00:24:485180 std::unique_ptr<LayerImpl> root =
5181 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065182 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195183 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065184 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195185
danakj60bc3bc2016-04-09 00:24:485186 std::unique_ptr<LayerImpl> child =
5187 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065188 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195189 child->SetDrawsContent(true);
5190
danakj60bc3bc2016-04-09 00:24:485191 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195192 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065193 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195194 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355195 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195196
jaydasika89f7b5a2016-06-22 02:08:395197 child->test_properties()->AddChild(std::move(grand_child));
5198 root->test_properties()->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005199 root->SetHasRenderSurface(true);
jaydasikabf1875a2016-06-28 03:39:595200 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195201
5202 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535203 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385204 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535205 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575206 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195207
5208 // We should have one render surface and two layers. The grand child has
5209 // hidden itself.
5210 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055211 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5212 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5213 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195214}
5215
[email protected]989386c2013-07-18 21:37:235216TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165217 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565218 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225219 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195220 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195221
danakj60bc3bc2016-04-09 00:24:485222 std::unique_ptr<LayerImpl> root =
5223 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065224 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195225 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095226 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195227
danakj60bc3bc2016-04-09 00:24:485228 std::unique_ptr<LayerImpl> child =
5229 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065230 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195231 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355232 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195233
danakj60bc3bc2016-04-09 00:24:485234 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195235 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065236 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195237 grand_child->SetDrawsContent(true);
5238
jaydasika89f7b5a2016-06-22 02:08:395239 child->test_properties()->AddChild(std::move(grand_child));
5240 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:595241 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195242
5243 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535244 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385245 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535246 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575247 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195248
5249 // We should have one render surface and one layers. The child has
5250 // hidden itself and the grand child.
5251 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095252 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5253 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195254}
5255
danakj60bc3bc2016-04-09 00:24:485256void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455257
[email protected]989386c2013-07-18 21:37:235258TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165259 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565260 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225261 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455262 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455263
danakj60bc3bc2016-04-09 00:24:485264 std::unique_ptr<LayerImpl> root =
5265 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065266 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305267 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095268 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455269
danakj60bc3bc2016-04-09 00:24:485270 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305271 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065272 copy_grand_parent->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305273 copy_grand_parent->SetDrawsContent(true);
5274 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455275
danakj60bc3bc2016-04-09 00:24:485276 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305277 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065278 copy_parent->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305279 copy_parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065280 copy_parent->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305281 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455282
danakj60bc3bc2016-04-09 00:24:485283 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305284 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065285 copy_request->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305286 copy_request->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065287 copy_request->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305288 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455289
danakj60bc3bc2016-04-09 00:24:485290 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305291 LayerImpl::Create(host_impl.pending_tree(), 5);
danakje4fa7b72016-07-25 22:00:065292 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305293 copy_child->SetDrawsContent(true);
5294 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455295
danakj60bc3bc2016-04-09 00:24:485296 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405297 LayerImpl::Create(host_impl.pending_tree(), 6);
danakje4fa7b72016-07-25 22:00:065298 copy_grand_child->SetBounds(gfx::Size(20, 20));
5299 copy_grand_child->SetDrawsContent(true);
jaydasika86654512016-01-27 17:05:075300 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5301
danakj60bc3bc2016-04-09 00:24:485302 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075303 LayerImpl::Create(host_impl.pending_tree(), 7);
danakje4fa7b72016-07-25 22:00:065304 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305305 copy_grand_parent_sibling_before->SetDrawsContent(true);
5306 LayerImpl* copy_grand_parent_sibling_before_layer =
5307 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535308
danakj60bc3bc2016-04-09 00:24:485309 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075310 LayerImpl::Create(host_impl.pending_tree(), 8);
danakje4fa7b72016-07-25 22:00:065311 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305312 copy_grand_parent_sibling_after->SetDrawsContent(true);
5313 LayerImpl* copy_grand_parent_sibling_after_layer =
5314 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535315
jaydasika89f7b5a2016-06-22 02:08:395316 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
5317 copy_request->test_properties()->AddChild(std::move(copy_child));
5318 copy_parent->test_properties()->AddChild(std::move(copy_request));
5319 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
5320 root->test_properties()->AddChild(
5321 std::move(copy_grand_parent_sibling_before));
5322 root->test_properties()->AddChild(std::move(copy_grand_parent));
5323 root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasikabf1875a2016-06-28 03:39:595324 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285325
[email protected]30fe19ff2013-07-04 00:54:455326 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075327 // hidden subtree on copy_layer. Also hide the copy grand child and its
5328 // subtree.
jaydasika5121caa82016-05-05 15:43:355329 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5330 copy_grand_parent_sibling_before_layer->test_properties()
5331 ->hide_layer_and_subtree = true;
5332 copy_grand_parent_sibling_after_layer->test_properties()
5333 ->hide_layer_and_subtree = true;
5334 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305335
ajumae6f541b2016-05-31 16:50:505336 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305337 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455338
weiliangc51fb255d2015-07-24 15:32:305339 LayerImplList render_surface_layer_list;
5340 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385341 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535342 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575343 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455344
jaydasika2411692c2016-03-23 01:56:095345 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025346 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5347 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5348 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535349
jaydasika86654512016-01-27 17:05:075350 // We should have four render surfaces, one for the root, one for the grand
5351 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455352 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075353 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095354 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075355 EXPECT_EQ(copy_grand_parent_layer->id(),
5356 render_surface_layer_list.at(1)->id());
5357 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5358 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455359
jaydasika86654512016-01-27 17:05:075360 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095361 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5362 EXPECT_EQ(root_layer->id(),
5363 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075364 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095365 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455366
[email protected]7392c7b2014-02-07 08:28:285367 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455368 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305369 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455370 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065371 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455372
5373 // The copy_layer's render surface should have two contributing layers.
5374 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5375 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235376 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305377 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235378 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075379
5380 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5381 // but the copy_layer and copy_child should be drawn for the copy request.
5382 // copy grand child should not be drawn as its hidden even in the copy
5383 // request.
ajumae4af47062016-05-24 23:59:045384 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095385 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075386 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015387 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075388 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015389 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075390 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015391 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075392 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015393 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075394 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015395 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075396
5397 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5398 // actually hidden.
5399 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455400}
5401
[email protected]989386c2013-07-18 21:37:235402TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165403 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565404 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225405 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455406 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455407
danakj60bc3bc2016-04-09 00:24:485408 std::unique_ptr<LayerImpl> root =
5409 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065410 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305411 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455412
danakj60bc3bc2016-04-09 00:24:485413 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305414 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:305415 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455416 copy_parent->SetMasksToBounds(true);
5417
danakj60bc3bc2016-04-09 00:24:485418 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305419 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065420 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305421 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065422 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:455423
danakj60bc3bc2016-04-09 00:24:485424 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305425 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065426 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305427 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455428
ajumae6f541b2016-05-31 16:50:505429 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305430 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455431
jaydasika89f7b5a2016-06-22 02:08:395432 copy_layer->test_properties()->AddChild(std::move(copy_child));
5433 copy_parent->test_properties()->AddChild(std::move(copy_layer));
5434 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305435
5436 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055437 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595438 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305439 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385440 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535441 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575442 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455443
xjze19f76402015-11-06 21:48:445444 // We should have two render surface, as the others are clipped out.
5445 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055446 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455447
xjze19f76402015-11-06 21:48:445448 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455449 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055450 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5451 EXPECT_EQ(root_layer->id(),
5452 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455453}
5454
weiliangcde7e0c32016-06-15 15:02:415455TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595456 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065457 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415458 root->SetDrawsContent(true);
5459 root->SetMasksToBounds(true);
5460
5461 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065462 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415463 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065464 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415465
5466 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065467 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5468 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415469 copy_child->SetDrawsContent(true);
5470
5471 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065472 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415473 copy_clip->SetMasksToBounds(true);
5474
5475 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065476 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5477 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415478 copy_clipped_child->SetDrawsContent(true);
5479
5480 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065481 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5482 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415483 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065484 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415485
5486 copy_layer->test_properties()->copy_requests.push_back(
5487 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5488
weiliangce22ce842016-07-04 23:31:535489 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415490 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535491 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415492
5493 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5494 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5495 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5496 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5497
5498 // Case 2: When the non root copy request layer is clipped.
5499 copy_layer->SetBounds(gfx::Size(50, 50));
5500 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535501 copy_layer->test_properties()->copy_requests.push_back(
5502 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415503 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5504
weiliangce22ce842016-07-04 23:31:535505 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415506 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535507 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415508
5509 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5510 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5511 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5512 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515513
5514 // Case 3: When there is device scale factor.
5515 float device_scale_factor = 2.f;
5516 copy_layer->test_properties()->copy_requests.push_back(
5517 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5518
5519 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5520 ExecuteCalculateDrawProperties(root, device_scale_factor);
5521 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5522
5523 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5524 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5525 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5526 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415527}
5528
[email protected]420fdf6e2013-08-26 20:36:385529TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5530 // Ensure that a transform between the layer and its render surface is not a
5531 // problem. Constructs the following layer tree.
5532 //
5533 // root (a render surface)
5534 // + render_surface
5535 // + clip_parent (scaled)
5536 // + intervening_clipping_layer
5537 // + clip_child
5538 //
5539 // The render surface should be resized correctly and the clip child should
5540 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595541 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315542 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5543 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285544 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315545 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285546 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315547 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5548 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565549 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485550 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315551 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565552 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385553
5554 intervening->SetMasksToBounds(true);
5555 clip_parent->SetMasksToBounds(true);
5556
[email protected]420fdf6e2013-08-26 20:36:385557 gfx::Transform scale_transform;
5558 scale_transform.Scale(2, 2);
5559
danakjf78fb272016-07-26 19:06:155560 root->SetBounds(gfx::Size(50, 50));
5561 render_surface->SetBounds(gfx::Size(10, 10));
5562 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:045563 clip_parent->test_properties()->transform = scale_transform;
danakjf78fb272016-07-26 19:06:155564 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5565 clip_parent->SetBounds(gfx::Size(10, 10));
5566 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5567 intervening->SetBounds(gfx::Size(5, 5));
5568 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5569 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315570 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385571
5572 ASSERT_TRUE(root->render_surface());
5573 ASSERT_TRUE(render_surface->render_surface());
5574
5575 // Ensure that we've inherited our clip parent's clip and weren't affected
5576 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145577 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5578 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5579 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385580
5581 // Ensure that the render surface reports a content rect that has been grown
5582 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145583 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5584 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385585
5586 // The above check implies the two below, but they nicely demonstrate that
5587 // we've grown, despite the intervening layer's clip.
5588 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5589 render_surface->render_surface()->content_rect()));
5590 ASSERT_FALSE(intervening->clip_rect().Contains(
5591 render_surface->render_surface()->content_rect()));
5592}
5593
5594TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5595 // Ensure that intervening render surfaces are not a problem in the basic
5596 // case. In the following tree, both render surfaces should be resized to
5597 // accomodate for the clip child, despite an intervening clip.
5598 //
5599 // root (a render surface)
5600 // + clip_parent (masks to bounds)
5601 // + render_surface1 (sets opacity)
5602 // + intervening (masks to bounds)
5603 // + render_surface2 (also sets opacity)
5604 // + clip_child
5605 //
jaydasikabf1875a2016-06-28 03:39:595606 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235607 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5608 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5609 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5610 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5611 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365612 render_surface1->SetDrawsContent(true);
5613 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235614 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385615
jaydasika1c0a27d42016-04-28 01:54:565616 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385617
5618 intervening->SetMasksToBounds(true);
5619 clip_parent->SetMasksToBounds(true);
5620
[email protected]420fdf6e2013-08-26 20:36:385621 gfx::Transform translation_transform;
5622 translation_transform.Translate(2, 2);
5623
danakjf78fb272016-07-26 19:06:155624 root->SetBounds(gfx::Size(50, 50));
5625 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5626 clip_parent->SetBounds(gfx::Size(40, 40));
5627 render_surface1->SetBounds(gfx::Size(10, 10));
5628 render_surface1->test_properties()->force_render_surface = true;
5629 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5630 intervening->SetBounds(gfx::Size(5, 5));
5631 render_surface2->SetBounds(gfx::Size(10, 10));
5632 render_surface2->test_properties()->force_render_surface = true;
5633 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5634 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235635 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385636
5637 EXPECT_TRUE(root->render_surface());
5638 EXPECT_TRUE(render_surface1->render_surface());
5639 EXPECT_TRUE(render_surface2->render_surface());
5640
5641 // Since the render surfaces could have expanded, they should not clip (their
5642 // bounds would no longer be reliable). We should resort to layer clipping
5643 // in this case.
jaydasika6f972de2016-04-07 16:16:145644 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5645 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385646 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145647 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5648 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385649 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5650
5651 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145652 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385653 EXPECT_TRUE(render_surface1->is_clipped());
5654
5655 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145656 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385657 EXPECT_TRUE(render_surface2->is_clipped());
5658
5659 // The content rects of both render surfaces should both have expanded to
5660 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145661 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5662 render_surface1->render_surface()->content_rect());
5663 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5664 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385665
5666 // The clip child should have inherited the clip parent's clip (projected to
5667 // the right space, of course), and should have the correctly sized visible
5668 // content rect.
jaydasika6f972de2016-04-07 16:16:145669 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5670 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385671 EXPECT_TRUE(clip_child->is_clipped());
5672}
5673
5674TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5675 // Ensure that intervening render surfaces are not a problem, even if there
5676 // is a scroll involved. Note, we do _not_ have to consider any other sort
5677 // of transform.
5678 //
5679 // root (a render surface)
5680 // + clip_parent (masks to bounds)
5681 // + render_surface1 (sets opacity)
5682 // + intervening (masks to bounds AND scrolls)
5683 // + render_surface2 (also sets opacity)
5684 // + clip_child
5685 //
jaydasikabf1875a2016-06-28 03:39:595686 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235687 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5688 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5689 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5690 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5691 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365692 render_surface1->SetDrawsContent(true);
5693 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235694 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385695
jaydasika1c0a27d42016-04-28 01:54:565696 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385697
5698 intervening->SetMasksToBounds(true);
5699 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235700 intervening->SetScrollClipLayer(clip_parent->id());
5701 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385702
5703 gfx::Transform translation_transform;
5704 translation_transform.Translate(2, 2);
5705
danakjf78fb272016-07-26 19:06:155706 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:045707 clip_parent->test_properties()->transform = translation_transform;
danakjf78fb272016-07-26 19:06:155708 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5709 clip_parent->SetBounds(gfx::Size(40, 40));
5710 render_surface1->SetBounds(gfx::Size(10, 10));
5711 render_surface1->test_properties()->force_render_surface = true;
5712 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5713 intervening->SetBounds(gfx::Size(5, 5));
5714 render_surface2->SetBounds(gfx::Size(10, 10));
5715 render_surface2->test_properties()->force_render_surface = true;
5716 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5717 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235718 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385719
5720 EXPECT_TRUE(root->render_surface());
5721 EXPECT_TRUE(render_surface1->render_surface());
5722 EXPECT_TRUE(render_surface2->render_surface());
5723
5724 // Since the render surfaces could have expanded, they should not clip (their
5725 // bounds would no longer be reliable). We should resort to layer clipping
5726 // in this case.
jaydasika6f972de2016-04-07 16:16:145727 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5728 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385729 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145730 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5731 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385732 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5733
5734 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145735 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385736 EXPECT_TRUE(render_surface1->is_clipped());
5737
5738 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145739 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385740 EXPECT_TRUE(render_surface2->is_clipped());
5741
5742 // The content rects of both render surfaces should both have expanded to
5743 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145744 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5745 render_surface1->render_surface()->content_rect());
5746 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
5747 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385748
5749 // The clip child should have inherited the clip parent's clip (projected to
5750 // the right space, of course), and should have the correctly sized visible
5751 // content rect.
jaydasika6f972de2016-04-07 16:16:145752 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
5753 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385754 EXPECT_TRUE(clip_child->is_clipped());
5755}
5756
5757TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5758 // Ensures that descendants of the clip child inherit the correct clip.
5759 //
5760 // root (a render surface)
5761 // + clip_parent (masks to bounds)
5762 // + intervening (masks to bounds)
5763 // + clip_child
5764 // + child
5765 //
jaydasikabf1875a2016-06-28 03:39:595766 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175767 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5768 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5769 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5770 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365771 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175772 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385773
jaydasika1c0a27d42016-04-28 01:54:565774 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155775 clip_parent->test_properties()->clip_children =
5776 base::MakeUnique<std::set<LayerImpl*>>();
5777 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385778
danakjf78fb272016-07-26 19:06:155779 root->SetBounds(gfx::Size(50, 50));
5780 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385781 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155782 intervening->SetBounds(gfx::Size(5, 5));
5783 intervening->SetMasksToBounds(true);
5784 clip_child->SetBounds(gfx::Size(60, 60));
5785 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385786
enne2d0d8e62015-08-18 18:29:175787 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385788
5789 EXPECT_TRUE(root->render_surface());
5790
5791 // Neither the clip child nor its descendant should have inherited the clip
5792 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145793 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385794 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145795 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385796 EXPECT_TRUE(child->is_clipped());
5797}
5798
5799TEST_F(LayerTreeHostCommonTest,
5800 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5801 // Ensures that non-descendant clip children in the tree do not affect
5802 // render surfaces.
5803 //
5804 // root (a render surface)
5805 // + clip_parent (masks to bounds)
5806 // + render_surface1
5807 // + clip_child
5808 // + render_surface2
5809 // + non_clip_child
5810 //
5811 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595812 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505813 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5814 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5815 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
enneb441cdd2015-07-28 22:47:505816 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
5817 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385818
jaydasika1c0a27d42016-04-28 01:54:565819 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155820 clip_parent->test_properties()->clip_children =
5821 base::MakeUnique<std::set<LayerImpl*>>();
5822 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385823
5824 clip_parent->SetMasksToBounds(true);
5825 render_surface1->SetMasksToBounds(true);
5826
danakjf78fb272016-07-26 19:06:155827 render_surface1->SetDrawsContent(true);
5828 clip_child->SetDrawsContent(true);
5829 render_surface2->SetDrawsContent(true);
5830 non_clip_child->SetDrawsContent(true);
5831
5832 root->SetBounds(gfx::Size(15, 15));
5833 clip_parent->SetBounds(gfx::Size(10, 10));
5834 render_surface1->SetPosition(gfx::PointF(5, 5));
5835 render_surface1->SetBounds(gfx::Size(5, 5));
5836 render_surface1->test_properties()->force_render_surface = true;
5837 render_surface2->SetBounds(gfx::Size(5, 5));
5838 render_surface2->test_properties()->force_render_surface = true;
5839 clip_child->SetPosition(gfx::PointF(-1, 1));
5840 clip_child->SetBounds(gfx::Size(10, 10));
5841 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:385842
enneb441cdd2015-07-28 22:47:505843 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385844
5845 EXPECT_TRUE(root->render_surface());
5846 EXPECT_TRUE(render_surface1->render_surface());
5847 EXPECT_TRUE(render_surface2->render_surface());
5848
jaydasika6f972de2016-04-07 16:16:145849 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385850 EXPECT_TRUE(render_surface1->is_clipped());
5851
5852 // The render surface should not clip (it has unclipped descendants), instead
5853 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:145854 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5855 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385856 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5857
jaydasika0d98ba92015-11-17 05:17:285858 // That said, it should have grown to accomodate the unclipped descendant and
5859 // its own size.
jaydasika6f972de2016-04-07 16:16:145860 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
5861 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385862
5863 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:145864 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
5865 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385866 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:425867 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385868
5869 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:145870 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
5871 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385872
5873 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:215874 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
5875 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:385876}
5877
weiliangc9ced1592015-11-17 19:04:375878TEST_F(LayerTreeHostCommonTest,
5879 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5880 // Verifies that Render Surfaces are created at the edge of rendering context.
5881
jaydasikabf1875a2016-06-28 03:39:595882 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:265883 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
5884 LayerImpl* child2 = AddChild<LayerImpl>(child1);
5885 LayerImpl* child3 = AddChild<LayerImpl>(child2);
5886 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375887
weiliangc9ced1592015-11-17 19:04:375888 gfx::Size bounds(100, 100);
5889
danakjf78fb272016-07-26 19:06:155890 root->SetBounds(bounds);
5891 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265892 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155893 child1->Set3dSortingContextId(1);
5894 child1->test_properties()->should_flatten_transform = false;
5895 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265896 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375897 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155898 child3->SetBounds(bounds);
5899 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375900 child3->Set3dSortingContextId(1);
jaydasika6ed869662016-09-21 14:29:595901 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
weiliangc9ced1592015-11-17 19:04:375902
5903 // Verify which render surfaces were created.
5904 EXPECT_TRUE(root->has_render_surface());
5905 EXPECT_FALSE(child1->has_render_surface());
5906 EXPECT_TRUE(child2->has_render_surface());
5907 EXPECT_FALSE(child3->has_render_surface());
5908}
5909
[email protected]45948712013-09-27 02:46:485910TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:165911 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:565912 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:225913 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:265914
danakj60bc3bc2016-04-09 00:24:485915 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:485916 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:485917 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:485918 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:485919 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:485920 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:485921 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:485922 LayerImpl::Create(host_impl.active_tree(), 12345678);
5923
[email protected]45948712013-09-27 02:46:485924 gfx::Size bounds(100, 100);
danakjf78fb272016-07-26 19:06:155925
5926 root->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485927 root->SetDrawsContent(true);
5928
5929 // This layer structure normally forces render surface due to preserves3d
5930 // behavior.
danakjf78fb272016-07-26 19:06:155931 child1->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485932 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155933 child1->Set3dSortingContextId(1);
5934 child1->test_properties()->should_flatten_transform = false;
5935 child2->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485936 child2->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:285937 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155938 child3->SetBounds(bounds);
5939 child3->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:285940 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:575941
jaydasika89f7b5a2016-06-22 02:08:395942 child2->test_properties()->AddChild(std::move(child3));
5943 child1->test_properties()->AddChild(std::move(child2));
5944 root->test_properties()->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:055945 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595946 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
[email protected]45948712013-09-27 02:46:485947
5948 {
5949 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055950 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:485951 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385952 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:485953 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:575954 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:485955
5956 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:025957
5958 int count_represents_target_render_surface = 0;
5959 int count_represents_contributing_render_surface = 0;
5960 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:515961 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5962 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:025963 it != end; ++it) {
5964 if (it.represents_target_render_surface())
5965 count_represents_target_render_surface++;
5966 if (it.represents_contributing_render_surface())
5967 count_represents_contributing_render_surface++;
5968 if (it.represents_itself())
5969 count_represents_itself++;
5970 }
5971
5972 // Two render surfaces.
5973 EXPECT_EQ(2, count_represents_target_render_surface);
5974 // Second render surface contributes to root render surface.
5975 EXPECT_EQ(1, count_represents_contributing_render_surface);
5976 // All 4 layers represent itself.
5977 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:485978 }
5979
5980 {
5981 LayerImplList render_surface_layer_list;
5982 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385983 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:485984 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:575985 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:485986
5987 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:025988
5989 int count_represents_target_render_surface = 0;
5990 int count_represents_contributing_render_surface = 0;
5991 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:515992 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5993 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:025994 it != end; ++it) {
5995 if (it.represents_target_render_surface())
5996 count_represents_target_render_surface++;
5997 if (it.represents_contributing_render_surface())
5998 count_represents_contributing_render_surface++;
5999 if (it.represents_itself())
6000 count_represents_itself++;
6001 }
6002
6003 // Only root layer has a render surface.
6004 EXPECT_EQ(1, count_represents_target_render_surface);
6005 // No layer contributes a render surface to root render surface.
6006 EXPECT_EQ(0, count_represents_contributing_render_surface);
6007 // All 4 layers represent itself.
6008 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486009 }
6010}
6011
[email protected]a9aa60a82013-08-29 04:28:266012TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:596013 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:336014 LayerImpl* back_facing = AddChild<LayerImpl>(root);
trchen75204782016-11-03 01:05:426015
jaydasikae00c8a42016-01-28 20:18:336016 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
jaydasikae00c8a42016-01-28 20:18:336017 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
trchen75204782016-11-03 01:05:426018
6019 LayerImpl* flattener = AddChild<LayerImpl>(back_facing);
6020 LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener);
jaydasikae00c8a42016-01-28 20:18:336021 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:156022
jaydasikae00c8a42016-01-28 20:18:336023 child1->SetDrawsContent(true);
6024 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266025
danakjf78fb272016-07-26 19:06:156026 root->SetBounds(gfx::Size(50, 50));
danakjf78fb272016-07-26 19:06:156027 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:526028 back_facing->test_properties()->should_flatten_transform = false;
trchen75204782016-11-03 01:05:426029
danakjf78fb272016-07-26 19:06:156030 render_surface1->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156031 render_surface1->test_properties()->should_flatten_transform = false;
6032 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366033 render_surface1->test_properties()->double_sided = false;
trchen75204782016-11-03 01:05:426034 child1->SetBounds(gfx::Size(20, 20));
6035
6036 flattener->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156037 render_surface2->SetBounds(gfx::Size(30, 30));
danakjf78fb272016-07-26 19:06:156038 render_surface2->test_properties()->should_flatten_transform = false;
6039 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366040 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156041 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:266042
enne03b0e9a2015-06-19 00:08:026043 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266044
jaydasikae00c8a42016-01-28 20:18:336045 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6046 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026047 ->at(0)
6048 ->render_surface()
6049 ->layer_list()
6050 .size());
6051 EXPECT_EQ(1u, render_surface_layer_list_impl()
6052 ->at(1)
6053 ->render_surface()
6054 ->layer_list()
6055 .size());
[email protected]a9aa60a82013-08-29 04:28:266056
danakjf78fb272016-07-26 19:06:156057 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:266058 rotation_transform.RotateAboutXAxis(180.0);
6059
jaydasika10d43fc2016-08-18 04:06:046060 back_facing->test_properties()->transform = rotation_transform;
jaydasika5aa88b82015-11-10 01:48:036061 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266062
enne03b0e9a2015-06-19 00:08:026063 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266064
jaydasikae00c8a42016-01-28 20:18:336065 // render_surface1 is in the same 3d rendering context as back_facing and is
6066 // not double sided, so it should not be in RSLL. render_surface2 is also not
6067 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6068 // context.
6069 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6070 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026071 ->at(0)
6072 ->render_surface()
6073 ->layer_list()
6074 .size());
[email protected]a9aa60a82013-08-29 04:28:266075}
6076
ajumaaa0d3862015-11-09 22:24:466077TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:596078 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:466079 LayerImpl* child = AddChild<LayerImpl>(root);
6080 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:466081
danakjf78fb272016-07-26 19:06:156082 root->SetBounds(gfx::Size(50, 50));
6083 root->test_properties()->should_flatten_transform = false;
6084 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:366085 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156086 child->test_properties()->should_flatten_transform = false;
6087 grand_child->SetBounds(gfx::Size(20, 20));
6088 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:466089 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:156090 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:466091 ExecuteCalculateDrawProperties(root);
6092
6093 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6094 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6095 ->at(0)
6096 ->render_surface()
6097 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556098
6099 // As all layers have identity transform, we shouldn't check for backface
6100 // visibility.
6101 EXPECT_FALSE(root->should_check_backface_visibility());
6102 EXPECT_FALSE(child->should_check_backface_visibility());
6103 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6104 // As there are no 3d rendering contexts, all layers should use their local
6105 // transform for backface visibility.
6106 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6107 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6108 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6109
danakjf78fb272016-07-26 19:06:156110 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:466111 rotation_transform.RotateAboutXAxis(180.0);
6112
jaydasika10d43fc2016-08-18 04:06:046113 child->test_properties()->transform = rotation_transform;
jaydasika62bd3dd2016-02-04 18:52:556114 child->Set3dSortingContextId(1);
6115 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466116 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6117
6118 ExecuteCalculateDrawProperties(root);
6119 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6120 EXPECT_EQ(0u, render_surface_layer_list_impl()
6121 ->at(0)
6122 ->render_surface()
6123 ->layer_list()
6124 .size());
jaydasika62bd3dd2016-02-04 18:52:556125
6126 // We should check for backface visibilty of child as it has a rotation
6127 // transform. We should also check for grand_child as it uses the backface
6128 // visibility of its parent.
6129 EXPECT_FALSE(root->should_check_backface_visibility());
6130 EXPECT_TRUE(child->should_check_backface_visibility());
6131 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6132 // child uses its local transform for backface visibility as it is the root of
6133 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6134 // the root, but it derives its backface visibility from its parent which uses
6135 // its local transform.
6136 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6137 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6138 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6139
6140 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366141 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556142 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6143
6144 ExecuteCalculateDrawProperties(root);
6145 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6146 EXPECT_EQ(0u, render_surface_layer_list_impl()
6147 ->at(0)
6148 ->render_surface()
6149 ->layer_list()
6150 .size());
6151
6152 // We should check the backface visibility of child as it has a rotation
6153 // transform and for grand_child as it is in a 3d rendering context and not
6154 // the root of it.
6155 EXPECT_FALSE(root->should_check_backface_visibility());
6156 EXPECT_TRUE(child->should_check_backface_visibility());
6157 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6158 // grand_child is in an existing 3d rendering context, so it should not use
6159 // local transform for backface visibility.
6160 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6161 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6162 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466163}
6164
sunxd59dd7da2016-05-19 20:07:476165TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:596166 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:476167 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6168 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6169 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6170
sunxd59dd7da2016-05-19 20:07:476171 gfx::Transform rotate_about_y;
6172 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:476173
danakjf78fb272016-07-26 19:06:156174 root->SetBounds(gfx::Size(50, 50));
6175 root->Set3dSortingContextId(1);
6176 root->test_properties()->should_flatten_transform = false;
jaydasika10d43fc2016-08-18 04:06:046177 back_facing->test_properties()->transform = rotate_about_y;
danakjf78fb272016-07-26 19:06:156178 back_facing->SetBounds(gfx::Size(50, 50));
6179 back_facing->Set3dSortingContextId(1);
6180 back_facing->test_properties()->should_flatten_transform = false;
6181 render_surface1->SetBounds(gfx::Size(30, 30));
6182 render_surface1->Set3dSortingContextId(1);
6183 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476184 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156185 render_surface1->test_properties()->force_render_surface = true;
6186 render_surface2->SetBounds(gfx::Size(30, 30));
6187 render_surface2->Set3dSortingContextId(1);
6188 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476189 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156190 render_surface2->test_properties()->force_render_surface = true;
sunxd59dd7da2016-05-19 20:07:476191 ExecuteCalculateDrawProperties(root);
6192
6193 const EffectTree& tree =
6194 root->layer_tree_impl()->property_trees()->effect_tree;
6195 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016196 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476197 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016198 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476199
jaydasika09e16132016-08-24 21:39:346200 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6201 gfx::Transform(), back_facing->transform_tree_index(),
6202 root->layer_tree_impl());
6203 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6204 rotate_about_y, render_surface2->transform_tree_index(),
6205 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476206 ExecuteCalculateDrawProperties(root);
6207 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016208 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476209 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016210 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476211
jaydasika09e16132016-08-24 21:39:346212 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
6213 rotate_about_y, render_surface1->transform_tree_index(),
6214 root->layer_tree_impl());
sunxd59dd7da2016-05-19 20:07:476215 ExecuteCalculateDrawProperties(root);
6216 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016217 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476218 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016219 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476220}
6221
[email protected]995708c52013-10-17 20:52:596222TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6223 // Checks that the simple case (being clipped by a scroll parent that would
6224 // have been processed before you anyhow) results in the right clips.
6225 //
6226 // + root
6227 // + scroll_parent_border
6228 // | + scroll_parent_clip
6229 // | + scroll_parent
6230 // + scroll_child
6231 //
jaydasikabf1875a2016-06-28 03:39:596232 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:486233 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6234 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6235 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6236 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596237
enne085b48a2015-08-18 17:54:486238 scroll_parent->SetDrawsContent(true);
6239 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596240 scroll_parent_clip->SetMasksToBounds(true);
6241
jaydasika1c0a27d42016-04-28 01:54:566242 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156243 scroll_parent->test_properties()->scroll_children =
6244 base::MakeUnique<std::set<LayerImpl*>>();
6245 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596246
danakjf78fb272016-07-26 19:06:156247 root->SetBounds(gfx::Size(50, 50));
6248 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6249 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6250 scroll_parent->SetBounds(gfx::Size(50, 50));
6251 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:486252 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596253
6254 EXPECT_TRUE(root->render_surface());
6255
jaydasika6f972de2016-04-07 16:16:146256 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596257 EXPECT_TRUE(scroll_child->is_clipped());
6258}
6259
jaydasika8ccff3d2016-01-20 19:51:306260TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6261 // Tests the computation of draw transform for the scroll child when its
6262 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:596263 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:306264 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6265 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6266 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6267 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6268
6269 scroll_parent->SetDrawsContent(true);
6270 scroll_child->SetDrawsContent(true);
6271
jaydasika1c0a27d42016-04-28 01:54:566272 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156273 scroll_parent->test_properties()->scroll_children =
6274 base::MakeUnique<std::set<LayerImpl*>>();
6275 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:306276
danakjf78fb272016-07-26 19:06:156277 root->SetBounds(gfx::Size(50, 50));
6278 scroll_child_target->SetBounds(gfx::Size(50, 50));
6279 scroll_child_target->test_properties()->force_render_surface = true;
6280 scroll_child->SetBounds(gfx::Size(50, 50));
6281 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
6282 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:006283 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156284 scroll_parent_target->test_properties()->force_render_surface = true;
6285 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:306286
jaydasika2489a442016-01-29 02:26:006287 float device_scale_factor = 1.5f;
6288 LayerImplList render_surface_layer_list_impl;
jaydasikab4df4032016-09-13 18:38:496289 gfx::Size device_viewport_size =
6290 gfx::Size(root->bounds().width() * device_scale_factor,
6291 root->bounds().height() * device_scale_factor);
jaydasika2489a442016-01-29 02:26:006292 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasikab4df4032016-09-13 18:38:496293 root, device_viewport_size, gfx::Transform(),
6294 &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006295 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576296 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006297
weiliangc1da3fb892016-03-14 20:23:526298 EXPECT_EQ(scroll_child->effect_tree_index(),
6299 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006300 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6301 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6302 gfx::Transform scale;
6303 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:026304 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306305}
6306
[email protected]08bdf1b2014-04-16 23:23:296307TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:596308 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:196309 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:196310 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:156311
6312 root->SetBounds(gfx::Size(50, 50));
6313 root->SetDrawsContent(true);
6314 root->Set3dSortingContextId(1);
6315 parent->SetBounds(gfx::Size(30, 30));
6316 parent->SetDrawsContent(true);
6317 parent->Set3dSortingContextId(1);
6318 parent->test_properties()->force_render_surface = true;
6319 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:196320 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156321 child->Set3dSortingContextId(1);
6322 child->test_properties()->force_render_surface = true;
enneca33fed2015-07-27 18:22:196323 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296324
enneca33fed2015-07-27 18:22:196325 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296326
6327 gfx::Transform singular_transform;
6328 singular_transform.Scale3d(
6329 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6330
jaydasika10d43fc2016-08-18 04:06:046331 child->test_properties()->transform = singular_transform;
[email protected]08bdf1b2014-04-16 23:23:296332
sunxd71aea3e2016-04-01 23:48:056333 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196334 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296335
enneca33fed2015-07-27 18:22:196336 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296337
6338 // Ensure that the entire subtree under a layer with singular transform does
6339 // not get rendered.
jaydasika10d43fc2016-08-18 04:06:046340 parent->test_properties()->transform = singular_transform;
6341 child->test_properties()->transform = gfx::Transform();
[email protected]08bdf1b2014-04-16 23:23:296342
sunxd71aea3e2016-04-01 23:48:056343 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196344 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296345
enneca33fed2015-07-27 18:22:196346 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296347}
6348
[email protected]995708c52013-10-17 20:52:596349TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6350 // Checks that clipping by a scroll parent that follows you in paint order
6351 // still results in correct clipping.
6352 //
6353 // + root
[email protected]995708c52013-10-17 20:52:596354 // + scroll_parent_border
6355 // + scroll_parent_clip
6356 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026357 // + scroll_child
[email protected]995708c52013-10-17 20:52:596358 //
jaydasikabf1875a2016-06-28 03:39:596359 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026360 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6361 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6362 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6363 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596364
enne03b0e9a2015-06-19 00:08:026365 scroll_parent->SetDrawsContent(true);
6366 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596367
danakjf78fb272016-07-26 19:06:156368 root->SetBounds(gfx::Size(50, 50));
6369 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6370 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:596371 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156372 scroll_parent->SetBounds(gfx::Size(50, 50));
6373 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596374
jaydasika1c0a27d42016-04-28 01:54:566375 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156376 scroll_parent->test_properties()->scroll_children =
6377 base::MakeUnique<std::set<LayerImpl*>>();
6378 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596379
enne03b0e9a2015-06-19 00:08:026380 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596381
6382 EXPECT_TRUE(root->render_surface());
6383
jaydasika6f972de2016-04-07 16:16:146384 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596385 EXPECT_TRUE(scroll_child->is_clipped());
6386}
6387
6388TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6389 // Checks that clipping by a scroll parent and scroll grandparent that follow
6390 // you in paint order still results in correct clipping.
6391 //
6392 // + root
6393 // + scroll_child
6394 // + scroll_parent_border
6395 // | + scroll_parent_clip
6396 // | + scroll_parent
6397 // + scroll_grandparent_border
6398 // + scroll_grandparent_clip
6399 // + scroll_grandparent
6400 //
jaydasikabf1875a2016-06-28 03:39:596401 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026402 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6403 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6404 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6405 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6406 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6407 LayerImpl* scroll_grandparent_clip =
6408 AddChild<LayerImpl>(scroll_grandparent_border);
6409 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596410
enne03b0e9a2015-06-19 00:08:026411 scroll_parent->SetDrawsContent(true);
6412 scroll_grandparent->SetDrawsContent(true);
6413 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596414
6415 scroll_parent_clip->SetMasksToBounds(true);
6416 scroll_grandparent_clip->SetMasksToBounds(true);
6417
jaydasika1c0a27d42016-04-28 01:54:566418 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156419 scroll_parent->test_properties()->scroll_children =
6420 base::MakeUnique<std::set<LayerImpl*>>();
6421 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386422
jaydasika1c0a27d42016-04-28 01:54:566423 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156424 scroll_grandparent->test_properties()->scroll_children =
6425 base::MakeUnique<std::set<LayerImpl*>>();
6426 scroll_grandparent->test_properties()->scroll_children->insert(
6427 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596428
danakjf78fb272016-07-26 19:06:156429 root->SetBounds(gfx::Size(50, 50));
6430 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6431 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6432 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6433 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6434 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6435 scroll_parent->SetBounds(gfx::Size(50, 50));
6436 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596437
enne03b0e9a2015-06-19 00:08:026438 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596439
6440 EXPECT_TRUE(root->render_surface());
6441
jaydasika6f972de2016-04-07 16:16:146442 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596443 EXPECT_TRUE(scroll_child->is_clipped());
6444
6445 // Despite the fact that we visited the above layers out of order to get the
6446 // correct clip, the layer lists should be unaffected.
6447 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026448 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6449 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6450 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596451}
6452
6453TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6454 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226455 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596456 // + root
6457 // + scroll_child
6458 // + scroll_parent_border
6459 // + scroll_parent_clip
6460 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026461 // + render_surface2
[email protected]995708c52013-10-17 20:52:596462 // + scroll_grandparent_border
6463 // + scroll_grandparent_clip
6464 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026465 // + render_surface1
[email protected]995708c52013-10-17 20:52:596466 //
jaydasikabf1875a2016-06-28 03:39:596467 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026468 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596469
enne03b0e9a2015-06-19 00:08:026470 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6471 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596472
enne03b0e9a2015-06-19 00:08:026473 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6474 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6475 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6476 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6477 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6478 LayerImpl* scroll_grandparent_clip =
6479 AddChild<LayerImpl>(scroll_grandparent_border);
6480 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6481 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596482
enne03b0e9a2015-06-19 00:08:026483 scroll_parent->SetDrawsContent(true);
6484 render_surface1->SetDrawsContent(true);
6485 scroll_grandparent->SetDrawsContent(true);
6486 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596487
6488 scroll_parent_clip->SetMasksToBounds(true);
6489 scroll_grandparent_clip->SetMasksToBounds(true);
6490
jaydasika1c0a27d42016-04-28 01:54:566491 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156492 scroll_parent->test_properties()->scroll_children =
6493 base::MakeUnique<std::set<LayerImpl*>>();
6494 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386495
jaydasika1c0a27d42016-04-28 01:54:566496 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156497 scroll_grandparent->test_properties()->scroll_children =
6498 base::MakeUnique<std::set<LayerImpl*>>();
6499 scroll_grandparent->test_properties()->scroll_children->insert(
6500 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596501
danakjf78fb272016-07-26 19:06:156502 root->SetBounds(gfx::Size(50, 50));
6503 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6504 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6505 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6506 render_surface1->SetBounds(gfx::Size(50, 50));
6507 render_surface1->test_properties()->force_render_surface = true;
6508 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6509 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6510 scroll_parent->SetBounds(gfx::Size(50, 50));
6511 render_surface2->SetBounds(gfx::Size(50, 50));
6512 render_surface2->test_properties()->force_render_surface = true;
6513 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596514
enne03b0e9a2015-06-19 00:08:026515 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596516
6517 EXPECT_TRUE(root->render_surface());
6518
jaydasika6f972de2016-04-07 16:16:146519 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596520 EXPECT_TRUE(scroll_child->is_clipped());
6521
6522 // Despite the fact that we had to process the layers out of order to get the
6523 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026524 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6525 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6526 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6527 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6528 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6529 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6530 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596531}
6532
ajuma0b10f942015-03-21 07:45:536533TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6534 // Ensures that when we have a render surface between a fixed position layer
6535 // and its container, we compute the fixed position layer's draw transform
6536 // with respect to that intervening render surface, not with respect to its
6537 // container's render target.
6538 //
6539 // + root
6540 // + render_surface
6541 // + fixed
ajuma737b2702015-05-06 01:18:376542 // + child
ajuma0b10f942015-03-21 07:45:536543 //
jaydasikabf1875a2016-06-28 03:39:596544 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516545 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6546 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6547 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536548
jaydasika6b5a32bf2016-04-22 21:56:366549 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526550 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536551
6552 LayerPositionConstraint constraint;
6553 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526554 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536555
danakjf78fb272016-07-26 19:06:156556 root->SetBounds(gfx::Size(50, 50));
6557 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6558 render_surface->SetBounds(gfx::Size(50, 50));
6559 render_surface->SetDrawsContent(true);
6560 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6561 fixed->SetBounds(gfx::Size(50, 50));
6562 fixed->SetDrawsContent(true);
6563 child->SetPosition(gfx::PointF(1.f, 2.f));
6564 child->SetBounds(gfx::Size(50, 50));
6565 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516566 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536567
jaydasikabaede2d92016-07-20 00:34:326568 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516569 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326570 EffectTree& effect_tree =
6571 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156572
ajuma737b2702015-05-06 01:18:376573 gfx::Transform expected_fixed_draw_transform;
6574 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026575 EXPECT_TRANSFORMATION_MATRIX_EQ(
6576 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326577 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536578
ajuma737b2702015-05-06 01:18:376579 gfx::Transform expected_fixed_screen_space_transform;
6580 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026581 EXPECT_TRANSFORMATION_MATRIX_EQ(
6582 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326583 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376584
6585 gfx::Transform expected_child_draw_transform;
6586 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026587 EXPECT_TRANSFORMATION_MATRIX_EQ(
6588 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326589 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376590
6591 gfx::Transform expected_child_screen_space_transform;
6592 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026593 EXPECT_TRANSFORMATION_MATRIX_EQ(
6594 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326595 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536596}
6597
[email protected]d81752b2013-10-25 08:32:236598TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6599 // This test verifies that a scrolling layer that gets snapped to
6600 // integer coordinates doesn't move a fixed position child.
6601 //
6602 // + root
6603 // + container
6604 // + scroller
6605 // + fixed
6606 //
khushalsagarb64b360d2015-10-21 19:25:166607 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:566608 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:226609 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236610 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486611 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426612 LayerImpl::Create(host_impl.active_tree(), 1);
6613 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486614 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236615 LayerImpl::Create(host_impl.active_tree(), 2);
6616 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486617 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236618 LayerImpl::Create(host_impl.active_tree(), 3);
6619 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486620 std::unique_ptr<LayerImpl> fixed =
6621 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236622 LayerImpl* fixed_layer = fixed.get();
6623
jaydasikaca2605e2016-04-23 02:52:526624 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236625
6626 LayerPositionConstraint constraint;
6627 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526628 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236629
[email protected]adeda572014-01-31 00:49:476630 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236631
[email protected]d81752b2013-10-25 08:32:236632 gfx::Transform container_transform;
6633 container_transform.Translate3d(10.0, 20.0, 0.0);
6634 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6635
danakjf78fb272016-07-26 19:06:156636 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046637 container->test_properties()->transform = container_transform;
danakjf78fb272016-07-26 19:06:156638 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286639 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156640 scroller->SetBounds(gfx::Size(30, 30));
jaydasika0d98ba92015-11-17 05:17:286641 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156642 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286643 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156644
jaydasika89f7b5a2016-06-22 02:08:396645 scroller->test_properties()->AddChild(std::move(fixed));
6646 container->test_properties()->AddChild(std::move(scroller));
6647 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486648 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6649 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236650
6651 // Rounded to integers already.
6652 {
6653 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426654 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236655
6656 LayerImplList render_surface_layer_list;
6657 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386658 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:426659 root->layer_tree_impl()
6660 ->property_trees()
6661 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576662 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236663
6664 EXPECT_TRANSFORMATION_MATRIX_EQ(
6665 container_layer->draw_properties().screen_space_transform,
6666 fixed_layer->draw_properties().screen_space_transform);
6667 EXPECT_VECTOR_EQ(
6668 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6669 container_offset);
6670 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6671 .screen_space_transform.To2dTranslation(),
6672 container_offset - scroll_delta);
6673 }
6674
6675 // Scroll delta requiring rounding.
6676 {
6677 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426678 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236679
6680 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6681
6682 LayerImplList render_surface_layer_list;
6683 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386684 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576685 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236686
6687 EXPECT_TRANSFORMATION_MATRIX_EQ(
6688 container_layer->draw_properties().screen_space_transform,
6689 fixed_layer->draw_properties().screen_space_transform);
6690 EXPECT_VECTOR_EQ(
6691 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6692 container_offset);
6693 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6694 .screen_space_transform.To2dTranslation(),
6695 container_offset - rounded_scroll_delta);
6696 }
[email protected]cf15ad7b2014-04-02 03:59:266697
6698 // Scale is applied earlier in the tree.
6699 {
sunxdb7e79432016-03-09 21:13:426700 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266701 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286702 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
jaydasika10d43fc2016-08-18 04:06:046703 container_layer->test_properties()->transform = scaled_container_transform;
danakj74af409e2016-07-01 00:41:486704
jaydasika0d98ba92015-11-17 05:17:286705 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266706
6707 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426708 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266709
6710 LayerImplList render_surface_layer_list;
6711 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386712 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576713 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266714
6715 EXPECT_TRANSFORMATION_MATRIX_EQ(
6716 container_layer->draw_properties().screen_space_transform,
6717 fixed_layer->draw_properties().screen_space_transform);
6718 EXPECT_VECTOR_EQ(
6719 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6720 container_offset);
6721
jaydasika10d43fc2016-08-18 04:06:046722 container_layer->test_properties()->transform = container_transform;
[email protected]cf15ad7b2014-04-02 03:59:266723 }
[email protected]d81752b2013-10-25 08:32:236724}
6725
miletus2c78036b2015-01-29 20:52:376726TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506727 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6728 // This test verifies that a scrolling layer whose screen space transform is
6729 // animating doesn't get snapped to integer coordinates.
6730 //
6731 // + root
6732 // + animated layer
6733 // + surface
6734 // + container
6735 // + scroller
6736 //
jaydasikabf1875a2016-06-28 03:39:596737 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506738 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6739 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6740 LayerImpl* container = AddChild<LayerImpl>(surface);
6741 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506742
ajuma5e8e40d2015-07-31 01:50:506743 gfx::Transform start_scale;
6744 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156745
6746 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:046747 animated_layer->test_properties()->transform = start_scale;
danakjf78fb272016-07-26 19:06:156748 animated_layer->SetBounds(gfx::Size(50, 50));
6749 surface->SetBounds(gfx::Size(50, 50));
6750 surface->test_properties()->force_render_surface = true;
6751 container->SetBounds(gfx::Size(50, 50));
6752 scroller->SetBounds(gfx::Size(100, 100));
6753 scroller->SetScrollClipLayer(container->id());
6754 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506755
6756 gfx::Transform end_scale;
6757 end_scale.Scale(2.f, 2.f);
6758 TransformOperations start_operations;
6759 start_operations.AppendMatrix(start_scale);
6760 TransformOperations end_operations;
6761 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276762 SetElementIdsForTesting();
6763
6764 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6765 timeline_impl(), 1.0,
6766 start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:506767 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426768 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506769
6770 ExecuteCalculateDrawProperties(root);
6771
6772 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6773 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446774 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506775}
6776
sunxd8a9a60982016-07-29 18:46:566777TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6778 // This test verifies that a scrolling child of a scrolling layer doesn't get
6779 // snapped to integer coordinates.
6780 //
6781 // + root
6782 // + container
6783 // + scroller
6784 // + scroll_child
6785 //
6786 scoped_refptr<Layer> root = Layer::Create();
6787 scoped_refptr<Layer> container = Layer::Create();
6788 scoped_refptr<Layer> scroller = Layer::Create();
6789 scoped_refptr<Layer> scroll_child = Layer::Create();
6790 root->AddChild(container);
6791 root->AddChild(scroll_child);
6792 container->AddChild(scroller);
6793 host()->SetRootLayer(root);
6794
6795 scroller->SetScrollClipLayerId(container->id());
6796 scroll_child->SetScrollParent(scroller.get());
6797
6798 gfx::Transform rotate;
6799 rotate.RotateAboutYAxis(30);
6800 root->SetBounds(gfx::Size(50, 50));
6801 container->SetBounds(gfx::Size(50, 50));
6802 scroller->SetBounds(gfx::Size(100, 100));
6803 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6804 scroll_child->SetBounds(gfx::Size(10, 10));
6805 scroll_child->SetTransform(rotate);
6806
6807 ExecuteCalculateDrawProperties(root.get());
6808
6809 host()->host_impl()->CreatePendingTree();
6810 host()->CommitAndCreatePendingTree();
6811 host()->host_impl()->ActivateSyncTree();
6812 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6813
6814 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6815 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6816 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
6817 gfx::Vector2dF scroll_delta(5.f, 9.f);
6818 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6819
6820 ExecuteCalculateDrawProperties(root_impl);
6821
6822 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6823 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6824 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6825
6826 gfx::Transform expected_scroll_child_screen_space_transform;
6827 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6828 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6829 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6830 scroll_child_impl->ScreenSpaceTransform());
6831}
6832
flackr2215b4e2016-09-21 20:16:016833TEST_F(LayerTreeHostCommonTest, StickyPositionTop) {
6834 scoped_refptr<Layer> root = Layer::Create();
6835 scoped_refptr<Layer> container = Layer::Create();
6836 scoped_refptr<Layer> scroller = Layer::Create();
6837 scoped_refptr<Layer> sticky_pos = Layer::Create();
6838 root->AddChild(container);
6839 container->AddChild(scroller);
6840 scroller->AddChild(sticky_pos);
6841 host()->SetRootLayer(root);
6842 scroller->SetScrollClipLayerId(container->id());
6843
6844 LayerStickyPositionConstraint sticky_position;
6845 sticky_position.is_sticky = true;
6846 sticky_position.is_anchored_top = true;
6847 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:426848 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
flackr2215b4e2016-09-21 20:16:016849 sticky_position.scroll_container_relative_sticky_box_rect =
6850 gfx::Rect(10, 20, 10, 10);
6851 sticky_position.scroll_container_relative_containing_block_rect =
6852 gfx::Rect(0, 0, 50, 50);
6853 sticky_pos->SetStickyPositionConstraint(sticky_position);
6854
6855 root->SetBounds(gfx::Size(100, 100));
6856 container->SetBounds(gfx::Size(100, 100));
6857 scroller->SetBounds(gfx::Size(1000, 1000));
6858 sticky_pos->SetBounds(gfx::Size(10, 10));
6859 sticky_pos->SetPosition(gfx::PointF(10, 20));
6860
6861 ExecuteCalculateDrawProperties(root.get());
6862 host()->host_impl()->CreatePendingTree();
6863 host()->CommitAndCreatePendingTree();
6864 host()->host_impl()->ActivateSyncTree();
6865 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6866
6867 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6868 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6869 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6870
6871 ExecuteCalculateDrawProperties(root_impl);
6872 EXPECT_VECTOR2DF_EQ(
6873 gfx::Vector2dF(10.f, 20.f),
6874 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6875
6876 // Scroll less than sticking point, sticky element should move with scroll as
6877 // we haven't gotten to the initial sticky item location yet.
6878 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
6879 ExecuteCalculateDrawProperties(root_impl);
6880 EXPECT_VECTOR2DF_EQ(
6881 gfx::Vector2dF(5.f, 15.f),
6882 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6883
6884 // Scroll past the sticking point, the Y coordinate should now be clamped.
6885 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
6886 ExecuteCalculateDrawProperties(root_impl);
6887 EXPECT_VECTOR2DF_EQ(
6888 gfx::Vector2dF(-5.f, 10.f),
6889 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6890 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f));
6891 ExecuteCalculateDrawProperties(root_impl);
6892 EXPECT_VECTOR2DF_EQ(
6893 gfx::Vector2dF(-5.f, 10.f),
6894 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6895
6896 // Scroll past the end of the sticky container (note: this element does not
6897 // have its own layer as it does not need to be composited).
6898 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f));
6899 ExecuteCalculateDrawProperties(root_impl);
6900 EXPECT_VECTOR2DF_EQ(
6901 gfx::Vector2dF(-5.f, -10.f),
6902 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6903}
6904
flackrdc5dfbe2016-10-24 21:43:386905TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) {
6906 scoped_refptr<Layer> root = Layer::Create();
6907 scoped_refptr<Layer> container = Layer::Create();
6908 scoped_refptr<Layer> scroller = Layer::Create();
6909 scoped_refptr<Layer> sticky_pos = Layer::Create();
6910 root->AddChild(container);
6911 container->AddChild(scroller);
6912 scroller->AddChild(sticky_pos);
6913 host()->SetRootLayer(root);
6914 scroller->SetScrollClipLayerId(container->id());
6915
6916 LayerStickyPositionConstraint sticky_position;
6917 sticky_position.is_sticky = true;
6918 sticky_position.is_anchored_bottom = true;
6919 sticky_position.bottom_offset = 10.0f;
6920 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200);
6921 sticky_position.scroll_container_relative_sticky_box_rect =
6922 gfx::Rect(0, 200, 10, 10);
6923 sticky_position.scroll_container_relative_containing_block_rect =
6924 gfx::Rect(0, 0, 100, 500);
6925 sticky_pos->SetStickyPositionConstraint(sticky_position);
6926
6927 root->SetBounds(gfx::Size(100, 100));
6928 container->SetBounds(gfx::Size(100, 100));
6929 scroller->SetBounds(gfx::Size(100, 1000));
6930 sticky_pos->SetBounds(gfx::Size(10, 10));
6931 sticky_pos->SetPosition(gfx::PointF(0, 200));
6932
6933 ExecuteCalculateDrawProperties(root.get());
6934 host()->host_impl()->CreatePendingTree();
6935 host()->CommitAndCreatePendingTree();
6936 host()->host_impl()->ActivateSyncTree();
6937 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6938
6939 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6940 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6941 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6942
6943 ExecuteCalculateDrawProperties(root_impl);
6944 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f));
6945 ExecuteCalculateDrawProperties(root_impl);
6946 EXPECT_VECTOR2DF_EQ(
6947 gfx::Vector2dF(0.f, 80.f),
6948 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6949}
6950
flackr2215b4e2016-09-21 20:16:016951TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) {
6952 scoped_refptr<Layer> root = Layer::Create();
6953 scoped_refptr<Layer> container = Layer::Create();
6954 scoped_refptr<Layer> scroller = Layer::Create();
6955 scoped_refptr<Layer> sticky_pos = Layer::Create();
6956 root->AddChild(container);
6957 container->AddChild(scroller);
6958 scroller->AddChild(sticky_pos);
6959 host()->SetRootLayer(root);
6960 scroller->SetScrollClipLayerId(container->id());
6961
6962 LayerStickyPositionConstraint sticky_position;
6963 sticky_position.is_sticky = true;
6964 sticky_position.is_anchored_bottom = true;
6965 sticky_position.bottom_offset = 10.0f;
flackr68e1c292016-10-11 16:34:426966 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150);
flackr2215b4e2016-09-21 20:16:016967 sticky_position.scroll_container_relative_sticky_box_rect =
6968 gfx::Rect(0, 150, 10, 10);
6969 sticky_position.scroll_container_relative_containing_block_rect =
6970 gfx::Rect(0, 100, 50, 50);
6971 sticky_pos->SetStickyPositionConstraint(sticky_position);
6972
6973 root->SetBounds(gfx::Size(100, 100));
6974 container->SetBounds(gfx::Size(100, 100));
6975 scroller->SetBounds(gfx::Size(1000, 1000));
6976 sticky_pos->SetBounds(gfx::Size(10, 10));
6977 sticky_pos->SetPosition(gfx::PointF(0, 150));
6978
6979 ExecuteCalculateDrawProperties(root.get());
6980 host()->host_impl()->CreatePendingTree();
6981 host()->CommitAndCreatePendingTree();
6982 host()->host_impl()->ActivateSyncTree();
6983 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6984
6985 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6986 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6987 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
6988
6989 // Initially the sticky element is moved up to the top of the container.
6990 ExecuteCalculateDrawProperties(root_impl);
6991 EXPECT_VECTOR2DF_EQ(
6992 gfx::Vector2dF(0.f, 100.f),
6993 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6994 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
6995 ExecuteCalculateDrawProperties(root_impl);
6996 EXPECT_VECTOR2DF_EQ(
6997 gfx::Vector2dF(0.f, 95.f),
6998 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
6999
7000 // Once we get past the top of the container it moves to be aligned 10px
7001 // up from the the bottom of the scroller.
7002 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7003 ExecuteCalculateDrawProperties(root_impl);
7004 EXPECT_VECTOR2DF_EQ(
7005 gfx::Vector2dF(0.f, 80.f),
7006 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7007 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7008 ExecuteCalculateDrawProperties(root_impl);
7009 EXPECT_VECTOR2DF_EQ(
7010 gfx::Vector2dF(0.f, 80.f),
7011 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7012
7013 // Once we scroll past its initial location, it sticks there.
7014 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 150.f));
7015 ExecuteCalculateDrawProperties(root_impl);
7016 EXPECT_VECTOR2DF_EQ(
7017 gfx::Vector2dF(0.f, 0.f),
7018 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7019}
7020
flackra283bed2016-10-31 14:49:427021TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) {
flackre310f292016-10-12 21:09:287022 scoped_refptr<Layer> root = Layer::Create();
7023 scoped_refptr<Layer> scroller = Layer::Create();
7024 scoped_refptr<Layer> sticky_pos = Layer::Create();
7025 root->AddChild(scroller);
7026 scroller->AddChild(sticky_pos);
7027 host()->SetRootLayer(root);
7028 scroller->SetScrollClipLayerId(root->id());
7029 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller,
7030 nullptr);
7031
7032 LayerStickyPositionConstraint sticky_position;
7033 sticky_position.is_sticky = true;
7034 sticky_position.is_anchored_bottom = true;
7035 sticky_position.bottom_offset = 10.0f;
flackra283bed2016-10-31 14:49:427036 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70);
flackre310f292016-10-12 21:09:287037 sticky_position.scroll_container_relative_sticky_box_rect =
flackra283bed2016-10-31 14:49:427038 gfx::Rect(0, 70, 10, 10);
flackre310f292016-10-12 21:09:287039 sticky_position.scroll_container_relative_containing_block_rect =
flackra283bed2016-10-31 14:49:427040 gfx::Rect(0, 60, 100, 100);
flackre310f292016-10-12 21:09:287041 sticky_pos->SetStickyPositionConstraint(sticky_position);
7042
7043 root->SetBounds(gfx::Size(100, 100));
7044 scroller->SetBounds(gfx::Size(100, 1000));
7045 sticky_pos->SetBounds(gfx::Size(10, 10));
flackra283bed2016-10-31 14:49:427046 sticky_pos->SetPosition(gfx::PointF(0, 70));
flackre310f292016-10-12 21:09:287047
7048 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
flackra283bed2016-10-31 14:49:427049 scroller.get(), nullptr);
flackre310f292016-10-12 21:09:287050 host()->CommitAndCreateLayerImplTree();
7051 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7052 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7053 ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id());
7054
7055 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
7056 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7057
7058 // Initially the sticky element is moved to the bottom of the container.
7059 EXPECT_VECTOR2DF_EQ(
flackra283bed2016-10-31 14:49:427060 gfx::Vector2dF(0.f, 70.f),
flackre310f292016-10-12 21:09:287061 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7062
flackra283bed2016-10-31 14:49:427063 // We start to hide the toolbar, but not far enough that the sticky element
7064 // should be moved up yet.
flackre310f292016-10-12 21:09:287065 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f));
flackra283bed2016-10-31 14:49:427066 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7067 nullptr);
flackre310f292016-10-12 21:09:287068 EXPECT_VECTOR2DF_EQ(
7069 gfx::Vector2dF(0.f, 70.f),
7070 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackra283bed2016-10-31 14:49:427071
7072 // On hiding more of the toolbar the sticky element starts to stick.
7073 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f));
7074 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7075 nullptr);
7076 EXPECT_VECTOR2DF_EQ(
7077 gfx::Vector2dF(0.f, 60.f),
7078 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7079
7080 // On hiding more the sticky element stops moving as it has reached its
7081 // limit.
7082 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f));
7083 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7084 nullptr);
7085 EXPECT_VECTOR2DF_EQ(
7086 gfx::Vector2dF(0.f, 60.f),
7087 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7088}
7089
7090TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) {
7091 scoped_refptr<Layer> root = Layer::Create();
7092 scoped_refptr<Layer> scroller = Layer::Create();
7093 scoped_refptr<Layer> outer_clip = Layer::Create();
7094 scoped_refptr<Layer> outer_viewport = Layer::Create();
7095 scoped_refptr<Layer> sticky_pos = Layer::Create();
7096 root->AddChild(scroller);
7097 scroller->AddChild(outer_clip);
7098 outer_clip->AddChild(outer_viewport);
7099 outer_viewport->AddChild(sticky_pos);
7100 host()->SetRootLayer(root);
7101 scroller->SetScrollClipLayerId(root->id());
7102 outer_viewport->SetScrollClipLayerId(outer_clip->id());
7103 host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller,
7104 outer_viewport);
7105
7106 LayerStickyPositionConstraint sticky_position;
7107 sticky_position.is_sticky = true;
7108 sticky_position.is_anchored_bottom = true;
7109 sticky_position.bottom_offset = 10.0f;
7110 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70);
7111 sticky_position.scroll_container_relative_sticky_box_rect =
7112 gfx::Rect(0, 70, 10, 10);
7113 sticky_position.scroll_container_relative_containing_block_rect =
7114 gfx::Rect(0, 60, 100, 100);
7115 sticky_pos->SetStickyPositionConstraint(sticky_position);
7116
7117 root->SetBounds(gfx::Size(100, 100));
7118 scroller->SetBounds(gfx::Size(100, 1000));
7119 outer_clip->SetBounds(gfx::Size(100, 100));
7120 sticky_pos->SetBounds(gfx::Size(10, 10));
7121 sticky_pos->SetPosition(gfx::PointF(0, 70));
7122
7123 ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(),
7124 scroller.get(), outer_viewport.get());
7125 host()->CommitAndCreateLayerImplTree();
7126 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7127 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7128 ASSERT_EQ(outer_viewport->id(),
7129 layer_tree_impl->OuterViewportScrollLayer()->id());
7130
7131 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer();
7132 LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer();
7133 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7134 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id());
7135
7136 // Initially the sticky element is moved to the bottom of the container.
7137 EXPECT_VECTOR2DF_EQ(
7138 gfx::Vector2dF(0.f, 70.f),
7139 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7140
7141 // We start to hide the toolbar, but not far enough that the sticky element
7142 // should be moved up yet.
7143 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f));
7144 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7145 outer_scroll);
7146 EXPECT_VECTOR2DF_EQ(
7147 gfx::Vector2dF(0.f, 70.f),
7148 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7149
7150 // On hiding more of the toolbar the sticky element starts to stick.
7151 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f));
7152 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7153 outer_scroll);
7154
7155 // On hiding more the sticky element stops moving as it has reached its
7156 // limit.
7157 EXPECT_VECTOR2DF_EQ(
7158 gfx::Vector2dF(0.f, 60.f),
7159 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7160
7161 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f));
7162 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll,
7163 outer_scroll);
7164
7165 EXPECT_VECTOR2DF_EQ(
7166 gfx::Vector2dF(0.f, 60.f),
7167 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
flackre310f292016-10-12 21:09:287168}
7169
flackr2215b4e2016-09-21 20:16:017170TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) {
7171 scoped_refptr<Layer> root = Layer::Create();
7172 scoped_refptr<Layer> container = Layer::Create();
7173 scoped_refptr<Layer> scroller = Layer::Create();
7174 scoped_refptr<Layer> sticky_pos = Layer::Create();
7175 root->AddChild(container);
7176 container->AddChild(scroller);
7177 scroller->AddChild(sticky_pos);
7178 host()->SetRootLayer(root);
7179 scroller->SetScrollClipLayerId(container->id());
7180
7181 LayerStickyPositionConstraint sticky_position;
7182 sticky_position.is_sticky = true;
7183 sticky_position.is_anchored_left = true;
7184 sticky_position.is_anchored_right = true;
7185 sticky_position.left_offset = 10.f;
7186 sticky_position.right_offset = 10.f;
flackr68e1c292016-10-11 16:34:427187 sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0);
flackr2215b4e2016-09-21 20:16:017188 sticky_position.scroll_container_relative_sticky_box_rect =
7189 gfx::Rect(145, 0, 10, 10);
7190 sticky_position.scroll_container_relative_containing_block_rect =
7191 gfx::Rect(100, 0, 100, 100);
7192 sticky_pos->SetStickyPositionConstraint(sticky_position);
7193
7194 root->SetBounds(gfx::Size(100, 100));
7195 container->SetBounds(gfx::Size(100, 100));
7196 scroller->SetBounds(gfx::Size(1000, 1000));
7197 sticky_pos->SetBounds(gfx::Size(10, 10));
7198 sticky_pos->SetPosition(gfx::PointF(145, 0));
7199
7200 ExecuteCalculateDrawProperties(root.get());
7201 host()->host_impl()->CreatePendingTree();
7202 host()->CommitAndCreatePendingTree();
7203 host()->host_impl()->ActivateSyncTree();
7204 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7205
7206 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7207 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7208 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7209
7210 // Initially the sticky element is moved the leftmost side of the container.
7211 ExecuteCalculateDrawProperties(root_impl);
7212 EXPECT_VECTOR2DF_EQ(
7213 gfx::Vector2dF(100.f, 0.f),
7214 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7215 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 0.f));
7216 ExecuteCalculateDrawProperties(root_impl);
7217 EXPECT_VECTOR2DF_EQ(
7218 gfx::Vector2dF(95.f, 0.f),
7219 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7220
7221 // Once we get past the left side of the container it moves to be aligned 10px
7222 // up from the the right of the scroller.
7223 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(25.f, 0.f));
7224 ExecuteCalculateDrawProperties(root_impl);
7225 EXPECT_VECTOR2DF_EQ(
7226 gfx::Vector2dF(80.f, 0.f),
7227 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7228 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(30.f, 0.f));
7229 ExecuteCalculateDrawProperties(root_impl);
7230 EXPECT_VECTOR2DF_EQ(
7231 gfx::Vector2dF(80.f, 0.f),
7232 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7233
7234 // When we get to the sticky element's original position we stop sticking
7235 // to the right.
7236 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(95.f, 0.f));
7237 ExecuteCalculateDrawProperties(root_impl);
7238 EXPECT_VECTOR2DF_EQ(
7239 gfx::Vector2dF(50.f, 0.f),
7240 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7241 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(105.f, 0.f));
7242 ExecuteCalculateDrawProperties(root_impl);
7243 EXPECT_VECTOR2DF_EQ(
7244 gfx::Vector2dF(40.f, 0.f),
7245 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7246
7247 // The element starts sticking to the left once we scroll far enough.
7248 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(150.f, 0.f));
7249 ExecuteCalculateDrawProperties(root_impl);
7250 EXPECT_VECTOR2DF_EQ(
7251 gfx::Vector2dF(10.f, 0.f),
7252 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7253 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(155.f, 0.f));
7254 ExecuteCalculateDrawProperties(root_impl);
7255 EXPECT_VECTOR2DF_EQ(
7256 gfx::Vector2dF(10.f, 0.f),
7257 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7258
7259 // Finally it stops sticking when it hits the right side of the container.
7260 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(190.f, 0.f));
7261 ExecuteCalculateDrawProperties(root_impl);
7262 EXPECT_VECTOR2DF_EQ(
7263 gfx::Vector2dF(0.f, 0.f),
7264 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7265 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(195.f, 0.f));
7266 ExecuteCalculateDrawProperties(root_impl);
7267 EXPECT_VECTOR2DF_EQ(
7268 gfx::Vector2dF(-5.f, 0.f),
7269 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7270}
7271
7272// This test ensures that the compositor sticky position code correctly accounts
7273// for the element having been given a position from the main thread sticky
7274// position code.
7275TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) {
7276 scoped_refptr<Layer> root = Layer::Create();
7277 scoped_refptr<Layer> container = Layer::Create();
7278 scoped_refptr<Layer> scroller = Layer::Create();
7279 scoped_refptr<Layer> sticky_pos = Layer::Create();
7280 root->AddChild(container);
7281 container->AddChild(scroller);
7282 scroller->AddChild(sticky_pos);
7283 host()->SetRootLayer(root);
7284 scroller->SetScrollClipLayerId(container->id());
7285
7286 LayerStickyPositionConstraint sticky_position;
7287 sticky_position.is_sticky = true;
7288 sticky_position.is_anchored_top = true;
7289 sticky_position.top_offset = 10.0f;
flackr68e1c292016-10-11 16:34:427290 sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20);
flackr2215b4e2016-09-21 20:16:017291 sticky_position.scroll_container_relative_sticky_box_rect =
7292 gfx::Rect(10, 20, 10, 10);
7293 sticky_position.scroll_container_relative_containing_block_rect =
7294 gfx::Rect(0, 0, 50, 50);
7295 sticky_pos->SetStickyPositionConstraint(sticky_position);
7296
7297 root->SetBounds(gfx::Size(100, 100));
7298 container->SetBounds(gfx::Size(100, 100));
7299 scroller->SetBounds(gfx::Size(1000, 1000));
7300 sticky_pos->SetBounds(gfx::Size(10, 10));
7301 sticky_pos->SetPosition(gfx::PointF(10, 20));
7302
7303 ExecuteCalculateDrawProperties(root.get());
7304 host()->host_impl()->CreatePendingTree();
7305 host()->CommitAndCreatePendingTree();
7306 host()->host_impl()->ActivateSyncTree();
7307 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7308
7309 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7310 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7311 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7312
7313 ExecuteCalculateDrawProperties(root_impl);
7314 EXPECT_VECTOR2DF_EQ(
7315 gfx::Vector2dF(10.f, 20.f),
7316 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7317
7318 // Scroll less than sticking point, sticky element should move with scroll as
7319 // we haven't gotten to the initial sticky item location yet.
7320 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f));
7321 ExecuteCalculateDrawProperties(root_impl);
7322 EXPECT_VECTOR2DF_EQ(
7323 gfx::Vector2dF(5.f, 15.f),
7324 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7325
7326 // Scroll past the sticking point, the Y coordinate should now be clamped.
7327 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f));
7328 ExecuteCalculateDrawProperties(root_impl);
7329 EXPECT_VECTOR2DF_EQ(
7330 gfx::Vector2dF(-5.f, 10.f),
7331 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7332
7333 // Now the main thread commits the new position of the sticky element.
7334 scroller->SetScrollOffset(gfx::ScrollOffset(15, 15));
7335 sticky_pos->SetPosition(gfx::PointF(10, 25));
7336 ExecuteCalculateDrawProperties(root.get());
7337 host()->host_impl()->CreatePendingTree();
7338 host()->CommitAndCreatePendingTree();
7339 host()->host_impl()->ActivateSyncTree();
7340 layer_tree_impl = host()->host_impl()->active_tree();
7341 root_impl = layer_tree_impl->LayerById(root->id());
7342 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7343 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7344
7345 // The element should still be where it was before. We reset the delta to
7346 // (0, 0) because we have synced a scroll offset of (15, 15) from the main
7347 // thread.
7348 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7349 ExecuteCalculateDrawProperties(root_impl);
7350 EXPECT_VECTOR2DF_EQ(
7351 gfx::Vector2dF(-5.f, 10.f),
7352 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7353
7354 // And if we scroll a little further it remains there.
7355 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7356 ExecuteCalculateDrawProperties(root_impl);
7357 EXPECT_VECTOR2DF_EQ(
7358 gfx::Vector2dF(-5.f, 10.f),
7359 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7360}
7361
flackr68e1c292016-10-11 16:34:427362// This tests the main thread updates with a composited sticky container. In
7363// this case the position received from main is relative to the container but
7364// the constraint rects are relative to the ancestor scroller.
7365TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) {
7366 scoped_refptr<Layer> root = Layer::Create();
7367 scoped_refptr<Layer> container = Layer::Create();
7368 scoped_refptr<Layer> scroller = Layer::Create();
7369 scoped_refptr<Layer> sticky_container = Layer::Create();
7370 scoped_refptr<Layer> sticky_pos = Layer::Create();
7371 root->AddChild(container);
7372 container->AddChild(scroller);
7373 scroller->AddChild(sticky_container);
7374 sticky_container->AddChild(sticky_pos);
7375 host()->SetRootLayer(root);
7376 scroller->SetScrollClipLayerId(container->id());
7377
7378 LayerStickyPositionConstraint sticky_position;
7379 sticky_position.is_sticky = true;
7380 sticky_position.is_anchored_top = true;
7381 sticky_position.top_offset = 10.0f;
7382 // The sticky position layer is only offset by (0, 10) from its parent
7383 // layer, this position is used to determine the offset applied by the main
7384 // thread.
7385 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10);
7386 sticky_position.scroll_container_relative_sticky_box_rect =
7387 gfx::Rect(20, 30, 10, 10);
7388 sticky_position.scroll_container_relative_containing_block_rect =
7389 gfx::Rect(20, 20, 30, 30);
7390 sticky_pos->SetStickyPositionConstraint(sticky_position);
7391
7392 root->SetBounds(gfx::Size(100, 100));
7393 container->SetBounds(gfx::Size(100, 100));
7394 scroller->SetBounds(gfx::Size(1000, 1000));
7395 sticky_container->SetPosition(gfx::PointF(20, 20));
7396 sticky_container->SetBounds(gfx::Size(30, 30));
7397 sticky_pos->SetBounds(gfx::Size(10, 10));
7398 sticky_pos->SetPosition(gfx::PointF(0, 10));
7399
7400 ExecuteCalculateDrawProperties(root.get());
7401 host()->host_impl()->CreatePendingTree();
7402 host()->CommitAndCreatePendingTree();
7403 host()->host_impl()->ActivateSyncTree();
7404 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7405
7406 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7407 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7408 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7409
7410 ExecuteCalculateDrawProperties(root_impl);
7411 EXPECT_VECTOR2DF_EQ(
7412 gfx::Vector2dF(20.f, 30.f),
7413 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7414
7415 // Scroll less than sticking point, sticky element should move with scroll as
7416 // we haven't gotten to the initial sticky item location yet.
7417 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7418 ExecuteCalculateDrawProperties(root_impl);
7419 EXPECT_VECTOR2DF_EQ(
7420 gfx::Vector2dF(20.f, 25.f),
7421 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7422
7423 // Scroll past the sticking point, the Y coordinate should now be clamped.
7424 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7425 ExecuteCalculateDrawProperties(root_impl);
7426 EXPECT_VECTOR2DF_EQ(
7427 gfx::Vector2dF(20.f, 10.f),
7428 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7429
7430 // Now the main thread commits the new position of the sticky element.
7431 scroller->SetScrollOffset(gfx::ScrollOffset(0, 25));
7432 sticky_pos->SetPosition(gfx::PointF(0, 15));
7433 ExecuteCalculateDrawProperties(root.get());
7434 host()->host_impl()->CreatePendingTree();
7435 host()->CommitAndCreatePendingTree();
7436 host()->host_impl()->ActivateSyncTree();
7437 layer_tree_impl = host()->host_impl()->active_tree();
7438 root_impl = layer_tree_impl->LayerById(root->id());
7439 scroller_impl = layer_tree_impl->LayerById(scroller->id());
7440 sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7441
7442 // The element should still be where it was before. We reset the delta to
7443 // (0, 0) because we have synced a scroll offset of (0, 25) from the main
7444 // thread.
7445 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f));
7446 ExecuteCalculateDrawProperties(root_impl);
7447 EXPECT_VECTOR2DF_EQ(
7448 gfx::Vector2dF(20.f, 10.f),
7449 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7450
7451 // And if we scroll a little further it remains there.
7452 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f));
7453 ExecuteCalculateDrawProperties(root_impl);
7454 EXPECT_VECTOR2DF_EQ(
7455 gfx::Vector2dF(20.f, 10.f),
7456 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7457
7458 // And hits the bottom of the container.
7459 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f));
7460 ExecuteCalculateDrawProperties(root_impl);
7461 EXPECT_VECTOR2DF_EQ(
7462 gfx::Vector2dF(20.f, 5.f),
7463 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7464}
7465
flackr2215b4e2016-09-21 20:16:017466// A transform on a sticky element should not affect its sticky position.
7467TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) {
7468 scoped_refptr<Layer> root = Layer::Create();
7469 scoped_refptr<Layer> container = Layer::Create();
7470 scoped_refptr<Layer> scroller = Layer::Create();
7471 scoped_refptr<Layer> sticky_pos = Layer::Create();
7472 root->AddChild(container);
7473 container->AddChild(scroller);
7474 scroller->AddChild(sticky_pos);
7475 host()->SetRootLayer(root);
7476 scroller->SetScrollClipLayerId(container->id());
7477 gfx::Transform t;
7478 t.Scale(2, 2);
7479 sticky_pos->SetTransform(t);
7480
7481 LayerStickyPositionConstraint sticky_position;
7482 sticky_position.is_sticky = true;
7483 sticky_position.is_anchored_top = true;
7484 sticky_position.top_offset = 0.0f;
flackr68e1c292016-10-11 16:34:427485 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20);
flackr2215b4e2016-09-21 20:16:017486 sticky_position.scroll_container_relative_sticky_box_rect =
7487 gfx::Rect(0, 20, 10, 10);
7488 sticky_position.scroll_container_relative_containing_block_rect =
7489 gfx::Rect(0, 0, 50, 50);
7490 sticky_pos->SetStickyPositionConstraint(sticky_position);
7491
7492 root->SetBounds(gfx::Size(100, 100));
7493 container->SetBounds(gfx::Size(100, 100));
7494 scroller->SetBounds(gfx::Size(1000, 1000));
7495 sticky_pos->SetBounds(gfx::Size(10, 10));
7496 sticky_pos->SetPosition(gfx::PointF(0, 20));
7497
7498 ExecuteCalculateDrawProperties(root.get());
7499 host()->host_impl()->CreatePendingTree();
7500 host()->CommitAndCreatePendingTree();
7501 host()->host_impl()->ActivateSyncTree();
7502 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7503
7504 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7505 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7506 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7507
7508 ExecuteCalculateDrawProperties(root_impl);
7509 EXPECT_VECTOR2DF_EQ(
7510 gfx::Vector2dF(0.f, 20.f),
7511 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7512
7513 // Scroll less than sticking point, sticky element should move with scroll as
7514 // we haven't gotten to the initial sticky item location yet.
7515 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7516 ExecuteCalculateDrawProperties(root_impl);
7517 EXPECT_VECTOR2DF_EQ(
7518 gfx::Vector2dF(0.f, 5.f),
7519 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7520
7521 // Scroll past the sticking point, the box is positioned at the scroller
7522 // edge.
7523 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7524 ExecuteCalculateDrawProperties(root_impl);
7525 EXPECT_VECTOR2DF_EQ(
7526 gfx::Vector2dF(0.f, 0.f),
7527 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7528 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7529 ExecuteCalculateDrawProperties(root_impl);
7530 EXPECT_VECTOR2DF_EQ(
7531 gfx::Vector2dF(0.f, 0.f),
7532 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7533
7534 // Scroll past the end of the sticky container.
7535 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7536 ExecuteCalculateDrawProperties(root_impl);
7537 EXPECT_VECTOR2DF_EQ(
7538 gfx::Vector2dF(0.f, -10.f),
7539 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7540}
7541
7542// Tests that a transform does not affect the sticking points. The sticky
7543// element will however move relative to the viewport due to its transform.
7544TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) {
7545 scoped_refptr<Layer> root = Layer::Create();
7546 scoped_refptr<Layer> container = Layer::Create();
7547 scoped_refptr<Layer> scroller = Layer::Create();
7548 scoped_refptr<Layer> sticky_container = Layer::Create();
7549 scoped_refptr<Layer> sticky_pos = Layer::Create();
7550 root->AddChild(container);
7551 container->AddChild(scroller);
7552 scroller->AddChild(sticky_container);
7553 sticky_container->AddChild(sticky_pos);
7554 host()->SetRootLayer(root);
7555 scroller->SetScrollClipLayerId(container->id());
7556 gfx::Transform t;
7557 t.Scale(2, 2);
7558 sticky_container->SetTransform(t);
7559
7560 LayerStickyPositionConstraint sticky_position;
7561 sticky_position.is_sticky = true;
7562 sticky_position.is_anchored_top = true;
7563 sticky_position.top_offset = 0.0f;
flackr68e1c292016-10-11 16:34:427564 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20);
flackr2215b4e2016-09-21 20:16:017565 sticky_position.scroll_container_relative_sticky_box_rect =
7566 gfx::Rect(0, 20, 10, 10);
7567 sticky_position.scroll_container_relative_containing_block_rect =
7568 gfx::Rect(0, 0, 50, 50);
7569 sticky_pos->SetStickyPositionConstraint(sticky_position);
7570
7571 root->SetBounds(gfx::Size(100, 100));
7572 container->SetBounds(gfx::Size(100, 100));
7573 scroller->SetBounds(gfx::Size(1000, 1000));
7574 sticky_container->SetBounds(gfx::Size(50, 50));
7575 sticky_pos->SetBounds(gfx::Size(10, 10));
7576 sticky_pos->SetPosition(gfx::PointF(0, 20));
7577
7578 ExecuteCalculateDrawProperties(root.get());
7579 host()->host_impl()->CreatePendingTree();
7580 host()->CommitAndCreatePendingTree();
7581 host()->host_impl()->ActivateSyncTree();
7582 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7583
7584 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7585 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7586 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id());
7587
7588 ExecuteCalculateDrawProperties(root_impl);
7589 EXPECT_VECTOR2DF_EQ(
7590 gfx::Vector2dF(0.f, 40.f),
7591 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7592
7593 // Scroll less than sticking point, sticky element should move with scroll as
7594 // we haven't gotten to the initial sticky item location yet.
7595 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 15.f));
7596 ExecuteCalculateDrawProperties(root_impl);
7597 EXPECT_VECTOR2DF_EQ(
7598 gfx::Vector2dF(0.f, 25.f),
7599 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7600
7601 // Scroll past the sticking point, the box is positioned at the scroller
7602 // edge but is also scaled by its container so it begins to move down.
7603 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f));
7604 ExecuteCalculateDrawProperties(root_impl);
7605 EXPECT_VECTOR2DF_EQ(
7606 gfx::Vector2dF(0.f, 25.f),
7607 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7608 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 30.f));
7609 ExecuteCalculateDrawProperties(root_impl);
7610 EXPECT_VECTOR2DF_EQ(
7611 gfx::Vector2dF(0.f, 30.f),
7612 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7613
7614 // Scroll past the end of the sticky container.
7615 SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 50.f));
7616 ExecuteCalculateDrawProperties(root_impl);
7617 EXPECT_VECTOR2DF_EQ(
7618 gfx::Vector2dF(0.f, 30.f),
7619 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation());
7620}
7621
jaydasikaaf1582f2016-08-10 18:39:387622TEST_F(LayerTreeHostCommonTest, NonFlatContainerForFixedPosLayer) {
7623 scoped_refptr<Layer> root = Layer::Create();
7624 scoped_refptr<Layer> container = Layer::Create();
7625 scoped_refptr<Layer> scroller = Layer::Create();
7626 scoped_refptr<Layer> fixed_pos = Layer::Create();
7627
7628 scroller->SetIsContainerForFixedPositionLayers(true);
7629 root->AddChild(container);
7630 container->AddChild(scroller);
7631 scroller->AddChild(fixed_pos);
7632 host()->SetRootLayer(root);
7633
7634 LayerPositionConstraint fixed_position;
7635 fixed_position.set_is_fixed_position(true);
7636 scroller->SetScrollClipLayerId(container->id());
7637 fixed_pos->SetPositionConstraint(fixed_position);
7638
7639 root->SetBounds(gfx::Size(50, 50));
7640 container->SetBounds(gfx::Size(50, 50));
7641 scroller->SetBounds(gfx::Size(50, 50));
7642 fixed_pos->SetBounds(gfx::Size(50, 50));
7643
7644 gfx::Transform rotate;
7645 rotate.RotateAboutXAxis(20);
7646 container->SetTransform(rotate);
7647
7648 ExecuteCalculateDrawProperties(root.get());
khushalsagar86928f92016-08-17 21:49:057649 TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree;
jaydasikaaf1582f2016-08-10 18:39:387650 gfx::Transform transform;
7651 tree.ComputeTranslation(fixed_pos->transform_tree_index(),
7652 container->transform_tree_index(), &transform);
7653 EXPECT_TRUE(transform.IsIdentity());
7654}
7655
sunxd8a9a60982016-07-29 18:46:567656TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
7657 // This test verifies that a fixed pos child of a scrolling layer doesn't get
7658 // snapped to integer coordinates.
7659 //
7660 // + root
7661 // + container
7662 // + scroller
7663 // + fixed_pos
7664 //
7665 scoped_refptr<Layer> root = Layer::Create();
7666 scoped_refptr<Layer> container = Layer::Create();
7667 scoped_refptr<Layer> scroller = Layer::Create();
7668 scoped_refptr<Layer> fixed_pos = Layer::Create();
7669
7670 scroller->SetIsContainerForFixedPositionLayers(true);
7671
7672 root->AddChild(container);
7673 container->AddChild(scroller);
7674 scroller->AddChild(fixed_pos);
7675 host()->SetRootLayer(root);
7676
7677 LayerPositionConstraint fixed_position;
7678 fixed_position.set_is_fixed_position(true);
7679 scroller->SetScrollClipLayerId(container->id());
7680 fixed_pos->SetPositionConstraint(fixed_position);
7681
7682 root->SetBounds(gfx::Size(50, 50));
7683 container->SetBounds(gfx::Size(50, 50));
7684 scroller->SetBounds(gfx::Size(100, 100));
7685 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
7686 fixed_pos->SetBounds(gfx::Size(10, 10));
7687
7688 ExecuteCalculateDrawProperties(root.get());
7689
7690 host()->host_impl()->CreatePendingTree();
7691 host()->CommitAndCreatePendingTree();
7692 host()->host_impl()->ActivateSyncTree();
7693 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
7694
7695 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
7696 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
7697 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
7698 gfx::Vector2dF scroll_delta(5.f, 9.f);
7699 SetScrollOffsetDelta(scroller_impl, scroll_delta);
7700
7701 ExecuteCalculateDrawProperties(root_impl);
7702
7703 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
7704 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
7705 scroller_impl->ScreenSpaceTransform().To2dTranslation());
7706
7707 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
7708 10.3f);
7709 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
7710 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
7711}
7712
[email protected]1c3626e2014-04-09 17:49:227713class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7714 public:
danakj60bc3bc2016-04-09 00:24:487715 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227716 LayerTreeImpl* tree_impl,
7717 int id) {
danakj60bc3bc2016-04-09 00:24:487718 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227719 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7720 }
7721
dcheng716bedf2014-10-21 09:51:087722 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227723
[email protected]1c3626e2014-04-09 17:49:227724 private:
7725 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7726 int id)
[email protected]a57cb8b12014-06-13 18:15:377727 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227728 SetDrawsContent(true);
7729 }
[email protected]1c3626e2014-04-09 17:49:227730};
7731
7732TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167733 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567734 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:017735 LayerTreeSettings settings = host()->GetSettings();
ajumab4a846f22015-08-24 19:13:447736 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167737 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:227738 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:487739 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227740 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487741 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227742 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487743 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227744 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487745 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227746 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7747
7748 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7749 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7750 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097751 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227752
danakjf78fb272016-07-26 19:06:157753 grand_parent->SetBounds(gfx::Size(1, 2));
7754 parent->SetBounds(gfx::Size(1, 2));
7755 child->SetBounds(gfx::Size(1, 2));
7756 grand_child->SetBounds(gfx::Size(1, 2));
7757
jaydasika89f7b5a2016-06-22 02:08:397758 child->test_properties()->AddChild(std::move(grand_child));
7759 parent->test_properties()->AddChild(std::move(child));
7760 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597761 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:057762
jaydasika2411692c2016-03-23 01:56:097763 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227764
7765 // No layers have animations.
sunxdf468675e2016-06-30 23:56:187766 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7767 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7768 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7769 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227770
sunxdf468675e2016-06-30 23:56:187771 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7772 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7773 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7774 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037775
[email protected]1c3626e2014-04-09 17:49:227776 TransformOperations translation;
7777 translation.AppendTranslate(1.f, 2.f, 3.f);
7778
loyso968163c92016-01-04 23:18:487779 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587780 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7781 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487782
vollickef2ae922016-06-29 17:54:277783 host_impl.active_tree()->SetElementIdsForTesting();
loysodb006882016-09-14 00:31:517784
7785 scoped_refptr<AnimationPlayer> grand_parent_player =
7786 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7787 timeline->AttachPlayer(grand_parent_player);
7788 grand_parent_player->AttachElement(grand_parent_raw->element_id());
7789
7790 scoped_refptr<AnimationPlayer> parent_player =
7791 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7792 timeline->AttachPlayer(parent_player);
7793 parent_player->AttachElement(parent_raw->element_id());
7794
7795 scoped_refptr<AnimationPlayer> child_player =
7796 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7797 timeline->AttachPlayer(child_player);
7798 child_player->AttachElement(child_raw->element_id());
7799
7800 scoped_refptr<AnimationPlayer> grand_child_player =
7801 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
7802 timeline->AttachPlayer(grand_child_player);
7803 grand_child_player->AttachElement(grand_child_raw->element_id());
7804
7805 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7806 translation);
[email protected]1c3626e2014-04-09 17:49:227807
7808 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187809 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7810 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7811 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7812 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227813
sunxdf468675e2016-06-30 23:56:187814 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7815 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7816 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7817 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037818
[email protected]1c3626e2014-04-09 17:49:227819 TransformOperations scale;
7820 scale.AppendScale(5.f, 4.f, 3.f);
7821
loysodb006882016-09-14 00:31:517822 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7823 scale);
ajumacaaa9b32015-08-04 15:55:297824 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097825 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227826
7827 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:187828 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7829 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7830 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
7831 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227832
sunxdf468675e2016-06-30 23:56:187833 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7834 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7835 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
7836 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037837
loysodb006882016-09-14 00:31:517838 AddAnimatedTransformToPlayer(grand_parent_player.get(), 1.0,
7839 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097840 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7841 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227842
7843 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187844 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7845 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:227846 // We don't support combining animated scales from two nodes; 0.f means
7847 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:187848 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7849 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227850
sunxdf468675e2016-06-30 23:56:187851 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7852 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
7853 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7854 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037855
loysodb006882016-09-14 00:31:517856 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7857 scale);
ajumacaaa9b32015-08-04 15:55:297858 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097859 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227860
7861 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187862 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7863 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7864 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7865 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227866
sunxdf468675e2016-06-30 23:56:187867 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7868 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7869 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7870 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037871
loysodb006882016-09-14 00:31:517872 grand_parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7873 parent_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7874 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
[email protected]1c3626e2014-04-09 17:49:227875
7876 TransformOperations perspective;
7877 perspective.AppendPerspective(10.f);
7878
loysodb006882016-09-14 00:31:517879 AddAnimatedTransformToPlayer(child_player.get(), 1.0, TransformOperations(),
7880 perspective);
ajumab4a846f22015-08-24 19:13:447881 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097882 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227883
7884 // |child| has a scale-affecting animation but computing the maximum of this
7885 // animation is not supported.
sunxdf468675e2016-06-30 23:56:187886 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7887 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7888 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7889 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227890
sunxdf468675e2016-06-30 23:56:187891 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7892 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7893 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7894 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037895
loysobb507792016-10-04 05:31:027896 child_player->AbortAnimations(TargetProperty::TRANSFORM, false);
7897
[email protected]1c3626e2014-04-09 17:49:227898 gfx::Transform scale_matrix;
7899 scale_matrix.Scale(1.f, 2.f);
jaydasika10d43fc2016-08-18 04:06:047900 grand_parent_raw->test_properties()->transform = scale_matrix;
7901 parent_raw->test_properties()->transform = scale_matrix;
jaydasika2411692c2016-03-23 01:56:097902 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487903
loysodb006882016-09-14 00:31:517904 AddAnimatedTransformToPlayer(parent_player.get(), 1.0, TransformOperations(),
7905 scale);
jaydasika2411692c2016-03-23 01:56:097906 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227907
7908 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7909 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:187910 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7911 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7912 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
7913 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227914
sunxdf468675e2016-06-30 23:56:187915 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7916 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7917 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
7918 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037919
[email protected]1c3626e2014-04-09 17:49:227920 gfx::Transform perspective_matrix;
7921 perspective_matrix.ApplyPerspectiveDepth(2.f);
jaydasika10d43fc2016-08-18 04:06:047922 child_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097923 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7924 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227925
7926 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187927 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7928 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7929 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7930 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227931
sunxdf468675e2016-06-30 23:56:187932 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7933 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7934 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7935 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037936
jaydasika10d43fc2016-08-18 04:06:047937 parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097938 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7939 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227940
7941 // |parent| and |child| have transforms that are neither translations nor
7942 // scales.
sunxdf468675e2016-06-30 23:56:187943 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7944 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7945 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7946 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227947
sunxdf468675e2016-06-30 23:56:187948 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7949 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7950 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7951 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037952
jaydasika10d43fc2016-08-18 04:06:047953 parent_raw->test_properties()->transform = gfx::Transform();
7954 child_raw->test_properties()->transform = gfx::Transform();
7955 grand_parent_raw->test_properties()->transform = perspective_matrix;
jaydasika2411692c2016-03-23 01:56:097956 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227957
jaydasika2411692c2016-03-23 01:56:097958 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227959
7960 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187961 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7962 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7963 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7964 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037965
sunxdf468675e2016-06-30 23:56:187966 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7967 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7968 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7969 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227970}
7971
danakj59931942016-07-26 22:11:297972static void GatherDrawnLayers(const LayerImplList* rsll,
[email protected]390bb1ff2014-05-09 17:14:407973 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517974 for (LayerIterator it = LayerIterator::Begin(rsll),
7975 end = LayerIterator::End(rsll);
7976 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407977 LayerImpl* layer = *it;
7978 if (it.represents_itself())
7979 drawn_layers->insert(layer);
7980
7981 if (!it.represents_contributing_render_surface())
7982 continue;
7983
ajuma1d4026a32016-06-14 13:18:507984 if (layer->render_surface()->MaskLayer())
7985 drawn_layers->insert(layer->render_surface()->MaskLayer());
[email protected]390bb1ff2014-05-09 17:14:407986 }
7987}
7988
7989TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167990 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:567991 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:227992 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407993
danakj60bc3bc2016-04-09 00:24:487994 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407995 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487996 std::unique_ptr<LayerImpl> parent =
7997 LayerImpl::Create(host_impl.active_tree(), 3);
7998 std::unique_ptr<LayerImpl> child =
7999 LayerImpl::Create(host_impl.active_tree(), 5);
8000 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:408001 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:488002 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:408003 LayerImpl::Create(host_impl.active_tree(), 9);
8004
8005 LayerImpl* grand_parent_raw = grand_parent.get();
8006 LayerImpl* parent_raw = parent.get();
8007 LayerImpl* child_raw = child.get();
8008 LayerImpl* grand_child1_raw = grand_child1.get();
8009 LayerImpl* grand_child2_raw = grand_child2.get();
8010
danakjf78fb272016-07-26 19:06:158011 grand_parent->SetBounds(gfx::Size(1, 2));
8012 parent->SetBounds(gfx::Size(1, 2));
8013 child->SetBounds(gfx::Size(1, 2));
8014 grand_child1->SetBounds(gfx::Size(1, 2));
8015 grand_child2->SetBounds(gfx::Size(1, 2));
8016
jaydasika89f7b5a2016-06-22 02:08:398017 child->test_properties()->AddChild(std::move(grand_child1));
8018 child->test_properties()->AddChild(std::move(grand_child2));
8019 parent->test_properties()->AddChild(std::move(child));
8020 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:598021 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:408022
[email protected]390bb1ff2014-05-09 17:14:408023 // Start with nothing being drawn.
8024 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408025
ajuma0adb5902016-04-28 16:32:388026 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8027 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8028 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8029 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8030 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408031
8032 std::set<LayerImpl*> expected;
8033 std::set<LayerImpl*> actual;
8034 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8035 EXPECT_EQ(expected, actual);
8036
8037 // If we force render surface, but none of the layers are in the layer list,
8038 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:008039 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:128040 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408041
8042 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408043
ajuma0adb5902016-04-28 16:32:388044 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8045 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8046 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8047 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8048 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408049
8050 expected.clear();
8051 actual.clear();
8052 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8053 EXPECT_EQ(expected, actual);
8054
8055 // However, if we say that this layer also draws content, it will appear in
8056 // RSLL.
8057 grand_child1_raw->SetDrawsContent(true);
8058
8059 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408060
ajuma0adb5902016-04-28 16:32:388061 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8062 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8063 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8064 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8065 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408066
8067 expected.clear();
8068 expected.insert(grand_child1_raw);
8069
8070 actual.clear();
8071 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8072 EXPECT_EQ(expected, actual);
8073
8074 // Now child is forced to have a render surface, and one if its children draws
8075 // content.
8076 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:008077 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:128078 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:008079 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408080 grand_child2_raw->SetDrawsContent(true);
8081
8082 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408083
ajuma0adb5902016-04-28 16:32:388084 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8085 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8086 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
8087 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8088 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408089
8090 expected.clear();
8091 expected.insert(grand_child2_raw);
8092
8093 actual.clear();
8094 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8095 EXPECT_EQ(expected, actual);
8096
8097 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:508098 child_raw->test_properties()->SetMaskLayer(
8099 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:048100 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408101
8102 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408103
ajuma0adb5902016-04-28 16:32:388104 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8105 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8106 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508107 EXPECT_TRUE(child_raw->test_properties()
8108 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388109 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8110 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408111
8112 expected.clear();
8113 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508114 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408115
8116 expected.clear();
8117 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508118 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408119
8120 actual.clear();
8121 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8122 EXPECT_EQ(expected, actual);
8123
[email protected]390bb1ff2014-05-09 17:14:408124 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408125
ajuma0adb5902016-04-28 16:32:388126 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8127 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8128 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508129 EXPECT_TRUE(child_raw->test_properties()
8130 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388131 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8132 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408133
8134 expected.clear();
8135 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:508136 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408137
8138 actual.clear();
8139 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8140 EXPECT_EQ(expected, actual);
8141
ajuma1d4026a32016-06-14 13:18:508142 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408143
8144 // With nothing drawing, we should have no layers.
8145 grand_child2_raw->SetDrawsContent(false);
8146
8147 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408148
ajuma0adb5902016-04-28 16:32:388149 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8150 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8151 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508152 EXPECT_FALSE(child_raw->test_properties()
8153 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388154 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8155 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408156
8157 expected.clear();
8158 actual.clear();
8159 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8160 EXPECT_EQ(expected, actual);
8161
8162 // Child itself draws means that we should have the child and the mask in the
8163 // list.
8164 child_raw->SetDrawsContent(true);
8165
8166 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408167
ajuma0adb5902016-04-28 16:32:388168 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8169 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
8170 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:508171 EXPECT_TRUE(child_raw->test_properties()
8172 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:388173 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8174 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408175
8176 expected.clear();
8177 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:508178 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:408179 actual.clear();
8180 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8181 EXPECT_EQ(expected, actual);
8182
ajuma1d4026a32016-06-14 13:18:508183 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:048184 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:408185
8186 // Now everyone's a member!
8187 grand_parent_raw->SetDrawsContent(true);
8188 parent_raw->SetDrawsContent(true);
8189 child_raw->SetDrawsContent(true);
8190 grand_child1_raw->SetDrawsContent(true);
8191 grand_child2_raw->SetDrawsContent(true);
8192
8193 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:408194
ajuma0adb5902016-04-28 16:32:388195 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
8196 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
8197 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
8198 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
8199 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:408200
8201 expected.clear();
8202 expected.insert(grand_parent_raw);
8203 expected.insert(parent_raw);
8204 expected.insert(child_raw);
8205 expected.insert(grand_child1_raw);
8206 expected.insert(grand_child2_raw);
8207
8208 actual.clear();
8209 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8210 EXPECT_EQ(expected, actual);
8211}
[email protected]18e69652014-06-13 12:50:588212
8213TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:168214 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568215 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018216 LayerTreeSettings settings = host()->GetSettings();
enne637715732015-07-07 02:05:268217 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:168218 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228219 &task_graph_runner);
[email protected]18e69652014-06-13 12:50:588220
danakj60bc3bc2016-04-09 00:24:488221 std::unique_ptr<LayerImpl> root =
8222 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:588223 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:488224 std::unique_ptr<LayerImpl> child1 =
8225 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:588226 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:488227 std::unique_ptr<LayerImpl> child2 =
8228 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:588229 LayerImpl* child2_layer = child2.get();
8230
danakjf78fb272016-07-26 19:06:158231 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:588232 scale_transform_child1.Scale(2, 3);
8233 scale_transform_child2.Scale(4, 5);
8234
danakjf78fb272016-07-26 19:06:158235 root->SetBounds(gfx::Size(1, 1));
8236 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048237 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158238 child1_layer->SetBounds(gfx::Size(1, 1));
8239 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:588240
ajuma1d4026a32016-06-14 13:18:508241 child1_layer->test_properties()->SetMaskLayer(
8242 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:588243
danakjf78fb272016-07-26 19:06:158244 root->test_properties()->AddChild(std::move(child1));
8245 root->test_properties()->AddChild(std::move(child2));
8246 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8247 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:588248
8249 ExecuteCalculateDrawProperties(root_layer);
8250
8251 TransformOperations scale;
8252 scale.AppendScale(5.f, 8.f, 3.f);
8253
loyso9556c732016-03-11 07:54:588254 scoped_refptr<AnimationTimeline> timeline =
8255 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8256 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:488257
jaydasika10d43fc2016-08-18 04:06:048258 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158259 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:288260 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278261 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8262 1.0, TransformOperations(), scale);
8263
jaydasika2411692c2016-03-23 01:56:098264 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:588265 ExecuteCalculateDrawProperties(root_layer);
8266
enne637715732015-07-07 02:05:268267 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
8268 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:508269 EXPECT_FLOAT_EQ(
8270 3.f,
8271 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268272 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588273
sunxdf468675e2016-06-30 23:56:188274 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8275 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8276 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:588277
[email protected]18e69652014-06-13 12:50:588278 // Changing page-scale would affect ideal_contents_scale and
8279 // maximum_animation_contents_scale.
8280
8281 float page_scale_factor = 3.f;
8282 float device_scale_factor = 1.0f;
8283 std::vector<LayerImpl*> render_surface_layer_list;
8284 gfx::Size device_viewport_size =
8285 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8286 root_layer->bounds().height() * device_scale_factor);
8287 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388288 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:588289
8290 inputs.page_scale_factor = page_scale_factor;
8291 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:118292 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:578293 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:588294
enne637715732015-07-07 02:05:268295 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
8296 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588297 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268298 9.f,
ajuma1d4026a32016-06-14 13:18:508299 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268300 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588301
sunxdf468675e2016-06-30 23:56:188302 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8303 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8304 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:588305
[email protected]18e69652014-06-13 12:50:588306 // Changing device-scale would affect ideal_contents_scale and
8307 // maximum_animation_contents_scale.
8308
8309 device_scale_factor = 4.0f;
8310 inputs.device_scale_factor = device_scale_factor;
8311 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:098312 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:578313 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:588314
enne637715732015-07-07 02:05:268315 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
8316 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588317 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268318 36.f,
ajuma1d4026a32016-06-14 13:18:508319 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:268320 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588321
sunxdf468675e2016-06-30 23:56:188322 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8323 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8324 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
8325}
8326
8327TEST_F(LayerTreeHostCommonTest, AnimationScales) {
8328 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188329 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018330 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188331 settings.layer_transforms_should_scale_layer_contents = true;
8332 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228333 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188334
8335 std::unique_ptr<LayerImpl> root =
8336 LayerImpl::Create(host_impl.active_tree(), 1);
8337 LayerImpl* root_layer = root.get();
8338 std::unique_ptr<LayerImpl> child1 =
8339 LayerImpl::Create(host_impl.active_tree(), 2);
8340 LayerImpl* child1_layer = child1.get();
8341 std::unique_ptr<LayerImpl> child2 =
8342 LayerImpl::Create(host_impl.active_tree(), 3);
8343 LayerImpl* child2_layer = child2.get();
8344
8345 root->test_properties()->AddChild(std::move(child1));
8346 child1_layer->test_properties()->AddChild(std::move(child2));
8347 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8348
8349 host_impl.active_tree()->SetElementIdsForTesting();
8350
danakjf78fb272016-07-26 19:06:158351 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:188352 scale_transform_child1.Scale(2, 3);
8353 scale_transform_child2.Scale(4, 5);
8354
danakjf78fb272016-07-26 19:06:158355 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048356 child1_layer->test_properties()->transform = scale_transform_child1;
danakjf78fb272016-07-26 19:06:158357 child1_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048358 child2_layer->test_properties()->transform = scale_transform_child2;
danakjf78fb272016-07-26 19:06:158359 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:188360
8361 TransformOperations scale;
8362 scale.AppendScale(5.f, 8.f, 3.f);
8363
8364 scoped_refptr<AnimationTimeline> timeline =
8365 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8366 host_impl.animation_host()->AddAnimationTimeline(timeline);
8367
8368 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
8369 1.0, TransformOperations(), scale);
8370
sunxdf468675e2016-06-30 23:56:188371 // Correctly computes animation scale when rebuilding property trees.
8372 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8373 ExecuteCalculateDrawProperties(root_layer);
8374
8375 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8376 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
8377 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
8378
8379 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8380 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
8381 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
8382
8383 // Correctly updates animation scale when layer property changes.
jaydasika10d43fc2016-08-18 04:06:048384 child1_layer->test_properties()->transform = gfx::Transform();
jaydasika09e16132016-08-24 21:39:348385 root_layer->layer_tree_impl()
8386 ->property_trees()
8387 ->transform_tree.OnTransformAnimated(gfx::Transform(),
8388 child1_layer->transform_tree_index(),
8389 root_layer->layer_tree_impl());
sunxdf468675e2016-06-30 23:56:188390 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
8391 ExecuteCalculateDrawProperties(root_layer);
8392 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
8393 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
8394
8395 // Do not update animation scale if already updated.
8396 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
8397 child2_layer->transform_tree_index(), 100.f, 100.f);
8398 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
8399 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
8400}
8401
8402TEST_F(LayerTreeHostCommonTest,
8403 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
8404 // Returns empty scale if layer_transforms_should_scale_layer_contents is
8405 // false.
8406 FakeImplTaskRunnerProvider task_runner_provider;
sunxdf468675e2016-06-30 23:56:188407 TestTaskGraphRunner task_graph_runner;
khushalsagarcebe4942016-09-07 23:27:018408 LayerTreeSettings settings = host()->GetSettings();
sunxdf468675e2016-06-30 23:56:188409 settings.layer_transforms_should_scale_layer_contents = false;
8410 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
pimanc44437a22016-10-29 00:09:228411 &task_graph_runner);
sunxdf468675e2016-06-30 23:56:188412
8413 std::unique_ptr<LayerImpl> root =
8414 LayerImpl::Create(host_impl.active_tree(), 1);
8415 LayerImpl* root_layer = root.get();
8416 std::unique_ptr<LayerImpl> child =
8417 LayerImpl::Create(host_impl.active_tree(), 2);
8418 LayerImpl* child_layer = child.get();
8419
8420 root->test_properties()->AddChild(std::move(child));
8421 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
8422
8423 host_impl.active_tree()->SetElementIdsForTesting();
8424
danakjf78fb272016-07-26 19:06:158425 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:188426 scale_transform_child.Scale(4, 5);
8427
danakjf78fb272016-07-26 19:06:158428 root_layer->SetBounds(gfx::Size(1, 1));
jaydasika10d43fc2016-08-18 04:06:048429 child_layer->test_properties()->transform = scale_transform_child;
danakjf78fb272016-07-26 19:06:158430 child_layer->SetBounds(gfx::Size(1, 1));
8431
sunxdf468675e2016-06-30 23:56:188432 TransformOperations scale;
8433 scale.AppendScale(5.f, 8.f, 3.f);
8434
8435 scoped_refptr<AnimationTimeline> timeline =
8436 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8437 host_impl.animation_host()->AddAnimationTimeline(timeline);
8438
8439 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
8440 1.0, TransformOperations(), scale);
8441
sunxdf468675e2016-06-30 23:56:188442 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
8443 ExecuteCalculateDrawProperties(root_layer);
8444
8445 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
8446 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
8447
8448 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
8449 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:588450}
8451
danakjf6069db2014-09-13 00:46:478452TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598453 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148454 LayerImpl* clip = AddChild<LayerImpl>(root);
8455 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:478456
danakjf78fb272016-07-26 19:06:158457 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:148458 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158459 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:478460 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158461 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:148462 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158463 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:478464
8465 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:148466 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:148467 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakjf78fb272016-07-26 19:06:158468 root, device_viewport_size, gfx::Transform(),
ajuma0adb5902016-04-28 16:32:388469 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:478470 inputs.device_scale_factor = 2.f;
8471 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:298472 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:578473 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478474
8475 // Layers in the root render surface have their visible content rect clipped
8476 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148477 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478478
8479 // Layers drawing to a child render surface should still have their visible
8480 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148481 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478482}
8483
timav599f4359d2014-12-05 00:12:228484TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168485 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:568486 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:228487 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
timav599f4359d2014-12-05 00:12:228488
8489 // Set two layers: the root layer clips it's child,
8490 // the child draws its content.
8491
8492 gfx::Size root_size = gfx::Size(300, 500);
8493
8494 // Sublayer should be bigger than the root enlarged by bounds_delta.
8495 gfx::Size sublayer_size = gfx::Size(300, 1000);
8496
mdjones2ee41afd2016-10-27 16:50:208497 // Device viewport accomidated the root and the browser controls.
timav599f4359d2014-12-05 00:12:228498 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:228499
miletus8bd08a622015-06-16 18:44:528500 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:598501 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:228502 LayerImpl::Create(host_impl.active_tree(), 1));
8503
jaydasikabf1875a2016-06-28 03:39:598504 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:158505 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:228506 root->SetMasksToBounds(true);
8507
jaydasika89f7b5a2016-06-22 02:08:398508 root->test_properties()->AddChild(
8509 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:228510
jaydasikafc66cfb2016-06-10 04:34:228511 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:158512 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:228513 sublayer->SetDrawsContent(true);
8514
danakj74af409e2016-07-01 00:41:488515 host_impl.active_tree()->BuildPropertyTreesForTesting();
8516
timav599f4359d2014-12-05 00:12:228517 LayerImplList layer_impl_list;
8518 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388519 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:228520
sunxdb365de02016-04-28 20:32:578521 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438522 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228523
8524 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578525 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228526
8527 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8528 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438529 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228530}
8531
ajumadd2802e72015-06-30 20:28:298532TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318533 scoped_refptr<Layer> root = Layer::Create();
8534 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8535 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8536 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8537 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298538
8539 root->AddChild(inner_viewport_container_layer);
8540 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8541 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8542 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8543
8544 inner_viewport_scroll_layer->SetScrollClipLayerId(
8545 inner_viewport_container_layer->id());
8546 outer_viewport_scroll_layer->SetScrollClipLayerId(
8547 outer_viewport_container_layer->id());
8548
8549 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8550 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8551
8552 host()->SetRootLayer(root);
khushalsagar86928f92016-08-17 21:49:058553 host()->GetLayerTree()->RegisterViewportLayers(
8554 nullptr, root, inner_viewport_scroll_layer, outer_viewport_scroll_layer);
ajumadd2802e72015-06-30 20:28:298555
loyso0940d412016-03-14 01:30:318556 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8557 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298558
8559 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8560 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8561
8562 LayerPositionConstraint fixed_to_right;
8563 fixed_to_right.set_is_fixed_position(true);
8564 fixed_to_right.set_is_fixed_to_right_edge(true);
8565
8566 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8567 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8568
jaydasika6ed869662016-09-21 14:29:598569 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298570
8571 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8572 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8573 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8574
8575 LayerPositionConstraint fixed_to_left;
8576 fixed_to_left.set_is_fixed_position(true);
8577 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8578
jaydasika6ed869662016-09-21 14:29:598579 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298580 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8581 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8582
8583 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8584
jaydasika6ed869662016-09-21 14:29:598585 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ajumadd2802e72015-06-30 20:28:298586 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8587 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8588}
8589
vollick7d83b452015-02-24 20:18:068590TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
sunxd713aedbd2016-08-10 22:22:148591 host_impl()->CreatePendingTree();
8592 std::unique_ptr<LayerImpl> pending_root =
8593 LayerImpl::Create(host_impl()->pending_tree(), 1);
8594 LayerImpl* root = pending_root.get();
8595 host_impl()->pending_tree()->SetRootLayerForTesting(std::move(pending_root));
8596 std::unique_ptr<LayerImpl> animated_ptr =
8597 LayerImpl::Create(host_impl()->pending_tree(), 2);
8598 LayerImpl* animated = animated_ptr.get();
8599 root->test_properties()->AddChild(std::move(animated_ptr));
vollick7d83b452015-02-24 20:18:068600
sunxd713aedbd2016-08-10 22:22:148601 animated->SetDrawsContent(true);
8602 host_impl()->pending_tree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:278603
danakjf78fb272016-07-26 19:06:158604 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:068605 root->SetMasksToBounds(true);
sunxd713aedbd2016-08-10 22:22:148606 root->test_properties()->force_render_surface = true;
8607 animated->test_properties()->opacity = 0.f;
danakjf78fb272016-07-26 19:06:158608 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:068609
sunxd713aedbd2016-08-10 22:22:148610 AddOpacityTransitionToElementWithPlayer(
8611 animated->element_id(), timeline_impl(), 10.0, 0.f, 1.f, false);
8612 animated->test_properties()->opacity_can_animate = true;
8613 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:598614 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
vollick7d83b452015-02-24 20:18:068615
sunxd713aedbd2016-08-10 22:22:148616 EXPECT_FALSE(animated->visible_layer_rect().IsEmpty());
vollick7d83b452015-02-24 20:18:068617}
8618
ajumaa92fdc12015-03-31 22:47:418619TEST_F(LayerTreeHostCommonTest,
8620 VisibleContentRectForAnimatedLayerWithSingularTransform) {
sunxd713aedbd2016-08-10 22:22:148621 LayerImpl* root = root_layer_for_testing();
8622 LayerImpl* clip = AddChild<LayerImpl>(root);
8623 LayerImpl* animated = AddChild<LayerImpl>(clip);
8624 LayerImpl* surface = AddChild<LayerImpl>(animated);
8625 LayerImpl* descendant_of_animation = AddChild<LayerImpl>(surface);
ajumaa92fdc12015-03-31 22:47:418626
sunxd713aedbd2016-08-10 22:22:148627 SetElementIdsForTesting();
ajumaa92fdc12015-03-31 22:47:418628
sunxd713aedbd2016-08-10 22:22:148629 animated->SetDrawsContent(true);
8630 surface->SetDrawsContent(true);
8631 descendant_of_animation->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:278632
ajumaa92fdc12015-03-31 22:47:418633 gfx::Transform uninvertible_matrix;
8634 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8635
danakjf78fb272016-07-26 19:06:158636 root->SetBounds(gfx::Size(100, 100));
8637 clip->SetBounds(gfx::Size(10, 10));
8638 clip->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:048639 animated->test_properties()->transform = uninvertible_matrix;
danakjf78fb272016-07-26 19:06:158640 animated->SetBounds(gfx::Size(120, 120));
8641 surface->SetBounds(gfx::Size(100, 100));
sunxd713aedbd2016-08-10 22:22:148642 surface->test_properties()->force_render_surface = true;
danakjf78fb272016-07-26 19:06:158643 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:418644
8645 TransformOperations start_transform_operations;
8646 start_transform_operations.AppendMatrix(uninvertible_matrix);
8647 TransformOperations end_transform_operations;
8648
sunxd713aedbd2016-08-10 22:22:148649 AddAnimatedTransformToElementWithPlayer(
8650 animated->element_id(), timeline_impl(), 10.0, start_transform_operations,
8651 end_transform_operations);
jaydasika6ed869662016-09-21 14:29:598652 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root);
ajumaa92fdc12015-03-31 22:47:418653
8654 // The animated layer has a singular transform and maps to a non-empty rect in
8655 // clipped target space, so is treated as fully visible.
sunxd713aedbd2016-08-10 22:22:148656 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418657
8658 // The singular transform on |animated| is flattened when inherited by
8659 // |surface|, and this happens to make it invertible.
sunxd713aedbd2016-08-10 22:22:148660 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect());
8661 EXPECT_EQ(gfx::Rect(2, 2), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418662
8663 gfx::Transform zero_matrix;
8664 zero_matrix.Scale3d(0.f, 0.f, 0.f);
jaydasika09e16132016-08-24 21:39:348665 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated(
8666 zero_matrix, animated->transform_tree_index(), root->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:598667 // While computing visible rects by combining clips in screen space, we set
8668 // the entire layer as visible if the screen space transform is singular. This
8669 // is not always true when we combine clips in target space because if the
8670 // intersection of combined_clip in taret space with layer_rect projected to
8671 // target space is empty, we set it to an empty rect.
8672 bool skip_verify_visible_rect_calculations = true;
8673 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(
8674 root, skip_verify_visible_rect_calculations);
ajumaa92fdc12015-03-31 22:47:418675
8676 // The animated layer maps to the empty rect in clipped target space, so is
8677 // treated as having an empty visible rect.
sunxd713aedbd2016-08-10 22:22:148678 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418679
jaydasika6ed869662016-09-21 14:29:598680 // The animated layer will be treated as fully visible when we combine clips
8681 // in screen space.
8682 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
8683 root->layer_tree_impl()->property_trees(), animated);
8684 EXPECT_EQ(gfx::Rect(120, 120), visible_rect);
8685
ajumaa92fdc12015-03-31 22:47:418686 // This time, flattening does not make |animated|'s transform invertible. This
8687 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348688 // |surface| and layers that draw into it as having empty visible rect.
sunxd713aedbd2016-08-10 22:22:148689 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect());
8690 EXPECT_EQ(gfx::Rect(), descendant_of_animation->visible_layer_rect());
ajumaa92fdc12015-03-31 22:47:418691}
8692
ajuma20384bf2016-07-22 13:26:158693// Verify that having animated opacity but current opacity 1 still creates
8694// a render surface.
8695TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
8696 LayerImpl* root = root_layer_for_testing();
8697 LayerImpl* child = AddChild<LayerImpl>(root);
8698 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:158699
danakjf78fb272016-07-26 19:06:158700 root->SetBounds(gfx::Size(50, 50));
8701 child->SetBounds(gfx::Size(50, 50));
8702 child->SetDrawsContent(true);
8703 grandchild->SetBounds(gfx::Size(50, 50));
8704 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:158705
8706 SetElementIdsForTesting();
8707 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
8708 10.0, 1.f, 0.2f, false);
8709 ExecuteCalculateDrawProperties(root);
8710
8711 EXPECT_EQ(1.f, child->Opacity());
8712 EXPECT_TRUE(root->has_render_surface());
8713 EXPECT_TRUE(child->has_render_surface());
8714 EXPECT_FALSE(grandchild->has_render_surface());
8715}
8716
enne92f2f6d92015-02-25 23:13:318717// Verify that having an animated filter (but no current filter, as these
8718// are mutually exclusive) correctly creates a render surface.
8719TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598720 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328721 LayerImpl* child = AddChild<LayerImpl>(root);
8722 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318723
danakjf78fb272016-07-26 19:06:158724 root->SetBounds(gfx::Size(50, 50));
8725 child->SetBounds(gfx::Size(50, 50));
8726 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:318727
vollickef2ae922016-06-29 17:54:278728 SetElementIdsForTesting();
8729 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
8730 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:328731 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318732
ennec1332992015-08-24 19:45:098733 EXPECT_TRUE(root->has_render_surface());
8734 EXPECT_TRUE(child->has_render_surface());
8735 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318736
ajumacb2b74432016-07-21 19:11:158737 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8738 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:318739
8740 EXPECT_FALSE(root->FilterIsAnimating());
8741 EXPECT_TRUE(child->FilterIsAnimating());
8742 EXPECT_FALSE(grandchild->FilterIsAnimating());
8743}
8744
ajuma315a4782015-07-24 21:16:348745// Verify that having a filter animation with a delayed start time creates a
8746// render surface.
8747TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:598748 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:328749 LayerImpl* child = AddChild<LayerImpl>(root);
8750 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348751
danakjf78fb272016-07-26 19:06:158752 root->SetBounds(gfx::Size(50, 50));
8753 child->SetBounds(gfx::Size(50, 50));
8754 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:348755
vollickef2ae922016-06-29 17:54:278756 SetElementIdsForTesting();
8757
danakj60bc3bc2016-04-09 00:24:488758 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348759 KeyframedFilterAnimationCurve::Create());
8760 FilterOperations start_filters;
8761 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8762 FilterOperations end_filters;
8763 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8764 curve->AddKeyframe(
8765 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8766 curve->AddKeyframe(FilterKeyframe::Create(
8767 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488768 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308769 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558770 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348771 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348772
vollickef2ae922016-06-29 17:54:278773 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
8774 std::move(animation));
ajuma4711f4b12016-05-16 18:48:328775 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348776
ennec1332992015-08-24 19:45:098777 EXPECT_TRUE(root->has_render_surface());
8778 EXPECT_TRUE(child->has_render_surface());
8779 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348780
ajumacb2b74432016-07-21 19:11:158781 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8782 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:348783
8784 EXPECT_FALSE(root->FilterIsAnimating());
8785 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8786 EXPECT_FALSE(child->FilterIsAnimating());
8787 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8788 EXPECT_FALSE(grandchild->FilterIsAnimating());
8789 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8790}
8791
vollick0120eb22015-03-02 03:07:348792// Ensures that the property tree code accounts for offsets between fixed
8793// position layers and their respective containers.
8794TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:598795 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148796 LayerImpl* child = AddChild<LayerImpl>(root);
8797 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348798
danakjf78fb272016-07-26 19:06:158799 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:348800 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528801 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158802 child->SetPosition(gfx::PointF(1000, 1000));
8803 child->SetBounds(gfx::Size(50, 50));
8804 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8805 grandchild->SetBounds(gfx::Size(50, 50));
8806 grandchild->SetDrawsContent(true);
8807
vollick0120eb22015-03-02 03:07:348808 LayerPositionConstraint constraint;
8809 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528810 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:348811
jaydasika6f972de2016-04-07 16:16:148812 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348813
jaydasika6f972de2016-04-07 16:16:148814 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348815}
8816
ajuma0178b522015-07-02 21:08:418817// Ensures that the property tree code accounts for offsets between fixed
8818// position containers and their transform tree parents, when a fixed position
8819// layer's container is its layer tree parent, but this parent doesn't have its
8820// own transform tree node.
8821TEST_F(LayerTreeHostCommonTest,
8822 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:598823 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148824 LayerImpl* child = AddChild<LayerImpl>(root);
8825 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418826
danakjf78fb272016-07-26 19:06:158827 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:418828 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158829 root->test_properties()->is_container_for_fixed_position_layers = true;
8830 child->SetPosition(gfx::PointF(1000, 1000));
8831 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:528832 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158833 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8834 grandchild->SetBounds(gfx::Size(50, 50));
8835 grandchild->SetDrawsContent(true);
8836
ajuma0178b522015-07-02 21:08:418837 LayerPositionConstraint constraint;
8838 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528839 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:418840
jaydasika6f972de2016-04-07 16:16:148841 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418842
jaydasika6f972de2016-04-07 16:16:148843 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418844}
8845
vollick8c824742015-03-20 22:21:088846TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:598847 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148848 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8849 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088850 gfx::Transform translate_z;
8851 translate_z.Translate3d(0, 0, 10);
8852
danakjf78fb272016-07-26 19:06:158853 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:528854 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088855
danakjf78fb272016-07-26 19:06:158856 frame_clip->SetPosition(gfx::PointF(500, 100));
8857 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:088858 frame_clip->SetMasksToBounds(true);
8859
danakjf78fb272016-07-26 19:06:158860 fixed->SetBounds(gfx::Size(1000, 1000));
8861 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088862
8863 LayerPositionConstraint constraint;
8864 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528865 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:088866
jaydasika6f972de2016-04-07 16:16:148867 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088868
8869 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148870 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088871}
8872
vollick06ca3e832015-03-31 19:37:128873TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:598874 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148875 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8876 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8877 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8878
danakjf78fb272016-07-26 19:06:158879 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:148880 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158881 root->test_properties()->is_container_for_fixed_position_layers = true;
8882 frame_clip->SetPosition(gfx::PointF(500, 100));
8883 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148884 frame_clip->SetMasksToBounds(true);
8885 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158886 scroller->SetBounds(gfx::Size(1000, 1000));
jaydasika6f972de2016-04-07 16:16:148887 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8888 scroller->SetScrollClipLayer(frame_clip->id());
8889 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158890 fixed->SetPosition(gfx::PointF(100, 100));
8891 fixed->SetBounds(gfx::Size(50, 50));
8892 fixed->SetMasksToBounds(true);
8893 fixed->SetDrawsContent(true);
8894 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:128895
8896 LayerPositionConstraint constraint;
8897 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528898 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128899
jaydasika6f972de2016-04-07 16:16:148900 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128901
8902 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148903 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128904}
8905
vollick5057e1e2015-04-17 19:12:328906TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:328907 gfx::Transform translate;
8908 gfx::Transform rotate;
8909
8910 translate.Translate(10, 10);
8911 rotate.Rotate(45);
8912
loyso0940d412016-03-14 01:30:318913 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:158914 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:328915 root->SetIsContainerForFixedPositionLayers(true);
8916
ennea7b43c32015-06-18 20:01:338917 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328918
jaydasika6ed869662016-09-21 14:29:598919 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
ennea7b43c32015-06-18 20:01:338920 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328921
8922 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338923 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328924
8925 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338926 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328927}
8928
ajumab0e0c1c2015-04-23 00:29:238929TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:598930 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148931 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238932
ajumab0e0c1c2015-04-23 00:29:238933 gfx::Transform scale_matrix;
8934 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:238935
danakjf78fb272016-07-26 19:06:158936 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148937 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:048938 child->test_properties()->transform = scale_matrix;
danakjf78fb272016-07-26 19:06:158939 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148940 child->SetDrawsContent(true);
8941
8942 ExecuteCalculateDrawProperties(root);
8943 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238944
jaydasika38be7a822016-04-21 16:07:068945 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238946
jaydasika6f972de2016-04-07 16:16:148947 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8948 ExecuteCalculateDrawProperties(root);
8949 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238950}
8951
ajumaf09db8962015-04-24 21:55:348952TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:598953 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148954 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8955 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348956
ajumaf09db8962015-04-24 21:55:348957 gfx::Transform scale;
8958 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:158959
8960 root->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:048961 scroll_child->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:158962 scroll_child->SetBounds(gfx::Size(40, 40));
8963 scroll_child->SetDrawsContent(true);
8964 scroll_parent->SetBounds(gfx::Size(30, 30));
8965 scroll_parent->SetDrawsContent(true);
8966
8967 scroll_child->test_properties()->scroll_parent = scroll_parent;
8968 scroll_parent->test_properties()->scroll_children =
8969 base::MakeUnique<std::set<LayerImpl*>>();
8970 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:348971
jaydasika6f972de2016-04-07 16:16:148972 ExecuteCalculateDrawProperties(root);
8973 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348974
8975 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148976 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8977 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8978 ExecuteCalculateDrawProperties(root);
8979 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348980}
8981
danakj60bc3bc2016-04-09 00:24:488982static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128983
sunxded58688e2016-01-11 21:01:028984TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8985 // If the layer has a node in effect_tree, the return value of
8986 // num_copy_requests_in_target_subtree() must be equal to the actual number
8987 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8988 // to be the value of its nearest ancestor that owns an effect node and
8989 // greater than or equal to the actual number of copy requests in the
8990 // sub-layer_tree.
8991
loyso0940d412016-03-14 01:30:318992 scoped_refptr<Layer> root = Layer::Create();
8993 scoped_refptr<Layer> child1 = Layer::Create();
8994 scoped_refptr<Layer> child2 = Layer::Create();
8995 scoped_refptr<Layer> grandchild = Layer::Create();
8996 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028997
8998 root->AddChild(child1);
8999 root->AddChild(child2);
9000 child1->AddChild(grandchild);
9001 grandchild->AddChild(greatgrandchild);
9002 host()->SetRootLayer(root);
9003
9004 child1->RequestCopyOfOutput(
9005 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
9006 greatgrandchild->RequestCopyOfOutput(
9007 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
9008 child2->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:599009 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029010
9011 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
9012 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
9013 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
9014 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
9015 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
9016}
9017
vollick2175fae82015-04-27 21:18:129018TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:319019 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:329020 FakeContentLayerClient client;
9021 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:129022 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:319023 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:129024 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:319025 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:259026 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:319027 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:159028
9029 root->SetBounds(gfx::Size(100, 100));
9030 child->SetBounds(gfx::Size(10, 10));
9031 grandchild->SetBounds(gfx::Size(10, 10));
9032 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129033
9034 root->AddChild(child);
9035 child->AddChild(grandchild);
9036 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:339037 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:089038 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:279039
vollick2175fae82015-04-27 21:18:129040 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599041 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149042 const LayerList* update_list = GetUpdateLayerList();
9043 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129044
9045 // Now we will reset the visible rect from property trees for the grandchild,
9046 // and we will configure |child| in several ways that should force the subtree
9047 // to be skipped. The visible content rect for |grandchild| should, therefore,
9048 // remain empty.
vollick2175fae82015-04-27 21:18:129049 gfx::Transform singular;
9050 singular.matrix().set(0, 0, 0);
9051
9052 child->SetTransform(singular);
jaydasika6ed869662016-09-21 14:29:599053 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149054 update_list = GetUpdateLayerList();
9055 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
danakjf78fb272016-07-26 19:06:159056 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:129057
9058 child->SetHideLayerAndSubtree(true);
jaydasika6ed869662016-09-21 14:29:599059 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149060 update_list = GetUpdateLayerList();
9061 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129062 child->SetHideLayerAndSubtree(false);
9063
ajuma315a4782015-07-24 21:16:349064 gfx::Transform zero_z_scale;
9065 zero_z_scale.Scale3d(1, 1, 0);
9066 child->SetTransform(zero_z_scale);
9067
9068 // Add a transform animation with a start delay. Now, even though |child| has
9069 // a singular transform, the subtree should still get processed.
9070 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:489071 std::unique_ptr<Animation> animation = Animation::Create(
9072 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:309073 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:559074 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:349075 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:279076 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
9077 std::move(animation));
jaydasika6ed869662016-09-21 14:29:599078 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149079 update_list = GetUpdateLayerList();
9080 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:349081
vollickef2ae922016-06-29 17:54:279082 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
9083 animation_id);
danakjf78fb272016-07-26 19:06:159084 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:129085 child->SetOpacity(0.f);
jaydasika6ed869662016-09-21 14:29:599086 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149087 update_list = GetUpdateLayerList();
9088 EXPECT_FALSE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129089
9090 // Now, even though child has zero opacity, we will configure |grandchild| and
9091 // |greatgrandchild| in several ways that should force the subtree to be
9092 // processed anyhow.
jaydasika86654512016-01-27 17:05:079093 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:129094 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
jaydasika6ed869662016-09-21 14:29:599095 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149096 update_list = GetUpdateLayerList();
9097 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
ajuma315a4782015-07-24 21:16:349098
9099 // Add an opacity animation with a start delay.
9100 animation_id = 1;
9101 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:489102 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:309103 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559104 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:349105 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:279106 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
9107 std::move(animation));
jaydasika6ed869662016-09-21 14:29:599108 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxd713aedbd2016-08-10 22:22:149109 update_list = GetUpdateLayerList();
9110 EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
vollick2175fae82015-04-27 21:18:129111}
9112
sunxd71aea3e2016-04-01 23:48:059113TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:169114 FakeImplTaskRunnerProvider task_runner_provider;
danakjcf610582015-06-16 22:48:569115 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:229116 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
vollick2175fae82015-04-27 21:18:129117
danakj60bc3bc2016-04-09 00:24:489118 std::unique_ptr<LayerImpl> root =
9119 LayerImpl::Create(host_impl.active_tree(), 1);
9120 std::unique_ptr<LayerImpl> child =
9121 LayerImpl::Create(host_impl.active_tree(), 2);
9122 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:129123 LayerImpl::Create(host_impl.active_tree(), 3);
9124
danakj60bc3bc2016-04-09 00:24:489125 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:259126 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:129127
danakjf78fb272016-07-26 19:06:159128 root->SetBounds(gfx::Size(100, 100));
9129 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129130 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159131 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:129132 grandchild->SetDrawsContent(true);
9133 greatgrandchild->SetDrawsContent(true);
9134
jaydasika2411692c2016-03-23 01:56:099135 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:129136 LayerImpl* child_ptr = child.get();
9137 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:129138
jaydasika89f7b5a2016-06-22 02:08:399139 child->test_properties()->AddChild(std::move(grandchild));
9140 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:599141 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:129142
vollickef2ae922016-06-29 17:54:279143 host_impl.active_tree()->SetElementIdsForTesting();
9144
vollick2175fae82015-04-27 21:18:129145 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599146 // ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059147 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129148
9149 // Now we will reset the visible rect from property trees for the grandchild,
9150 // and we will configure |child| in several ways that should force the subtree
9151 // to be skipped. The visible content rect for |grandchild| should, therefore,
9152 // remain empty.
weiliangcc97575c2016-03-03 18:34:279153 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:059154
vollick2175fae82015-04-27 21:18:129155 gfx::Transform singular;
9156 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:059157 // This line is used to make the results of skipping and not skipping layers
9158 // different.
9159 singular.matrix().set(0, 1, 1);
9160
9161 gfx::Transform rotate;
9162 rotate.Rotate(90);
9163
9164 gfx::Transform rotate_back_and_translate;
9165 rotate_back_and_translate.RotateAboutYAxis(180);
9166 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:129167
jaydasika10d43fc2016-08-18 04:06:049168 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059169 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599170 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279171 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049172 child_ptr->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129173
jaydasika5121caa82016-05-05 15:43:359174 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika6ed869662016-09-21 14:29:599175 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279176 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359177 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129178
jaydasikab5bc1a22016-08-24 02:59:059179 child_ptr->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated(
9180 0.f, child_ptr->effect_tree_index(), child_ptr->layer_tree_impl());
jaydasika6ed869662016-09-21 14:29:599181 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279182 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:189183 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:129184
jaydasika10d43fc2016-08-18 04:06:049185 root_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059186 // Force transform tree to have a node for child, so that ancestor's
9187 // invertible transform can be tested.
jaydasika10d43fc2016-08-18 04:06:049188 child_ptr->test_properties()->transform = rotate;
sunxd71aea3e2016-04-01 23:48:059189 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599190 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059191 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049192 root_ptr->test_properties()->transform = gfx::Transform();
9193 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:059194
jaydasikaab317e02016-06-01 00:53:189195 root_ptr->test_properties()->opacity = 0.f;
9196 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:059197 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599198 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059199 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:189200 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:059201
jaydasikaab317e02016-06-01 00:53:189202 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:129203 // Now, even though child has zero opacity, we will configure |grandchild| and
9204 // |greatgrandchild| in several ways that should force the subtree to be
9205 // processed anyhow.
ajumae6f541b2016-05-31 16:50:509206 grandchild_ptr->test_properties()->copy_requests.push_back(
9207 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:099208 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599209 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
weiliangcc97575c2016-03-03 18:34:279210 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:509211
9212 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:189213 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:059214
9215 // A double sided render surface with backface visible should not be skipped
9216 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9217 child_ptr->SetHasRenderSurface(true);
jaydasika6b5a32bf2016-04-22 21:56:369218 child_ptr->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049219 child_ptr->test_properties()->transform = rotate_back_and_translate;
sunxd71aea3e2016-04-01 23:48:059220 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599221 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059222 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
jaydasika10d43fc2016-08-18 04:06:049223 child_ptr->test_properties()->transform = gfx::Transform();
sunxd71aea3e2016-04-01 23:48:059224
danakj60bc3bc2016-04-09 00:24:489225 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059226 KeyframedTransformAnimationCurve::Create());
9227 TransformOperations start;
9228 start.AppendTranslate(1.f, 2.f, 3.f);
9229 gfx::Transform transform;
9230 transform.Scale3d(1.0, 2.0, 3.0);
9231 TransformOperations operation;
9232 operation.AppendMatrix(transform);
9233 curve->AddKeyframe(
9234 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9235 curve->AddKeyframe(TransformKeyframe::Create(
9236 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:489237 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:059238 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9239 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089240 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
9241 player.get());
loysobb507792016-10-04 05:31:029242 player->AddAnimation(std::move(transform_animation));
sunxd71aea3e2016-04-01 23:48:059243 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9244 child_ptr->SetScrollClipLayer(root_ptr->id());
jaydasika10d43fc2016-08-18 04:06:049245 root_ptr->test_properties()->transform = singular;
9246 child_ptr->test_properties()->transform = singular;
sunxd71aea3e2016-04-01 23:48:059247 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599248 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:279249 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:059250
loyso6d6356e2016-11-02 23:41:089251 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
9252 player.get());
sunxd71aea3e2016-04-01 23:48:059253}
9254
jaydasikaf187b06b2016-04-11 23:30:279255TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:599256 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:279257 LayerImpl* child = AddChild<LayerImpl>(root);
9258 LayerImpl* grand_child = AddChild<LayerImpl>(child);
9259
vollickef2ae922016-06-29 17:54:279260 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:279261
9262 gfx::Transform singular;
9263 singular.matrix().set(0, 0, 0);
9264 singular.matrix().set(0, 1, 1);
9265
danakjf78fb272016-07-26 19:06:159266 root->SetBounds(gfx::Size(10, 10));
jaydasika10d43fc2016-08-18 04:06:049267 child->test_properties()->transform = singular;
danakjf78fb272016-07-26 19:06:159268 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:279269 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159270 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:279271 grand_child->SetDrawsContent(true);
9272
danakj25c52c32016-04-12 21:51:089273 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:279274 KeyframedTransformAnimationCurve::Create());
9275 TransformOperations start;
9276 start.AppendTranslate(1.f, 2.f, 3.f);
9277 gfx::Transform transform;
9278 transform.Scale3d(1.0, 2.0, 3.0);
9279 TransformOperations operation;
9280 operation.AppendMatrix(transform);
9281 curve->AddKeyframe(
9282 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9283 curve->AddKeyframe(TransformKeyframe::Create(
9284 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:089285 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:279286 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9287 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089288 host_impl()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279289 grand_child->element_id(), player.get());
loysobb507792016-10-04 05:31:029290 player->AddAnimation(std::move(transform_animation));
jaydasikaf187b06b2016-04-11 23:30:279291
9292 ExecuteCalculateDrawProperties(root);
9293 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
9294 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
9295
loyso6d6356e2016-11-02 23:41:089296 host_impl()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:279297 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:279298}
9299
sunxd71aea3e2016-04-01 23:48:059300TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
9301 FakeImplTaskRunnerProvider task_runner_provider;
sunxd71aea3e2016-04-01 23:48:059302 TestTaskGraphRunner task_graph_runner;
pimanc44437a22016-10-29 00:09:229303 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner);
sunxd71aea3e2016-04-01 23:48:059304
sunxd71aea3e2016-04-01 23:48:059305 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:489306 std::unique_ptr<LayerImpl> root =
9307 LayerImpl::Create(host_impl.pending_tree(), 1);
9308 std::unique_ptr<LayerImpl> child =
9309 LayerImpl::Create(host_impl.pending_tree(), 2);
9310 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:059311 LayerImpl::Create(host_impl.pending_tree(), 3);
9312
danakj60bc3bc2016-04-09 00:24:489313 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:059314 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
9315
danakjf78fb272016-07-26 19:06:159316 root->SetBounds(gfx::Size(100, 100));
9317 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:059318 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159319 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:059320 grandchild->SetDrawsContent(true);
9321 greatgrandchild->SetDrawsContent(true);
9322
sunxd71aea3e2016-04-01 23:48:059323 LayerImpl* root_ptr = root.get();
9324 LayerImpl* grandchild_ptr = grandchild.get();
9325
jaydasika89f7b5a2016-06-22 02:08:399326 child->test_properties()->AddChild(std::move(grandchild));
9327 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:059328
jaydasikabf1875a2016-06-28 03:39:599329 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:279330 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:059331
9332 // Check the non-skipped case.
jaydasika6ed869662016-09-21 14:29:599333 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059334 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9335
danakj60bc3bc2016-04-09 00:24:489336 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:059337 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:499338 std::unique_ptr<TimingFunction> func =
9339 CubicBezierTimingFunction::CreatePreset(
9340 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:059341 curve->AddKeyframe(
9342 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9343 curve->AddKeyframe(
9344 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489345 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059346 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9347 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loyso6d6356e2016-11-02 23:41:089348 host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
9349 player.get());
loysobb507792016-10-04 05:31:029350 player->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189351 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059352 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9353 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika6ed869662016-09-21 14:29:599354 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
sunxd71aea3e2016-04-01 23:48:059355 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9356
loyso6d6356e2016-11-02 23:41:089357 host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
9358 player.get());
vollick2175fae82015-04-27 21:18:129359}
9360
9361TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:599362 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:149363 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129364
danakjf78fb272016-07-26 19:06:159365 root->SetBounds(gfx::Size(100, 100));
9366 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:149367 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129368
jaydasika6f972de2016-04-07 16:16:149369 ExecuteCalculateDrawProperties(root);
9370 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279371 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129372
jaydasika5121caa82016-05-05 15:43:359373 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149374 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9375 ExecuteCalculateDrawProperties(root);
9376 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359377 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129378
9379 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149380 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9381 ExecuteCalculateDrawProperties(root);
9382 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129383 child->SetBounds(gfx::Size(10, 10));
9384
9385 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369386 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129387 rotate.RotateAboutXAxis(180.f);
jaydasika10d43fc2016-08-18 04:06:049388 child->test_properties()->transform = rotate;
jaydasika6f972de2016-04-07 16:16:149389 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9390 ExecuteCalculateDrawProperties(root);
9391 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369392 child->test_properties()->double_sided = true;
jaydasika10d43fc2016-08-18 04:06:049393 child->test_properties()->transform = gfx::Transform();
vollick2175fae82015-04-27 21:18:129394
jaydasikaab317e02016-06-01 00:53:189395 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149396 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9397 ExecuteCalculateDrawProperties(root);
9398 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129399}
9400
jaydasika3d10aa62015-05-06 17:50:449401TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9402 // Ensure that the treewalk in LayerTreeHostCommom::
9403 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319404 scoped_refptr<Layer> root = Layer::Create();
9405 scoped_refptr<Layer> parent = Layer::Create();
9406 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449407
danakjf78fb272016-07-26 19:06:159408 root->SetBounds(gfx::Size(100, 100));
9409 parent->SetBounds(gfx::Size(100, 100));
9410 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:449411 child->SetClipParent(root.get());
9412
danakjf78fb272016-07-26 19:06:159413 root->AddChild(parent);
9414 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:339415 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449416
jaydasika3d10aa62015-05-06 17:50:449417 child->RequestCopyOfOutput(
9418 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029419
jaydasika6ed869662016-09-21 14:29:599420 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029421 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9422
9423 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika6ed869662016-09-21 14:29:599424 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
sunxded58688e2016-01-11 21:01:029425 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449426}
9427
vollick692444f2015-05-20 15:39:149428TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:159429 scoped_refptr<Layer> root = Layer::Create();
9430 root->SetBounds(gfx::Size(800, 800));
9431
vollick692444f2015-05-20 15:39:149432 gfx::Transform translate_z;
9433 translate_z.Translate3d(0, 0, 10);
9434
loyso0940d412016-03-14 01:30:319435 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:159436 child->SetTransform(translate_z);
9437 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:149438
9439 root->AddChild(child);
9440
ennea7b43c32015-06-18 20:01:339441 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149442
jaydasika6ed869662016-09-21 14:29:599443 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149444 EXPECT_NE(-1, child->transform_tree_index());
9445
9446 child->RemoveFromParent();
9447
jaydasika6ed869662016-09-21 14:29:599448 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
vollick692444f2015-05-20 15:39:149449 EXPECT_EQ(-1, child->transform_tree_index());
9450}
9451
jaydasika67d7989e2015-08-06 21:55:349452TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9453 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:599454 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349455 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9456 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9457 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9458 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9459
jaydasika67d7989e2015-08-06 21:55:349460 // This transform should be a significant one so that a transform node is
9461 // formed for it.
9462 gfx::Transform transform1;
9463 transform1.RotateAboutYAxis(45);
9464 transform1.RotateAboutXAxis(30);
9465 // This transform should be a 3d transform as we want the render surface
9466 // to flatten the transform
9467 gfx::Transform transform2;
9468 transform2.Translate3d(10, 10, 10);
9469
danakjf78fb272016-07-26 19:06:159470 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049471 significant_transform->test_properties()->transform = transform1;
danakjf78fb272016-07-26 19:06:159472 significant_transform->SetBounds(gfx::Size(30, 30));
9473 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349474 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159475 layer_clips_subtree->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049476 render_surface->test_properties()->transform = transform2;
danakjf78fb272016-07-26 19:06:159477 render_surface->SetBounds(gfx::Size(30, 30));
9478 render_surface->test_properties()->force_render_surface = true;
9479 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349480 test_layer->SetDrawsContent(true);
9481
jaydasika5237db02016-09-20 01:34:309482 float device_scale_factor = 1.f;
9483 float page_scale_factor = 1.f;
9484 LayerImpl* page_scale_layer = nullptr;
flackre310f292016-10-12 21:09:289485 LayerImpl* inner_viewport_scroll_layer = nullptr;
flackra283bed2016-10-31 14:49:429486 LayerImpl* outer_viewport_scroll_layer = nullptr;
jaydasika5237db02016-09-20 01:34:309487 // Visible rects computed by combining clips in target space and root space
9488 // don't match because of rotation transforms. So, we skip
9489 // verify_visible_rect_calculations.
9490 bool skip_verify_visible_rect_calculations = true;
9491 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
flackre310f292016-10-12 21:09:289492 page_scale_layer, inner_viewport_scroll_layer,
flackra283bed2016-10-31 14:49:429493 outer_viewport_scroll_layer,
jaydasika5237db02016-09-20 01:34:309494 skip_verify_visible_rect_calculations);
jaydasika67d7989e2015-08-06 21:55:349495
ajumae4af47062016-05-24 23:59:049496 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:349497 root->layer_tree_impl()->property_trees()->transform_tree;
9498 TransformNode* transform_node =
9499 transform_tree.Node(significant_transform->transform_tree_index());
9500 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9501
weiliangcc154ce22015-12-09 03:39:269502 EXPECT_TRUE(root->has_render_surface());
9503 EXPECT_FALSE(significant_transform->has_render_surface());
9504 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9505 EXPECT_TRUE(render_surface->has_render_surface());
9506 EXPECT_FALSE(test_layer->has_render_surface());
9507
ajumae4af47062016-05-24 23:59:049508 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:349509 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma259f1e72016-10-24 16:25:389510 EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE);
weiliangcd15784432016-06-07 17:57:339511 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect());
jaydasika5237db02016-09-20 01:34:309512
9513 // Also test the visible rects computed by combining clips in root space.
9514 gfx::Rect visible_rect = draw_property_utils::ComputeLayerVisibleRectDynamic(
9515 root->layer_tree_impl()->property_trees(), test_layer);
9516 EXPECT_EQ(gfx::Rect(30, 20), visible_rect);
jaydasika67d7989e2015-08-06 21:55:349517}
9518
9519TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9520 // Ensure that when parent clip node's transform is an ancestor of current
9521 // clip node's target, clip is 'projected' from parent space to current
9522 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:599523 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:349524 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9525 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9526 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9527
jaydasika67d7989e2015-08-06 21:55:349528 gfx::Transform transform;
9529 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:159530
9531 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049532 clip_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159533 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349534 clip_layer->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049535 target_layer->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159536 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349537 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159538 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:349539 test_layer->SetDrawsContent(true);
9540
jaydasika67d7989e2015-08-06 21:55:349541 ExecuteCalculateDrawProperties(root);
9542
weiliangcc97575c2016-03-03 18:34:279543 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349544}
9545
jaydasika7d5c1ed2015-08-14 14:27:029546TEST_F(LayerTreeHostCommonTest,
9547 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9548 // Ensure clip rect is calculated correctly when render surface has unclipped
9549 // descendants.
jaydasikabf1875a2016-06-28 03:39:599550 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:029551 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9552 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9553 LayerImpl* render_surface =
9554 AddChild<LayerImpl>(between_clip_parent_and_child);
9555 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9556
weiliangcbb2e8642016-03-04 00:24:429557 gfx::Transform translate;
9558 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029559
danakjf78fb272016-07-26 19:06:159560 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:049561 clip_parent->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159562 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:429563 clip_parent->SetMasksToBounds(true);
jaydasika10d43fc2016-08-18 04:06:049564 between_clip_parent_and_child->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159565 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
9566 render_surface->SetBounds(gfx::Size(30, 30));
9567 render_surface->test_properties()->force_render_surface = true;
9568 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:029569 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159570
jaydasika1c0a27d42016-04-28 01:54:569571 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159572 clip_parent->test_properties()->clip_children =
9573 base::MakeUnique<std::set<LayerImpl*>>();
9574 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:029575
9576 ExecuteCalculateDrawProperties(root);
9577
weiliangcbb2e8642016-03-04 00:24:429578 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259579 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569580 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9581 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029582}
9583
jaydasika571dd2cf2015-09-25 20:55:429584TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089585 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9586 // Ensure that the visible layer rect of a descendant of a surface with
9587 // unclipped descendants is computed correctly, when the surface doesn't apply
9588 // a clip.
jaydasikabf1875a2016-06-28 03:39:599589 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:089590 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9591 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9592 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9593 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9594
danakjf78fb272016-07-26 19:06:159595 root->SetBounds(gfx::Size(30, 10));
9596 clip_parent->SetBounds(gfx::Size(30, 30));
9597 render_surface->SetBounds(gfx::Size(10, 15));
9598 render_surface->test_properties()->force_render_surface = true;
9599 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:089600 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159601 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:089602 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159603
jaydasika1c0a27d42016-04-28 01:54:569604 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159605 clip_parent->test_properties()->clip_children =
9606 base::MakeUnique<std::set<LayerImpl*>>();
9607 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:089608
9609 ExecuteCalculateDrawProperties(root);
jaydasika94bebdd2016-09-16 22:11:189610 EXPECT_EQ(gfx::Rect(30, 10), child->visible_layer_rect());
ajuma01734dd02015-10-07 01:22:089611}
9612
9613TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429614 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:599615 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429616 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9617 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9618 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9619 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9620 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9621
danakjf78fb272016-07-26 19:06:159622 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429623 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159624 clip_parent->SetBounds(gfx::Size(30, 30));
9625 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429626 render_surface->SetMasksToBounds(true);
9627 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159628 render_surface->test_properties()->force_render_surface = true;
9629 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429630 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159631 clip_child->SetBounds(gfx::Size(50, 50));
9632 clip_child->SetDrawsContent(true);
9633 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429634 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429635
danakjf78fb272016-07-26 19:06:159636 clip_child->test_properties()->clip_parent = clip_parent;
9637 clip_parent->test_properties()->clip_children =
9638 base::MakeUnique<std::set<LayerImpl*>>();
9639 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:429640
9641 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569642 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9643 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429644 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9645 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9646}
9647
ajumae2b7a5c2015-09-30 21:41:429648TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:599649 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:429650 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9651 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9652 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9653
danakjf78fb272016-07-26 19:06:159654 root->SetBounds(gfx::Size(50, 50));
9655 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429656 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159657 render_surface->SetBounds(gfx::Size(30, 30));
9658 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:429659 render_surface->SetMasksToBounds(true);
9660 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159661 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:429662 clip_child->SetDrawsContent(true);
9663
jaydasika1c0a27d42016-04-28 01:54:569664 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:159665 clip_parent->test_properties()->clip_children =
9666 base::MakeUnique<std::set<LayerImpl*>>();
9667 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:429668
9669 ExecuteCalculateDrawProperties(root);
9670
9671 // The clip child should inherit its clip parent's clipping state, not its
9672 // tree parent's clipping state.
9673 EXPECT_FALSE(clip_parent->is_clipped());
9674 EXPECT_TRUE(render_surface->is_clipped());
9675 EXPECT_FALSE(clip_child->is_clipped());
9676}
9677
jaydasika77a4a072015-10-20 21:47:279678TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9679 // Tests the value of render surface content rect when we have multiple types
9680 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9681 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:599682 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279683 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9684 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9685 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9686 LayerImpl* unclipped_desc_surface2 =
9687 AddChild<LayerImpl>(unclipped_desc_surface);
9688 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9689 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9690
danakjf78fb272016-07-26 19:06:159691 root->SetBounds(gfx::Size(80, 80));
9692 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:279693 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159694 unclipped_surface->SetDrawsContent(true);
9695 unclipped_surface->test_properties()->force_render_surface = true;
9696 clip_parent->SetBounds(gfx::Size(50, 50));
9697 clip_parent->SetMasksToBounds(true);
9698 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279699 unclipped_desc_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159700 unclipped_desc_surface->SetDrawsContent(true);
9701 unclipped_desc_surface->test_properties()->force_render_surface = true;
9702 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
9703 unclipped_desc_surface2->SetDrawsContent(true);
9704 unclipped_desc_surface2->test_properties()->force_render_surface = true;
9705 clip_child->SetBounds(gfx::Size(100, 100));
9706 clipped_surface->SetBounds(gfx::Size(70, 70));
9707 clipped_surface->SetDrawsContent(true);
9708 clipped_surface->test_properties()->force_render_surface = true;
9709
9710 clip_child->test_properties()->clip_parent = clip_parent;
9711 clip_parent->test_properties()->clip_children =
9712 base::MakeUnique<std::set<LayerImpl*>>();
9713 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279714
9715 ExecuteCalculateDrawProperties(root);
9716 EXPECT_EQ(gfx::Rect(50, 50),
9717 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:569718 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:279719 unclipped_desc_surface->render_surface()->content_rect());
9720 EXPECT_EQ(gfx::Rect(50, 50),
9721 unclipped_desc_surface2->render_surface()->content_rect());
9722 EXPECT_EQ(gfx::Rect(50, 50),
9723 clipped_surface->render_surface()->content_rect());
9724}
9725
9726TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9727 // Tests the value of render surface content rect when we have a layer that
9728 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:599729 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:279730 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9731 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9732 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9733 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9734 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9735
jaydasika77a4a072015-10-20 21:47:279736 gfx::Transform translate;
9737 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:159738
jaydasika778cb272016-08-15 19:00:549739 gfx::Transform rotate;
9740 rotate.RotateAboutXAxis(10);
9741
danakjf78fb272016-07-26 19:06:159742 root->SetBounds(gfx::Size(100, 100));
9743 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:279744 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159745 surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049746 surface->test_properties()->transform = rotate;
danakjf78fb272016-07-26 19:06:159747 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:279748 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159749 clip_parent->SetBounds(gfx::Size(50, 50));
jaydasika10d43fc2016-08-18 04:06:049750 unclipped_desc_surface->test_properties()->transform = translate;
danakjf78fb272016-07-26 19:06:159751 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9752 unclipped_desc_surface->SetDrawsContent(true);
9753 unclipped_desc_surface->test_properties()->force_render_surface = true;
9754 clip_child->SetBounds(gfx::Size(100, 100));
9755 clip_child->SetDrawsContent(true);
9756
9757 clip_child->test_properties()->clip_parent = clip_parent;
9758 clip_parent->test_properties()->clip_children =
9759 base::MakeUnique<std::set<LayerImpl*>>();
9760 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:279761
9762 ExecuteCalculateDrawProperties(root);
9763
9764 EXPECT_EQ(gfx::Rect(10, 10),
9765 unclipped_desc_surface->render_surface()->content_rect());
9766}
9767
jaydasika2c8c2872015-10-21 23:28:219768TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:599769 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:219770 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9771 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9772 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9773 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9774 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9775
jaydasika2c8c2872015-10-21 23:28:219776
jaydasika2c8c2872015-10-21 23:28:219777 gfx::Transform scale;
9778 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:159779
9780 root->SetBounds(gfx::Size(100, 100));
jaydasika10d43fc2016-08-18 04:06:049781 surface->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:159782 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:219783 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159784 surface->test_properties()->force_render_surface = true;
9785 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:219786 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159787 clip_parent->SetBounds(gfx::Size(50, 50));
9788 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9789 unclipped_desc_surface->SetDrawsContent(true);
9790 unclipped_desc_surface->test_properties()->force_render_surface = true;
9791 clip_child->SetBounds(gfx::Size(100, 100));
9792 clip_child->SetDrawsContent(true);
9793
9794 clip_child->test_properties()->clip_parent = clip_parent;
9795 clip_parent->test_properties()->clip_children =
9796 base::MakeUnique<std::set<LayerImpl*>>();
9797 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:219798
9799 ExecuteCalculateDrawProperties(root);
9800
9801 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9802}
9803
jaydasika60f85862015-10-01 20:36:149804TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:599805 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:149806 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9807 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9808
jaydasika86654512016-01-27 17:05:079809 gfx::Transform translation;
9810 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:149811
danakjf78fb272016-07-26 19:06:159812 root->SetBounds(gfx::Size(30, 30));
9813 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:149814 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159815 render_surface->test_properties()->force_render_surface = true;
jaydasika10d43fc2016-08-18 04:06:049816 test_layer->test_properties()->transform = translation;
danakjf78fb272016-07-26 19:06:159817 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:149818 test_layer->SetDrawsContent(true);
dtapuskaee0b6982016-01-29 15:14:489819 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
danakjf78fb272016-07-26 19:06:159820 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:149821
9822 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:029823 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
9824 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149825}
9826
jaydasikab874eddc2016-11-02 22:34:289827TEST_F(LayerTreeHostCommonTest, ClipParentDrawsIntoScaledRootSurface) {
9828 LayerImpl* root = root_layer_for_testing();
9829 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9830 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9831 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9832 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9833
9834 root->SetBounds(gfx::Size(100, 100));
9835 clip_layer->SetBounds(gfx::Size(20, 20));
9836 clip_layer->SetMasksToBounds(true);
9837 clip_parent->SetBounds(gfx::Size(50, 50));
9838 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9839 unclipped_desc_surface->SetDrawsContent(true);
9840 unclipped_desc_surface->test_properties()->force_render_surface = true;
9841 clip_child->SetBounds(gfx::Size(100, 100));
9842 clip_child->SetDrawsContent(true);
9843
9844 clip_child->test_properties()->clip_parent = clip_parent;
9845 clip_parent->test_properties()->clip_children =
9846 base::MakeUnique<std::set<LayerImpl*>>();
9847 clip_parent->test_properties()->clip_children->insert(clip_child);
9848
9849 float device_scale_factor = 1.f;
9850 ExecuteCalculateDrawProperties(root, device_scale_factor);
9851 EXPECT_EQ(gfx::Rect(20, 20), clip_child->clip_rect());
9852 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9853
9854 device_scale_factor = 2.f;
9855 ExecuteCalculateDrawProperties(root, device_scale_factor);
9856 EXPECT_EQ(gfx::Rect(40, 40), clip_child->clip_rect());
9857 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9858}
9859
jaydasikae4910fa22015-10-09 00:52:099860TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:599861 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:099862 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9863 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9864 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9865
danakjf78fb272016-07-26 19:06:159866 root->SetBounds(gfx::Size(30, 30));
9867 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:099868 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159869 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099870 render_surface->SetMasksToBounds(true);
9871 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159872 render_surface->test_properties()->force_render_surface = true;
9873 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099874 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:099875
danakjf78fb272016-07-26 19:06:159876 clip_child->test_properties()->clip_parent = clip_parent;
9877 clip_parent->test_properties()->clip_children =
9878 base::MakeUnique<std::set<LayerImpl*>>();
9879 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:099880
9881 ExecuteCalculateDrawProperties(root);
jaydasikab4df4032016-09-13 18:38:499882 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
jaydasikae4910fa22015-10-09 00:52:099883}
9884
jaydasika571dd2cf2015-09-25 20:55:429885TEST_F(LayerTreeHostCommonTest,
9886 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:599887 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429888 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9889 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:159890
9891 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429892 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369893 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159894 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429895 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369896 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159897 render_surface->test_properties()->force_render_surface = true;
9898 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429899 test_layer->SetMasksToBounds(true);
9900 test_layer->SetDrawsContent(true);
9901 ExecuteCalculateDrawProperties(root);
9902
9903 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9904 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9905 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9906}
9907
jaydasikab5504ca2015-12-18 23:41:559908TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9909 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:599910 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:559911 LayerImpl* hidden = AddChild<LayerImpl>(root);
9912 LayerImpl* test = AddChild<LayerImpl>(hidden);
9913
danakjf78fb272016-07-26 19:06:159914 root->SetBounds(gfx::Size(30, 30));
9915 hidden->SetBounds(gfx::Size(30, 30));
9916 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:359917 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:159918 test->SetBounds(gfx::Size(30, 30));
9919 test->test_properties()->force_render_surface = true;
9920
jaydasikab5504ca2015-12-18 23:41:559921 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079922 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559923
jaydasika5121caa82016-05-05 15:43:359924 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559925 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9926 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079927 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559928}
9929
jaydasikac0137282015-10-01 15:50:309930TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:599931 LayerImpl* root = root_layer_for_testing();
jaydasikac0137282015-10-01 15:50:309932 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9933 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9934 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9935
danakjf78fb272016-07-26 19:06:159936 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309937 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159938 render_surface1->SetPosition(gfx::PointF(10, 10));
9939 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309940 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159941 render_surface1->test_properties()->force_render_surface = true;
9942 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309943 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159944 render_surface2->test_properties()->force_render_surface = true;
9945 clip_child->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309946
danakjf78fb272016-07-26 19:06:159947 clip_child->test_properties()->clip_parent = root;
9948 root->test_properties()->clip_children =
9949 base::MakeUnique<std::set<LayerImpl*>>();
9950 root->test_properties()->clip_children->insert(clip_child);
9951
jaydasikac0137282015-10-01 15:50:309952 ExecuteCalculateDrawProperties(root);
9953
9954 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379955 // A clip node is created for every render surface and for layers that have
9956 // local clip. So, here it should be craeted for every layer.
9957 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309958}
9959
ajumadb6216f2c2016-06-07 21:44:059960TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
9961 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599962 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:099963 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509964 child->test_properties()->SetMaskLayer(
9965 LayerImpl::Create(root->layer_tree_impl(), 100));
9966 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:099967
jaydasika224bca02015-12-18 02:37:099968 gfx::Transform transform;
9969 transform.Translate(10, 10);
9970
danakjf78fb272016-07-26 19:06:159971 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:099972 root->SetDrawsContent(true);
jaydasika10d43fc2016-08-18 04:06:049973 child->test_properties()->transform = transform;
danakjf78fb272016-07-26 19:06:159974 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:099975 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:159976 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:099977 ExecuteCalculateDrawProperties(root);
9978
ajumadb6216f2c2016-06-07 21:44:059979 // The render surface created for the mask has no contributing content, so the
9980 // mask isn't a drawn RSLL member. This means it has an empty visible rect,
9981 // but its screen space transform can still be computed correctly on-demand.
ajuma1d4026a32016-06-14 13:18:509982 EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member());
9983 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
9984 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059985
9986 // Make the child's render surface have contributing content.
9987 child->SetDrawsContent(true);
9988 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9989 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509990 EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member());
9991 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
9992 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059993
jaydasika224bca02015-12-18 02:37:099994 transform.Translate(10, 10);
jaydasika10d43fc2016-08-18 04:06:049995 child->test_properties()->transform = transform;
jaydasika224bca02015-12-18 02:37:099996 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9997 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509998 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
9999 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:0510000}
10001
jaydasikaf62311f2016-04-20 14:38:4510002TEST_F(LayerTreeHostCommonTest,
10003 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:5910004 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:4510005 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
10006 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
10007 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
10008 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:4510009
10010 gfx::Transform scale;
10011 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:1510012
10013 root->SetBounds(gfx::Size(30, 30));
jaydasika10d43fc2016-08-18 04:06:0410014 render_surface1->test_properties()->transform = scale;
danakjf78fb272016-07-26 19:06:1510015 render_surface1->SetBounds(gfx::Size(30, 30));
10016 render_surface1->test_properties()->force_render_surface = true;
10017 between_targets->SetBounds(gfx::Size(30, 30));
10018 render_surface2->SetBounds(gfx::Size(30, 30));
10019 render_surface2->test_properties()->force_render_surface = true;
10020 test_layer->SetBounds(gfx::Size(30, 30));
10021 test_layer->SetDrawsContent(true);
10022
jaydasikab433552b2016-10-26 18:49:4410023 // We want layer between the two targets to create a clip node and effect
jaydasikaf62311f2016-04-20 14:38:4510024 // node but it shouldn't create a render surface.
10025 between_targets->SetMasksToBounds(true);
jaydasikab433552b2016-10-26 18:49:4410026 between_targets->test_properties()->opacity = 0.5f;
jaydasikaf62311f2016-04-20 14:38:4510027
10028 ExecuteCalculateDrawProperties(root);
10029
jaydasikab433552b2016-10-26 18:49:4410030 EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree;
10031 EffectNode* node = tree.Node(render_surface1->effect_tree_index());
jaydasika6be761602016-07-18 20:11:4310032 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:4510033
jaydasikab433552b2016-10-26 18:49:4410034 node = tree.Node(between_targets->effect_tree_index());
jaydasika6be761602016-07-18 20:11:4310035 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:4510036
jaydasikab433552b2016-10-26 18:49:4410037 node = tree.Node(render_surface2->effect_tree_index());
jaydasika6be761602016-07-18 20:11:4310038 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:4510039
10040 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
10041}
10042
jaydasika3c5633d2016-08-25 00:39:2210043TEST_F(LayerTreeHostCommonTest, NoisyTransform) {
10044 LayerImpl* root = root_layer_for_testing();
10045 LayerImpl* render_surface = AddChild<LayerImpl>(root);
10046 LayerImpl* scroll_child = AddChild<LayerImpl>(render_surface);
10047 LayerImpl* scroll_clip = AddChild<LayerImpl>(render_surface);
10048 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_clip);
10049
10050 scroll_child->test_properties()->scroll_parent = scroll_parent;
10051 scroll_parent->test_properties()->scroll_children =
10052 base::MakeUnique<std::set<LayerImpl*>>();
10053 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
10054 scroll_parent->SetScrollClipLayer(scroll_clip->id());
10055
10056 scroll_parent->SetDrawsContent(true);
10057 scroll_child->SetDrawsContent(true);
10058 render_surface->test_properties()->force_render_surface = true;
10059
10060 // A noisy transform that's invertible.
10061 gfx::Transform transform;
10062 transform.matrix().setDouble(0, 0, 6.12323e-17);
10063 transform.matrix().setDouble(0, 2, 1);
10064 transform.matrix().setDouble(2, 2, 6.12323e-17);
10065 transform.matrix().setDouble(2, 0, -1);
10066
10067 scroll_child->test_properties()->transform = transform;
10068 render_surface->test_properties()->transform = transform;
10069
10070 root->SetBounds(gfx::Size(30, 30));
10071 scroll_child->SetBounds(gfx::Size(30, 30));
10072 scroll_parent->SetBounds(gfx::Size(30, 30));
10073 ExecuteCalculateDrawProperties(root);
10074
10075 gfx::Transform expected;
10076 expected.matrix().setDouble(0, 0, 3.749395e-33);
10077 expected.matrix().setDouble(0, 2, 6.12323e-17);
10078 expected.matrix().setDouble(2, 0, -1);
10079 expected.matrix().setDouble(2, 2, 6.12323e-17);
10080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected,
10081 scroll_child->ScreenSpaceTransform());
10082}
10083
jaydasika5160e672015-10-15 15:25:1410084TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:5910085 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:1410086 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:0510087 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:1410088
sunxd71aea3e2016-04-01 23:48:0510089 child->SetDrawsContent(true);
10090 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:1410091
10092 gfx::Transform large_transform;
10093 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
10094 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
10095 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
10096 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
10097
danakjf78fb272016-07-26 19:06:1510098 root->SetBounds(gfx::Size(30, 30));
10099 render_surface1->SetBounds(gfx::Size(30, 30));
10100 render_surface1->test_properties()->force_render_surface = true;
10101
sunxd71aea3e2016-04-01 23:48:0510102 // TODO(sunxd): we make child have no render surface, because if the
10103 // child has one, the large transform applied to child will result in NaNs in
10104 // the draw_transform of the render_surface, thus make draw property updates
10105 // skip the child layer. We need further investigation into this to know
10106 // what exactly happens here.
jaydasika10d43fc2016-08-18 04:06:0410107 child->test_properties()->transform = large_transform;
danakjf78fb272016-07-26 19:06:1510108 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:1410109
10110 ExecuteCalculateDrawProperties(root);
10111
jaydasika5160e672015-10-15 15:25:1410112 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:0510113 render_surface1->render_surface()->DrawableContentRect());
10114
10115 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
10116 std::isnan(child->DrawTransform().matrix().get(0, 0));
10117 EXPECT_TRUE(is_inf_or_nan);
10118
10119 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
10120 std::isnan(child->DrawTransform().matrix().get(1, 1));
10121 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:1410122
danakj59931942016-07-26 22:11:2910123 // The root layer should be in the RenderSurfaceLayerListImpl.
10124 const auto* rsll = render_surface_layer_list_impl();
10125 EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end());
jaydasika5160e672015-10-15 15:25:1410126}
10127
jaydasika8d6efe2e2016-05-17 15:37:2110128TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:2110129 scoped_refptr<Layer> root = Layer::Create();
10130 scoped_refptr<LayerWithForcedDrawsContent> child =
10131 make_scoped_refptr(new LayerWithForcedDrawsContent());
10132 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:2110133 host()->SetRootLayer(root);
10134
danakjf78fb272016-07-26 19:06:1510135 root->SetBounds(gfx::Size(100, 100));
10136 child->SetBounds(gfx::Size(20, 20));
jaydasika6ed869662016-09-21 14:29:5910137 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110138
10139 // Changing the opacity from 1 to non-1 value should trigger rebuild of
10140 // property trees as a new effect node will be created.
10141 child->SetOpacity(0.5f);
10142 PropertyTrees* property_trees = host()->property_trees();
10143 EXPECT_TRUE(property_trees->needs_rebuild);
10144
jaydasika6ed869662016-09-21 14:29:5910145 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110146 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
10147 property_trees->effect_id_to_index_map.end());
10148
10149 // child already has an effect node. Changing its opacity shouldn't trigger
10150 // a property trees rebuild.
10151 child->SetOpacity(0.8f);
10152 property_trees = host()->property_trees();
10153 EXPECT_FALSE(property_trees->needs_rebuild);
10154
jaydasika6ed869662016-09-21 14:29:5910155 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110156 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
10157 property_trees->effect_id_to_index_map.end());
10158
10159 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
10160 // property trees as the effect node may no longer be needed.
10161 child->SetOpacity(1.f);
10162 property_trees = host()->property_trees();
10163 EXPECT_TRUE(property_trees->needs_rebuild);
10164
jaydasika6ed869662016-09-21 14:29:5910165 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika8d6efe2e2016-05-17 15:37:2110166 EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()),
10167 property_trees->effect_id_to_index_map.end());
10168}
10169
jaydasika9cb21c772016-05-10 22:37:0810170TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:0810171 scoped_refptr<Layer> root = Layer::Create();
10172 scoped_refptr<LayerWithForcedDrawsContent> animated =
10173 make_scoped_refptr(new LayerWithForcedDrawsContent());
10174 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:0810175 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:0810176 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:2710177
danakjf78fb272016-07-26 19:06:1510178 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:0810179 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:1510180 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:0810181 animated->SetOpacity(0.f);
10182
10183 scoped_refptr<AnimationPlayer> player =
10184 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
10185 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:2710186
10187 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:0810188
10189 int animation_id = 0;
10190 std::unique_ptr<Animation> animation = Animation::Create(
10191 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
10192 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:5510193 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:0810194 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
10195 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:2710196 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
10197 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:0810198
jaydasika6ed869662016-09-21 14:29:5910199 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika9cb21c772016-05-10 22:37:0810200
khushalsagar86928f92016-08-17 21:49:0510201 EffectTree& tree = root->GetLayerTree()->property_trees()->effect_tree;
jaydasika9cb21c772016-05-10 22:37:0810202 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110203 EXPECT_FALSE(node->is_currently_animating_opacity);
10204 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810205
10206 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:5810207 host()->AnimateLayers(
jaydasika9cb21c772016-05-10 22:37:0810208 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
10209 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110210 EXPECT_TRUE(node->is_currently_animating_opacity);
10211 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810212
10213 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
10214 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:0110215 EXPECT_FALSE(node->is_currently_animating_opacity);
10216 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:0810217}
10218
jaydasika6c3404e92016-05-19 02:40:3610219TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:3610220 scoped_refptr<Layer> root = Layer::Create();
10221 scoped_refptr<LayerWithForcedDrawsContent> animated =
10222 make_scoped_refptr(new LayerWithForcedDrawsContent());
10223 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:3610224 host()->SetRootLayer(root);
xingliu95d9e6b62016-08-18 03:53:0810225 host()->GetLayerTree()->SetElementIdsForTesting();
vollickef2ae922016-06-29 17:54:2710226
danakjf78fb272016-07-26 19:06:1510227 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:3610228 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:1510229 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:3610230
10231 scoped_refptr<AnimationPlayer> player =
10232 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
10233 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:2710234 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:3610235
10236 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
10237 KeyframedTransformAnimationCurve::Create());
10238 TransformOperations start;
10239 start.AppendTranslate(1.f, 2.f, 3.f);
10240 gfx::Transform transform;
10241 transform.Scale3d(1.0, 2.0, 3.0);
10242 TransformOperations operation;
10243 operation.AppendMatrix(transform);
10244 curve->AddKeyframe(
10245 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
10246 curve->AddKeyframe(TransformKeyframe::Create(
10247 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
10248 std::unique_ptr<Animation> animation(
10249 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
10250 animation->set_fill_mode(Animation::FillMode::NONE);
10251 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
10252 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:2710253 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
10254 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:3610255
jaydasika6ed869662016-09-21 14:29:5910256 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
jaydasika6c3404e92016-05-19 02:40:3610257
khushalsagar86928f92016-08-17 21:49:0510258 TransformTree& tree = root->GetLayerTree()->property_trees()->transform_tree;
jaydasika6c3404e92016-05-19 02:40:3610259 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110260 EXPECT_FALSE(node->is_currently_animating);
10261 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610262
10263 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
khushalsagar61567792016-09-17 00:13:5810264 host()->AnimateLayers(
jaydasika6c3404e92016-05-19 02:40:3610265 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
10266 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110267 EXPECT_TRUE(node->is_currently_animating);
10268 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610269
10270 player->AbortAnimations(TargetProperty::TRANSFORM,
10271 false /*needs_completion*/);
10272 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:0110273 EXPECT_FALSE(node->is_currently_animating);
10274 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:3610275}
10276
khushalsagar37694212016-01-15 20:46:4810277TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
10278 LayerTreeHostCommon::ScrollUpdateInfo scroll;
10279 scroll.layer_id = 2;
10280 scroll.scroll_delta = gfx::Vector2d(5, 10);
10281
10282 proto::ScrollUpdateInfo proto;
10283 scroll.ToProtobuf(&proto);
10284 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
10285 new_scroll.FromProtobuf(proto);
10286
10287 EXPECT_EQ(scroll, new_scroll);
10288}
10289
10290TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
10291 ScrollAndScaleSet scroll_and_scale_set;
10292
10293 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
10294 scroll1.layer_id = 1;
10295 scroll1.scroll_delta = gfx::Vector2d(5, 10);
10296 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
10297 scroll2.layer_id = 2;
10298 scroll2.scroll_delta = gfx::Vector2d(1, 5);
10299 scroll_and_scale_set.scrolls.push_back(scroll1);
10300 scroll_and_scale_set.scrolls.push_back(scroll2);
10301
10302 scroll_and_scale_set.page_scale_delta = 0.3f;
10303 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
10304 scroll_and_scale_set.top_controls_delta = 0.9f;
10305
10306 proto::ScrollAndScaleSet proto;
10307 scroll_and_scale_set.ToProtobuf(&proto);
10308 ScrollAndScaleSet new_scroll_and_scale_set;
10309 new_scroll_and_scale_set.FromProtobuf(proto);
10310
10311 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
10312}
10313
sunxdea1df782016-01-28 00:12:3310314TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
10315 // Test the behavior of scroll tree builder
10316 // Topology:
sunxdcfccd1b32016-02-11 00:54:2010317 // +root1(1)[inner_viewport_container_layer]
10318 // +-page_scale_layer
10319 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
10320 // scrollable, inner_viewport_scroll_layer]
10321 // +------child6(6)[kScrollbarScrolling]
10322 // +--------grand_child10(10)[kScrollbarScrolling]
10323 // +----parent3(3)
10324 // +------child7(7)[scrollable]
10325 // +------child8(8)[scroll_parent=7]
10326 // +--------grand_child11(11)[scrollable]
10327 // +----parent4(4)
10328 // +------child9(9)
10329 // +--------grand_child12(12)
10330 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:3310331 //
10332 // Expected scroll tree topology:
10333 // +property_tree_root---owner:-1
10334 // +--root---owner:1, id:1
10335 // +----node---owner:2, id:2
10336 // +------node---owner:6, id:3
10337 // +----node---owner:7, id:4
10338 // +------node---owner:11, id:5
10339 // +----node---owner:5, id:6
10340 //
10341 // Extra check:
10342 // scroll_tree_index() of:
10343 // grand_child10:3
10344 // parent3:1
10345 // child8:4
10346 // parent4:1
10347 // child9:1
10348 // grand_child12:1
loyso0940d412016-03-14 01:30:3110349 scoped_refptr<Layer> root1 = Layer::Create();
10350 scoped_refptr<Layer> page_scale_layer = Layer::Create();
10351 scoped_refptr<Layer> parent2 = Layer::Create();
10352 scoped_refptr<Layer> parent3 = Layer::Create();
10353 scoped_refptr<Layer> parent4 = Layer::Create();
10354 scoped_refptr<Layer> parent5 = Layer::Create();
10355 scoped_refptr<Layer> child6 = Layer::Create();
10356 scoped_refptr<Layer> child7 = Layer::Create();
10357 scoped_refptr<Layer> child8 = Layer::Create();
10358 scoped_refptr<Layer> child9 = Layer::Create();
10359 scoped_refptr<Layer> grand_child10 = Layer::Create();
10360 scoped_refptr<Layer> grand_child11 = Layer::Create();
10361 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:3310362
sunxdcfccd1b32016-02-11 00:54:2010363 root1->AddChild(page_scale_layer);
10364 page_scale_layer->AddChild(parent2);
10365 page_scale_layer->AddChild(parent3);
10366 page_scale_layer->AddChild(parent4);
10367 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310368 parent2->AddChild(child6);
10369 parent3->AddChild(child7);
10370 parent3->AddChild(child8);
10371 parent4->AddChild(child9);
10372 child6->AddChild(grand_child10);
10373 child8->AddChild(grand_child11);
10374 child9->AddChild(grand_child12);
10375 host()->SetRootLayer(root1);
10376
10377 parent2->AddMainThreadScrollingReasons(
10378 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:4810379 parent2->AddMainThreadScrollingReasons(
10380 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310381 parent2->SetScrollClipLayerId(root1->id());
10382 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810383 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310384 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:4810385 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310386
sunxdcfccd1b32016-02-11 00:54:2010387 child7->SetScrollClipLayerId(parent3->id());
10388
sunxdea1df782016-01-28 00:12:3310389 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:2010390 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:3310391
10392 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010393 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310394
khushalsagar86928f92016-08-17 21:49:0510395 host()->GetLayerTree()->RegisterViewportLayers(nullptr, page_scale_layer,
10396 parent2, nullptr);
jaydasika6ed869662016-09-21 14:29:5910397 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get());
sunxdea1df782016-01-28 00:12:3310398
10399 const int kInvalidPropertyTreeNodeId = -1;
10400 const int kRootPropertyTreeNodeId = 0;
10401
10402 // Property tree root
ajumae4af47062016-05-24 23:59:0410403 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010404 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010405 property_trees.is_main_thread = true;
10406 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410407 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310408 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10409 property_tree_root->id = kRootPropertyTreeNodeId;
10410 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
10411 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
trchendba8b1502016-07-08 09:47:0110412 property_tree_root->scrollable = false;
10413 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810414 MainThreadScrollingReason::kNotScrollingOnMain;
trchendba8b1502016-07-08 09:47:0110415 property_tree_root->contains_non_fast_scrollable_region = false;
10416 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310417
10418 // The node owned by root1
10419 ScrollNode scroll_root1;
10420 scroll_root1.id = 1;
10421 scroll_root1.owner_id = root1->id();
trchendba8b1502016-07-08 09:47:0110422 scroll_root1.user_scrollable_horizontal = true;
10423 scroll_root1.user_scrollable_vertical = true;
10424 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310425 expected_scroll_tree.Insert(scroll_root1, 0);
10426
10427 // The node owned by parent2
10428 ScrollNode scroll_parent2;
10429 scroll_parent2.id = 2;
10430 scroll_parent2.owner_id = parent2->id();
trchendba8b1502016-07-08 09:47:0110431 scroll_parent2.scrollable = true;
10432 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810433 parent2->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110434 scroll_parent2.scroll_clip_layer_bounds = root1->bounds();
10435 scroll_parent2.bounds = parent2->bounds();
10436 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
10437 scroll_parent2.is_inner_viewport_scroll_layer = true;
10438 scroll_parent2.user_scrollable_horizontal = true;
10439 scroll_parent2.user_scrollable_vertical = true;
10440 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310441 expected_scroll_tree.Insert(scroll_parent2, 1);
10442
10443 // The node owned by child6
10444 ScrollNode scroll_child6;
10445 scroll_child6.id = 3;
10446 scroll_child6.owner_id = child6->id();
trchendba8b1502016-07-08 09:47:0110447 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:4810448 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:0110449 scroll_child6.should_flatten = true;
10450 scroll_child6.user_scrollable_horizontal = true;
10451 scroll_child6.user_scrollable_vertical = true;
10452 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310453 expected_scroll_tree.Insert(scroll_child6, 2);
10454
10455 // The node owned by child7, child7 also owns a transform node
10456 ScrollNode scroll_child7;
10457 scroll_child7.id = 4;
10458 scroll_child7.owner_id = child7->id();
trchendba8b1502016-07-08 09:47:0110459 scroll_child7.scrollable = true;
10460 scroll_child7.scroll_clip_layer_bounds = parent3->bounds();
10461 scroll_child7.bounds = child7->bounds();
10462 scroll_child7.user_scrollable_horizontal = true;
10463 scroll_child7.user_scrollable_vertical = true;
10464 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310465 expected_scroll_tree.Insert(scroll_child7, 1);
10466
10467 // The node owned by grand_child11, grand_child11 also owns a transform node
10468 ScrollNode scroll_grand_child11;
10469 scroll_grand_child11.id = 5;
10470 scroll_grand_child11.owner_id = grand_child11->id();
trchendba8b1502016-07-08 09:47:0110471 scroll_grand_child11.scrollable = true;
10472 scroll_grand_child11.user_scrollable_horizontal = true;
10473 scroll_grand_child11.user_scrollable_vertical = true;
10474 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310475 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10476
10477 // The node owned by parent5
10478 ScrollNode scroll_parent5;
10479 scroll_parent5.id = 8;
10480 scroll_parent5.owner_id = parent5->id();
trchendba8b1502016-07-08 09:47:0110481 scroll_parent5.contains_non_fast_scrollable_region = true;
10482 scroll_parent5.bounds = gfx::Size(10, 10);
10483 scroll_parent5.should_flatten = true;
10484 scroll_parent5.user_scrollable_horizontal = true;
10485 scroll_parent5.user_scrollable_vertical = true;
10486 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310487 expected_scroll_tree.Insert(scroll_parent5, 1);
10488
sunxdc044b11a2016-03-16 16:23:2010489 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10490 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10491 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10492 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310493 expected_scroll_tree.set_needs_update(false);
10494
10495 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10496
10497 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010498 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310499 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10500 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10501 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10502 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10503 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10504 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10505}
10506
[email protected]ba565742012-11-10 09:29:4810507} // namespace
10508} // namespace cc