blob: 09e196eeee3e04820a79eeea76bde37fafe61ef4 [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"
vollick2175fae82015-04-27 21:18:1234#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1635#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2836#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4537#include "cc/test/fake_layer_tree_host_impl.h"
ajumaae0dc2d2015-08-05 21:55:5638#include "cc/test/fake_output_surface.h"
sohan.jyotie3bd6192014-10-13 07:13:5939#include "cc/test/fake_picture_layer.h"
40#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0341#include "cc/test/geometry_test_utils.h"
danakj59931942016-07-26 22:11:2942#include "cc/test/layer_test_common.h"
reveman34b7a1522015-03-23 20:27:4743#include "cc/test/test_task_graph_runner.h"
trchendba8b1502016-07-08 09:47:0144#include "cc/trees/clip_node.h"
ennef6903532015-08-18 05:10:1545#include "cc/trees/draw_property_utils.h"
trchendba8b1502016-07-08 09:47:0146#include "cc/trees/effect_node.h"
[email protected]556fd292013-03-18 08:03:0447#include "cc/trees/layer_tree_impl.h"
danakj59931942016-07-26 22:11:2948#include "cc/trees/property_tree_builder.h"
trchendba8b1502016-07-08 09:47:0149#include "cc/trees/scroll_node.h"
[email protected]556fd292013-03-18 08:03:0450#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1651#include "cc/trees/task_runner_provider.h"
trchendba8b1502016-07-08 09:47:0152#include "cc/trees/transform_node.h"
[email protected]7f0c53db2012-10-02 00:23:1853#include "testing/gtest/include/gtest/gtest.h"
jbroman1c44d5b52016-06-06 21:19:3054#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2055#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3756#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0057#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1458
[email protected]ba565742012-11-10 09:29:4859namespace cc {
[email protected]94f206c12012-08-25 00:09:1460namespace {
61
danakj59931942016-07-26 22:11:2962class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings {
63 public:
64 VerifyTreeCalcsLayerTreeSettings() {
65 verify_transform_tree_calculations = true;
jaydasika853306a2016-07-29 19:28:3466 verify_clip_tree_calculations = true;
danakj59931942016-07-26 22:11:2967 }
68};
69
70class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest {
71 public:
72 LayerTreeHostCommonTestBase()
73 : LayerTestCommon::LayerImplTest(VerifyTreeCalcsLayerTreeSettings()) {}
74 explicit LayerTreeHostCommonTestBase(const LayerTreeSettings& settings)
75 : LayerTestCommon::LayerImplTest(settings) {}
76
77 static void SetScrollOffsetDelta(LayerImpl* layer_impl,
78 const gfx::Vector2dF& delta) {
79 if (layer_impl->layer_tree_impl()
80 ->property_trees()
81 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(),
82 delta))
83 layer_impl->layer_tree_impl()->DidUpdateScrollOffset(
84 layer_impl->id(), layer_impl->transform_tree_index());
85 }
86
87 static float GetMaximumAnimationScale(LayerImpl* layer_impl) {
88 return layer_impl->layer_tree_impl()
89 ->property_trees()
90 ->GetAnimationScales(layer_impl->transform_tree_index(),
91 layer_impl->layer_tree_impl())
92 .maximum_animation_scale;
93 }
94
95 static float GetStartingAnimationScale(LayerImpl* layer_impl) {
96 return layer_impl->layer_tree_impl()
97 ->property_trees()
98 ->GetAnimationScales(layer_impl->transform_tree_index(),
99 layer_impl->layer_tree_impl())
100 .starting_animation_scale;
101 }
102
103 void ExecuteCalculateDrawProperties(Layer* root_layer,
104 float device_scale_factor,
105 float page_scale_factor,
106 Layer* page_scale_layer) {
107 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;
122 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
123 }
124
125 void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
126 float device_scale_factor,
127 float page_scale_factor,
128 LayerImpl* page_scale_layer) {
129 if (device_scale_factor !=
130 root_layer->layer_tree_impl()->device_scale_factor())
131 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
132
133 root_layer->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
134
135 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
136
137 gfx::Size device_viewport_size =
138 gfx::Size(root_layer->bounds().width() * device_scale_factor,
139 root_layer->bounds().height() * device_scale_factor);
140
141 render_surface_layer_list_impl_.reset(new LayerImplList);
142
143 // We are probably not testing what is intended if the root_layer bounds are
144 // empty.
145 DCHECK(!root_layer->bounds().IsEmpty());
146 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
147 root_layer, device_viewport_size,
148 render_surface_layer_list_impl_.get());
149 inputs.device_scale_factor = device_scale_factor;
150 inputs.page_scale_factor = page_scale_factor;
151 inputs.page_scale_layer = page_scale_layer;
152 inputs.can_adjust_raster_scales = true;
153
154 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
155 }
156
157 template <class LayerType>
158 void ExecuteCalculateDrawProperties(LayerType* root_layer) {
159 LayerType* page_scale_application_layer = nullptr;
160 ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f,
161 page_scale_application_layer);
162 }
163
164 template <class LayerType>
165 void ExecuteCalculateDrawProperties(LayerType* root_layer,
166 float device_scale_factor) {
167 LayerType* page_scale_application_layer = nullptr;
168 ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f,
169 page_scale_application_layer);
170 }
171
172 void ExecuteCalculateDrawPropertiesWithPropertyTrees(Layer* root_layer) {
173 DCHECK(root_layer->layer_tree_host());
174 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer);
175
176 bool can_render_to_separate_surface = true;
177
178 const Layer* page_scale_layer =
179 root_layer->layer_tree_host()->page_scale_layer();
180 Layer* inner_viewport_scroll_layer =
181 root_layer->layer_tree_host()->inner_viewport_scroll_layer();
182 Layer* outer_viewport_scroll_layer =
183 root_layer->layer_tree_host()->outer_viewport_scroll_layer();
184 const Layer* overscroll_elasticity_layer =
185 root_layer->layer_tree_host()->overscroll_elasticity_layer();
186 gfx::Vector2dF elastic_overscroll =
187 root_layer->layer_tree_host()->elastic_overscroll();
188 float page_scale_factor = 1.f;
189 float device_scale_factor = 1.f;
190 gfx::Size device_viewport_size =
191 gfx::Size(root_layer->bounds().width() * device_scale_factor,
192 root_layer->bounds().height() * device_scale_factor);
193 PropertyTrees* property_trees =
194 root_layer->layer_tree_host()->property_trees();
195 update_layer_list_.clear();
196 PropertyTreeBuilder::BuildPropertyTrees(
197 root_layer, page_scale_layer, inner_viewport_scroll_layer,
198 outer_viewport_scroll_layer, overscroll_elasticity_layer,
199 elastic_overscroll, page_scale_factor, device_scale_factor,
200 gfx::Rect(device_viewport_size), gfx::Transform(), property_trees);
201 draw_property_utils::UpdatePropertyTrees(property_trees,
202 can_render_to_separate_surface);
203 draw_property_utils::FindLayersThatNeedUpdates(
204 root_layer->layer_tree_host(), property_trees->transform_tree,
205 property_trees->effect_tree, &update_layer_list_);
206 draw_property_utils::ComputeVisibleRectsForTesting(
207 property_trees, can_render_to_separate_surface, &update_layer_list_);
208 }
209
210 void ExecuteCalculateDrawPropertiesWithPropertyTrees(LayerImpl* root_layer) {
211 DCHECK(root_layer->layer_tree_impl());
212 PropertyTreeBuilder::PreCalculateMetaInformationForTesting(root_layer);
213
214 bool can_render_to_separate_surface = true;
215
216 LayerImpl* page_scale_layer = nullptr;
217 LayerImpl* inner_viewport_scroll_layer =
218 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
219 LayerImpl* outer_viewport_scroll_layer =
220 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
221 LayerImpl* overscroll_elasticity_layer =
222 root_layer->layer_tree_impl()->OverscrollElasticityLayer();
223 gfx::Vector2dF elastic_overscroll =
224 root_layer->layer_tree_impl()->elastic_overscroll()->Current(
225 root_layer->layer_tree_impl()->IsActiveTree());
226 float page_scale_factor = 1.f;
227 float device_scale_factor = 1.f;
228 gfx::Size device_viewport_size =
229 gfx::Size(root_layer->bounds().width() * device_scale_factor,
230 root_layer->bounds().height() * device_scale_factor);
231 update_layer_list_impl_.reset(new LayerImplList);
232 root_layer->layer_tree_impl()->BuildLayerListForTesting();
233 draw_property_utils::BuildPropertyTreesAndComputeVisibleRects(
234 root_layer, page_scale_layer, inner_viewport_scroll_layer,
235 outer_viewport_scroll_layer, overscroll_elasticity_layer,
236 elastic_overscroll, page_scale_factor, device_scale_factor,
237 gfx::Rect(device_viewport_size), gfx::Transform(),
238 can_render_to_separate_surface,
239 root_layer->layer_tree_impl()->property_trees(),
240 update_layer_list_impl_.get());
241 }
242
243 void ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(
244 LayerImpl* root_layer) {
245 gfx::Size device_viewport_size =
246 gfx::Size(root_layer->bounds().width(), root_layer->bounds().height());
247 render_surface_layer_list_impl_.reset(new LayerImplList);
248
249 DCHECK(!root_layer->bounds().IsEmpty());
250 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
251 root_layer, device_viewport_size,
252 render_surface_layer_list_impl_.get());
253 inputs.can_adjust_raster_scales = true;
254 inputs.can_render_to_separate_surface = false;
255
256 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
257 }
258
259 bool UpdateLayerListImplContains(int id) const {
260 for (auto* layer : *update_layer_list_impl_) {
261 if (layer->id() == id)
262 return true;
263 }
264 return false;
265 }
266
267 bool UpdateLayerListContains(int id) const {
268 for (const auto& layer : update_layer_list_) {
269 if (layer->id() == id)
270 return true;
271 }
272 return false;
273 }
274
275 const LayerImplList* render_surface_layer_list_impl() const {
276 return render_surface_layer_list_impl_.get();
277 }
278 const LayerImplList* update_layer_list_impl() const {
279 return update_layer_list_impl_.get();
280 }
281 const LayerList& update_layer_list() const { return update_layer_list_; }
282
283 private:
284 std::unique_ptr<std::vector<LayerImpl*>> render_surface_layer_list_impl_;
285 LayerList update_layer_list_;
286 std::unique_ptr<LayerImplList> update_layer_list_impl_;
287};
288
289class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
290 public testing::Test {};
291
[email protected]96baf3e2012-10-22 23:09:55292class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:32293 public:
loyso0940d412016-03-14 01:30:31294 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:14295
danakj59931942016-07-26 22:11:29296 bool DrawsContent() const override { return true; }
[email protected]d58499a2012-10-09 22:27:47297
[email protected]fb661802013-03-25 01:59:32298 private:
dcheng716bedf2014-10-21 09:51:08299 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:14300};
301
danakj59931942016-07-26 22:11:29302class LayerTreeSettingsScaleContent : public VerifyTreeCalcsLayerTreeSettings {
enne637715732015-07-07 02:05:26303 public:
304 LayerTreeSettingsScaleContent() {
305 layer_transforms_should_scale_layer_contents = true;
enne637715732015-07-07 02:05:26306 }
307};
308
danakj59931942016-07-26 22:11:29309class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTestBase,
310 public testing::Test {
enne637715732015-07-07 02:05:26311 public:
312 LayerTreeHostCommonScalingTest()
danakj59931942016-07-26 22:11:29313 : LayerTreeHostCommonTestBase(LayerTreeSettingsScaleContent()) {}
enne637715732015-07-07 02:05:26314};
315
weiliangc6da32862016-04-20 16:40:11316class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
317 public:
318 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
319
320 LayerImpl* TestVisibleRectAndDrawableContentRect(
321 const gfx::Rect& target_rect,
322 const gfx::Transform& layer_transform,
323 const gfx::Rect& layer_rect) {
jaydasikabf1875a2016-06-28 03:39:59324 LayerImpl* root = root_layer_for_testing();
weiliangc6da32862016-04-20 16:40:11325 LayerImpl* target = AddChild<LayerImpl>(root);
326 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
327
328 root->SetDrawsContent(true);
329 target->SetDrawsContent(true);
330 target->SetMasksToBounds(true);
331 drawing_layer->SetDrawsContent(true);
332
danakje4fa7b72016-07-25 22:00:06333 root->SetBounds(gfx::Size(500, 500));
334 root->test_properties()->force_render_surface = true;
335 target->SetPosition(gfx::PointF(target_rect.origin()));
336 target->SetBounds(target_rect.size());
337 target->test_properties()->force_render_surface = true;
338 drawing_layer->SetTransform(layer_transform);
339 drawing_layer->SetPosition(gfx::PointF(layer_rect.origin()));
340 drawing_layer->SetBounds(layer_rect.size());
341 drawing_layer->test_properties()->should_flatten_transform = false;
weiliangc6da32862016-04-20 16:40:11342
343 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
344 ExecuteCalculateDrawProperties(root);
345
346 return drawing_layer;
347 }
348};
349
[email protected]989386c2013-07-18 21:37:23350TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32351 // Sanity check: For layers positioned at zero, with zero size,
352 // and with identity transforms, then the draw transform,
353 // screen space transform, and the hierarchy passed on to children
354 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14355
jaydasikabf1875a2016-06-28 03:39:59356 LayerImpl* parent = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51357 LayerImpl* child = AddChild<LayerImpl>(parent);
358 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28359
danakje4fa7b72016-07-25 22:00:06360 parent->SetBounds(gfx::Size(100, 100));
[email protected]94f206c12012-08-25 00:09:14361
sunxdfd920f3f2016-04-05 16:17:51362 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14363
danakjf78fb272016-07-26 19:06:15364 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
365 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51366 child->ScreenSpaceTransform());
danakjf78fb272016-07-26 19:06:15367 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51368 grand_child->DrawTransform());
danakjf78fb272016-07-26 19:06:15369 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
sunxdfd920f3f2016-04-05 16:17:51370 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14371}
372
jaydasika322436372015-12-16 23:42:38373TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
374 // Tests that effect tree node gets a valid transform id when a layer
375 // has opacity but doesn't create a render surface.
jaydasikabf1875a2016-06-28 03:39:59376 LayerImpl* parent = root_layer_for_testing();
jaydasika322436372015-12-16 23:42:38377 LayerImpl* child = AddChild<LayerImpl>(parent);
378 child->SetDrawsContent(true);
379
danakje4fa7b72016-07-25 22:00:06380 parent->SetBounds(gfx::Size(100, 100));
381 child->SetPosition(gfx::PointF(10, 10));
382 child->SetBounds(gfx::Size(100, 100));
jaydasikaab317e02016-06-01 00:53:18383 child->test_properties()->opacity = 0.f;
jaydasika322436372015-12-16 23:42:38384 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04385 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38386 parent->layer_tree_impl()->property_trees()->effect_tree;
387 EffectNode* node = effect_tree.Node(child->effect_tree_index());
388 const int transform_tree_size = parent->layer_tree_impl()
389 ->property_trees()
390 ->transform_tree.next_available_id();
trchendba8b1502016-07-08 09:47:01391 EXPECT_LT(node->transform_id, transform_tree_size);
jaydasika322436372015-12-16 23:42:38392}
393
[email protected]989386c2013-07-18 21:37:23394TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
jaydasikabf1875a2016-06-28 03:39:59395 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51396 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14397
jaydasikabaede2d92016-07-20 00:34:32398 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51399 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32400 EffectTree& effect_tree =
401 host_impl()->active_tree()->property_trees()->effect_tree;
enne826452722015-08-18 22:22:31402
danakje4fa7b72016-07-25 22:00:06403 root->SetBounds(gfx::Size(1, 2));
404
405 // Case 1: Setting the bounds of the layer should not affect either the draw
[email protected]fb661802013-03-25 01:59:32406 // transform or the screenspace transform.
danakje4fa7b72016-07-25 22:00:06407 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51408 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31409 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15410 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32411 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31412 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15413 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32414 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14415
danakje4fa7b72016-07-25 22:00:06416 // Case 2: The anchor point by itself (without a layer transform) should have
[email protected]fb661802013-03-25 01:59:32417 // no effect on the transforms.
danakje4fa7b72016-07-25 22:00:06418 layer->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
419 layer->SetBounds(gfx::Size(10, 12));
sunxdfd920f3f2016-04-05 16:17:51420 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
421 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31422 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15423 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32424 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31425 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15426 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32427 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14428
danakje4fa7b72016-07-25 22:00:06429 // Case 3: A change in actual position affects both the draw transform and
[email protected]fb661802013-03-25 01:59:32430 // screen space transform.
431 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05432 position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06433 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51434 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
435 ExecuteCalculateDrawProperties(root);
436 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32437 position_transform,
438 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31439 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27440 position_transform,
jaydasikabaede2d92016-07-20 00:34:32441 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14442
danakje4fa7b72016-07-25 22:00:06443 // Case 4: In the correct sequence of transforms, the layer transform should
444 // pre-multiply the translation-to-center. This is easily tested by using a
[email protected]fb661802013-03-25 01:59:32445 // scale transform, because scale and translation are not commutative.
446 gfx::Transform layer_transform;
447 layer_transform.Scale3d(2.0, 2.0, 1.0);
danakje4fa7b72016-07-25 22:00:06448 layer->SetTransform(layer_transform);
449 layer->test_properties()->transform_origin = gfx::Point3F();
450 layer->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51451 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
452 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31453 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32454 layer_transform,
455 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31456 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32457 layer_transform,
458 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14459
danakje4fa7b72016-07-25 22:00:06460 // Case 5: The layer transform should occur with respect to the anchor point.
[email protected]fb661802013-03-25 01:59:32461 gfx::Transform translation_to_anchor;
462 translation_to_anchor.Translate(5.0, 0.0);
463 gfx::Transform expected_result =
464 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06465 layer->test_properties()->transform_origin = gfx::Point3F(5.f, 0.f, 0.f);
sunxdfd920f3f2016-04-05 16:17:51466 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
467 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31468 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32469 expected_result,
470 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31471 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32472 expected_result,
473 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14474
danakje4fa7b72016-07-25 22:00:06475 // Case 6: Verify that position pre-multiplies the layer transform. The
[email protected]fb661802013-03-25 01:59:32476 // current implementation of CalculateDrawProperties does this implicitly, but
477 // it is still worth testing to detect accidental regressions.
478 expected_result = position_transform * translation_to_anchor *
479 layer_transform * Inverse(translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06480 layer->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51481 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
482 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31483 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32484 expected_result,
485 draw_property_utils::DrawTransform(layer, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31486 EXPECT_TRANSFORMATION_MATRIX_EQ(
jaydasikabaede2d92016-07-20 00:34:32487 expected_result,
488 draw_property_utils::ScreenSpaceTransform(layer, transform_tree));
[email protected]94f206c12012-08-25 00:09:14489}
490
[email protected]989386c2013-07-18 21:37:23491TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13492 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32493 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01494 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32495 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
496 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16497 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32498 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20499
khushalsagarb64b360d2015-10-21 19:25:16500 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45501 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56502 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16503 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56504 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20505
danakj60bc3bc2016-04-09 00:24:48506 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32507 LayerImpl::Create(host_impl.active_tree(), 1));
508 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28509 sublayer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:06510 sublayer->SetBounds(gfx::Size(500, 500));
[email protected]657b24c2013-03-06 09:01:20511
danakj60bc3bc2016-04-09 00:24:48512 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32513 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47514 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
danakje4fa7b72016-07-25 22:00:06515 scroll_layer->SetBounds(gfx::Size(10, 20));
danakj60bc3bc2016-04-09 00:24:48516 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
[email protected]adeda572014-01-31 00:49:47517 LayerImpl::Create(host_impl.active_tree(), 4));
518 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
519
520 scroll_layer->SetScrollClipLayer(clip_layer->id());
521 clip_layer->SetBounds(
522 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
523 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
524 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42525 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32526 gfx::Transform impl_transform;
jaydasika89f7b5a2016-06-22 02:08:39527 scroll_layer->test_properties()->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47528 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
jaydasika89f7b5a2016-06-22 02:08:39529 clip_layer->test_properties()->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42530 scroll_layer_raw_ptr->layer_tree_impl()
531 ->property_trees()
532 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
533 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20534
danakj60bc3bc2016-04-09 00:24:48535 std::unique_ptr<LayerImpl> root(
536 LayerImpl::Create(host_impl.active_tree(), 3));
danakje4fa7b72016-07-25 22:00:06537 root->SetBounds(gfx::Size(3, 4));
jaydasika89f7b5a2016-06-22 02:08:39538 root->test_properties()->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00539 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09540 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:59541 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
[email protected]657b24c2013-03-06 09:01:20542
jaydasikaa534a472016-03-31 01:12:16543 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasikaf419bf72016-06-15 10:21:21544 scroll_layer->test_properties()->parent);
danakjf78fb272016-07-26 19:06:15545 gfx::Transform expected_transform;
[email protected]fb661802013-03-25 01:59:32546 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33547 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16548 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33549 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16550 page_scale * kDeviceScale));
551 expected_transform.Scale(page_scale * kDeviceScale,
552 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32553 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44554 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32555 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10556 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20557
[email protected]fb661802013-03-25 01:59:32558 gfx::Transform arbitrary_translate;
559 const float kTranslateX = 10.6f;
560 const float kTranslateY = 20.6f;
561 arbitrary_translate.Translate(kTranslateX, kTranslateY);
danakje4fa7b72016-07-25 22:00:06562 scroll_layer->SetTransform(arbitrary_translate);
jaydasika2411692c2016-03-23 01:56:09563 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16564 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasikaf419bf72016-06-15 10:21:21565 scroll_layer->test_properties()->parent);
[email protected]fb661802013-03-25 01:59:32566 expected_transform.MakeIdentity();
567 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16568 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
569 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33570 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16571 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
572 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33573 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16574 expected_transform.Scale(page_scale * kDeviceScale,
575 page_scale * kDeviceScale);
576 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
577 sublayer->DrawTransform());
578
579 // Test that page scale is updated even when we don't rebuild property trees.
580 page_scale = 1.888f;
581 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
jaydasikaf419bf72016-06-15 10:21:21582 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(),
583 Layer::INVALID_ID, Layer::INVALID_ID);
jaydasikaa534a472016-03-31 01:12:16584 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
585 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
586 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasikaf419bf72016-06-15 10:21:21587 scroll_layer->test_properties()->parent);
jaydasikaa534a472016-03-31 01:12:16588
589 expected_transform.MakeIdentity();
590 expected_transform.Translate(
591 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
592 sub_layer_screen_position.x() * page_scale *
593 kDeviceScale),
594 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
595 sub_layer_screen_position.y() * page_scale *
596 kDeviceScale));
597 expected_transform.Scale(page_scale * kDeviceScale,
598 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32599 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44600 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20601}
602
[email protected]989386c2013-07-18 21:37:23603TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
jaydasikabf1875a2016-06-28 03:39:59604 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:51605 LayerImpl* parent = AddChild<LayerImpl>(root);
606 LayerImpl* child = AddChild<LayerImpl>(parent);
607 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28608
[email protected]fb661802013-03-25 01:59:32609 // One-time setup of root layer
danakje4fa7b72016-07-25 22:00:06610 root->SetBounds(gfx::Size(1, 2));
enne826452722015-08-18 22:22:31611
jaydasikabaede2d92016-07-20 00:34:32612 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:51613 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:32614 EffectTree& effect_tree =
615 host_impl()->active_tree()->property_trees()->effect_tree;
[email protected]ecc12622012-10-30 20:45:42616
[email protected]fb661802013-03-25 01:59:32617 // Case 1: parent's anchor point should not affect child or grand_child.
danakje4fa7b72016-07-25 22:00:06618 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
619 parent->SetBounds(gfx::Size(10, 12));
620 child->SetBounds(gfx::Size(16, 18));
621 grand_child->SetBounds(gfx::Size(76, 78));
sunxdfd920f3f2016-04-05 16:17:51622 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31623
624 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15625 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32626 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31627 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15628 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32629 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
630 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15631 gfx::Transform(), draw_property_utils::DrawTransform(
632 grand_child, transform_tree, effect_tree));
jaydasikabaede2d92016-07-20 00:34:32633 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:15634 gfx::Transform(),
jaydasikabaede2d92016-07-20 00:34:32635 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14636
[email protected]fb661802013-03-25 01:59:32637 // Case 2: parent's position affects child and grand_child.
638 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05639 parent_position_transform.Translate(0.f, 1.2f);
danakje4fa7b72016-07-25 22:00:06640 parent->SetPosition(gfx::PointF(0.f, 1.2f));
sunxdfd920f3f2016-04-05 16:17:51641 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
642 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31643 EXPECT_TRANSFORMATION_MATRIX_EQ(
644 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32645 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31646 EXPECT_TRANSFORMATION_MATRIX_EQ(
647 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32648 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
649 EXPECT_TRANSFORMATION_MATRIX_EQ(
650 parent_position_transform, draw_property_utils::DrawTransform(
651 grand_child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31652 EXPECT_TRANSFORMATION_MATRIX_EQ(
653 parent_position_transform,
jaydasikabaede2d92016-07-20 00:34:32654 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14655
[email protected]fb661802013-03-25 01:59:32656 // Case 3: parent's local transform affects child and grandchild
657 gfx::Transform parent_layer_transform;
658 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
659 gfx::Transform parent_translation_to_anchor;
660 parent_translation_to_anchor.Translate(2.5, 3.0);
661 gfx::Transform parent_composite_transform =
662 parent_translation_to_anchor * parent_layer_transform *
663 Inverse(parent_translation_to_anchor);
danakje4fa7b72016-07-25 22:00:06664 parent->SetTransform(parent_layer_transform);
665 parent->SetPosition(gfx::PointF());
sunxdfd920f3f2016-04-05 16:17:51666 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
667 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31668 EXPECT_TRANSFORMATION_MATRIX_EQ(
669 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32670 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
enne826452722015-08-18 22:22:31671 EXPECT_TRANSFORMATION_MATRIX_EQ(
672 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32673 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
enne826452722015-08-18 22:22:31674 EXPECT_TRANSFORMATION_MATRIX_EQ(
675 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32676 draw_property_utils::DrawTransform(grand_child, transform_tree,
677 effect_tree));
enne826452722015-08-18 22:22:31678 EXPECT_TRANSFORMATION_MATRIX_EQ(
679 parent_composite_transform,
jaydasikabaede2d92016-07-20 00:34:32680 draw_property_utils::ScreenSpaceTransform(grand_child, transform_tree));
[email protected]94f206c12012-08-25 00:09:14681}
682
[email protected]989386c2013-07-18 21:37:23683TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:59684 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28685 LayerImpl* parent = AddChildToRoot<LayerImpl>();
686 LayerImpl* child = AddChild<LayerImpl>(parent);
687 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]94f206c12012-08-25 00:09:14688
[email protected]fb661802013-03-25 01:59:32689 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05690 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32691 gfx::Transform parent_translation_to_anchor;
692 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44693
[email protected]fb661802013-03-25 01:59:32694 gfx::Transform parent_composite_transform =
695 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39696 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32697 gfx::Vector2dF parent_composite_scale =
698 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
699 1.f);
700 gfx::Transform surface_sublayer_transform;
701 surface_sublayer_transform.Scale(parent_composite_scale.x(),
702 parent_composite_scale.y());
703 gfx::Transform surface_sublayer_composite_transform =
704 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14705
danakje4fa7b72016-07-25 22:00:06706 root->SetBounds(gfx::Size(1, 2));
707 parent->SetTransform(parent_layer_transform);
708 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 30.f, 0.f);
709 parent->SetBounds(gfx::Size(100, 120));
710 child->SetBounds(gfx::Size(16, 18));
711 child->test_properties()->force_render_surface = true;
712 grand_child->SetBounds(gfx::Size(8, 10));
713 grand_child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28714 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14715
[email protected]fb661802013-03-25 01:59:32716 // Render surface should have been created now.
717 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25718 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14719
[email protected]fb661802013-03-25 01:59:32720 // The child layer's draw transform should refer to its new render surface.
721 // The screen-space transform, however, should still refer to the root.
722 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44723 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32724 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10725 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14726
[email protected]fb661802013-03-25 01:59:32727 // Because the grand_child is the only drawable content, the child's render
728 // surface will tighten its bounds to the grand_child. The scale at which the
729 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25730 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
731 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14732
[email protected]fb661802013-03-25 01:59:32733 // The screen space is the same as the target since the child surface draws
734 // into the root.
735 EXPECT_TRANSFORMATION_MATRIX_EQ(
736 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25737 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14738}
739
ajuma51d73f72015-10-19 19:43:58740TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:59741 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:58742 LayerImpl* parent = AddChildToRoot<LayerImpl>();
743 LayerImpl* child = AddChild<LayerImpl>(parent);
744 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma51d73f72015-10-19 19:43:58745
746 gfx::Transform parent_transform;
747 parent_transform.Translate(10.0, 10.0);
748
749 gfx::Transform child_transform;
750 child_transform.Rotate(45.0);
751
danakje4fa7b72016-07-25 22:00:06752 root->SetBounds(gfx::Size(100, 100));
753 parent->SetTransform(parent_transform);
754 parent->SetBounds(gfx::Size(10, 10));
755 child->SetTransform(child_transform);
756 child->SetBounds(gfx::Size(10, 10));
757 child->test_properties()->force_render_surface = true;
758 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
759 grand_child->SetBounds(gfx::Size(20, 20));
760 grand_child->SetDrawsContent(true);
ajuma51d73f72015-10-19 19:43:58761
762 gfx::Transform expected_grand_child_screen_space_transform;
763 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
764 expected_grand_child_screen_space_transform.Rotate(45.0);
765 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
766
767 // First compute draw properties with separate surfaces enabled.
768 ExecuteCalculateDrawProperties(root);
769
770 // The grand child's draw transform should be its offset wrt the child.
771 gfx::Transform expected_grand_child_draw_transform;
772 expected_grand_child_draw_transform.Translate(2.0, 2.0);
773 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44774 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58775 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10776 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58777
778 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
779
780 // With separate surfaces disabled, the grand child's draw transform should be
781 // the same as its screen space transform.
782 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44783 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58784 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10785 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58786}
787
[email protected]989386c2013-07-18 21:37:23788TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
jaydasikabf1875a2016-06-28 03:39:59789 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28790 LayerImpl* parent = AddChildToRoot<LayerImpl>();
791 LayerImpl* child = AddChild<LayerImpl>(parent);
792 LayerImpl* grand_child = AddChild<LayerImpl>(child);
danakj60bc3bc2016-04-09 00:24:48793 std::unique_ptr<LayerImpl> child_replica =
enne25dea3f2015-07-27 16:44:28794 LayerImpl::Create(host_impl()->active_tree(), 100);
[email protected]d600df7d2013-08-03 02:34:28795
[email protected]fb661802013-03-25 01:59:32796 gfx::Transform parent_layer_transform;
797 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
798 gfx::Transform parent_translation_to_anchor;
799 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32800 gfx::Transform parent_composite_transform =
801 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39802 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32803 gfx::Transform replica_layer_transform;
804 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
805 gfx::Vector2dF parent_composite_scale =
806 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
807 1.f);
808 gfx::Transform surface_sublayer_transform;
809 surface_sublayer_transform.Scale(parent_composite_scale.x(),
810 parent_composite_scale.y());
811 gfx::Transform replica_composite_transform =
812 parent_composite_transform * replica_layer_transform *
813 Inverse(surface_sublayer_transform);
[email protected]fb661802013-03-25 01:59:32814
danakje4fa7b72016-07-25 22:00:06815 root->SetBounds(gfx::Size(1, 2));
816 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 3.0f, 0.f);
817 parent->SetTransform(parent_layer_transform);
818 parent->SetBounds(gfx::Size(10, 12));
819 child->SetBounds(gfx::Size(16, 18));
820 child->test_properties()->force_render_surface = true;
821 grand_child->SetPosition(gfx::PointF(-0.5f, -0.5f));
822 grand_child->SetBounds(gfx::Size(1, 1));
823
824 child_replica->SetTransform(replica_layer_transform);
ajuma1d4026a32016-06-14 13:18:50825 child->test_properties()->SetReplicaLayer(std::move(child_replica));
enne25dea3f2015-07-27 16:44:28826
827 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32828
829 // Render surface should have been created now.
830 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25831 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]fb661802013-03-25 01:59:32832
833 EXPECT_TRANSFORMATION_MATRIX_EQ(
834 replica_composite_transform,
weiliangc189c1a12016-04-11 16:16:25835 child->render_target()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32836 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57837 child->render_target()
[email protected]fb661802013-03-25 01:59:32838 ->replica_screen_space_transform());
839}
840
[email protected]989386c2013-07-18 21:37:23841TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32842 // This test creates a more complex tree and verifies it all at once. This
843 // covers the following cases:
844 // - layers that are described w.r.t. a render surface: should have draw
845 // transforms described w.r.t. that surface
846 // - A render surface described w.r.t. an ancestor render surface: should
847 // have a draw transform described w.r.t. that ancestor surface
848 // - Replicas of a render surface are described w.r.t. the replica's
849 // transform around its anchor, along with the surface itself.
850 // - Sanity check on recursion: verify transforms of layers described w.r.t.
851 // a render surface that is described w.r.t. an ancestor render surface.
852 // - verifying that each layer has a reference to the correct render surface
853 // and render target values.
854
jaydasikabf1875a2016-06-28 03:39:59855 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:28856 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36857 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28858 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36859 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28860 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36861 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28862 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36863 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28864 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36865 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28866 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36867 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28868 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36869 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28870 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
871 grand_child_of_rs1->SetDrawsContent(true);
872 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
873 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32874
danakj60bc3bc2016-04-09 00:24:48875 std::unique_ptr<LayerImpl> replica_of_rs1 =
enne25dea3f2015-07-27 16:44:28876 LayerImpl::Create(host_impl()->active_tree(), 101);
danakj60bc3bc2016-04-09 00:24:48877 std::unique_ptr<LayerImpl> replica_of_rs2 =
enne25dea3f2015-07-27 16:44:28878 LayerImpl::Create(host_impl()->active_tree(), 102);
[email protected]d600df7d2013-08-03 02:34:28879
[email protected]fb661802013-03-25 01:59:32880 // In combination with descendant draws content, opacity != 1 forces the layer
881 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18882 render_surface1->test_properties()->opacity = 0.5f;
883 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32884
[email protected]fb661802013-03-25 01:59:32885 // All layers in the tree are initialized with an anchor at .25 and a size of
886 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39887 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32888 gfx::Transform translation_to_anchor;
889 translation_to_anchor.Translate(2.5, 0.0);
890 gfx::Transform layer_transform;
891 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32892 gfx::Transform replica_layer_transform;
893 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
894
895 gfx::Transform A =
896 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32897 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
898 Inverse(translation_to_anchor);
899
900 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39901 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32902 gfx::Transform surface1_sublayer_transform;
903 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
904 surface1_parent_transform_scale.y());
905
906 // SS1 = transform given to the subtree of render_surface1
907 gfx::Transform SS1 = surface1_sublayer_transform;
908 // S1 = transform to move from render_surface1 pixels to the layer space of
909 // the owning layer
910 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
911
912 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39913 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32914 gfx::Transform surface2_sublayer_transform;
915 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
916 surface2_parent_transform_scale.y());
917
918 // SS2 = transform given to the subtree of render_surface2
919 gfx::Transform SS2 = surface2_sublayer_transform;
920 // S2 = transform to move from render_surface2 pixels to the layer space of
921 // the owning layer
922 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
923
danakje4fa7b72016-07-25 22:00:06924 root->SetBounds(gfx::Size(1, 2));
925 parent->test_properties()->transform_origin = gfx::Point3F(2.5f, 0.f, 0.f);
926 parent->SetTransform(layer_transform);
927 parent->SetBounds(gfx::Size(10, 10));
928 render_surface1->test_properties()->transform_origin =
929 gfx::Point3F(2.5f, 0.f, 0.f);
930 render_surface1->SetTransform(layer_transform);
931 render_surface1->SetBounds(gfx::Size(10, 10));
932 render_surface1->test_properties()->force_render_surface = true;
933 render_surface2->test_properties()->transform_origin =
934 gfx::Point3F(2.5f, 0.f, 0.f);
935 render_surface2->SetTransform(layer_transform);
936 render_surface2->SetBounds(gfx::Size(10, 10));
937 render_surface2->test_properties()->force_render_surface = true;
938 child_of_root->test_properties()->transform_origin =
939 gfx::Point3F(2.5f, 0.f, 0.f);
940 child_of_root->SetTransform(layer_transform);
941 child_of_root->SetBounds(gfx::Size(10, 10));
942 child_of_rs1->test_properties()->transform_origin =
943 gfx::Point3F(2.5f, 0.f, 0.f);
944 child_of_rs1->SetTransform(layer_transform);
945 child_of_rs1->SetBounds(gfx::Size(10, 10));
946 child_of_rs2->test_properties()->transform_origin =
947 gfx::Point3F(2.5f, 0.f, 0.f);
948 child_of_rs2->SetTransform(layer_transform);
949 child_of_rs2->SetBounds(gfx::Size(10, 10));
950 grand_child_of_root->test_properties()->transform_origin =
951 gfx::Point3F(2.5f, 0.f, 0.f);
952 grand_child_of_root->SetTransform(layer_transform);
953 grand_child_of_root->SetBounds(gfx::Size(10, 10));
954 grand_child_of_rs1->test_properties()->transform_origin =
955 gfx::Point3F(2.5f, 0.f, 0.f);
956 grand_child_of_rs1->SetTransform(layer_transform);
957 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
958 grand_child_of_rs2->test_properties()->transform_origin =
959 gfx::Point3F(2.5f, 0.f, 0.f);
960 grand_child_of_rs2->SetTransform(layer_transform);
961 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
962 replica_of_rs1->test_properties()->transform_origin =
963 gfx::Point3F(2.5f, 0.f, 0.f);
964 replica_of_rs1->SetTransform(replica_layer_transform);
965 replica_of_rs2->test_properties()->transform_origin =
966 gfx::Point3F(2.5f, 0.f, 0.f);
967 replica_of_rs2->SetTransform(replica_layer_transform);
[email protected]fb661802013-03-25 01:59:32968
jaydasika5017a332016-03-31 01:06:22969 // We need to set parent on replica layers for property tree building.
jaydasikaf419bf72016-06-15 10:21:21970 replica_of_rs1->test_properties()->parent = render_surface1;
971 replica_of_rs2->test_properties()->parent = render_surface2;
ajuma1d4026a32016-06-14 13:18:50972 render_surface1->test_properties()->SetReplicaLayer(
973 std::move(replica_of_rs1));
974 render_surface2->test_properties()->SetReplicaLayer(
975 std::move(replica_of_rs2));
enne25dea3f2015-07-27 16:44:28976 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32977
978 // Only layers that are associated with render surfaces should have an actual
979 // RenderSurface() value.
980 ASSERT_TRUE(root->render_surface());
981 ASSERT_FALSE(child_of_root->render_surface());
982 ASSERT_FALSE(grand_child_of_root->render_surface());
983
984 ASSERT_TRUE(render_surface1->render_surface());
985 ASSERT_FALSE(child_of_rs1->render_surface());
986 ASSERT_FALSE(grand_child_of_rs1->render_surface());
987
988 ASSERT_TRUE(render_surface2->render_surface());
989 ASSERT_FALSE(child_of_rs2->render_surface());
990 ASSERT_FALSE(grand_child_of_rs2->render_surface());
991
992 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25993 EXPECT_EQ(root->render_surface(), parent->render_target());
994 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
995 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32996
weiliangc189c1a12016-04-11 16:16:25997 EXPECT_EQ(render_surface1->render_surface(),
998 render_surface1->render_target());
999 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
1000 EXPECT_EQ(render_surface1->render_surface(),
1001 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:321002
weiliangc189c1a12016-04-11 16:16:251003 EXPECT_EQ(render_surface2->render_surface(),
1004 render_surface2->render_target());
1005 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
1006 EXPECT_EQ(render_surface2->render_surface(),
1007 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:321008
1009 // Verify layer draw transforms note that draw transforms are described with
1010 // respect to the nearest ancestor render surface but screen space transforms
1011 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:441012 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
1013 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:391014 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:441015 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:321016
ajumad9432e32015-11-30 19:43:441017 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
1018 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:391019 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:441020 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:321021
ajumad9432e32015-11-30 19:43:441022 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
1023 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:391024 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:441025 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:321026
1027 // Verify layer screen-space transforms
1028 //
ajumab6aa1c62015-12-01 21:01:101029 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
1030 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
1031 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
1032 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321033
[email protected]baf64d062014-02-16 22:10:391034 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:101035 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:391036 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:101037 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:391038 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:101039 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321040
[email protected]baf64d062014-02-16 22:10:391041 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:101042 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:391043 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:101044 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:391045 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:101046 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321047
1048 // Verify render surface transforms.
1049 //
1050 // Draw transform of render surface 1 is described with respect to root.
1051 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391052 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321053 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391054 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:321055 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391056 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321057 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391058 A * R * S1,
[email protected]fb661802013-03-25 01:59:321059 render_surface1->render_surface()->replica_screen_space_transform());
1060 // Draw transform of render surface 2 is described with respect to render
1061 // surface 1.
1062 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391063 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:321064 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391065 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:321066 render_surface2->render_surface()->replica_draw_transform());
1067 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391068 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:321069 render_surface2->render_surface()->screen_space_transform());
1070 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391071 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:321072 render_surface2->render_surface()->replica_screen_space_transform());
1073
1074 // Sanity check. If these fail there is probably a bug in the test itself. It
1075 // is expected that we correctly set up transforms so that the y-component of
1076 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:101077 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:261078 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101079 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321080 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101081 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321082
[email protected]803f6b52013-09-12 00:51:261083 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:101084 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
1085 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321086 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101087 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321088
[email protected]803f6b52013-09-12 00:51:261089 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:101090 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
1091 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321092 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:101093 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321094}
1095
[email protected]989386c2013-07-18 21:37:231096TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321097 // For layers that flatten their subtree, there should be an orthographic
1098 // projection (for x and y values) in the middle of the transform sequence.
1099 // Note that the way the code is currently implemented, it is not expected to
1100 // use a canonical orthographic projection.
1101
jaydasikabf1875a2016-06-28 03:39:591102 LayerImpl* root = root_layer_for_testing();
enne25dea3f2015-07-27 16:44:281103 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:361104 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:281105 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1106 grand_child->SetDrawsContent(true);
1107 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1108 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321109
1110 gfx::Transform rotation_about_y_axis;
1111 rotation_about_y_axis.RotateAboutYAxis(30.0);
1112
danakje4fa7b72016-07-25 22:00:061113 root->SetBounds(gfx::Size(100, 100));
1114 child->SetTransform(rotation_about_y_axis);
1115 child->SetBounds(gfx::Size(10, 10));
1116 child->test_properties()->force_render_surface = true;
1117 grand_child->SetTransform(rotation_about_y_axis);
1118 grand_child->SetBounds(gfx::Size(10, 10));
1119 great_grand_child->SetBounds(gfx::Size(10, 10));
[email protected]d600df7d2013-08-03 02:34:281120
[email protected]fb661802013-03-25 01:59:321121 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521122 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
1123 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
1124 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
1125 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:321126
1127 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1128 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1129 gfx::Transform expected_grand_child_draw_transform =
1130 rotation_about_y_axis; // draws onto child's render surface
1131 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1132 flattened_rotation_about_y.FlattenTo2d();
1133 gfx::Transform expected_grand_child_screen_space_transform =
1134 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081135 gfx::Transform expected_great_grand_child_draw_transform =
1136 flattened_rotation_about_y;
1137 gfx::Transform expected_great_grand_child_screen_space_transform =
1138 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321139
enne25dea3f2015-07-27 16:44:281140 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321141
1142 // The child's draw transform should have been taken by its surface.
1143 ASSERT_TRUE(child->render_surface());
1144 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1145 child->render_surface()->draw_transform());
1146 EXPECT_TRANSFORMATION_MATRIX_EQ(
1147 expected_child_screen_space_transform,
1148 child->render_surface()->screen_space_transform());
danakje4fa7b72016-07-25 22:00:061149 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321150 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101151 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321152 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441153 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321154 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101155 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081156 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441157 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081158 EXPECT_TRANSFORMATION_MATRIX_EQ(
1159 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101160 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321161}
1162
ajumadbd92cb2015-07-16 13:47:061163TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasikabf1875a2016-06-28 03:39:591164 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:141165 LayerImpl* child = AddChild<LayerImpl>(root);
1166 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061167
1168 gfx::Transform child_transform;
1169 child_transform.Translate(50.0, 50.0);
1170 child_transform.RotateAboutZAxis(30.0);
1171
1172 gfx::Transform grand_child_transform;
1173 grand_child_transform.RotateAboutYAxis(90.0);
1174
danakje4fa7b72016-07-25 22:00:061175 root->SetBounds(gfx::Size(200, 200));
1176 child->SetTransform(child_transform);
1177 child->SetBounds(gfx::Size(10, 10));
1178 grand_child->SetTransform(grand_child_transform);
1179 grand_child->SetBounds(gfx::Size(100, 100));
jaydasikaca2605e2016-04-23 02:52:521180 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141181 grand_child->SetDrawsContent(true);
jaydasika6f972de2016-04-07 16:16:141182 ExecuteCalculateDrawProperties(root);
ajumadbd92cb2015-07-16 13:47:061183
1184 // Mapping grand_child's bounds to target space produces a non-empty rect
1185 // that is fully contained within the target's bounds, so grand_child should
1186 // be considered fully visible.
1187 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141188 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061189}
1190
[email protected]989386c2013-07-18 21:37:231191TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321192 // A layer that is empty in one axis, but not the other, was accidentally
1193 // skipping a necessary translation. Without that translation, the coordinate
1194 // space of the layer's draw transform is incorrect.
1195 //
1196 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1197 // but if that layer becomes a render surface, then its draw transform is
1198 // implicitly inherited by the rest of the subtree, which then is positioned
1199 // incorrectly as a result.
1200
jaydasikabf1875a2016-06-28 03:39:591201 LayerImpl* root = root_layer_for_testing();
ennec1332992015-08-24 19:45:091202 LayerImpl* child = AddChild<LayerImpl>(root);
1203 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1204 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321205
danakje4fa7b72016-07-25 22:00:061206 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:321207 // The child height is zero, but has non-zero width that should be accounted
1208 // for while computing draw transforms.
danakje4fa7b72016-07-25 22:00:061209 child->SetBounds(gfx::Size(10, 0));
1210 child->test_properties()->force_render_surface = true;
1211 grand_child->SetBounds(gfx::Size(10, 10));
ennec1332992015-08-24 19:45:091212 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321213
ennec1332992015-08-24 19:45:091214 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321215 // This is the real test, the rest are sanity checks.
danakje4fa7b72016-07-25 22:00:061216 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:321217 child->render_surface()->draw_transform());
danakje4fa7b72016-07-25 22:00:061218 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1219 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441220 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321221}
1222
jaydasika9bbee9b2016-01-13 00:36:481223TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
jaydasikabf1875a2016-06-28 03:39:591224 LayerImpl* root = root_layer_for_testing();
jaydasika9bbee9b2016-01-13 00:36:481225 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1226 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1227 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1228
jaydasika9bbee9b2016-01-13 00:36:481229 gfx::Transform translate;
1230 translate.Translate3d(5, 5, 5);
danakje4fa7b72016-07-25 22:00:061231
1232 root->SetBounds(gfx::Size(100, 100));
1233 render_surface->SetTransform(translate);
1234 render_surface->SetBounds(gfx::Size(100, 100));
1235 render_surface->test_properties()->force_render_surface = true;
1236 child->SetTransform(translate);
1237 child->SetBounds(gfx::Size(100, 100));
1238 grand_child->SetTransform(translate);
1239 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika9bbee9b2016-01-13 00:36:481240 grand_child->SetDrawsContent(true);
1241
1242 // render_surface will have a sublayer scale because of device scale factor.
1243 float device_scale_factor = 2.0f;
1244 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481245 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381246 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481247 inputs.device_scale_factor = device_scale_factor;
1248 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571249 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481250
1251 // Between grand_child and render_surface, we translate by (10, 10) and scale
1252 // by a factor of 2.
1253 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1254 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1255 expected_translation);
1256}
1257
[email protected]989386c2013-07-18 21:37:231258TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321259 // Transformations applied at the root of the tree should be forwarded
1260 // to child layers instead of applied to the root RenderSurface.
jaydasikabf1875a2016-06-28 03:39:591261 LayerImpl* root = root_layer_for_testing();
enned3f61fb02015-08-18 22:54:391262 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061263
1264 root->SetDrawsContent(true);
1265 root->SetBounds(gfx::Size(20, 20));
enned3f61fb02015-08-18 22:54:391266 child->SetDrawsContent(true);
enned3f61fb02015-08-18 22:54:391267 child->SetScrollClipLayer(root->id());
danakje4fa7b72016-07-25 22:00:061268 child->SetBounds(gfx::Size(20, 20));
[email protected]f224cc92013-06-06 23:23:321269
[email protected]f224cc92013-06-06 23:23:321270 gfx::Transform translate;
1271 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231272 {
enned3f61fb02015-08-18 22:54:391273 LayerImplList render_surface_layer_list_impl;
1274 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381275 root, root->bounds(), translate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321276 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571277 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021278 EXPECT_TRANSFORMATION_MATRIX_EQ(
1279 translate, root->draw_properties().target_space_transform);
1280 EXPECT_TRANSFORMATION_MATRIX_EQ(
1281 translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151282 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021283 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231284 }
[email protected]f224cc92013-06-06 23:23:321285
1286 gfx::Transform scale;
1287 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231288 {
enned3f61fb02015-08-18 22:54:391289 LayerImplList render_surface_layer_list_impl;
1290 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381291 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321292 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571293 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021294 EXPECT_TRANSFORMATION_MATRIX_EQ(
1295 scale, root->draw_properties().target_space_transform);
1296 EXPECT_TRANSFORMATION_MATRIX_EQ(
1297 scale, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151298 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021299 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231300 }
[email protected]f224cc92013-06-06 23:23:321301
1302 gfx::Transform rotate;
1303 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231304 {
enned3f61fb02015-08-18 22:54:391305 LayerImplList render_surface_layer_list_impl;
1306 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381307 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321308 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571309 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021310 EXPECT_TRANSFORMATION_MATRIX_EQ(
1311 rotate, root->draw_properties().target_space_transform);
1312 EXPECT_TRANSFORMATION_MATRIX_EQ(
1313 rotate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151314 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021315 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231316 }
[email protected]f224cc92013-06-06 23:23:321317
1318 gfx::Transform composite;
1319 composite.ConcatTransform(translate);
1320 composite.ConcatTransform(scale);
1321 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231322 {
enned3f61fb02015-08-18 22:54:391323 LayerImplList render_surface_layer_list_impl;
1324 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381325 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321326 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571327 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
weiliangcc3517722016-06-28 22:52:021328 EXPECT_TRANSFORMATION_MATRIX_EQ(
1329 composite, root->draw_properties().target_space_transform);
1330 EXPECT_TRANSFORMATION_MATRIX_EQ(
1331 composite, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151332 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021333 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231334 }
[email protected]f224cc92013-06-06 23:23:321335
[email protected]9781afa2013-07-17 23:15:321336 // Verify it composes correctly with device scale.
1337 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231338
1339 {
enned3f61fb02015-08-18 22:54:391340 LayerImplList render_surface_layer_list_impl;
1341 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381342 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531343 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321344 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571345 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231346 gfx::Transform device_scaled_translate = translate;
1347 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
weiliangcc3517722016-06-28 22:52:021348 EXPECT_TRANSFORMATION_MATRIX_EQ(
1349 device_scaled_translate,
1350 root->draw_properties().target_space_transform);
1351 EXPECT_TRANSFORMATION_MATRIX_EQ(
1352 device_scaled_translate,
1353 child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151354 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021355 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231356 }
[email protected]9781afa2013-07-17 23:15:321357
1358 // Verify it composes correctly with page scale.
1359 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231360
1361 {
enned3f61fb02015-08-18 22:54:391362 LayerImplList render_surface_layer_list_impl;
1363 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381364 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531365 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391366 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321367 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571368 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231369 gfx::Transform page_scaled_translate = translate;
1370 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
weiliangcc3517722016-06-28 22:52:021371 EXPECT_TRANSFORMATION_MATRIX_EQ(
1372 page_scaled_translate, root->draw_properties().target_space_transform);
1373 EXPECT_TRANSFORMATION_MATRIX_EQ(
1374 page_scaled_translate, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151375 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021376 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231377 }
[email protected]9781afa2013-07-17 23:15:321378
[email protected]f224cc92013-06-06 23:23:321379 // Verify that it composes correctly with transforms directly on root layer.
1380 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231381
1382 {
enned3f61fb02015-08-18 22:54:391383 LayerImplList render_surface_layer_list_impl;
1384 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381385 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391386 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571387 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231388 gfx::Transform compositeSquared = composite;
1389 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261390 EXPECT_TRANSFORMATION_MATRIX_EQ(
1391 compositeSquared, root->draw_properties().target_space_transform);
1392 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391393 compositeSquared, child->draw_properties().target_space_transform);
danakjf78fb272016-07-26 19:06:151394 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
weiliangcc3517722016-06-28 22:52:021395 root->render_surface()->draw_transform());
[email protected]989386c2013-07-18 21:37:231396 }
[email protected]f224cc92013-06-06 23:23:321397}
1398
[email protected]989386c2013-07-18 21:37:231399TEST_F(LayerTreeHostCommonTest,
1400 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
danakje4fa7b72016-07-25 22:00:061401 LayerImpl* root = root_layer_for_testing();
enneea850232015-07-27 16:43:121402 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1403 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
danakje4fa7b72016-07-25 22:00:061404
1405 root->SetBounds(gfx::Size(10, 10));
1406 root->SetMasksToBounds(true);
1407 render_surface1->SetBounds(gfx::Size(10, 10));
1408 render_surface1->test_properties()->force_render_surface = true;
enneea850232015-07-27 16:43:121409 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061410 child->SetPosition(gfx::PointF(30.f, 30.f));
1411 child->SetBounds(gfx::Size(10, 10));
1412 ExecuteCalculateDrawProperties(root);
[email protected]d600df7d2013-08-03 02:34:281413
danakje4fa7b72016-07-25 22:00:061414 // The child layer's content is entirely outside the root's clip rect, so
[email protected]fb661802013-03-25 01:59:321415 // the intermediate render surface should not be listed here, even if it was
1416 // forced to be created. Render surfaces without children or visible content
1417 // are unexpected at draw time (e.g. we might try to create a content texture
1418 // of size 0).
danakje4fa7b72016-07-25 22:00:061419 ASSERT_TRUE(root->render_surface());
enneea850232015-07-27 16:43:121420 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321421}
1422
[email protected]989386c2013-07-18 21:37:231423TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
danakje4fa7b72016-07-25 22:00:061424 LayerImpl* root = root_layer_for_testing();
1425 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
enne03b0e9a2015-06-19 00:08:021426 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
[email protected]d600df7d2013-08-03 02:34:281427
danakje4fa7b72016-07-25 22:00:061428 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;
danakje4fa7b72016-07-25 22:00:061431 child->SetBounds(gfx::Size(10, 10));
1432 child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321433
enne03b0e9a2015-06-19 00:08:021434 LayerImplList render_surface_layer_list;
1435 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061436 root, root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531437 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571438 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321439
1440 // Since the layer is transparent, render_surface1->render_surface() should
1441 // not have gotten added anywhere. Also, the drawable content rect should not
1442 // have been extended by the children.
danakje4fa7b72016-07-25 22:00:061443 ASSERT_TRUE(root->render_surface());
1444 EXPECT_EQ(0U, root->render_surface()->layer_list().size());
[email protected]fb661802013-03-25 01:59:321445 EXPECT_EQ(1U, render_surface_layer_list.size());
danakje4fa7b72016-07-25 22:00:061446 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
1447 EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321448}
1449
hendrikwc266f7b2015-08-21 23:41:341450TEST_F(LayerTreeHostCommonTest,
1451 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
danakje4fa7b72016-07-25 22:00:061452 LayerImpl* root = root_layer_for_testing();
1453 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
hendrikwc266f7b2015-08-21 23:41:341454 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
hendrikwc266f7b2015-08-21 23:41:341455
danakje4fa7b72016-07-25 22:00:061456 root->SetBounds(gfx::Size(10, 10));
1457 render_surface1->SetBounds(gfx::Size(10, 10));
1458 render_surface1->test_properties()->force_render_surface = true;
jaydasikaab317e02016-06-01 00:53:181459 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071460 render_surface1->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341461 FilterOperations filters;
1462 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
ajuma50bce7e2016-06-24 20:56:041463 render_surface1->test_properties()->background_filters = filters;
danakje4fa7b72016-07-25 22:00:061464 child->SetBounds(gfx::Size(10, 10));
1465 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341466
jaydasika369c24b2016-04-06 23:44:161467 {
1468 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161469 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061470 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161471 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571472 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161473 EXPECT_EQ(2U, render_surface_layer_list.size());
1474 }
hendrikwc266f7b2015-08-21 23:41:341475 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161476 // shouldn't be skipped and should be drawn.
danakje4fa7b72016-07-25 22:00:061477 ASSERT_TRUE(root->render_surface());
1478 EXPECT_EQ(1U, root->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361479 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
danakje4fa7b72016-07-25 22:00:061480 root->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161481 EffectTree& effect_tree =
danakje4fa7b72016-07-25 22:00:061482 root->layer_tree_impl()->property_trees()->effect_tree;
jaydasika369c24b2016-04-06 23:44:161483 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011484 EXPECT_TRUE(node->is_drawn);
jaydasika369c24b2016-04-06 23:44:161485
danakje4fa7b72016-07-25 22:00:061486 // When root is transparent, the layer should not be drawn.
1487 root->OnOpacityAnimated(0.f);
jaydasika369c24b2016-04-06 23:44:161488 render_surface1->OnOpacityAnimated(1.f);
jaydasika8185d302016-04-14 15:20:061489 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161490 {
1491 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161492 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakje4fa7b72016-07-25 22:00:061493 root, root->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161494 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571495 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161496 }
1497
1498 node = effect_tree.Node(render_surface1->effect_tree_index());
trchendba8b1502016-07-08 09:47:011499 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:061500 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341501}
1502
senorblanco38858c52016-01-20 23:15:001503TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
jaydasikabf1875a2016-06-28 03:39:591504 LayerImpl* root = root_layer_for_testing();
senorblanco38858c52016-01-20 23:15:001505 LayerImpl* parent = AddChild<LayerImpl>(root);
1506 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1507 LayerImpl* child2 = AddChild<LayerImpl>(parent);
senorblanco38858c52016-01-20 23:15:001508
senorblanco38858c52016-01-20 23:15:001509 gfx::Transform scale_matrix;
1510 scale_matrix.Scale(2.0f, 2.0f);
danakje4fa7b72016-07-25 22:00:061511
1512 root->SetBounds(gfx::Size(100, 100));
1513 parent->SetTransform(scale_matrix);
senorblanco38858c52016-01-20 23:15:001514 FilterOperations filters;
1515 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
ajumacb2b74432016-07-21 19:11:151516 parent->test_properties()->filters = filters;
danakje4fa7b72016-07-25 22:00:061517 parent->test_properties()->force_render_surface = true;
1518 child1->SetBounds(gfx::Size(25, 25));
1519 child1->SetDrawsContent(true);
1520 child1->test_properties()->force_render_surface = true;
1521 child2->SetPosition(gfx::PointF(25, 25));
1522 child2->SetBounds(gfx::Size(25, 25));
1523 child2->SetDrawsContent(true);
1524 child2->test_properties()->force_render_surface = true;
senorblanco38858c52016-01-20 23:15:001525
1526 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001527 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381528 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001529 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571530 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001531
1532 ASSERT_TRUE(parent->render_surface());
1533 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1534 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman1c44d5b52016-06-06 21:19:301535
1536 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1537 // blur (-30,-30 110x110), and then scaled by the scale matrix
1538 // (-60,-60 220x220).
1539 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
senorblanco38858c52016-01-20 23:15:001540 parent->render_surface()->DrawableContentRect());
1541}
1542
jbroman1c44d5b52016-06-06 21:19:301543TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
jaydasikabf1875a2016-06-28 03:39:591544 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301545 LayerImpl* child = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:061546
1547 root->SetBounds(gfx::Size(100, 100));
1548 child->SetBounds(gfx::Size(25, 25));
jbroman1c44d5b52016-06-06 21:19:301549 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061550 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301551 FilterOperations filters;
1552 filters.Append(FilterOperation::CreateReferenceFilter(
1553 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151554 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301555 ExecuteCalculateDrawProperties(root);
1556
1557 // The render surface's size should be unaffected by the offset image filter;
1558 // it need only have a drawable content rect large enough to contain the
1559 // contents (at the new offset).
1560 ASSERT_TRUE(child->render_surface());
1561 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1562 child->render_surface()->DrawableContentRect());
1563}
1564
1565TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1566 const float device_scale_factor = 2.0f;
1567
jaydasikabf1875a2016-06-28 03:39:591568 LayerImpl* root = root_layer_for_testing();
jbroman1c44d5b52016-06-06 21:19:301569 LayerImpl* child = AddChild<LayerImpl>(root);
jbroman1c44d5b52016-06-06 21:19:301570
danakje4fa7b72016-07-25 22:00:061571 root->SetBounds(gfx::Size(100, 100));
1572 child->SetBounds(gfx::Size(25, 25));
1573 child->SetDrawsContent(true);
1574 child->test_properties()->force_render_surface = true;
jbroman1c44d5b52016-06-06 21:19:301575
1576 FilterOperations filters;
1577 filters.Append(FilterOperation::CreateReferenceFilter(
1578 SkOffsetImageFilter::Make(50, 50, nullptr)));
ajumacb2b74432016-07-21 19:11:151579 child->test_properties()->filters = filters;
jbroman1c44d5b52016-06-06 21:19:301580
1581 ExecuteCalculateDrawProperties(root, device_scale_factor);
1582
1583 // The render surface's size should be unaffected by the offset image filter;
1584 // it need only have a drawable content rect large enough to contain the
1585 // contents (at the new offset). All coordinates should be scaled by 2,
1586 // corresponding to the device scale factor.
1587 ASSERT_TRUE(child->render_surface());
1588 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1589 child->render_surface()->DrawableContentRect());
1590}
1591
rosca948d29d2014-11-09 10:25:131592TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
danakje4fa7b72016-07-25 22:00:061593 LayerImpl* root = root_layer_for_testing();
1594 LayerImpl* child = AddChild<LayerImpl>(root);
1595
1596 root->SetBounds(gfx::Size(10, 10));
1597 child->SetBounds(gfx::Size(10, 10));
enned5f4ddd2015-08-18 16:50:061598 child->SetDrawsContent(true);
ajuma4c14b252016-07-26 20:10:591599 child->test_properties()->blend_mode = SkXfermode::kMultiply_Mode;
jaydasikaab317e02016-06-01 00:53:181600 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061601 child->test_properties()->force_render_surface = true;
1602 ExecuteCalculateDrawProperties(root);
rosca948d29d2014-11-09 10:25:131603
1604 // Since the child layer has a blend mode other than normal, it should get
1605 // its own render surface. Also, layer's draw_properties should contain the
1606 // default blend mode, since the render surface becomes responsible for
1607 // applying the blend mode.
1608 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291609 EXPECT_EQ(1.0f, child->draw_opacity());
1610 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261611 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131612}
1613
jaydasikafbdb86e2016-01-21 18:57:511614TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
jaydasikabf1875a2016-06-28 03:39:591615 LayerImpl* root = root_layer_for_testing();
jaydasikafbdb86e2016-01-21 18:57:511616 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1617 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1618 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1619
danakje4fa7b72016-07-25 22:00:061620 root->SetBounds(gfx::Size(10, 10));
1621 surface1->SetBounds(gfx::Size(10, 10));
jaydasikafbdb86e2016-01-21 18:57:511622 surface1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181623 surface1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061624 surface1->test_properties()->force_render_surface = true;
1625 not_surface->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:181626 not_surface->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061627 surface2->SetBounds(gfx::Size(10, 10));
1628 surface2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181629 surface2->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061630 surface2->test_properties()->force_render_surface = true;
jaydasikafbdb86e2016-01-21 18:57:511631 ExecuteCalculateDrawProperties(root);
1632
1633 ASSERT_TRUE(surface1->render_surface());
1634 ASSERT_FALSE(not_surface->render_surface());
1635 ASSERT_TRUE(surface2->render_surface());
1636 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1637 // surface2's draw opacity should include the opacity of not-surface and
1638 // itself, but not the opacity of surface1.
1639 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1640}
1641
ajuma51d73f72015-10-19 19:43:581642TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1643 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1644 // the product of all ancestor layer opacties and the layer's own opacity.
1645 // (Rendering will still be incorrect in situations where we really do need
1646 // surfaces to apply opacity, such as when we have overlapping layers with an
1647 // ancestor whose opacity is <1.)
jaydasikabf1875a2016-06-28 03:39:591648 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581649 LayerImpl* parent = AddChild<LayerImpl>(root);
1650 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1651 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1652 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1653 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1654 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1655
danakje4fa7b72016-07-25 22:00:061656 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581657 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061658 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581659 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061660 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581661 child1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181662 child1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061663 child1->test_properties()->force_render_surface = true;
1664 child2->SetBounds(gfx::Size(100, 100));
1665 child2->SetDrawsContent(true);
1666 grand_child->SetBounds(gfx::Size(100, 100));
1667 grand_child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181668 grand_child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061669 grand_child->test_properties()->force_render_surface = true;
1670 leaf_node1->SetBounds(gfx::Size(100, 100));
1671 leaf_node1->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181672 leaf_node1->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:061673 leaf_node2->SetBounds(gfx::Size(100, 100));
1674 leaf_node2->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:181675 leaf_node2->test_properties()->opacity = 0.5f;
ajuma51d73f72015-10-19 19:43:581676
1677 // With surfaces enabled, each layer's draw opacity is the product of layer
1678 // opacities on the path from the layer to its render target, not including
1679 // the opacity of the layer that owns the target surface (since that opacity
1680 // is applied by the surface).
1681 ExecuteCalculateDrawProperties(root);
1682 EXPECT_EQ(1.f, root->draw_opacity());
1683 EXPECT_EQ(1.f, parent->draw_opacity());
1684 EXPECT_EQ(1.f, child1->draw_opacity());
1685 EXPECT_EQ(1.f, child2->draw_opacity());
1686 EXPECT_EQ(1.f, grand_child->draw_opacity());
1687 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1688 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1689
1690 // With surfaces disabled, each layer's draw opacity is the product of layer
1691 // opacities on the path from the layer to the root.
1692 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1693 EXPECT_EQ(1.f, root->draw_opacity());
1694 EXPECT_EQ(1.f, parent->draw_opacity());
1695 EXPECT_EQ(0.5f, child1->draw_opacity());
1696 EXPECT_EQ(1.f, child2->draw_opacity());
1697 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1698 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1699 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1700}
1701
[email protected]989386c2013-07-18 21:37:231702TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
danakje4fa7b72016-07-25 22:00:061703 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:261704 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1705 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261706
danakje4fa7b72016-07-25 22:00:061707 root->SetBounds(gfx::Size(10, 10));
1708 render_surface1->SetBounds(gfx::Size(10, 10));
jaydasika6b5a32bf2016-04-22 21:56:361709 render_surface1->test_properties()->force_render_surface = true;
danakje4fa7b72016-07-25 22:00:061710 child->SetBounds(gfx::Size(10, 10));
1711 child->SetDrawsContent(true);
weiliangceffae0462015-12-08 23:17:261712
[email protected]989386c2013-07-18 21:37:231713 {
danakje4fa7b72016-07-25 22:00:061714 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
[email protected]fb661802013-03-25 01:59:321715
[email protected]989386c2013-07-18 21:37:231716 // The root layer always creates a render surface
danakje4fa7b72016-07-25 22:00:061717 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091718 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231719 }
[email protected]fb661802013-03-25 01:59:321720
[email protected]989386c2013-07-18 21:37:231721 {
jaydasika6b5a32bf2016-04-22 21:56:361722 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261723 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakje4fa7b72016-07-25 22:00:061724 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
1725 EXPECT_TRUE(root->has_render_surface());
ennec1332992015-08-24 19:45:091726 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231727 }
[email protected]fb661802013-03-25 01:59:321728}
1729
ajuma246190a2015-03-11 20:56:031730TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1731 // Render surfaces act as a flattening point for their subtree, so should
1732 // always flatten the target-to-screen space transform seen by descendants.
jaydasikabf1875a2016-06-28 03:39:591733 LayerImpl* root = root_layer_for_testing();
enne1a79c5542015-08-18 19:43:571734 LayerImpl* parent = AddChild<LayerImpl>(root);
1735 LayerImpl* child = AddChild<LayerImpl>(parent);
1736 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1737
ajuma246190a2015-03-11 20:56:031738 gfx::Transform rotation_about_y_axis;
1739 rotation_about_y_axis.RotateAboutYAxis(30.0);
ajuma246190a2015-03-11 20:56:031740
danakje4fa7b72016-07-25 22:00:061741 root->SetBounds(gfx::Size(100, 100));
1742 parent->SetTransform(rotation_about_y_axis);
1743 parent->SetBounds(gfx::Size(10, 10));
1744 parent->test_properties()->force_render_surface = true;
1745 child->SetBounds(gfx::Size(10, 10));
1746 child->SetDrawsContent(true);
1747 grand_child->SetBounds(gfx::Size(10, 10));
1748 grand_child->SetDrawsContent(true);
jaydasikaca2605e2016-04-23 02:52:521749 grand_child->test_properties()->should_flatten_transform = false;
enne1a79c5542015-08-18 19:43:571750 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031751
1752 EXPECT_TRUE(parent->render_surface());
1753 EXPECT_FALSE(child->render_surface());
1754 EXPECT_FALSE(grand_child->render_surface());
1755
danakje4fa7b72016-07-25 22:00:061756 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(), child->DrawTransform());
1757 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
ajumad9432e32015-11-30 19:43:441758 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031759
1760 // The screen-space transform inherited by |child| and |grand_child| should
1761 // have been flattened at their render target. In particular, the fact that
1762 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
danakje4fa7b72016-07-25 22:00:061763 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1764 flattened_rotation_about_y.FlattenTo2d();
ajuma246190a2015-03-11 20:56:031765 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101766 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031767 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101768 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031769}
1770
[email protected]989386c2013-07-18 21:37:231771TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321772 // The entire subtree of layers that are outside the clip rect should be
1773 // culled away, and should not affect the render_surface_layer_list.
1774 //
1775 // The test tree is set up as follows:
1776 // - all layers except the leaf_nodes are forced to be a new render surface
1777 // that have something to draw.
1778 // - parent is a large container layer.
danakje4fa7b72016-07-25 22:00:061779 // - child has MasksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321780 // - grand_child is positioned outside of the child's bounds
1781 // - great_grand_child is also kept outside child's bounds.
1782 //
1783 // In this configuration, grand_child and great_grand_child are completely
1784 // outside the clip rect, and they should never get scheduled on the list of
1785 // render surfaces.
[email protected]fb661802013-03-25 01:59:321786
danakje4fa7b72016-07-25 22:00:061787 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571788 LayerImpl* child = AddChildToRoot<LayerImpl>();
1789 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1790 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281791
danakje4fa7b72016-07-25 22:00:061792 // leaf_node1 ensures that root and child are kept on the
[email protected]fb661802013-03-25 01:59:321793 // render_surface_layer_list, even though grand_child and great_grand_child
1794 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571795 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
weiliangcfb3d5eaa2015-07-28 23:54:571796 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
[email protected]fb661802013-03-25 01:59:321797
danakje4fa7b72016-07-25 22:00:061798 root->SetBounds(gfx::Size(500, 500));
1799 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:321800 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061801 child->test_properties()->force_render_surface = true;
1802 grand_child->SetPosition(gfx::PointF(45.f, 45.f));
1803 grand_child->SetBounds(gfx::Size(10, 10));
1804 great_grand_child->SetBounds(gfx::Size(10, 10));
1805 leaf_node1->SetBounds(gfx::Size(500, 500));
1806 leaf_node1->SetDrawsContent(true);
1807 leaf_node1->SetBounds(gfx::Size(20, 20));
1808 leaf_node2->SetDrawsContent(true);
1809 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321810
weiliangcfb3d5eaa2015-07-28 23:54:571811 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061812 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
weiliangcfb3d5eaa2015-07-28 23:54:571813 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321814}
1815
[email protected]989386c2013-07-18 21:37:231816TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321817 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571818 // of the surface.
[email protected]fb661802013-03-25 01:59:321819
1820 // The test tree is set up as follows:
danakje4fa7b72016-07-25 22:00:061821 // - root is a container layer that masksToBounds=true to cause clipping.
[email protected]fb661802013-03-25 01:59:321822 // - child is a render surface, which has a clip rect set to the bounds of
danakje4fa7b72016-07-25 22:00:061823 // the root.
[email protected]fb661802013-03-25 01:59:321824 // - grand_child is a render surface, and the only visible content in child.
danakje4fa7b72016-07-25 22:00:061825 // It is positioned outside of the clip rect from root.
[email protected]fb661802013-03-25 01:59:321826
1827 // In this configuration, grand_child should be outside the clipped
1828 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571829 // render_surface_layer_list.
1830
danakje4fa7b72016-07-25 22:00:061831 LayerImpl* root = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:571832 LayerImpl* child = AddChildToRoot<LayerImpl>();
1833 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1834 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
[email protected]fb661802013-03-25 01:59:321835
danakje4fa7b72016-07-25 22:00:061836 root->SetMasksToBounds(true);
1837 root->SetBounds(gfx::Size(100, 100));
1838 child->SetBounds(gfx::Size(20, 20));
1839 child->test_properties()->force_render_surface = true;
1840 grand_child->SetPosition(gfx::PointF(200.f, 200.f));
1841 grand_child->SetBounds(gfx::Size(10, 10));
1842 grand_child->test_properties()->force_render_surface = true;
1843 leaf_node->SetBounds(gfx::Size(10, 10));
1844 leaf_node->SetDrawsContent(true);
1845 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321846
weiliangcfb3d5eaa2015-07-28 23:54:571847 // We should cull child and grand_child from the
1848 // render_surface_layer_list.
1849 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
danakje4fa7b72016-07-25 22:00:061850 EXPECT_EQ(root->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321851}
1852
ajumae2b7a5c2015-09-30 21:41:421853TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1854 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321855 // - the layer clips its subtree, e.g. masks to bounds,
1856 // - the layer is clipped by an ancestor that contributes to the same
1857 // render target,
1858 // - a surface is clipped by an ancestor that contributes to the same
1859 // render target.
1860 //
1861 // In particular, for a layer that owns a render surface:
1862 // - the render surface inherits any clip from ancestors, and does NOT
1863 // pass that clipped status to the layer itself.
1864 // - but if the layer itself masks to bounds, it is considered clipped
1865 // and propagates the clip to the subtree.
1866
jaydasikabf1875a2016-06-28 03:39:591867 LayerImpl* root = root_layer_for_testing();
enne76bf8982015-08-18 17:55:331868 LayerImpl* parent = AddChild<LayerImpl>(root);
enne76bf8982015-08-18 17:55:331869 LayerImpl* child1 = AddChild<LayerImpl>(parent);
enne76bf8982015-08-18 17:55:331870 LayerImpl* child2 = AddChild<LayerImpl>(parent);
enne76bf8982015-08-18 17:55:331871 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
enne76bf8982015-08-18 17:55:331872 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
enne76bf8982015-08-18 17:55:331873 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
enne76bf8982015-08-18 17:55:331874
danakje4fa7b72016-07-25 22:00:061875 root->SetBounds(gfx::Size(100, 100));
1876 parent->SetBounds(gfx::Size(100, 100));
1877 parent->SetDrawsContent(true);
1878 child1->SetBounds(gfx::Size(100, 100));
1879 child1->SetDrawsContent(true);
1880 child2->SetBounds(gfx::Size(100, 100));
1881 child2->SetDrawsContent(true);
1882 child2->test_properties()->force_render_surface = true;
1883 grand_child->SetBounds(gfx::Size(100, 100));
1884 grand_child->SetDrawsContent(true);
1885 leaf_node1->SetBounds(gfx::Size(100, 100));
1886 leaf_node1->SetDrawsContent(true);
1887 leaf_node2->SetBounds(gfx::Size(100, 100));
1888 leaf_node2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331889
1890 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521891 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331892
weiliangce3f09a612016-03-16 17:02:521893 ASSERT_TRUE(root->render_surface());
1894 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331895
weiliangce3f09a612016-03-16 17:02:521896 EXPECT_FALSE(root->is_clipped());
1897 EXPECT_TRUE(root->render_surface()->is_clipped());
1898 EXPECT_FALSE(parent->is_clipped());
1899 EXPECT_FALSE(child1->is_clipped());
1900 EXPECT_FALSE(child2->is_clipped());
1901 EXPECT_FALSE(child2->render_surface()->is_clipped());
1902 EXPECT_FALSE(grand_child->is_clipped());
1903 EXPECT_FALSE(leaf_node1->is_clipped());
1904 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331905
danakje4fa7b72016-07-25 22:00:061906 // Case 2: parent MasksToBounds, so the parent, child1, and child2's
enne76bf8982015-08-18 17:55:331907 // surface are clipped. But layers that contribute to child2's surface are
1908 // not clipped explicitly because child2's surface already accounts for
1909 // that clip.
weiliangce3f09a612016-03-16 17:02:521910 parent->SetMasksToBounds(true);
1911 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331912
weiliangce3f09a612016-03-16 17:02:521913 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331914
weiliangce3f09a612016-03-16 17:02:521915 ASSERT_TRUE(root->render_surface());
1916 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331917
weiliangce3f09a612016-03-16 17:02:521918 EXPECT_FALSE(root->is_clipped());
1919 EXPECT_TRUE(root->render_surface()->is_clipped());
1920 EXPECT_TRUE(parent->is_clipped());
1921 EXPECT_TRUE(child1->is_clipped());
1922 EXPECT_FALSE(child2->is_clipped());
1923 EXPECT_TRUE(child2->render_surface()->is_clipped());
1924 EXPECT_TRUE(grand_child->is_clipped());
1925 EXPECT_TRUE(leaf_node1->is_clipped());
1926 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331927
weiliangce3f09a612016-03-16 17:02:521928 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331929
danakje4fa7b72016-07-25 22:00:061930 // Case 3: child2 MasksToBounds. The layer and subtree are clipped, and
enne76bf8982015-08-18 17:55:331931 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521932 child2->SetMasksToBounds(true);
1933 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331934
weiliangce3f09a612016-03-16 17:02:521935 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331936
weiliangce3f09a612016-03-16 17:02:521937 ASSERT_TRUE(root->render_surface());
1938 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331939
weiliangce3f09a612016-03-16 17:02:521940 EXPECT_FALSE(root->is_clipped());
1941 EXPECT_TRUE(root->render_surface()->is_clipped());
1942 EXPECT_FALSE(parent->is_clipped());
1943 EXPECT_FALSE(child1->is_clipped());
1944 EXPECT_TRUE(child2->is_clipped());
1945 EXPECT_FALSE(child2->render_surface()->is_clipped());
1946 EXPECT_FALSE(grand_child->is_clipped());
1947 EXPECT_FALSE(leaf_node1->is_clipped());
1948 EXPECT_TRUE(leaf_node2->is_clipped());
1949}
1950
1951TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1952 // Tests that when as long as layer is clipped, it's clip rect is set to
1953 // correct value.
jaydasikabf1875a2016-06-28 03:39:591954 LayerImpl* root = root_layer_for_testing();
weiliangce3f09a612016-03-16 17:02:521955 LayerImpl* parent = AddChild<LayerImpl>(root);
1956 LayerImpl* child = AddChild<LayerImpl>(parent);
1957
danakje4fa7b72016-07-25 22:00:061958 root->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521959 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061960 parent->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521961 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:061962 child->SetBounds(gfx::Size(100, 100));
weiliangce3f09a612016-03-16 17:02:521963 child->SetDrawsContent(true);
weiliangce3f09a612016-03-16 17:02:521964 child->SetMasksToBounds(true);
1965
1966 ExecuteCalculateDrawProperties(root);
1967
1968 EXPECT_FALSE(root->is_clipped());
1969 EXPECT_FALSE(parent->is_clipped());
1970 EXPECT_TRUE(child->is_clipped());
1971 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1972
1973 parent->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:061974 child->SetPosition(gfx::PointF(100.f, 100.f));
weiliangce3f09a612016-03-16 17:02:521975 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1976
1977 ExecuteCalculateDrawProperties(root);
1978
1979 EXPECT_FALSE(root->is_clipped());
1980 EXPECT_TRUE(parent->is_clipped());
1981 EXPECT_TRUE(child->is_clipped());
1982 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321983}
1984
ajuma51d73f72015-10-19 19:43:581985TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1986 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1987 // when a layer or its ancestor has a clip; in particular, if a layer
1988 // is_clipped, so is its entire subtree (since there are no render surfaces
1989 // that can reset is_clipped).
jaydasikabf1875a2016-06-28 03:39:591990 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:581991 LayerImpl* parent = AddChild<LayerImpl>(root);
1992 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1993 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1994 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1995 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1996 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1997
danakje4fa7b72016-07-25 22:00:061998 root->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:581999 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:062000 parent->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:582001 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:062002 child1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:582003 child1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:062004 child1->test_properties()->force_render_surface = true;
2005 child2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:582006 child2->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:062007 grand_child->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:582008 grand_child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:062009 grand_child->test_properties()->force_render_surface = true;
2010 leaf_node1->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:582011 leaf_node1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:062012 leaf_node2->SetBounds(gfx::Size(100, 100));
ajuma51d73f72015-10-19 19:43:582013 leaf_node2->SetDrawsContent(true);
2014
ajuma51d73f72015-10-19 19:43:582015 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
2016 // or without surfaces.
ajuma51d73f72015-10-19 19:43:582017 ExecuteCalculateDrawProperties(root);
2018 EXPECT_FALSE(root->is_clipped());
2019 EXPECT_FALSE(parent->is_clipped());
2020 EXPECT_FALSE(child1->is_clipped());
2021 EXPECT_FALSE(child2->is_clipped());
2022 EXPECT_FALSE(grand_child->is_clipped());
2023 EXPECT_FALSE(leaf_node1->is_clipped());
2024 EXPECT_FALSE(leaf_node2->is_clipped());
2025
2026 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2027 EXPECT_FALSE(root->is_clipped());
2028 EXPECT_FALSE(parent->is_clipped());
2029 EXPECT_FALSE(child1->is_clipped());
2030 EXPECT_FALSE(child2->is_clipped());
2031 EXPECT_FALSE(grand_child->is_clipped());
2032 EXPECT_FALSE(leaf_node1->is_clipped());
2033 EXPECT_FALSE(leaf_node2->is_clipped());
2034
2035 // Case 2: The root is clipped. With surfaces, this only persists until the
2036 // next render surface. Without surfaces, the entire tree is clipped.
2037 root->SetMasksToBounds(true);
2038 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
ajuma51d73f72015-10-19 19:43:582039 ExecuteCalculateDrawProperties(root);
2040 EXPECT_TRUE(root->is_clipped());
2041 EXPECT_TRUE(parent->is_clipped());
2042 EXPECT_FALSE(child1->is_clipped());
2043 EXPECT_TRUE(child2->is_clipped());
2044 EXPECT_FALSE(grand_child->is_clipped());
2045 EXPECT_FALSE(leaf_node1->is_clipped());
2046 EXPECT_TRUE(leaf_node2->is_clipped());
2047
2048 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2049 EXPECT_TRUE(root->is_clipped());
2050 EXPECT_TRUE(parent->is_clipped());
2051 EXPECT_TRUE(child1->is_clipped());
2052 EXPECT_TRUE(child2->is_clipped());
2053 EXPECT_TRUE(grand_child->is_clipped());
2054 EXPECT_TRUE(leaf_node1->is_clipped());
2055 EXPECT_TRUE(leaf_node2->is_clipped());
2056
2057 root->SetMasksToBounds(false);
2058
2059 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2060 // until the next render surface. Without surfaces, parent's entire subtree is
2061 // clipped.
2062 parent->SetMasksToBounds(true);
2063 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
ajuma51d73f72015-10-19 19:43:582064 ExecuteCalculateDrawProperties(root);
2065 EXPECT_FALSE(root->is_clipped());
2066 EXPECT_TRUE(parent->is_clipped());
2067 EXPECT_FALSE(child1->is_clipped());
2068 EXPECT_TRUE(child2->is_clipped());
2069 EXPECT_FALSE(grand_child->is_clipped());
2070 EXPECT_FALSE(leaf_node1->is_clipped());
2071 EXPECT_TRUE(leaf_node2->is_clipped());
2072
2073 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2074 EXPECT_FALSE(root->is_clipped());
2075 EXPECT_TRUE(parent->is_clipped());
2076 EXPECT_TRUE(child1->is_clipped());
2077 EXPECT_TRUE(child2->is_clipped());
2078 EXPECT_TRUE(grand_child->is_clipped());
2079 EXPECT_TRUE(leaf_node1->is_clipped());
2080 EXPECT_TRUE(leaf_node2->is_clipped());
2081
2082 parent->SetMasksToBounds(false);
2083
2084 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2085 // has no non-surface children. Without surfaces, child1's entire subtree is
2086 // clipped.
2087 child1->SetMasksToBounds(true);
2088 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
ajuma51d73f72015-10-19 19:43:582089 ExecuteCalculateDrawProperties(root);
2090 EXPECT_FALSE(root->is_clipped());
2091 EXPECT_FALSE(parent->is_clipped());
2092 EXPECT_TRUE(child1->is_clipped());
2093 EXPECT_FALSE(child2->is_clipped());
2094 EXPECT_FALSE(grand_child->is_clipped());
2095 EXPECT_FALSE(leaf_node1->is_clipped());
2096 EXPECT_FALSE(leaf_node2->is_clipped());
2097
2098 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2099 EXPECT_FALSE(root->is_clipped());
2100 EXPECT_FALSE(parent->is_clipped());
2101 EXPECT_TRUE(child1->is_clipped());
2102 EXPECT_FALSE(child2->is_clipped());
2103 EXPECT_TRUE(grand_child->is_clipped());
2104 EXPECT_TRUE(leaf_node1->is_clipped());
2105 EXPECT_FALSE(leaf_node2->is_clipped());
2106
2107 child1->SetMasksToBounds(false);
2108
2109 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2110 // surfaces is the same.
2111 leaf_node1->SetMasksToBounds(true);
2112 leaf_node2->SetMasksToBounds(true);
2113 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
ajuma51d73f72015-10-19 19:43:582114 ExecuteCalculateDrawProperties(root);
2115 EXPECT_FALSE(root->is_clipped());
2116 EXPECT_FALSE(parent->is_clipped());
2117 EXPECT_FALSE(child1->is_clipped());
2118 EXPECT_FALSE(child2->is_clipped());
2119 EXPECT_FALSE(grand_child->is_clipped());
2120 EXPECT_TRUE(leaf_node1->is_clipped());
2121 EXPECT_TRUE(leaf_node2->is_clipped());
2122
2123 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2124 EXPECT_FALSE(root->is_clipped());
2125 EXPECT_FALSE(parent->is_clipped());
2126 EXPECT_FALSE(child1->is_clipped());
2127 EXPECT_FALSE(child2->is_clipped());
2128 EXPECT_FALSE(grand_child->is_clipped());
2129 EXPECT_TRUE(leaf_node1->is_clipped());
2130 EXPECT_TRUE(leaf_node2->is_clipped());
2131}
2132
[email protected]fd9a3b6d2013-08-03 00:46:172133TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322134 // Verify that layers get the appropriate DrawableContentRect when their
danakje4fa7b72016-07-25 22:00:062135 // parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322136 //
2137 // grand_child1 - completely inside the region; DrawableContentRect should
2138 // be the layer rect expressed in target space.
danakje4fa7b72016-07-25 22:00:062139 // grand_child2 - partially clipped but NOT MasksToBounds; the clip rect
[email protected]fb661802013-03-25 01:59:322140 // will be the intersection of layer bounds and the mask region.
danakje4fa7b72016-07-25 22:00:062141 // grand_child3 - partially clipped and MasksToBounds; the
[email protected]fb661802013-03-25 01:59:322142 // DrawableContentRect will still be the intersection of layer bounds and
2143 // the mask region.
2144 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2145 // be empty.
[email protected]fb661802013-03-25 01:59:322146
jaydasikabf1875a2016-06-28 03:39:592147 LayerImpl* parent = root_layer_for_testing();
enne07405c772015-08-18 17:56:452148 LayerImpl* child = AddChild<LayerImpl>(parent);
2149 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
enne07405c772015-08-18 17:56:452150 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
enne07405c772015-08-18 17:56:452151 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
enne07405c772015-08-18 17:56:452152 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322153
danakje4fa7b72016-07-25 22:00:062154 parent->SetBounds(gfx::Size(500, 500));
[email protected]fb661802013-03-25 01:59:322155 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062156 child->SetBounds(gfx::Size(20, 20));
2157 child->test_properties()->force_render_surface = true;
2158 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2159 grand_child1->SetBounds(gfx::Size(10, 10));
2160 grand_child1->SetDrawsContent(true);
2161 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2162 grand_child2->SetBounds(gfx::Size(10, 10));
2163 grand_child2->SetDrawsContent(true);
2164 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
[email protected]fb661802013-03-25 01:59:322165 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062166 grand_child3->SetBounds(gfx::Size(10, 10));
2167 grand_child3->SetDrawsContent(true);
2168 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2169 grand_child4->SetBounds(gfx::Size(10, 10));
2170 grand_child4->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452171 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322172
hush6b614212014-12-04 22:37:322173 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2174 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2175 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322176 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2177}
2178
[email protected]989386c2013-07-18 21:37:232179TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322180 // Verify that render surfaces (and their layers) get the appropriate
danakje4fa7b72016-07-25 22:00:062181 // clip rects when their parent MasksToBounds is true.
[email protected]fb661802013-03-25 01:59:322182 //
2183 // Layers that own render surfaces (at least for now) do not inherit any
2184 // clipping; instead the surface will enforce the clip for the entire subtree.
2185 // They may still have a clip rect of their own layer bounds, however, if
danakje4fa7b72016-07-25 22:00:062186 // MasksToBounds was true.
jaydasikabf1875a2016-06-28 03:39:592187 LayerImpl* parent = root_layer_for_testing();
weiliangcfb3d5eaa2015-07-28 23:54:572188 LayerImpl* child = AddChildToRoot<LayerImpl>();
2189 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2190 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2191 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2192 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:062193 // The leaf nodes ensure that these grand_children become render surfaces for
[email protected]fb661802013-03-25 01:59:322194 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572195 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
weiliangcfb3d5eaa2015-07-28 23:54:572196 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
weiliangcfb3d5eaa2015-07-28 23:54:572197 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
weiliangcfb3d5eaa2015-07-28 23:54:572198 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
[email protected]fb661802013-03-25 01:59:322199
danakje4fa7b72016-07-25 22:00:062200 parent->SetBounds(gfx::Size(500, 500));
2201 child->SetBounds(gfx::Size(20, 20));
[email protected]fb661802013-03-25 01:59:322202 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062203 child->test_properties()->force_render_surface = true;
2204 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
2205 grand_child1->SetBounds(gfx::Size(10, 10));
2206 grand_child1->test_properties()->force_render_surface = true;
2207 grand_child2->SetPosition(gfx::PointF(15.f, 15.f));
2208 grand_child2->SetBounds(gfx::Size(10, 10));
2209 grand_child2->test_properties()->force_render_surface = true;
2210 grand_child3->SetPosition(gfx::PointF(15.f, 15.f));
2211 grand_child3->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322212 grand_child3->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062213 grand_child3->test_properties()->force_render_surface = true;
2214 grand_child4->SetPosition(gfx::PointF(45.f, 45.f));
2215 grand_child4->SetBounds(gfx::Size(10, 10));
[email protected]fb661802013-03-25 01:59:322216 grand_child4->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:062217 grand_child4->test_properties()->force_render_surface = true;
2218 leaf_node1->SetBounds(gfx::Size(10, 10));
2219 leaf_node1->SetDrawsContent(true);
2220 leaf_node2->SetBounds(gfx::Size(10, 10));
2221 leaf_node2->SetDrawsContent(true);
2222 leaf_node3->SetBounds(gfx::Size(10, 10));
2223 leaf_node3->SetDrawsContent(true);
2224 leaf_node4->SetBounds(gfx::Size(10, 10));
2225 leaf_node4->SetDrawsContent(true);
weiliangcfb3d5eaa2015-07-28 23:54:572226 ExecuteCalculateDrawProperties(parent);
2227
[email protected]fb661802013-03-25 01:59:322228 ASSERT_TRUE(grand_child1->render_surface());
2229 ASSERT_TRUE(grand_child2->render_surface());
2230 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322231
2232 // Surfaces are clipped by their parent, but un-affected by the owning layer's
danakje4fa7b72016-07-25 22:00:062233 // MasksToBounds.
hush6b614212014-12-04 22:37:322234 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2235 grand_child1->render_surface()->clip_rect());
2236 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2237 grand_child2->render_surface()->clip_rect());
2238 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2239 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322240}
2241
ajuma51d73f72015-10-19 19:43:582242TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2243 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2244 // intersection of all ancestor clips in screen space; in particular, if a
2245 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2246 // subtree (since there are no render surfaces that can reset the clip_rect).
jaydasikabf1875a2016-06-28 03:39:592247 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582248 LayerImpl* parent = AddChild<LayerImpl>(root);
2249 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2250 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2251 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2252 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2253 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2254
danakje4fa7b72016-07-25 22:00:062255 root->SetBounds(gfx::Size(100, 100));
2256 parent->SetPosition(gfx::PointF(2.f, 2.f));
2257 parent->SetBounds(gfx::Size(400, 400));
2258 child1->SetPosition(gfx::PointF(4.f, 4.f));
2259 child1->SetBounds(gfx::Size(800, 800));
2260 child2->SetPosition(gfx::PointF(3.f, 3.f));
2261 child2->SetBounds(gfx::Size(800, 800));
2262 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2263 grand_child->SetBounds(gfx::Size(1500, 1500));
2264 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
2265 leaf_node1->SetBounds(gfx::Size(2000, 2000));
2266 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
2267 leaf_node2->SetBounds(gfx::Size(2000, 2000));
2268
ajuma51d73f72015-10-19 19:43:582269 root->SetDrawsContent(true);
2270 parent->SetDrawsContent(true);
2271 child1->SetDrawsContent(true);
2272 child2->SetDrawsContent(true);
2273 grand_child->SetDrawsContent(true);
2274 leaf_node1->SetDrawsContent(true);
2275 leaf_node2->SetDrawsContent(true);
2276
danakje4fa7b72016-07-25 22:00:062277 root->test_properties()->force_render_surface = true;
2278 child1->test_properties()->force_render_surface = true;
2279 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582280
2281 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2282 // bounds in target space. The only thing that changes when surfaces are
2283 // disabled is that target space is always screen space.
ajuma51d73f72015-10-19 19:43:582284 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262285 EXPECT_TRUE(root->has_render_surface());
2286 EXPECT_FALSE(parent->has_render_surface());
2287 EXPECT_TRUE(child1->has_render_surface());
2288 EXPECT_FALSE(child2->has_render_surface());
2289 EXPECT_TRUE(grand_child->has_render_surface());
2290 EXPECT_FALSE(leaf_node1->has_render_surface());
2291 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422292 EXPECT_FALSE(root->is_clipped());
2293 EXPECT_FALSE(parent->is_clipped());
2294 EXPECT_FALSE(child1->is_clipped());
2295 EXPECT_FALSE(child2->is_clipped());
2296 EXPECT_FALSE(grand_child->is_clipped());
2297 EXPECT_FALSE(leaf_node1->is_clipped());
2298 EXPECT_FALSE(leaf_node2->is_clipped());
2299 EXPECT_TRUE(root->render_surface()->is_clipped());
2300 EXPECT_FALSE(child1->render_surface()->is_clipped());
2301 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2302 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582303
2304 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422305 EXPECT_FALSE(root->is_clipped());
2306 EXPECT_FALSE(parent->is_clipped());
2307 EXPECT_FALSE(child1->is_clipped());
2308 EXPECT_FALSE(child2->is_clipped());
2309 EXPECT_FALSE(grand_child->is_clipped());
2310 EXPECT_FALSE(leaf_node1->is_clipped());
2311 EXPECT_FALSE(leaf_node2->is_clipped());
2312 EXPECT_TRUE(root->render_surface()->is_clipped());
2313 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582314
2315 // Case 2: The root is clipped. In this case, layers that draw into the root
2316 // render surface are clipped by the root's bounds.
2317 root->SetMasksToBounds(true);
2318 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362319 root->test_properties()->force_render_surface = true;
2320 child1->test_properties()->force_render_surface = true;
2321 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582322 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262323 EXPECT_TRUE(root->has_render_surface());
2324 EXPECT_FALSE(parent->has_render_surface());
2325 EXPECT_TRUE(child1->has_render_surface());
2326 EXPECT_FALSE(child2->has_render_surface());
2327 EXPECT_TRUE(grand_child->has_render_surface());
2328 EXPECT_FALSE(leaf_node1->has_render_surface());
2329 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422330 EXPECT_TRUE(root->is_clipped());
2331 EXPECT_TRUE(parent->is_clipped());
2332 EXPECT_FALSE(child1->is_clipped());
2333 EXPECT_TRUE(child1->render_surface()->is_clipped());
2334 EXPECT_TRUE(child2->is_clipped());
2335 EXPECT_FALSE(grand_child->is_clipped());
2336 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2337 EXPECT_FALSE(leaf_node1->is_clipped());
2338 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582339 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2340 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422341 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582342 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582343 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2344
2345 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422346 EXPECT_TRUE(root->is_clipped());
2347 EXPECT_TRUE(parent->is_clipped());
2348 EXPECT_TRUE(child1->is_clipped());
2349 EXPECT_TRUE(child2->is_clipped());
2350 EXPECT_TRUE(grand_child->is_clipped());
2351 EXPECT_TRUE(leaf_node1->is_clipped());
2352 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582353 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2354 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2355 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2356 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2357 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2358 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2359 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2360
2361 root->SetMasksToBounds(false);
2362
2363 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2364 // parent clip rect only contributes to the subtree rooted at child2, since
2365 // the subtree rooted at child1 renders into a separate surface. Similarly,
2366 // child1's clip rect doesn't contribute to its descendants, since its only
2367 // child is a render surface. However, without surfaces, these clip rects
2368 // contribute to all descendants.
2369 parent->SetMasksToBounds(true);
2370 child1->SetMasksToBounds(true);
2371 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362372 root->test_properties()->force_render_surface = true;
2373 child1->test_properties()->force_render_surface = true;
2374 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582375 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262376 EXPECT_TRUE(root->has_render_surface());
2377 EXPECT_FALSE(parent->has_render_surface());
2378 EXPECT_TRUE(child1->has_render_surface());
2379 EXPECT_FALSE(child2->has_render_surface());
2380 EXPECT_TRUE(grand_child->has_render_surface());
2381 EXPECT_FALSE(leaf_node1->has_render_surface());
2382 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422383 EXPECT_FALSE(root->is_clipped());
2384 EXPECT_TRUE(root->render_surface()->is_clipped());
2385 EXPECT_TRUE(parent->is_clipped());
2386 EXPECT_TRUE(child1->is_clipped());
2387 EXPECT_TRUE(child2->is_clipped());
2388 EXPECT_FALSE(grand_child->is_clipped());
2389 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2390 EXPECT_FALSE(leaf_node1->is_clipped());
2391 EXPECT_TRUE(leaf_node2->is_clipped());
2392 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582393 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2394 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2395 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422396 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582397 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2398
2399 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422400 EXPECT_FALSE(root->is_clipped());
2401 EXPECT_TRUE(root->render_surface()->is_clipped());
2402 EXPECT_TRUE(parent->is_clipped());
2403 EXPECT_TRUE(child1->is_clipped());
2404 EXPECT_TRUE(child2->is_clipped());
2405 EXPECT_TRUE(grand_child->is_clipped());
2406 EXPECT_TRUE(leaf_node1->is_clipped());
2407 EXPECT_TRUE(leaf_node2->is_clipped());
2408 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582409 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2410 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2411 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2412 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2413 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2414 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2415}
2416
jaydasika8d0064f2016-06-02 23:34:542417TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
jaydasikabf1875a2016-06-28 03:39:592418 LayerImpl* root = root_layer_for_testing();
jaydasika8d0064f2016-06-02 23:34:542419 LayerImpl* parent = AddChild<LayerImpl>(root);
2420 LayerImpl* child = AddChild<LayerImpl>(parent);
2421 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2422 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2423
danakje4fa7b72016-07-25 22:00:062424 root->SetBounds(gfx::Size(100, 100));
2425 parent->SetPosition(gfx::PointF(2.f, 2.f));
2426 parent->SetBounds(gfx::Size(400, 400));
2427 parent->SetMasksToBounds(true);
2428 child->SetPosition(gfx::PointF(4.f, 4.f));
2429 child->SetBounds(gfx::Size(800, 800));
2430 child->SetMasksToBounds(true);
2431 child->test_properties()->force_render_surface = true;
2432 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2433 grand_child->SetBounds(gfx::Size(1500, 1500));
2434 grand_child->test_properties()->force_render_surface = true;
2435 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2436 leaf_node->SetBounds(gfx::Size(2000, 2000));
2437
jaydasika8d0064f2016-06-02 23:34:542438 root->SetDrawsContent(true);
2439 parent->SetDrawsContent(true);
2440 child->SetDrawsContent(true);
2441 grand_child->SetDrawsContent(true);
2442 leaf_node->SetDrawsContent(true);
2443
jaydasika8d0064f2016-06-02 23:34:542444 host_impl()->set_resourceless_software_draw_for_testing();
2445 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2446 gfx::PointF test_point(90.f, 90.f);
2447 LayerImpl* result_layer =
2448 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2449 ASSERT_TRUE(result_layer);
2450 EXPECT_EQ(leaf_node, result_layer);
2451}
2452
ajuma51d73f72015-10-19 19:43:582453TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2454 // Tests that draw properties are computed correctly when we disable and then
2455 // re-enable separate surfaces.
jaydasikabf1875a2016-06-28 03:39:592456 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:582457 LayerImpl* parent = AddChild<LayerImpl>(root);
2458 LayerImpl* child = AddChild<LayerImpl>(parent);
2459 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2460 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2461
danakje4fa7b72016-07-25 22:00:062462 root->SetBounds(gfx::Size(100, 100));
2463 parent->SetPosition(gfx::PointF(2.f, 2.f));
2464 parent->SetBounds(gfx::Size(400, 400));
2465 parent->SetMasksToBounds(true);
2466 child->SetPosition(gfx::PointF(4.f, 4.f));
2467 child->SetBounds(gfx::Size(800, 800));
2468 child->SetMasksToBounds(true);
2469 child->test_properties()->force_render_surface = true;
2470 grand_child->SetPosition(gfx::PointF(8.f, 8.f));
2471 grand_child->SetBounds(gfx::Size(1500, 1500));
2472 grand_child->test_properties()->force_render_surface = true;
2473 leaf_node->SetPosition(gfx::PointF(16.f, 16.f));
2474 leaf_node->SetBounds(gfx::Size(2000, 2000));
2475
ajuma51d73f72015-10-19 19:43:582476 root->SetDrawsContent(true);
2477 parent->SetDrawsContent(true);
2478 child->SetDrawsContent(true);
2479 grand_child->SetDrawsContent(true);
2480 leaf_node->SetDrawsContent(true);
2481
ajuma51d73f72015-10-19 19:43:582482 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2483 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2484
2485 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2486 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2487
2488 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422489 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252490 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582491 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022492 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2493 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582494
ajuma51d73f72015-10-19 19:43:582495 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422496 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582497 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2498 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022499 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_without_surfaces,
2500 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582501
ajuma51d73f72015-10-19 19:43:582502 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422503 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252504 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582505 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
weiliangcc3517722016-06-28 22:52:022506 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_leaf_draw_transform_with_surfaces,
2507 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582508}
2509
[email protected]989386c2013-07-18 21:37:232510TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
danakje4fa7b72016-07-25 22:00:062511 LayerImpl* root = root_layer_for_testing();
enneab0fee42015-07-07 17:36:422512 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2513 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2514 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2515 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2516 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2517 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2518 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2519 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322520
danakje4fa7b72016-07-25 22:00:062521 root->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362522 render_surface1->SetDrawsContent(true);
2523 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422524 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362525 render_surface2->SetDrawsContent(true);
2526 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422527 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362528 child_of_root->SetDrawsContent(true);
2529 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322530
2531 gfx::Transform layer_transform;
2532 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322533
danakje4fa7b72016-07-25 22:00:062534 root->SetTransform(layer_transform);
2535 root->SetPosition(gfx::PointF(2.5f, 0.f));
2536 root->SetBounds(gfx::Size(10, 10));
2537 root->test_properties()->transform_origin = gfx::Point3F(0.25f, 0.f, 0.f);
2538 render_surface1->SetTransform(layer_transform);
2539 render_surface1->SetPosition(gfx::PointF(2.5f, 0.f));
2540 render_surface1->SetBounds(gfx::Size(10, 10));
2541 render_surface1->test_properties()->transform_origin =
2542 gfx::Point3F(0.25f, 0.f, 0.f);
2543 render_surface1->test_properties()->force_render_surface = true;
2544 render_surface2->SetTransform(layer_transform);
2545 render_surface2->SetPosition(gfx::PointF(2.5f, 0.f));
2546 render_surface2->SetBounds(gfx::Size(10, 10));
2547 render_surface2->test_properties()->transform_origin =
2548 gfx::Point3F(0.25f, 0.f, 0.f);
2549 render_surface2->test_properties()->force_render_surface = true;
2550 child_of_root->SetTransform(layer_transform);
2551 child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2552 child_of_root->SetBounds(gfx::Size(10, 10));
2553 child_of_root->test_properties()->transform_origin =
2554 gfx::Point3F(0.25f, 0.f, 0.f);
2555 child_of_rs1->SetTransform(layer_transform);
2556 child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2557 child_of_rs1->SetBounds(gfx::Size(10, 10));
2558 child_of_rs1->test_properties()->transform_origin =
2559 gfx::Point3F(0.25f, 0.f, 0.f);
2560 child_of_rs2->SetTransform(layer_transform);
2561 child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2562 child_of_rs2->SetBounds(gfx::Size(10, 10));
2563 child_of_rs2->test_properties()->transform_origin =
2564 gfx::Point3F(0.25f, 0.f, 0.f);
2565 grand_child_of_root->SetTransform(layer_transform);
2566 grand_child_of_root->SetPosition(gfx::PointF(2.5f, 0.f));
2567 grand_child_of_root->SetBounds(gfx::Size(10, 10));
2568 grand_child_of_root->test_properties()->transform_origin =
2569 gfx::Point3F(0.25f, 0.f, 0.f);
2570 grand_child_of_rs1->SetTransform(layer_transform);
2571 grand_child_of_rs1->SetPosition(gfx::PointF(2.5f, 0.f));
2572 grand_child_of_rs1->SetBounds(gfx::Size(10, 10));
2573 grand_child_of_rs1->test_properties()->transform_origin =
2574 gfx::Point3F(0.25f, 0.f, 0.f);
2575 grand_child_of_rs2->SetTransform(layer_transform);
2576 grand_child_of_rs2->SetPosition(gfx::PointF(2.5f, 0.f));
2577 grand_child_of_rs2->SetBounds(gfx::Size(10, 10));
2578 grand_child_of_rs2->test_properties()->transform_origin =
2579 gfx::Point3F(0.25f, 0.f, 0.f);
[email protected]fb661802013-03-25 01:59:322580
danakje4fa7b72016-07-25 22:00:062581 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:272582 SetElementIdsForTesting();
jaydasika9cb21c772016-05-10 22:37:082583
loyso9556c732016-03-11 07:54:582584 // Put an animated opacity on the render surface.
vollickef2ae922016-06-29 17:54:272585 AddOpacityTransitionToElementWithPlayer(
2586 render_surface1->element_id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322587
loyso9556c732016-03-11 07:54:582588 // Also put an animated opacity on a layer without descendants.
vollickef2ae922016-06-29 17:54:272589 AddOpacityTransitionToElementWithPlayer(grand_child_of_root->element_id(),
2590 timeline_impl(), 10.0, 1.f, 0.f,
2591 false);
[email protected]fb661802013-03-25 01:59:322592
loyso9556c732016-03-11 07:54:582593 // Put a transform animation on the render surface.
vollickef2ae922016-06-29 17:54:272594 AddAnimatedTransformToElementWithPlayer(render_surface2->element_id(),
2595 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322596
loyso9556c732016-03-11 07:54:582597 // Also put transform animations on grand_child_of_root, and
2598 // grand_child_of_rs2
vollickef2ae922016-06-29 17:54:272599 AddAnimatedTransformToElementWithPlayer(grand_child_of_root->element_id(),
2600 timeline_impl(), 10.0, 30, 0);
2601 AddAnimatedTransformToElementWithPlayer(grand_child_of_rs2->element_id(),
2602 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322603
danakje4fa7b72016-07-25 22:00:062604 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
2605 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322606
2607 // Only layers that are associated with render surfaces should have an actual
2608 // RenderSurface() value.
danakje4fa7b72016-07-25 22:00:062609 ASSERT_TRUE(root->render_surface());
[email protected]fb661802013-03-25 01:59:322610 ASSERT_FALSE(child_of_root->render_surface());
2611 ASSERT_FALSE(grand_child_of_root->render_surface());
2612
2613 ASSERT_TRUE(render_surface1->render_surface());
2614 ASSERT_FALSE(child_of_rs1->render_surface());
2615 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2616
2617 ASSERT_TRUE(render_surface2->render_surface());
2618 ASSERT_FALSE(child_of_rs2->render_surface());
2619 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2620
2621 // Verify all render target accessors
danakje4fa7b72016-07-25 22:00:062622 EXPECT_EQ(root->render_surface(), root->render_target());
2623 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
2624 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322625
weiliangc189c1a12016-04-11 16:16:252626 EXPECT_EQ(render_surface1->render_surface(),
2627 render_surface1->render_target());
2628 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2629 EXPECT_EQ(render_surface1->render_surface(),
2630 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322631
weiliangc189c1a12016-04-11 16:16:252632 EXPECT_EQ(render_surface2->render_surface(),
2633 render_surface2->render_target());
2634 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2635 EXPECT_EQ(render_surface2->render_surface(),
2636 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322637
[email protected]fb661802013-03-25 01:59:322638 // Verify screen_space_transform_is_animating values
danakje4fa7b72016-07-25 22:00:062639 EXPECT_FALSE(root->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322640 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2641 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2642 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322643 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2644 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2645 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322646 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2647 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2648
2649 // Sanity check. If these fail there is probably a bug in the test itself.
2650 // It is expected that we correctly set up transforms so that the y-component
2651 // of the screen-space transform encodes the "depth" of the layer in the tree.
danakje4fa7b72016-07-25 22:00:062652 EXPECT_FLOAT_EQ(1.0, root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262653 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102654 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322655 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102656 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322657
[email protected]803f6b52013-09-12 00:51:262658 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102659 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2660 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322661 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102662 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322663
[email protected]803f6b52013-09-12 00:51:262664 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102665 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2666 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322667 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102668 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322669}
2670
ajuma9384b9c22015-09-17 20:35:032671TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
danakje4fa7b72016-07-25 22:00:062672 LayerImpl* root = root_layer_for_testing();
ajuma9384b9c22015-09-17 20:35:032673 LayerImpl* child = AddChildToRoot<LayerImpl>();
2674 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2675
ajuma9384b9c22015-09-17 20:35:032676 gfx::Transform large_transform;
2677 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2678
danakje4fa7b72016-07-25 22:00:062679 root->SetBounds(gfx::Size(10, 10));
2680 child->SetTransform(large_transform);
2681 child->SetBounds(gfx::Size(10, 10));
2682 grand_child->SetTransform(large_transform);
2683 grand_child->SetBounds(gfx::Size(10, 10));
2684 grand_child->SetDrawsContent(true);
2685 ExecuteCalculateDrawProperties(root);
ajuma9384b9c22015-09-17 20:35:032686
2687 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2688}
2689
ajuma315a4782015-07-24 21:16:342690TEST_F(LayerTreeHostCommonTest,
2691 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
danakje4fa7b72016-07-25 22:00:062692 LayerImpl* root = root_layer_for_testing();
2693 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma315a4782015-07-24 21:16:342694 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2695 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2696
danakje4fa7b72016-07-25 22:00:062697 root->SetDrawsContent(true);
ajuma315a4782015-07-24 21:16:342698 child->SetDrawsContent(true);
2699 grand_child->SetDrawsContent(true);
2700 great_grand_child->SetDrawsContent(true);
2701
danakje4fa7b72016-07-25 22:00:062702 root->SetBounds(gfx::Size(10, 10));
2703 child->SetBounds(gfx::Size(10, 10));
2704 grand_child->SetBounds(gfx::Size(10, 10));
2705 great_grand_child->SetBounds(gfx::Size(10, 10));
ajuma315a4782015-07-24 21:16:342706
vollickef2ae922016-06-29 17:54:272707 SetElementIdsForTesting();
2708
ajuma315a4782015-07-24 21:16:342709 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482710 std::unique_ptr<Animation> animation = Animation::Create(
2711 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302712 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552713 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342714 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:272715 AddAnimationToElementWithPlayer(grand_child->element_id(), timeline_impl(),
2716 std::move(animation));
danakje4fa7b72016-07-25 22:00:062717 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:342718
danakje4fa7b72016-07-25 22:00:062719 EXPECT_FALSE(root->screen_space_transform_is_animating());
ajuma315a4782015-07-24 21:16:342720 EXPECT_FALSE(child->screen_space_transform_is_animating());
2721
2722 EXPECT_FALSE(grand_child->TransformIsAnimating());
2723 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2724 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2725 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2726}
2727
weiliangc6da32862016-04-20 16:40:112728TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2729 // Test visible layer rect and drawable content rect are calculated correctly
2730 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322731
[email protected]2c7c6702013-03-26 03:14:052732 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322733 gfx::Transform layer_to_surface_transform;
2734
2735 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232736 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112737 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2738 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2739 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2740 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2741 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2742 EXPECT_EQ(expected_drawable_content_rect,
2743 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322744
2745 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052746 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112747 expected_visible_layer_rect = gfx::Rect();
2748 expected_drawable_content_rect = gfx::Rect();
2749 drawing_layer = TestVisibleRectAndDrawableContentRect(
2750 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2751 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2752 EXPECT_EQ(expected_drawable_content_rect,
2753 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322754
2755 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052756 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112757 expected_visible_layer_rect = gfx::Rect(20, 20);
2758 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2759 drawing_layer = TestVisibleRectAndDrawableContentRect(
2760 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2761 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2762 EXPECT_EQ(expected_drawable_content_rect,
2763 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322764}
2765
weiliangc6da32862016-04-20 16:40:112766TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2767 // Test visible layer rect and drawable content rect are calculated correctly
2768 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322769
[email protected]2c7c6702013-03-26 03:14:052770 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2771 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322772 gfx::Transform layer_to_surface_transform;
2773
2774 // Case 1: Layer is contained within the surface.
2775 layer_to_surface_transform.MakeIdentity();
2776 layer_to_surface_transform.Translate(50.0, 50.0);
2777 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112778 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2779 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2780 LayerImpl* 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 2: Layer is outside the surface rect.
2787 layer_to_surface_transform.MakeIdentity();
2788 layer_to_surface_transform.Translate(-50.0, 0.0);
2789 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112790 expected_visible_layer_rect = gfx::Rect();
2791 expected_drawable_content_rect = gfx::Rect();
2792 drawing_layer = TestVisibleRectAndDrawableContentRect(
2793 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2794 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2795 EXPECT_EQ(expected_drawable_content_rect,
2796 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322797
2798 // Case 3: The layer is rotated about its top-left corner. In surface space,
2799 // the layer is oriented diagonally, with the left half outside of the render
2800 // surface. In this case, the g should still be the entire layer
2801 // (remember the g is computed in layer space); both the top-left
2802 // and bottom-right corners of the layer are still visible.
2803 layer_to_surface_transform.MakeIdentity();
2804 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112805 expected_visible_layer_rect = gfx::Rect(30, 30);
2806 expected_drawable_content_rect = gfx::Rect(22, 43);
2807 drawing_layer = TestVisibleRectAndDrawableContentRect(
2808 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2809 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2810 EXPECT_EQ(expected_drawable_content_rect,
2811 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322812
2813 // Case 4: The layer is rotated about its top-left corner, and translated
2814 // upwards. In surface space, the layer is oriented diagonally, with only the
2815 // top corner of the surface overlapping the layer. In layer space, the render
2816 // surface overlaps the right side of the layer. The g should be
2817 // the layer's right half.
2818 layer_to_surface_transform.MakeIdentity();
2819 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2820 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112821 // Right half of layer bounds.
2822 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2823 expected_drawable_content_rect = gfx::Rect(22, 22);
2824 drawing_layer = TestVisibleRectAndDrawableContentRect(
2825 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2826 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2827 EXPECT_EQ(expected_drawable_content_rect,
2828 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322829}
2830
weiliangc6da32862016-04-20 16:40:112831TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2832 // Test visible layer rect and drawable content rect are calculated correctly
2833 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322834
[email protected]2c7c6702013-03-26 03:14:052835 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2836 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322837 gfx::Transform layer_to_surface_transform;
2838
2839 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2840 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112841 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322842 layer_to_surface_transform.MakeIdentity();
2843 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112844 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2845 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2846 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2847 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2848 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2849 EXPECT_EQ(expected_drawable_content_rect,
2850 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322851
2852 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2853 // degrees, but shifted to the side so only the right-half the layer would be
2854 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112855 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262856 SkMScalar half_width_of_rotated_layer =
2857 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322858 layer_to_surface_transform.MakeIdentity();
2859 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232860 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2861 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112862 // Tight half of the layer.
2863 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2864 expected_drawable_content_rect = gfx::Rect(36, 100);
2865 drawing_layer = TestVisibleRectAndDrawableContentRect(
2866 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2867 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2868 EXPECT_EQ(expected_drawable_content_rect,
2869 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322870}
2871
weiliangc6da32862016-04-20 16:40:112872TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2873 // Test visible layer rect and drawable content rect are calculated correctly
2874 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322875
[email protected]2c7c6702013-03-26 03:14:052876 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2877 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322878 gfx::Transform layer_to_surface_transform;
2879
2880 // Case 1: Even though the layer is twice as large as the surface, due to
2881 // perspective foreshortening, the layer will fit fully in the surface when
2882 // its translated more than the perspective amount.
2883 layer_to_surface_transform.MakeIdentity();
2884
2885 // The following sequence of transforms applies the perspective about the
2886 // center of the surface.
2887 layer_to_surface_transform.Translate(50.0, 50.0);
2888 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2889 layer_to_surface_transform.Translate(-50.0, -50.0);
2890
2891 // This translate places the layer in front of the surface's projection plane.
2892 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2893
weiliangc6da32862016-04-20 16:40:112894 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2895 // offset by layer position.
2896 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2897 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2898 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2899 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2900 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2901 EXPECT_EQ(expected_drawable_content_rect,
2902 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322903
2904 // Case 2: same projection as before, except that the layer is also translated
2905 // to the side, so that only the right half of the layer should be visible.
2906 //
2907 // Explanation of expected result: The perspective ratio is (z distance
2908 // between layer and camera origin) / (z distance between projection plane and
2909 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112910 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322911 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112912 // -25 == -100 in the layer's units.
2913 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2914 // Visible layer rect is moved by 100, and drawable content rect is in target
2915 // space and is moved by 25.
2916 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2917 expected_drawable_content_rect = gfx::Rect(13, 38);
2918 drawing_layer = TestVisibleRectAndDrawableContentRect(
2919 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2920 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2921 EXPECT_EQ(expected_drawable_content_rect,
2922 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322923}
2924
weiliangc6da32862016-04-20 16:40:112925TEST_F(LayerTreeHostCommonDrawRectsTest,
2926 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322927 // There is currently no explicit concept of an orthographic projection plane
2928 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2929 // are technically behind the surface in an orthographic world should not be
2930 // clipped when they are flattened to the surface.
2931
[email protected]2c7c6702013-03-26 03:14:052932 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2933 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322934 gfx::Transform layer_to_surface_transform;
2935
2936 // This sequence of transforms effectively rotates the layer about the y-axis
2937 // at the center of the layer.
2938 layer_to_surface_transform.MakeIdentity();
2939 layer_to_surface_transform.Translate(50.0, 0.0);
2940 layer_to_surface_transform.RotateAboutYAxis(45.0);
2941 layer_to_surface_transform.Translate(-50.0, 0.0);
2942
weiliangc6da32862016-04-20 16:40:112943 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2944 // space.
2945 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2946 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2947 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2948 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2949 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2950 EXPECT_EQ(expected_drawable_content_rect,
2951 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322952}
2953
weiliangc6da32862016-04-20 16:40:112954TEST_F(LayerTreeHostCommonDrawRectsTest,
2955 DrawRectsFor3dPerspectiveWhenClippedByW) {
2956 // Test visible layer rect and drawable content rect are calculated correctly
2957 // when projecting a surface onto a layer, but the layer is partially behind
2958 // the camera (not just behind the projection plane). In this case, the
2959 // cartesian coordinates may seem to be valid, but actually they are not. The
2960 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2961 // coordinates before converting to cartesian coordinates. The drawable
2962 // content rect would be entire surface rect because layer is rotated at the
2963 // camera position.
[email protected]fb661802013-03-25 01:59:322964
weiliangc6da32862016-04-20 16:40:112965 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2966 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322967 gfx::Transform layer_to_surface_transform;
2968
2969 // The layer is positioned so that the right half of the layer should be in
2970 // front of the camera, while the other half is behind the surface's
2971 // projection plane. The following sequence of transforms applies the
2972 // perspective and rotation about the center of the layer.
2973 layer_to_surface_transform.MakeIdentity();
2974 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112975 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2976 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2977 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322978
2979 // Sanity check that this transform does indeed cause w < 0 when applying the
2980 // transform, otherwise this code is not testing the intended scenario.
2981 bool clipped;
2982 MathUtil::MapQuad(layer_to_surface_transform,
2983 gfx::QuadF(gfx::RectF(layer_content_rect)),
2984 &clipped);
2985 ASSERT_TRUE(clipped);
2986
weiliangc6da32862016-04-20 16:40:112987 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2988 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2989 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2990 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2991 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2992 EXPECT_EQ(expected_drawable_content_rect,
2993 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322994}
2995
weiliangc6da32862016-04-20 16:40:112996TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322997 // To determine visible rect in layer space, there needs to be an
2998 // un-projection from surface space to layer space. When the original
2999 // transform was a perspective projection that was clipped, it returns a rect
3000 // that encloses the clipped bounds. Un-projecting this new rect may require
3001 // clipping again.
3002
3003 // This sequence of transforms causes one corner of the layer to protrude
3004 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:113005 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
3006 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:323007 gfx::Transform layer_to_surface_transform;
3008 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:113009 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:323010 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
3011 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
3012 layer_to_surface_transform.RotateAboutYAxis(45.0);
3013 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:113014 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:323015
3016 // Sanity check that un-projection does indeed cause w < 0, otherwise this
3017 // code is not testing the intended scenario.
3018 bool clipped;
danakj5e6ff6d2015-09-05 04:43:443019 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
3020 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:323021 MathUtil::ProjectQuad(
3022 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
3023 ASSERT_TRUE(clipped);
3024
3025 // Only the corner of the layer is not visible on the surface because of being
3026 // clipped. But, the net result of rounding visible region to an axis-aligned
3027 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:113028 gfx::Rect expected_visible_layer_rect = layer_content_rect;
3029 gfx::Rect expected_drawable_content_rect = target_surface_rect;
3030 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3031 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3032 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3033 EXPECT_EQ(expected_drawable_content_rect,
3034 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323035}
3036
miletus9d3da522015-06-05 19:45:073037TEST_F(LayerTreeHostCommonTest,
3038 VisibleRectsForPositionedRootLayerClippedByViewport) {
jaydasikabf1875a2016-06-28 03:39:593039 LayerImpl* root = root_layer_for_testing();
miletus9d3da522015-06-05 19:45:073040
danakje4fa7b72016-07-25 22:00:063041 root->SetPosition(gfx::PointF(60, 70));
3042 root->SetBounds(gfx::Size(100, 100));
3043 root->SetDrawsContent(true);
enne6c281f6e2015-08-18 23:23:003044 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:073045
danakj5e6ff6d2015-09-05 04:43:443046 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:073047 root->render_surface()->DrawableContentRect());
3048 // In target space, not clipped.
3049 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3050 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:443051 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:073052}
3053
[email protected]989386c2013-07-18 21:37:233054TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
jaydasikabf1875a2016-06-28 03:39:593055 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173056 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173057 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
weiliangc0dece732015-07-27 19:06:173058 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063059
3060 root->SetBounds(gfx::Size(100, 100));
3061 child1_layer->SetBounds(gfx::Size(50, 50));
3062 child1_layer->SetDrawsContent(true);
3063 child2_layer->SetPosition(gfx::PointF(75.f, 75.f));
3064 child2_layer->SetBounds(gfx::Size(50, 50));
3065 child2_layer->SetDrawsContent(true);
3066 child3_layer->SetPosition(gfx::PointF(125.f, 125.f));
3067 child3_layer->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173068 child3_layer->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173069 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323070
danakj5e6ff6d2015-09-05 04:43:443071 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323072 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323073
danakj64767d902015-06-19 00:10:433074 // Layers that do not draw content should have empty visible_layer_rects.
3075 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323076
danakj64767d902015-06-19 00:10:433077 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173078 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3079 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3080 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323081
3082 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173083 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3084 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3085 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323086}
3087
[email protected]989386c2013-07-18 21:37:233088TEST_F(LayerTreeHostCommonTest,
3089 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
jaydasikabf1875a2016-06-28 03:39:593090 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173091 LayerImpl* child = AddChildToRoot<LayerImpl>();
3092 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173093 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
weiliangc0dece732015-07-27 19:06:173094 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:283095
danakje4fa7b72016-07-25 22:00:063096 root->SetBounds(gfx::Size(100, 100));
3097 child->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323098 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063099 grand_child1->SetPosition(gfx::PointF(5.f, 5.f));
3100 grand_child1->SetBounds(gfx::Size(50, 50));
3101 grand_child1->SetDrawsContent(true);
3102 grand_child2->SetPosition(gfx::PointF(75.f, 75.f));
3103 grand_child2->SetBounds(gfx::Size(50, 50));
3104 grand_child2->SetDrawsContent(true);
3105 grand_child3->SetPosition(gfx::PointF(125.f, 125.f));
3106 grand_child3->SetBounds(gfx::Size(50, 50));
3107 grand_child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173108 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323109
danakj5e6ff6d2015-09-05 04:43:443110 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323111 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323112
3113 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433114 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3115 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323116
3117 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433118 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3119 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3120 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323121
3122 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323123 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3124 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323125 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3126}
3127
ajuma27442dd2015-03-30 19:19:483128TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasikabf1875a2016-06-28 03:39:593129 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:143130 LayerImpl* child = AddChild<LayerImpl>(root);
3131 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483132
ajuma27442dd2015-03-30 19:19:483133 gfx::Transform child_scale_matrix;
3134 child_scale_matrix.Scale(0.25f, 0.25f);
3135 gfx::Transform grand_child_scale_matrix;
3136 grand_child_scale_matrix.Scale(0.246f, 0.246f);
ajuma27442dd2015-03-30 19:19:483137
danakje4fa7b72016-07-25 22:00:063138 root->SetBounds(gfx::Size(100, 100));
3139 child->SetTransform(child_scale_matrix);
3140 child->SetBounds(gfx::Size(10, 10));
ajuma27442dd2015-03-30 19:19:483141 child->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063142 grand_child->SetTransform(grand_child_scale_matrix);
3143 grand_child->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:143144 grand_child->SetDrawsContent(true);
3145 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483146
weiliangcd15784432016-06-07 17:57:333147 // The visible rect is expanded to integer coordinates.
3148 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483149}
3150
[email protected]989386c2013-07-18 21:37:233151TEST_F(LayerTreeHostCommonTest,
3152 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593153 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173154 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3155 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173156 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173157 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
danakje4fa7b72016-07-25 22:00:063158
3159 root->SetBounds(gfx::Size(100, 100));
3160 render_surface->SetBounds(gfx::Size(3, 4));
3161 render_surface->test_properties()->force_render_surface = true;
3162 child1->SetPosition(gfx::PointF(5.f, 5.f));
3163 child1->SetBounds(gfx::Size(50, 50));
3164 child1->SetDrawsContent(true);
3165 child2->SetPosition(gfx::PointF(75.f, 75.f));
3166 child2->SetBounds(gfx::Size(50, 50));
3167 child2->SetDrawsContent(true);
3168 child3->SetPosition(gfx::PointF(125.f, 125.f));
3169 child3->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173170 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173171 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323172
weiliangc0dece732015-07-27 19:06:173173 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323174
danakj5e6ff6d2015-09-05 04:43:443175 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323176 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323177
3178 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433179 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173180 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323181
3182 // An unclipped surface grows its DrawableContentRect to include all drawable
3183 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443184 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173185 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323186
3187 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433188 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3189 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3190 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323191
hush6b614212014-12-04 22:37:323192 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3193 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3194 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323195}
3196
[email protected]989386c2013-07-18 21:37:233197TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583198 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
jaydasikabf1875a2016-06-28 03:39:593199 LayerImpl* root = root_layer_for_testing();
ajuma51d73f72015-10-19 19:43:583200 LayerImpl* parent = AddChild<LayerImpl>(root);
3201 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3202 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3203 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3204 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3205 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3206 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3207
danakje4fa7b72016-07-25 22:00:063208 root->SetBounds(gfx::Size(100, 100));
3209 parent->SetPosition(gfx::PointF(2.f, 2.f));
3210 parent->SetBounds(gfx::Size(400, 400));
3211 child1->SetPosition(gfx::PointF(4.f, 4.f));
3212 child1->SetBounds(gfx::Size(800, 800));
3213 child1->test_properties()->force_render_surface = true;
3214 child2->SetPosition(gfx::PointF(3.f, 3.f));
3215 child2->SetBounds(gfx::Size(800, 800));
3216 child2->test_properties()->force_render_surface = true;
3217 grand_child1->SetPosition(gfx::PointF(8.f, 8.f));
3218 grand_child1->SetBounds(gfx::Size(1500, 1500));
3219 grand_child2->SetPosition(gfx::PointF(7.f, 7.f));
3220 grand_child2->SetBounds(gfx::Size(1500, 1500));
3221 leaf_node1->SetPosition(gfx::PointF(16.f, 16.f));
3222 leaf_node1->SetBounds(gfx::Size(2000, 2000));
3223 leaf_node2->SetPosition(gfx::PointF(9.f, 9.f));
3224 leaf_node2->SetBounds(gfx::Size(2000, 2000));
3225
ajuma51d73f72015-10-19 19:43:583226 root->SetDrawsContent(true);
3227 parent->SetDrawsContent(true);
3228 child1->SetDrawsContent(true);
3229 child2->SetDrawsContent(true);
3230 grand_child1->SetDrawsContent(true);
3231 grand_child2->SetDrawsContent(true);
3232 leaf_node1->SetDrawsContent(true);
3233 leaf_node2->SetDrawsContent(true);
3234
ajuma51d73f72015-10-19 19:43:583235 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
3236 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
3237 // Each layer's drawable content rect is its bounds in target space; the only
3238 // thing that changes with surfaces disabled is that target space is always
3239 // screen space.
weiliangcc154ce22015-12-09 03:39:263240 root->SetHasRenderSurface(true);
3241 child1->SetHasRenderSurface(true);
3242 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583243 ExecuteCalculateDrawProperties(root);
3244 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3245 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
3246 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3247 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3248 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
3249 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3250 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
3251 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
3252
3253 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3254 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3255 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3256 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3257 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3258 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3259 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3260 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3261
3262 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3263 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3264 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3265 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3266 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3267 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3268 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3269 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3270 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3271
3272 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3273 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3274 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3275 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3276 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3277 grand_child1->drawable_content_rect());
3278 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3279 grand_child2->drawable_content_rect());
3280 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3281 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3282
3283 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3284 // all visible layer rects are clipped by the intersection of all ancestor
3285 // clips, whether or not surfaces are disabled. However, drawable content
3286 // rects are clipped only until the next render surface is reached, so
3287 // descendants of parent have their drawable content rects clipped only when
3288 // surfaces are disabled.
3289 parent->SetMasksToBounds(true);
3290 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
ajuma51d73f72015-10-19 19:43:583291 ExecuteCalculateDrawProperties(root);
3292 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3293 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3294 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3295 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3296 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3297 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3298 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3299 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3300
3301 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3302 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3303 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3304 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3305 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3306 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3307 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3308 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3309
3310 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3311 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3312 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3313 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3314 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3315 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());
3319
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(6, 6, 396, 396), child1->drawable_content_rect());
3323 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3324 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3325 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3326 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3327 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3328
3329 parent->SetMasksToBounds(false);
3330
3331 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3332 // layers have their visible rects clipped by them; without surfaces, these
3333 // rects are also clipped by the viewport. Similarly, descendants of these
3334 // layers have their drawable content rects clipped by them.
3335 child1->SetMasksToBounds(true);
3336 grand_child2->SetMasksToBounds(true);
3337 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
ajuma51d73f72015-10-19 19:43:583338 ExecuteCalculateDrawProperties(root);
3339 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3340 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3341 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3342 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3343 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3344 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3345 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3346 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3347
3348 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3349 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3350 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3351 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3352 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3353 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3354 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3355 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3356
3357 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3358 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3359 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3360 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3361 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3362 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3363 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3364 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3365 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3366
3367 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3368 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3369 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3370 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3371 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3372 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3373 grand_child2->drawable_content_rect());
3374 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3375 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3376}
3377
3378TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023379 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
jaydasikabf1875a2016-06-28 03:39:593380 LayerImpl* root = root_layer_for_testing();
enne6c281f6e2015-08-18 23:23:003381 LayerImpl* child1 = AddChild<LayerImpl>(root);
3382 LayerImpl* child2 = AddChild<LayerImpl>(root);
3383 LayerImpl* child3 = AddChild<LayerImpl>(root);
hush887bb542014-12-02 22:49:023384
danakje4fa7b72016-07-25 22:00:063385 root->SetBounds(gfx::Size(100, 100));
3386 child1->SetPosition(gfx::PointF(5.f, 5.f));
3387 child1->SetBounds(gfx::Size(50, 50));
3388 child1->SetDrawsContent(true);
3389 child2->SetPosition(gfx::PointF(75.f, 75.f));
3390 child2->SetBounds(gfx::Size(50, 50));
3391 child2->SetDrawsContent(true);
3392 child3->SetPosition(gfx::PointF(125.f, 125.f));
3393 child3->SetBounds(gfx::Size(50, 50));
3394 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023395
enne6c281f6e2015-08-18 23:23:003396 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023397 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003398 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383399 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023400
sunxdb365de02016-04-28 20:32:573401 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023402 ASSERT_TRUE(root->render_surface());
3403 EXPECT_FALSE(root->is_clipped());
3404
3405 gfx::Rect empty;
3406 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3407 EXPECT_TRUE(root->render_surface()->is_clipped());
3408
3409 // Visible content rect calculation will check if the target surface is
3410 // clipped or not. An empty clip rect does not indicate the render surface
3411 // is unclipped.
danakj64767d902015-06-19 00:10:433412 EXPECT_EQ(empty, child1->visible_layer_rect());
3413 EXPECT_EQ(empty, child2->visible_layer_rect());
3414 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023415}
3416
3417TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233418 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
jaydasikabf1875a2016-06-28 03:39:593419 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173420 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:063421
3422 root->SetBounds(gfx::Size(100, 100));
3423 child->SetPosition(gfx::PointF(5.f, 5.f));
3424 child->SetBounds(gfx::Size(50, 50));
weiliangc0dece732015-07-27 19:06:173425 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283426
[email protected]630ddad2013-08-16 03:01:323427 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473428 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323429 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473430
danakje4fa7b72016-07-25 22:00:063431 child->SetTransform(uninvertible_matrix);
weiliangc0dece732015-07-27 19:06:173432 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473433
danakj64767d902015-06-19 00:10:433434 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473435 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323436
[email protected]08bdf1b2014-04-16 23:23:293437 // Case 2: a matrix with flattened z, uninvertible and not visible according
3438 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323439 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263440 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323441 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3442
danakje4fa7b72016-07-25 22:00:063443 child->SetTransform(uninvertible_matrix);
weiliangc0dece732015-07-27 19:06:173444 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323445
danakj64767d902015-06-19 00:10:433446 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293447 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323448
[email protected]08bdf1b2014-04-16 23:23:293449 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323450 uninvertible_matrix.MakeIdentity();
3451 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263452 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323453 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3454
danakje4fa7b72016-07-25 22:00:063455 child->SetTransform(uninvertible_matrix);
weiliangc0dece732015-07-27 19:06:173456 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323457
danakj64767d902015-06-19 00:10:433458 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293459 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473460}
3461
[email protected]989386c2013-07-18 21:37:233462TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563463 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
jaydasikabf1875a2016-06-28 03:39:593464 LayerImpl* root = root_layer_for_testing();
ajumaae0dc2d2015-08-05 21:55:563465 LayerImpl* child = AddChildToRoot<LayerImpl>();
3466 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaae0dc2d2015-08-05 21:55:563467
ajumaae0dc2d2015-08-05 21:55:563468 gfx::Transform perspective;
3469 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3470
3471 gfx::Transform rotation;
3472 rotation.RotateAboutYAxis(45.0);
3473
danakje4fa7b72016-07-25 22:00:063474 root->SetBounds(gfx::Size(100, 100));
3475 child->SetTransform(perspective);
3476 child->SetPosition(gfx::PointF(10.f, 10.f));
3477 child->SetBounds(gfx::Size(100, 100));
3478 child->SetDrawsContent(true);
3479 child->Set3dSortingContextId(1);
3480 child->test_properties()->should_flatten_transform = false;
3481 grand_child->SetTransform(rotation);
3482 grand_child->SetBounds(gfx::Size(100, 100));
3483 grand_child->SetDrawsContent(true);
3484 grand_child->Set3dSortingContextId(1);
3485 grand_child->test_properties()->should_flatten_transform = false;
ajumaae0dc2d2015-08-05 21:55:563486 ExecuteCalculateDrawProperties(root);
3487
3488 // Though all layers have invertible transforms, matrix multiplication using
3489 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053490 EXPECT_FALSE(root->layer_tree_impl()
3491 ->property_trees()
3492 ->transform_tree.Node(grand_child->transform_tree_index())
trchendba8b1502016-07-08 09:47:013493 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563494
sunxd71aea3e2016-04-01 23:48:053495 // CalcDrawProps skips a subtree when a layer's screen space transform is
3496 // uninvertible
3497 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563498}
3499
jaydasika69c77aa2016-07-14 22:48:483500TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) {
3501 FakeImplTaskRunnerProvider task_runner_provider;
3502 TestSharedBitmapManager shared_bitmap_manager;
3503 TestTaskGraphRunner task_graph_runner;
danakj6021ec32016-07-22 22:16:083504 std::unique_ptr<OutputSurface> output_surface =
3505 FakeOutputSurface::CreateDelegating3d();
jaydasika69c77aa2016-07-14 22:48:483506 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
3507 &task_graph_runner);
3508
3509 std::unique_ptr<LayerImpl> root =
3510 LayerImpl::Create(host_impl.active_tree(), 1);
3511 std::unique_ptr<LayerImpl> child =
3512 LayerImpl::Create(host_impl.active_tree(), 2);
3513 std::unique_ptr<TextureLayerImpl> surface =
3514 TextureLayerImpl::Create(host_impl.active_tree(), 3);
3515 std::unique_ptr<TextureLayerImpl> surface_child =
3516 TextureLayerImpl::Create(host_impl.active_tree(), 4);
3517 std::unique_ptr<TextureLayerImpl> surface_sibling =
3518 TextureLayerImpl::Create(host_impl.active_tree(), 5);
3519 std::unique_ptr<TextureLayerImpl> surface_child_mask =
3520 TextureLayerImpl::Create(host_impl.active_tree(), 6);
3521
3522 surface->SetDrawsContent(true);
3523 surface_child->SetDrawsContent(true);
3524 surface_sibling->SetDrawsContent(true);
3525 surface_child_mask->SetDrawsContent(true);
3526 surface->SetContentsOpaque(true);
3527 surface_child->SetContentsOpaque(true);
3528 surface_sibling->SetContentsOpaque(true);
3529 surface_child_mask->SetContentsOpaque(true);
3530
jaydasika69c77aa2016-07-14 22:48:483531 gfx::Transform translate;
3532 translate.Translate(20.f, 20.f);
3533
danakje4fa7b72016-07-25 22:00:063534 root->SetBounds(gfx::Size(1000, 1000));
3535 child->SetBounds(gfx::Size(300, 300));
3536 surface->SetTransform(translate);
3537 surface->SetBounds(gfx::Size(300, 300));
3538 surface->test_properties()->force_render_surface = true;
3539 surface_child->SetBounds(gfx::Size(300, 300));
3540 surface_child->test_properties()->force_render_surface = true;
3541 surface_sibling->SetBounds(gfx::Size(200, 200));
jaydasika69c77aa2016-07-14 22:48:483542
3543 LayerImpl* surface_ptr = surface.get();
3544 LayerImpl* surface_child_ptr = surface_child.get();
3545 LayerImpl* surface_child_mask_ptr = surface_child_mask.get();
3546
3547 host_impl.SetViewportSize(root->bounds());
3548
3549 surface_child->test_properties()->SetMaskLayer(std::move(surface_child_mask));
3550 surface->test_properties()->AddChild(std::move(surface_child));
3551 child->test_properties()->AddChild(std::move(surface));
3552 child->test_properties()->AddChild(std::move(surface_sibling));
3553 root->test_properties()->AddChild(std::move(child));
3554 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
3555 host_impl.SetVisible(true);
3556 host_impl.InitializeRenderer(output_surface.get());
3557 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
3558 bool update_lcd_text = false;
3559 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3560
3561 EXPECT_TRANSFORMATION_MATRIX_EQ(
3562 surface_ptr->render_surface()->draw_transform(), translate);
3563 // surface_sibling draws into the root render surface and occludes
3564 // surface_child's contents.
3565 Occlusion actual_occlusion =
3566 surface_child_ptr->render_surface()->occlusion_in_content_space();
3567 Occlusion expected_occlusion(translate, SimpleEnclosedRegion(gfx::Rect()),
3568 SimpleEnclosedRegion(gfx::Rect(200, 200)));
3569 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3570
3571 // Mask layer should have the same occlusion.
3572 actual_occlusion =
3573 surface_child_mask_ptr->draw_properties().occlusion_in_content_space;
3574 EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion));
3575}
3576
ajumaae0dc2d2015-08-05 21:55:563577TEST_F(LayerTreeHostCommonTest,
3578 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163579 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563580 TestSharedBitmapManager shared_bitmap_manager;
3581 TestTaskGraphRunner task_graph_runner;
danakj6021ec32016-07-22 22:16:083582 std::unique_ptr<OutputSurface> output_surface =
3583 FakeOutputSurface::CreateDelegating3d();
khushalsagarb64b360d2015-10-21 19:25:163584 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563585 &task_graph_runner);
jaydasika69c77aa2016-07-14 22:48:483586
danakj60bc3bc2016-04-09 00:24:483587 std::unique_ptr<LayerImpl> root =
3588 LayerImpl::Create(host_impl.active_tree(), 1);
3589 std::unique_ptr<LayerImpl> child =
3590 LayerImpl::Create(host_impl.active_tree(), 2);
3591 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563592 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483593 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563594 LayerImpl::Create(host_impl.active_tree(), 4);
ajumaae0dc2d2015-08-05 21:55:563595
ajumaae0dc2d2015-08-05 21:55:563596 gfx::Transform perspective;
3597 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3598
3599 gfx::Transform rotation;
3600 rotation.RotateAboutYAxis(45.0);
3601
danakje4fa7b72016-07-25 22:00:063602 root->SetBounds(gfx::Size(1000, 1000));
3603 child->SetTransform(perspective);
3604 child->SetPosition(gfx::PointF(10.f, 10.f));
3605 child->SetBounds(gfx::Size(300, 300));
3606 child->test_properties()->should_flatten_transform = false;
3607 child->Set3dSortingContextId(1);
3608 grand_child->SetTransform(rotation);
3609 grand_child->SetBounds(gfx::Size(200, 200));
3610 grand_child->test_properties()->should_flatten_transform = false;
3611 grand_child->Set3dSortingContextId(1);
3612 occluding_child->SetBounds(gfx::Size(200, 200));
3613 occluding_child->test_properties()->should_flatten_transform = false;
3614
3615 child->SetDrawsContent(true);
3616 grand_child->SetDrawsContent(true);
3617 occluding_child->SetDrawsContent(true);
3618 occluding_child->SetContentsOpaque(true);
ajumaae0dc2d2015-08-05 21:55:563619
3620 host_impl.SetViewportSize(root->bounds());
3621
jaydasika89f7b5a2016-06-22 02:08:393622 child->test_properties()->AddChild(std::move(grand_child));
3623 root->test_properties()->AddChild(std::move(child));
3624 root->test_properties()->AddChild(std::move(occluding_child));
jaydasikabf1875a2016-06-28 03:39:593625 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
sievers71c62dd52015-10-07 01:44:393626 host_impl.SetVisible(true);
revemand180dfc32015-09-24 00:19:433627 host_impl.InitializeRenderer(output_surface.get());
jaydasika4340ea02016-06-06 19:44:263628 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563629 bool update_lcd_text = false;
3630 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3631
jaydasikafc66cfb2016-06-10 04:34:223632 LayerImpl* grand_child_ptr = host_impl.active_tree()
jaydasikabf1875a2016-06-28 03:39:593633 ->root_layer_for_testing()
jaydasikafc66cfb2016-06-10 04:34:223634 ->test_properties()
3635 ->children[0]
3636 ->test_properties()
3637 ->children[0];
ajumaae0dc2d2015-08-05 21:55:563638
3639 // Though all layers have invertible transforms, matrix multiplication using
3640 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053641 EXPECT_FALSE(
3642 host_impl.active_tree()
3643 ->property_trees()
3644 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
trchendba8b1502016-07-08 09:47:013645 ->ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563646
sunxd71aea3e2016-04-01 23:48:053647 // Since |grand_child| has an uninvertible screen space transform, it is
3648 // skipped so
3649 // that we are not computing its occlusion_in_content_space.
3650 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563651 EXPECT_EQ(
3652 layer_bounds,
3653 grand_child_ptr->draw_properties()
3654 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3655}
3656
3657TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233658 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:593659 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173660 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3661 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173662 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
weiliangc0dece732015-07-27 19:06:173663 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283664
danakje4fa7b72016-07-25 22:00:063665 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323666 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063667 render_surface->SetBounds(gfx::Size(3, 4));
3668 render_surface->test_properties()->force_render_surface = true;
3669 child1->SetPosition(gfx::PointF(5.f, 5.f));
3670 child1->SetBounds(gfx::Size(50, 50));
3671 child1->SetDrawsContent(true);
3672 child2->SetPosition(gfx::PointF(75.f, 75.f));
3673 child2->SetBounds(gfx::Size(50, 50));
3674 child2->SetDrawsContent(true);
3675 child3->SetPosition(gfx::PointF(125.f, 125.f));
3676 child3->SetBounds(gfx::Size(50, 50));
3677 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173678 ExecuteCalculateDrawProperties(root);
3679
3680 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323681
danakj5e6ff6d2015-09-05 04:43:443682 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323683 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323684
3685 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433686 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173687 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323688
3689 // A clipped surface grows its DrawableContentRect to include all drawable
3690 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443691 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173692 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323693
3694 // All layers that draw content into the surface have their visible content
3695 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433696 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3697 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3698 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323699
3700 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323701 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3702 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3703 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323704}
3705
[email protected]989386c2013-07-18 21:37:233706TEST_F(LayerTreeHostCommonTest,
3707 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323708 // Check that clipping does not propagate down surfaces.
jaydasikabf1875a2016-06-28 03:39:593709 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173710 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3711 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3712 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173713 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:173714 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:283715
danakje4fa7b72016-07-25 22:00:063716 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:323717 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:063718 render_surface1->SetBounds(gfx::Size(3, 4));
3719 render_surface1->test_properties()->force_render_surface = true;
3720 render_surface2->SetBounds(gfx::Size(7, 13));
3721 render_surface2->test_properties()->force_render_surface = true;
3722 child1->SetPosition(gfx::PointF(5.f, 5.f));
3723 child1->SetBounds(gfx::Size(50, 50));
3724 child1->SetDrawsContent(true);
3725 child2->SetPosition(gfx::PointF(75.f, 75.f));
3726 child2->SetBounds(gfx::Size(50, 50));
3727 child2->SetDrawsContent(true);
3728 child3->SetPosition(gfx::PointF(125.f, 125.f));
3729 child3->SetBounds(gfx::Size(50, 50));
3730 child3->SetDrawsContent(true);
weiliangc0dece732015-07-27 19:06:173731 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323732
3733 ASSERT_TRUE(render_surface1->render_surface());
3734 ASSERT_TRUE(render_surface2->render_surface());
3735
danakj5e6ff6d2015-09-05 04:43:443736 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323737 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323738
3739 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433740 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3741 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3742 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323743
3744 // A clipped surface grows its DrawableContentRect to include all drawable
3745 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443746 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323747 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323748
3749 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3750 // is only implicitly clipped by render_surface1's content rect. So,
3751 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443752 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323753 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323754
3755 // All layers that draw content into render_surface2 think they are unclipped.
danakj64767d902015-06-19 00:10:433756 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3757 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3758 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323759
3760 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323761 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3762 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3763 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323764}
3765
[email protected]989386c2013-07-18 21:37:233766TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463767 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593768 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463769 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3770 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3771 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3772 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
jaydasika27d0f2e2015-10-16 23:52:463773
danakje4fa7b72016-07-25 22:00:063774 root->SetBounds(gfx::Size(100, 100));
3775 render_surface1->SetBounds(gfx::Size(100, 100));
3776 render_surface1->test_properties()->force_render_surface = true;
3777 child1->SetBounds(gfx::Size(500, 500));
3778 child1->SetDrawsContent(true);
3779 child2->SetBounds(gfx::Size(700, 700));
3780 child2->SetDrawsContent(true);
3781 render_surface2->SetBounds(gfx::Size(1000, 1000));
3782 render_surface2->test_properties()->force_render_surface = true;
3783 render_surface2->SetDrawsContent(true);
jaydasika27d0f2e2015-10-16 23:52:463784
3785 child1->SetMasksToBounds(true);
3786 child2->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463787 ExecuteCalculateDrawProperties(root);
3788 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
3789 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3790}
3791
3792TEST_F(LayerTreeHostCommonTest,
3793 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:593794 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463795 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3796 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3797 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3798 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3799
danakje4fa7b72016-07-25 22:00:063800 root->SetBounds(gfx::Size(100, 100));
3801
3802 clip_parent->SetBounds(gfx::Size(50, 50));
3803 clip_parent->SetMasksToBounds(true);
3804 clip_parent->test_properties()->clip_children =
3805 base::MakeUnique<std::set<LayerImpl*>>();
3806 clip_parent->test_properties()->clip_children->insert(clip_child);
3807
3808 render_surface1->SetBounds(gfx::Size(20, 20));
3809 render_surface1->SetMasksToBounds(true);
jaydasika27d0f2e2015-10-16 23:52:463810 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063811 render_surface1->test_properties()->force_render_surface = true;
3812
3813 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika27d0f2e2015-10-16 23:52:463814 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563815 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika27d0f2e2015-10-16 23:52:463816
danakje4fa7b72016-07-25 22:00:063817 render_surface2->SetBounds(gfx::Size(60, 60));
3818 render_surface2->SetDrawsContent(true);
3819 render_surface2->test_properties()->force_render_surface = true;
jaydasika27d0f2e2015-10-16 23:52:463820
3821 ExecuteCalculateDrawProperties(root);
3822 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3823 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3824 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3825}
3826
jaydasika1f5312d2015-10-21 21:34:323827TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
jaydasikabf1875a2016-06-28 03:39:593828 LayerImpl* root = root_layer_for_testing();
jaydasika1f5312d2015-10-21 21:34:323829 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3830 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3831 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3832 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3833
danakje4fa7b72016-07-25 22:00:063834 root->SetBounds(gfx::Size(100, 100));
3835
3836 clip_parent->SetPosition(gfx::PointF(2.f, 2.f));
3837 clip_parent->SetBounds(gfx::Size(50, 50));
3838 clip_parent->test_properties()->clip_children =
3839 base::MakeUnique<std::set<LayerImpl*>>();
3840 clip_parent->test_properties()->clip_children->insert(clip_child);
3841
3842 render_surface1->SetBounds(gfx::Size(20, 20));
jaydasika1f5312d2015-10-21 21:34:323843 render_surface1->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063844 render_surface1->test_properties()->force_render_surface = true;
3845
3846 clip_child->SetBounds(gfx::Size(60, 60));
jaydasika1f5312d2015-10-21 21:34:323847 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563848 clip_child->test_properties()->clip_parent = clip_parent;
jaydasika1f5312d2015-10-21 21:34:323849
danakje4fa7b72016-07-25 22:00:063850 render_surface2->SetBounds(gfx::Size(60, 60));
3851 render_surface2->SetDrawsContent(true);
3852 render_surface2->test_properties()->force_render_surface = true;
3853
jaydasika1f5312d2015-10-21 21:34:323854 clip_parent->SetMasksToBounds(true);
3855 render_surface1->SetMasksToBounds(true);
3856
3857 ExecuteCalculateDrawProperties(root);
3858 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3859}
3860
jaydasika77a4a072015-10-20 21:47:273861TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3862 // Test that only drawn layers contribute to render surface content rect.
jaydasikabf1875a2016-06-28 03:39:593863 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:273864 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3865 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3866
danakje4fa7b72016-07-25 22:00:063867 root->SetBounds(gfx::Size(200, 200));
3868 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:273869 surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:063870 surface->test_properties()->force_render_surface = true;
3871 test_layer->SetBounds(gfx::Size(150, 150));
jaydasika77a4a072015-10-20 21:47:273872
3873 ExecuteCalculateDrawProperties(root);
3874 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3875
3876 test_layer->SetDrawsContent(true);
3877 ExecuteCalculateDrawProperties(root);
3878 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3879}
3880
jaydasika27d0f2e2015-10-16 23:52:463881TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3882 // Tests visible rects computation when we have unclipped_surface->
3883 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3884 // of surface_with_unclipped_descendants doesn't propagate to the
3885 // clipped_surface below it.
jaydasikabf1875a2016-06-28 03:39:593886 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463887 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3888 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3889 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3890 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3891 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3892
danakje4fa7b72016-07-25 22:00:063893 root->SetBounds(gfx::Size(100, 100));
jaydasika27d0f2e2015-10-16 23:52:463894
danakje4fa7b72016-07-25 22:00:063895 unclipped_surface->SetBounds(gfx::Size(30, 30));
3896 unclipped_surface->SetDrawsContent(true);
3897 unclipped_surface->test_properties()->force_render_surface = true;
3898
3899 clip_parent->SetBounds(gfx::Size(50, 50));
3900 clip_parent->test_properties()->clip_children =
3901 base::MakeUnique<std::set<LayerImpl*>>();
3902 clip_parent->test_properties()->clip_children->insert(clip_child);
3903
3904 unclipped_desc_surface->SetBounds(gfx::Size(20, 20));
3905 unclipped_desc_surface->SetDrawsContent(true);
3906 unclipped_desc_surface->test_properties()->force_render_surface = true;
3907
3908 clip_child->SetBounds(gfx::Size(60, 60));
3909 clip_child->test_properties()->clip_parent = clip_parent;
3910
3911 clipped_surface->SetBounds(gfx::Size(60, 60));
3912 clipped_surface->SetDrawsContent(true);
3913 clipped_surface->test_properties()->force_render_surface = true;
3914
jaydasika27d0f2e2015-10-16 23:52:463915 clip_parent->SetMasksToBounds(true);
3916
3917 ExecuteCalculateDrawProperties(root);
3918 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3919 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3920 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3921}
3922
3923TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3924 // Tests visible rects computation when we have unclipped_surface->
3925 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3926 // of root propagate to the clipped_surface.
jaydasikabf1875a2016-06-28 03:39:593927 LayerImpl* root = root_layer_for_testing();
jaydasika27d0f2e2015-10-16 23:52:463928 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3929 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3930 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3931 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3932 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3933
danakje4fa7b72016-07-25 22:00:063934 root->SetBounds(gfx::Size(10, 10));
jaydasika27d0f2e2015-10-16 23:52:463935
danakje4fa7b72016-07-25 22:00:063936 unclipped_surface->SetBounds(gfx::Size(50, 50));
3937 unclipped_surface->SetDrawsContent(true);
3938 unclipped_surface->test_properties()->force_render_surface = true;
3939
3940 clip_parent->SetBounds(gfx::Size(50, 50));
3941 clip_parent->test_properties()->clip_children =
3942 base::MakeUnique<std::set<LayerImpl*>>();
3943 clip_parent->test_properties()->clip_children->insert(clip_child);
3944
3945 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
3946 unclipped_desc_surface->SetDrawsContent(true);
3947 unclipped_desc_surface->test_properties()->force_render_surface = true;
3948
3949 clip_child->SetBounds(gfx::Size(100, 100));
3950 clip_child->test_properties()->clip_parent = clip_parent;
3951
3952 clipped_surface->SetBounds(gfx::Size(50, 50));
3953 clipped_surface->SetDrawsContent(true);
3954 clipped_surface->test_properties()->force_render_surface = true;
3955
jaydasika27d0f2e2015-10-16 23:52:463956 clip_parent->SetMasksToBounds(true);
3957 unclipped_desc_surface->SetMasksToBounds(true);
3958
3959 ExecuteCalculateDrawProperties(root);
3960 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
weiliangc0e13ba602016-03-12 04:53:563961 EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463962 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3963}
3964
3965TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233966 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323967 // Layers that have non-axis aligned bounds (due to transforms) have an
3968 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:593969 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:173970 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3971 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:283972
[email protected]fb661802013-03-25 01:59:323973 gfx::Transform child_rotation;
3974 child_rotation.Rotate(45.0);
[email protected]fb661802013-03-25 01:59:323975
danakje4fa7b72016-07-25 22:00:063976 root->SetBounds(gfx::Size(100, 100));
3977 render_surface->SetBounds(gfx::Size(3, 4));
3978 render_surface->test_properties()->force_render_surface = true;
3979 child1->SetTransform(child_rotation);
3980 child1->SetPosition(gfx::PointF(25.f, 25.f));
3981 child1->SetBounds(gfx::Size(50, 50));
3982 child1->SetDrawsContent(true);
3983 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:173984 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323985
weiliangc0dece732015-07-27 19:06:173986 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323987
danakj5e6ff6d2015-09-05 04:43:443988 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323989 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323990
3991 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433992 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173993 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323994
3995 // The unclipped surface grows its DrawableContentRect to include all drawable
3996 // regions of the subtree.
3997 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3998 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263999 gfx::Rect(50 - diagonal_radius,
4000 50 - diagonal_radius,
4001 diagonal_radius * 2,
4002 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444003 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174004 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324005
4006 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434007 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324008 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324009}
4010
[email protected]989386c2013-07-18 21:37:234011TEST_F(LayerTreeHostCommonTest,
4012 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324013 // Layers that have non-axis aligned bounds (due to transforms) have an
4014 // expanded, axis-aligned DrawableContentRect and visible content rect.
jaydasikabf1875a2016-06-28 03:39:594015 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174016 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4017 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
[email protected]d600df7d2013-08-03 02:34:284018
[email protected]fb661802013-03-25 01:59:324019 gfx::Transform child_rotation;
4020 child_rotation.Rotate(45.0);
[email protected]a2566412014-06-05 03:14:204021
danakje4fa7b72016-07-25 22:00:064022 root->SetBounds(gfx::Size(50, 50));
[email protected]fb661802013-03-25 01:59:324023 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064024 render_surface->SetBounds(gfx::Size(3, 4));
4025 render_surface->test_properties()->force_render_surface = true;
4026 child1->SetPosition(gfx::PointF(25.f, 25.f));
4027 child1->SetBounds(gfx::Size(50, 50));
4028 child1->SetDrawsContent(true);
4029 child1->SetTransform(child_rotation);
4030 child1->test_properties()->transform_origin = gfx::Point3F(25.f, 25.f, 0.f);
weiliangc0dece732015-07-27 19:06:174031 ExecuteCalculateDrawProperties(root);
4032
4033 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324034
4035 // The clipped surface clamps the DrawableContentRect that encloses the
4036 // rotated layer.
4037 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264038 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4039 50 - diagonal_radius,
4040 diagonal_radius * 2,
4041 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444042 gfx::RectF expected_surface_drawable_content(
4043 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324044 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174045 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324046
4047 // On the clipped surface, only a quarter of the child1 is visible, but when
4048 // rotating it back to child1's content space, the actual enclosing rect ends
4049 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:334050 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324051
4052 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324053 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324054}
4055
[email protected]989386c2013-07-18 21:37:234056TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594057 LayerImpl* root = root_layer_for_testing();
weiliangc0dece732015-07-27 19:06:174058 FakePictureLayerImpl* render_surface1 =
4059 AddChildToRoot<FakePictureLayerImpl>();
weiliangc0dece732015-07-27 19:06:174060 FakePictureLayerImpl* render_surface2 =
4061 AddChild<FakePictureLayerImpl>(render_surface1);
weiliangc0dece732015-07-27 19:06:174062 FakePictureLayerImpl* child1 =
4063 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174064 FakePictureLayerImpl* child2 =
4065 AddChild<FakePictureLayerImpl>(render_surface2);
weiliangc0dece732015-07-27 19:06:174066 FakePictureLayerImpl* child3 =
4067 AddChild<FakePictureLayerImpl>(render_surface2);
[email protected]d600df7d2013-08-03 02:34:284068
danakje4fa7b72016-07-25 22:00:064069 root->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324070 root->SetMasksToBounds(true);
danakje4fa7b72016-07-25 22:00:064071 render_surface1->SetBounds(gfx::Size(3, 4));
4072 render_surface1->SetPosition(gfx::PointF(5.f, 5.f));
4073 render_surface1->SetDrawsContent(true);
4074 render_surface1->test_properties()->force_render_surface = true;
4075 render_surface2->SetBounds(gfx::Size(7, 13));
4076 render_surface2->SetPosition(gfx::PointF(5.f, 5.f));
4077 render_surface2->SetDrawsContent(true);
4078 render_surface2->test_properties()->force_render_surface = true;
4079 child1->SetBounds(gfx::Size(50, 50));
4080 child1->SetPosition(gfx::PointF(5.f, 5.f));
4081 child1->SetDrawsContent(true);
4082 child2->SetBounds(gfx::Size(50, 50));
4083 child2->SetPosition(gfx::PointF(75.f, 75.f));
4084 child2->SetDrawsContent(true);
4085 child3->SetBounds(gfx::Size(50, 50));
4086 child3->SetPosition(gfx::PointF(125.f, 125.f));
4087 child3->SetDrawsContent(true);
4088 float device_scale_factor = 2.f;
weiliangc0dece732015-07-27 19:06:174089 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324090
4091 ASSERT_TRUE(render_surface1->render_surface());
4092 ASSERT_TRUE(render_surface2->render_surface());
4093
4094 // drawable_content_rects for all layers and surfaces are scaled by
4095 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444096 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324097 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444098 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324099 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324100
4101 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4102 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444103 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324104 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324105
hush6b614212014-12-04 22:37:324106 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4107 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4108 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324109
4110 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434111 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324112
sohan.jyotie3bd6192014-10-13 07:13:594113 // All layer visible content rects are not expressed in content space of each
4114 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434115 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4116 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4117 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
4118 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
4119 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324120}
4121
[email protected]989386c2013-07-18 21:37:234122TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324123 // Verify the behavior of back-face culling when there are no preserve-3d
4124 // layers. Note that 3d transforms still apply in this case, but they are
4125 // "flattened" to each parent layer according to current W3C spec.
4126
danakje4fa7b72016-07-25 22:00:064127 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324128 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4129 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4130 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4131 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4132 LayerImpl* front_facing_child_of_front_facing_surface =
4133 AddChild<LayerImpl>(front_facing_surface);
4134 LayerImpl* back_facing_child_of_front_facing_surface =
4135 AddChild<LayerImpl>(front_facing_surface);
4136 LayerImpl* front_facing_child_of_back_facing_surface =
4137 AddChild<LayerImpl>(back_facing_surface);
4138 LayerImpl* back_facing_child_of_back_facing_surface =
4139 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284140
[email protected]fb661802013-03-25 01:59:324141 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324142 front_facing_child->test_properties()->double_sided = false;
4143 back_facing_child->test_properties()->double_sided = false;
4144 front_facing_surface->test_properties()->double_sided = false;
4145 back_facing_surface->test_properties()->double_sided = false;
4146 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4147 false;
4148 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4149 false;
4150 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4151 false;
4152 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4153 false;
4154
4155 // Everything draws content.
4156 front_facing_child->SetDrawsContent(true);
4157 back_facing_child->SetDrawsContent(true);
4158 front_facing_surface->SetDrawsContent(true);
4159 back_facing_surface->SetDrawsContent(true);
4160 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4161 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4162 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4163 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324164
4165 gfx::Transform backface_matrix;
4166 backface_matrix.Translate(50.0, 50.0);
4167 backface_matrix.RotateAboutYAxis(180.0);
4168 backface_matrix.Translate(-50.0, -50.0);
4169
danakje4fa7b72016-07-25 22:00:064170 root->SetBounds(gfx::Size(100, 100));
4171 front_facing_child->SetBounds(gfx::Size(100, 100));
4172 back_facing_child->SetBounds(gfx::Size(100, 100));
4173 front_facing_surface->SetBounds(gfx::Size(100, 100));
4174 back_facing_surface->SetBounds(gfx::Size(100, 100));
4175 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4176 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4177 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4178 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324179
danakje4fa7b72016-07-25 22:00:064180 front_facing_surface->test_properties()->force_render_surface = true;
4181 back_facing_surface->test_properties()->force_render_surface = true;
[email protected]fb661802013-03-25 01:59:324182
danakje4fa7b72016-07-25 22:00:064183 back_facing_child->SetTransform(backface_matrix);
4184 back_facing_surface->SetTransform(backface_matrix);
4185 back_facing_child_of_front_facing_surface->SetTransform(backface_matrix);
4186 back_facing_child_of_back_facing_surface->SetTransform(backface_matrix);
4187
4188 // Note: No layers preserve 3d. According to current W3C CSS gfx::Transforms
4189 // spec, these layers should blindly use their own local transforms to
4190 // determine back-face culling.
4191 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
[email protected]fb661802013-03-25 01:59:324192
4193 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094194 EXPECT_FALSE(front_facing_child->has_render_surface());
4195 EXPECT_FALSE(back_facing_child->has_render_surface());
4196 EXPECT_TRUE(front_facing_surface->has_render_surface());
4197 EXPECT_TRUE(back_facing_surface->has_render_surface());
4198 EXPECT_FALSE(
4199 front_facing_child_of_front_facing_surface->has_render_surface());
4200 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4201 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4202 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324203
ajuma4711f4b12016-05-16 18:48:324204 EXPECT_EQ(4u, update_layer_list_impl()->size());
4205 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4206 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4207 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534208 front_facing_child_of_front_facing_surface->id()));
ajuma4711f4b12016-05-16 18:48:324209 EXPECT_TRUE(UpdateLayerListImplContains(
4210 front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324211}
4212
[email protected]989386c2013-07-18 21:37:234213TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324214 // Verify the behavior of back-face culling when preserves-3d transform style
4215 // is used.
4216
danakje4fa7b72016-07-25 22:00:064217 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:264218 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4219 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4220 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4221 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4222 LayerImpl* front_facing_child_of_front_facing_surface =
4223 AddChild<LayerImpl>(front_facing_surface);
4224 LayerImpl* back_facing_child_of_front_facing_surface =
4225 AddChild<LayerImpl>(front_facing_surface);
4226 LayerImpl* front_facing_child_of_back_facing_surface =
4227 AddChild<LayerImpl>(back_facing_surface);
4228 LayerImpl* back_facing_child_of_back_facing_surface =
4229 AddChild<LayerImpl>(back_facing_surface);
4230 // Opacity will not force creation of render surfaces in this case because of
4231 // the preserve-3d transform style. Instead, an example of when a surface
4232 // would be created with preserve-3d is when there is a replica layer.
4233 LayerImpl* dummy_replica_layer1 =
4234 AddReplicaLayer<LayerImpl>(front_facing_surface);
4235 LayerImpl* dummy_replica_layer2 =
4236 AddReplicaLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284237
[email protected]fb661802013-03-25 01:59:324238 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364239 front_facing_child->test_properties()->double_sided = false;
4240 back_facing_child->test_properties()->double_sided = false;
4241 front_facing_surface->test_properties()->double_sided = false;
4242 back_facing_surface->test_properties()->double_sided = false;
4243 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4244 false;
4245 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4246 false;
4247 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4248 false;
4249 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4250 false;
[email protected]fb661802013-03-25 01:59:324251
weiliangcc154ce22015-12-09 03:39:264252 // Everything draws content.
4253 front_facing_child->SetDrawsContent(true);
4254 back_facing_child->SetDrawsContent(true);
4255 front_facing_surface->SetDrawsContent(true);
4256 back_facing_surface->SetDrawsContent(true);
4257 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4258 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4259 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4260 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4261 dummy_replica_layer1->SetDrawsContent(true);
4262 dummy_replica_layer2->SetDrawsContent(true);
4263
[email protected]fb661802013-03-25 01:59:324264 gfx::Transform backface_matrix;
4265 backface_matrix.Translate(50.0, 50.0);
4266 backface_matrix.RotateAboutYAxis(180.0);
4267 backface_matrix.Translate(-50.0, -50.0);
4268
danakje4fa7b72016-07-25 22:00:064269 root->SetBounds(gfx::Size(100, 100));
4270 front_facing_child->SetBounds(gfx::Size(100, 100));
4271 back_facing_child->SetBounds(gfx::Size(100, 100));
4272 front_facing_surface->SetBounds(gfx::Size(100, 100));
4273 back_facing_surface->SetBounds(gfx::Size(100, 100));
4274 front_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4275 back_facing_child_of_front_facing_surface->SetBounds(gfx::Size(100, 100));
4276 front_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4277 back_facing_child_of_back_facing_surface->SetBounds(gfx::Size(100, 100));
4278
4279 back_facing_child->SetTransform(backface_matrix);
4280 back_facing_surface->SetTransform(backface_matrix);
4281 back_facing_child_of_front_facing_surface->SetTransform(backface_matrix);
4282 back_facing_child_of_back_facing_surface->SetTransform(backface_matrix);
4283
[email protected]fb661802013-03-25 01:59:324284 // Each surface creates its own new 3d rendering context (as defined by W3C
4285 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4286 // rendering context should use the transform with respect to that context.
4287 // This 3d rendering context occurs when (a) parent's transform style is flat
4288 // and (b) the layer's transform style is preserve-3d.
danakje4fa7b72016-07-25 22:00:064289 front_facing_surface->test_properties()->should_flatten_transform = false;
4290 front_facing_surface->Set3dSortingContextId(1);
4291 back_facing_surface->test_properties()->should_flatten_transform = false;
4292 back_facing_surface->Set3dSortingContextId(1);
4293 front_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4294 back_facing_child_of_front_facing_surface->Set3dSortingContextId(1);
4295 front_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
4296 back_facing_child_of_back_facing_surface->Set3dSortingContextId(1);
[email protected]fb661802013-03-25 01:59:324297
danakje4fa7b72016-07-25 22:00:064298 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
[email protected]fb661802013-03-25 01:59:324299
awoloszyne83f28c2014-12-22 15:40:004300 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094301 EXPECT_FALSE(front_facing_child->has_render_surface());
4302 EXPECT_FALSE(back_facing_child->has_render_surface());
4303 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094304 // We expect that a has_render_surface was created but not used.
4305 EXPECT_TRUE(back_facing_surface->has_render_surface());
4306 EXPECT_FALSE(
4307 front_facing_child_of_front_facing_surface->has_render_surface());
4308 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4309 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4310 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324311
weiliangcc154ce22015-12-09 03:39:264312 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324313
weiliangcc154ce22015-12-09 03:39:264314 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4315 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4316 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534317 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324318}
4319
[email protected]989386c2013-07-18 21:37:234320TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324321 // Verify that layers are appropriately culled when their back face is showing
4322 // and they are not double sided, while animations are going on.
4323 //
ajuma4711f4b12016-05-16 18:48:324324 // Even layers that are animating get culled if their back face is showing and
4325 // they are not double sided.
danakje4fa7b72016-07-25 22:00:064326 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324327 LayerImpl* child = AddChildToRoot<LayerImpl>();
4328 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4329 LayerImpl* child_of_animating_surface =
4330 AddChild<LayerImpl>(animating_surface);
4331 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4332 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284333
[email protected]fb661802013-03-25 01:59:324334 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324335 child->test_properties()->double_sided = false;
4336 child2->test_properties()->double_sided = false;
4337 animating_surface->test_properties()->double_sided = false;
4338 child_of_animating_surface->test_properties()->double_sided = false;
4339 animating_child->test_properties()->double_sided = false;
4340
4341 // Everything draws content.
4342 child->SetDrawsContent(true);
4343 child2->SetDrawsContent(true);
4344 animating_surface->SetDrawsContent(true);
4345 child_of_animating_surface->SetDrawsContent(true);
4346 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324347
4348 gfx::Transform backface_matrix;
4349 backface_matrix.Translate(50.0, 50.0);
4350 backface_matrix.RotateAboutYAxis(180.0);
4351 backface_matrix.Translate(-50.0, -50.0);
4352
vollickef2ae922016-06-29 17:54:274353 SetElementIdsForTesting();
4354
loyso9556c732016-03-11 07:54:584355 // Animate the transform on the render surface.
vollickef2ae922016-06-29 17:54:274356 AddAnimatedTransformToElementWithPlayer(animating_surface->element_id(),
4357 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584358 // This is just an animating layer, not a surface.
vollickef2ae922016-06-29 17:54:274359 AddAnimatedTransformToElementWithPlayer(animating_child->element_id(),
4360 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324361
danakje4fa7b72016-07-25 22:00:064362 root->SetBounds(gfx::Size(100, 100));
4363 child->SetBounds(gfx::Size(100, 100));
4364 child->SetTransform(backface_matrix);
4365 animating_surface->SetBounds(gfx::Size(100, 100));
4366 animating_surface->SetTransform(backface_matrix);
4367 animating_surface->test_properties()->force_render_surface = true;
4368 child_of_animating_surface->SetBounds(gfx::Size(100, 100));
4369 child_of_animating_surface->SetTransform(backface_matrix);
4370 animating_child->SetBounds(gfx::Size(100, 100));
4371 animating_child->SetTransform(backface_matrix);
4372 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324373
danakje4fa7b72016-07-25 22:00:064374 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
[email protected]fb661802013-03-25 01:59:324375
ennec1332992015-08-24 19:45:094376 EXPECT_FALSE(child->has_render_surface());
4377 EXPECT_TRUE(animating_surface->has_render_surface());
4378 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4379 EXPECT_FALSE(animating_child->has_render_surface());
4380 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324381
ajuma4711f4b12016-05-16 18:48:324382 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534383
ajuma4711f4b12016-05-16 18:48:324384 // The back facing layers are culled from the layer list, and have an empty
4385 // visible rect.
4386 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4387 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4388 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4389 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4390 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324391
ajuma4711f4b12016-05-16 18:48:324392 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324393}
4394
[email protected]989386c2013-07-18 21:37:234395TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324396 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4397 // Verify the behavior of back-face culling for a render surface that is
4398 // created when it flattens its subtree, and its parent has preserves-3d.
4399
danakje4fa7b72016-07-25 22:00:064400 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324401 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4402 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4403 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4404 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284405
[email protected]fb661802013-03-25 01:59:324406 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324407 front_facing_surface->test_properties()->double_sided = false;
4408 back_facing_surface->test_properties()->double_sided = false;
4409
4410 // Everything draws content.
4411 front_facing_surface->SetDrawsContent(true);
4412 back_facing_surface->SetDrawsContent(true);
4413 child1->SetDrawsContent(true);
4414 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324415
4416 gfx::Transform backface_matrix;
4417 backface_matrix.Translate(50.0, 50.0);
4418 backface_matrix.RotateAboutYAxis(180.0);
4419 backface_matrix.Translate(-50.0, -50.0);
4420
danakje4fa7b72016-07-25 22:00:064421 root->SetBounds(gfx::Size(100, 100));
4422 front_facing_surface->SetBounds(gfx::Size(100, 100));
4423 front_facing_surface->test_properties()->force_render_surface = true;
4424 back_facing_surface->SetBounds(gfx::Size(100, 100));
4425 back_facing_surface->SetTransform(backface_matrix);
4426 back_facing_surface->test_properties()->force_render_surface = true;
4427 child1->SetBounds(gfx::Size(100, 100));
4428 child2->SetBounds(gfx::Size(100, 100));
[email protected]fb661802013-03-25 01:59:324429
[email protected]a9d4d4f2014-06-19 06:49:284430 front_facing_surface->Set3dSortingContextId(1);
4431 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574432
danakje4fa7b72016-07-25 22:00:064433 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
[email protected]fb661802013-03-25 01:59:324434
awoloszyne83f28c2014-12-22 15:40:004435 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094436 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004437
4438 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094439 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094440 EXPECT_FALSE(child1->has_render_surface());
4441 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324442
ajuma4711f4b12016-05-16 18:48:324443 EXPECT_EQ(2u, update_layer_list_impl()->size());
4444 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4445 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324446}
4447
enne637715732015-07-07 02:05:264448TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324449 // Verify draw and screen space transforms of layers not in a surface.
danakje4fa7b72016-07-25 22:00:064450 LayerImpl* root = root_layer_for_testing();
4451 root->SetBounds(gfx::Size(100, 100));
4452 root->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144453
enne637715732015-07-07 02:05:264454 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064455 child->SetPosition(gfx::PointF(2.f, 2.f));
4456 child->SetBounds(gfx::Size(10, 10));
jaydasika8640f9f2015-11-10 01:34:364457 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144458
jaydasika8640f9f2015-11-10 01:34:364459 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064460 child2->SetPosition(gfx::PointF(2.f, 2.f));
4461 child2->SetBounds(gfx::Size(5, 5));
jaydasika8640f9f2015-11-10 01:34:364462 child2->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284463
[email protected]fb661802013-03-25 01:59:324464 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264465 gfx::Size viewport_size(100, 100);
danakje4fa7b72016-07-25 22:00:064466 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144467
danakj59931942016-07-26 22:11:294468 EXPECT_FLOAT_EQ(device_scale_factor, root->GetIdealContentsScale());
4469 EXPECT_FLOAT_EQ(device_scale_factor, child->GetIdealContentsScale());
4470 EXPECT_FLOAT_EQ(device_scale_factor, child2->GetIdealContentsScale());
[email protected]518ee582012-10-24 18:29:444471
enne637715732015-07-07 02:05:264472 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144473
danakje4fa7b72016-07-25 22:00:064474 // Verify root transforms
4475 gfx::Transform expected_root_transform;
4476 expected_root_transform.Scale(device_scale_factor, device_scale_factor);
4477 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4478 root->ScreenSpaceTransform());
4479 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_root_transform,
4480 root->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144481
danakje4fa7b72016-07-25 22:00:064482 // Verify results of transformed root rects
4483 gfx::RectF root_bounds(gfx::SizeF(root->bounds()));
[email protected]94f206c12012-08-25 00:09:144484
danakje4fa7b72016-07-25 22:00:064485 gfx::RectF root_draw_rect =
4486 MathUtil::MapClippedRect(root->DrawTransform(), root_bounds);
4487 gfx::RectF root_screen_space_rect =
4488 MathUtil::MapClippedRect(root->ScreenSpaceTransform(), root_bounds);
[email protected]94f206c12012-08-25 00:09:144489
danakje4fa7b72016-07-25 22:00:064490 gfx::RectF expected_root_draw_rect(gfx::SizeF(root->bounds()));
4491 expected_root_draw_rect.Scale(device_scale_factor);
4492 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_draw_rect);
4493 EXPECT_FLOAT_RECT_EQ(expected_root_draw_rect, root_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144494
jaydasika8640f9f2015-11-10 01:34:364495 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324496 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594497 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4498 expected_child_transform.Translate(child->position().x(),
4499 child->position().y());
[email protected]fb661802013-03-25 01:59:324500 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444501 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324502 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104503 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324504 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444505 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324506 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104507 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144508
jaydasika8640f9f2015-11-10 01:34:364509 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324510 // match.
danakjddaec912015-09-25 19:38:404511 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144512
[email protected]fb661802013-03-25 01:59:324513 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444514 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144515 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104516 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144517
jaydasika8640f9f2015-11-10 01:34:364518 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444519 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364520 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104521 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454522
danakjddaec912015-09-25 19:38:404523 gfx::RectF expected_child_draw_rect(child->position(),
4524 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324525 expected_child_draw_rect.Scale(device_scale_factor);
4526 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4527 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364528 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4529 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144530}
4531
enne637715732015-07-07 02:05:264532TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324533 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324534 gfx::Transform perspective_matrix;
4535 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094536
[email protected]fb661802013-03-25 01:59:324537 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054538 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094539
jaydasikabf1875a2016-06-28 03:39:594540 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064541 root->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094542
4543 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064544 page_scale->SetBounds(gfx::Size(100, 100));
sunxdc5d4fb42016-05-27 04:40:094545
4546 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
danakje4fa7b72016-07-25 22:00:064547 parent->SetBounds(gfx::Size(100, 100));
jaydasika8640f9f2015-11-10 01:34:364548 parent->SetDrawsContent(true);
[email protected]9781afa2013-07-17 23:15:324549
enne637715732015-07-07 02:05:264550 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064551 perspective_surface->SetPosition(gfx::PointF(2.f, 2.f));
4552 perspective_surface->SetBounds(gfx::Size(10, 10));
4553 perspective_surface->SetTransform(perspective_matrix * scale_small_matrix);
enne637715732015-07-07 02:05:264554 perspective_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064555 perspective_surface->test_properties()->force_render_surface = true;
[email protected]1b30e8e2012-12-21 02:59:094556
enne637715732015-07-07 02:05:264557 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064558 scale_surface->SetPosition(gfx::PointF(2.f, 2.f));
4559 scale_surface->SetBounds(gfx::Size(10, 10));
4560 scale_surface->SetTransform(scale_small_matrix);
enne637715732015-07-07 02:05:264561 scale_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064562 scale_surface->test_properties()->force_render_surface = true;
[email protected]d600df7d2013-08-03 02:34:284563
[email protected]fb661802013-03-25 01:59:324564 float device_scale_factor = 2.5f;
4565 float page_scale_factor = 3.f;
sunxdc5d4fb42016-05-27 04:40:094566 root->layer_tree_impl()->SetViewportLayersFromIds(
4567 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4568 Layer::INVALID_ID);
jaydasika4340ea02016-06-06 19:44:264569 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094570 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264571 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4572 root);
[email protected]1b30e8e2012-12-21 02:59:094573
danakj59931942016-07-26 22:11:294574 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4575 parent->GetIdealContentsScale());
4576 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor,
4577 perspective_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594578 // Ideal scale is the max 2d scale component of the combined transform up to
4579 // the nearest render target. Here this includes the layer transform as well
4580 // as the device and page scale factors.
4581 gfx::Transform transform = scale_small_matrix;
4582 transform.Scale(device_scale_factor * page_scale_factor,
4583 device_scale_factor * page_scale_factor);
4584 gfx::Vector2dF scales =
4585 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4586 float max_2d_scale = std::max(scales.x(), scales.y());
danakj59931942016-07-26 22:11:294587 EXPECT_FLOAT_EQ(max_2d_scale, scale_surface->GetIdealContentsScale());
sohan.jyotie3bd6192014-10-13 07:13:594588
4589 // The ideal scale will draw 1:1 with its render target space along
4590 // the larger-scale axis.
4591 gfx::Vector2dF target_space_transform_scales =
4592 MathUtil::ComputeTransform2dScaleComponents(
4593 scale_surface->draw_properties().target_space_transform, 0.f);
4594 EXPECT_FLOAT_EQ(max_2d_scale,
4595 std::max(target_space_transform_scales.x(),
4596 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094597
enne637715732015-07-07 02:05:264598 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094599
[email protected]fb661802013-03-25 01:59:324600 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594601 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4602 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324603 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444604 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094605
[email protected]fb661802013-03-25 01:59:324606 // The scale for the perspective surface is not known, so it is rendered 1:1
4607 // with the screen, and then scaled during drawing.
4608 gfx::Transform expected_perspective_surface_draw_transform;
4609 expected_perspective_surface_draw_transform.Translate(
4610 device_scale_factor * page_scale_factor *
4611 perspective_surface->position().x(),
4612 device_scale_factor * page_scale_factor *
4613 perspective_surface->position().y());
4614 expected_perspective_surface_draw_transform.PreconcatTransform(
4615 perspective_matrix);
4616 expected_perspective_surface_draw_transform.PreconcatTransform(
4617 scale_small_matrix);
4618 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594619 expected_perspective_surface_layer_draw_transform.Scale(
4620 device_scale_factor * page_scale_factor,
4621 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324622 EXPECT_TRANSFORMATION_MATRIX_EQ(
4623 expected_perspective_surface_draw_transform,
4624 perspective_surface->render_surface()->draw_transform());
4625 EXPECT_TRANSFORMATION_MATRIX_EQ(
4626 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444627 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094628}
4629
enne637715732015-07-07 02:05:264630TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294631 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264632 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294633 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4634
4635 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264636 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294637 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4638
jaydasikabf1875a2016-06-28 03:39:594639 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294640 root->SetBounds(gfx::Size(100, 100));
4641
enne637715732015-07-07 02:05:264642 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064643 parent->SetBounds(gfx::Size(100, 100));
4644 parent->SetTransform(parent_scale_matrix);
jaydasika8640f9f2015-11-10 01:34:364645 parent->SetDrawsContent(true);
[email protected]35a99a12013-05-09 23:52:294646
enne637715732015-07-07 02:05:264647 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064648 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4649 child_scale->SetBounds(gfx::Size(10, 10));
4650 child_scale->SetTransform(child_scale_matrix);
jaydasika8640f9f2015-11-10 01:34:364651 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284652
[email protected]fb661802013-03-25 01:59:324653 float device_scale_factor = 2.5f;
4654 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214655
[email protected]989386c2013-07-18 21:37:234656 {
enne637715732015-07-07 02:05:264657 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4658 root);
[email protected]11ec92972012-11-10 03:06:214659
sohan.jyotie3bd6192014-10-13 07:13:594660 // The ideal scale is able to go below 1.
4661 float expected_ideal_scale =
4662 device_scale_factor * page_scale_factor * initial_parent_scale;
4663 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294664 EXPECT_FLOAT_EQ(expected_ideal_scale, parent->GetIdealContentsScale());
[email protected]11ec92972012-11-10 03:06:214665
sohan.jyotie3bd6192014-10-13 07:13:594666 expected_ideal_scale = device_scale_factor * page_scale_factor *
4667 initial_parent_scale * initial_child_scale;
4668 EXPECT_LT(expected_ideal_scale, 1.f);
danakj59931942016-07-26 22:11:294669 EXPECT_FLOAT_EQ(expected_ideal_scale, child_scale->GetIdealContentsScale());
[email protected]989386c2013-07-18 21:37:234670 }
[email protected]11ec92972012-11-10 03:06:214671}
4672
enne637715732015-07-07 02:05:264673TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324674 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264675 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324676 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264677
[email protected]fb661802013-03-25 01:59:324678 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264679 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324680 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264681
jaydasikabf1875a2016-06-28 03:39:594682 LayerImpl* root = root_layer_for_testing();
[email protected]35a99a12013-05-09 23:52:294683 root->SetBounds(gfx::Size(100, 100));
4684
enne637715732015-07-07 02:05:264685 LayerImpl* parent = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064686 parent->SetBounds(gfx::Size(100, 100));
4687 parent->SetTransform(parent_scale_matrix);
jaydasika8640f9f2015-11-10 01:34:364688 parent->SetDrawsContent(true);
[email protected]6a9cff92012-11-08 11:53:264689
enne637715732015-07-07 02:05:264690 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
danakje4fa7b72016-07-25 22:00:064691 child_scale->SetBounds(gfx::Size(10, 10));
4692 child_scale->SetPosition(gfx::PointF(2.f, 2.f));
4693 child_scale->SetTransform(child_scale_matrix);
jaydasika8640f9f2015-11-10 01:34:364694 child_scale->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284695
danakje4fa7b72016-07-25 22:00:064696 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264697
danakj59931942016-07-26 22:11:294698 EXPECT_FLOAT_EQ(initial_parent_scale, parent->GetIdealContentsScale());
danakje4fa7b72016-07-25 22:00:064699 // Animating layers compute ideal scale in the same way as when
4700 // they are static.
danakj59931942016-07-26 22:11:294701 EXPECT_FLOAT_EQ(initial_child_scale * initial_parent_scale,
4702 child_scale->GetIdealContentsScale());
[email protected]6a9cff92012-11-08 11:53:264703}
4704
[email protected]989386c2013-07-18 21:37:234705TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
jaydasikabf1875a2016-06-28 03:39:594706 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064707 parent->SetBounds(gfx::Size(30, 30));
enneea850232015-07-27 16:43:124708 parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064709 parent->Set3dSortingContextId(1);
4710 parent->test_properties()->should_flatten_transform = false;
[email protected]94f206c12012-08-25 00:09:144711
enneea850232015-07-27 16:43:124712 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064713 child->SetBounds(gfx::Size(10, 10));
4714 child->SetPosition(gfx::PointF(2.f, 2.f));
enneea850232015-07-27 16:43:124715 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064716 child->test_properties()->force_render_surface = true;
[email protected]94f206c12012-08-25 00:09:144717
[email protected]fb661802013-03-25 01:59:324718 gfx::Transform replica_transform;
4719 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124720
danakj60bc3bc2016-04-09 00:24:484721 std::unique_ptr<LayerImpl> replica =
enneea850232015-07-27 16:43:124722 LayerImpl::Create(host_impl()->active_tree(), 7);
danakje4fa7b72016-07-25 22:00:064723 replica->SetPosition(gfx::PointF(2.f, 2.f));
4724 replica->SetTransform(replica_transform);
4725
jaydasika5017a332016-03-31 01:06:224726 // We need to set parent on replica layer for property tree building.
jaydasikaf419bf72016-06-15 10:21:214727 replica->test_properties()->parent = child;
ajuma1d4026a32016-06-14 13:18:504728 child->test_properties()->SetReplicaLayer(std::move(replica));
[email protected]94f206c12012-08-25 00:09:144729
[email protected]fb661802013-03-25 01:59:324730 // This layer should end up in the same surface as child, with the same draw
4731 // and screen space transforms.
enneea850232015-07-27 16:43:124732 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
danakje4fa7b72016-07-25 22:00:064733 duplicate_child_non_owner->SetBounds(gfx::Size(10, 10));
enneea850232015-07-27 16:43:124734 duplicate_child_non_owner->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:144735
[email protected]fb661802013-03-25 01:59:324736 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124737 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144738
[email protected]fb661802013-03-25 01:59:324739 // We should have two render surfaces. The root's render surface and child's
4740 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124741 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144742
[email protected]fb661802013-03-25 01:59:324743 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594744 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324745 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104746 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324747 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444748 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144749
[email protected]fb661802013-03-25 01:59:324750 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594751 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324752 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444753 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144754
[email protected]fb661802013-03-25 01:59:324755 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594756 expected_screen_space_transform.Scale(device_scale_factor,
4757 device_scale_factor);
4758 expected_screen_space_transform.Translate(child->position().x(),
4759 child->position().y());
[email protected]fb661802013-03-25 01:59:324760 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104761 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144762
[email protected]fb661802013-03-25 01:59:324763 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444764 child->DrawTransform();
trchendba8b1502016-07-08 09:47:014765 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_duplicate_child_draw_transform,
ajumad9432e32015-11-30 19:43:444766 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324767 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104768 child->ScreenSpaceTransform(),
4769 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324770 EXPECT_EQ(child->drawable_content_rect(),
4771 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144772 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144773
[email protected]fb661802013-03-25 01:59:324774 gfx::Transform expected_render_surface_draw_transform;
4775 expected_render_surface_draw_transform.Translate(
4776 device_scale_factor * child->position().x(),
4777 device_scale_factor * child->position().y());
4778 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4779 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144780
[email protected]fb661802013-03-25 01:59:324781 gfx::Transform expected_surface_draw_transform;
4782 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4783 device_scale_factor * 2.f);
4784 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4785 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144786
[email protected]fb661802013-03-25 01:59:324787 gfx::Transform expected_surface_screen_space_transform;
4788 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4789 device_scale_factor * 2.f);
4790 EXPECT_TRANSFORMATION_MATRIX_EQ(
4791 expected_surface_screen_space_transform,
4792 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144793
[email protected]fb661802013-03-25 01:59:324794 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264795 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4796 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
4797 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324798 EXPECT_TRANSFORMATION_MATRIX_EQ(
4799 expected_replica_draw_transform,
4800 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:144801
[email protected]fb661802013-03-25 01:59:324802 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:264803 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4804 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
4805 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324806 EXPECT_TRANSFORMATION_MATRIX_EQ(
4807 expected_replica_screen_space_transform,
4808 child->render_surface()->replica_screen_space_transform());
4809 EXPECT_TRANSFORMATION_MATRIX_EQ(
4810 expected_replica_screen_space_transform,
4811 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:474812}
4813
[email protected]989386c2013-07-18 21:37:234814TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324815 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
jaydasikabf1875a2016-06-28 03:39:594816 LayerImpl* parent = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:064817 parent->SetBounds(gfx::Size(33, 31));
enneea850232015-07-27 16:43:124818 parent->SetDrawsContent(true);
[email protected]904e9132012-11-01 00:12:474819
enneea850232015-07-27 16:43:124820 LayerImpl* child = AddChildToRoot<LayerImpl>();
danakje4fa7b72016-07-25 22:00:064821 child->SetBounds(gfx::Size(13, 11));
enneea850232015-07-27 16:43:124822 child->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:064823 child->test_properties()->force_render_surface = true;
[email protected]904e9132012-11-01 00:12:474824
[email protected]fb661802013-03-25 01:59:324825 gfx::Transform replica_transform;
4826 replica_transform.Scale(1.0, -1.0);
danakj60bc3bc2016-04-09 00:24:484827 std::unique_ptr<LayerImpl> replica =
enneea850232015-07-27 16:43:124828 LayerImpl::Create(host_impl()->active_tree(), 7);
danakje4fa7b72016-07-25 22:00:064829 replica->SetTransform(replica_transform);
ajuma1d4026a32016-06-14 13:18:504830 child->test_properties()->SetReplicaLayer(std::move(replica));
[email protected]d600df7d2013-08-03 02:34:284831
[email protected]873639e2013-07-24 19:56:314832 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124833 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474834
[email protected]fb661802013-03-25 01:59:324835 // We should have two render surfaces. The root's render surface and child's
4836 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124837 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474838
danakjf78fb272016-07-26 19:06:154839 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324840 child->render_surface()->draw_transform());
danakjf78fb272016-07-26 19:06:154841 EXPECT_TRANSFORMATION_MATRIX_EQ(gfx::Transform(),
[email protected]fb661802013-03-25 01:59:324842 child->render_surface()->draw_transform());
4843 EXPECT_TRANSFORMATION_MATRIX_EQ(
danakjf78fb272016-07-26 19:06:154844 gfx::Transform(), child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474845
[email protected]fb661802013-03-25 01:59:324846 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264847 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:324848 EXPECT_TRANSFORMATION_MATRIX_EQ(
4849 expected_replica_draw_transform,
4850 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:474851
[email protected]fb661802013-03-25 01:59:324852 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:264853 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:324854 EXPECT_TRANSFORMATION_MATRIX_EQ(
4855 expected_replica_screen_space_transform,
4856 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144857}
4858
jaydasikadb41a582016-03-28 20:48:214859TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314860 scoped_refptr<Layer> root = Layer::Create();
4861 scoped_refptr<Layer> child = Layer::Create();
4862 scoped_refptr<Layer> grand_child = Layer::Create();
4863 scoped_refptr<Layer> mask_layer = Layer::Create();
4864 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:144865
[email protected]fb661802013-03-25 01:59:324866 grand_child->SetReplicaLayer(replica_layer.get());
4867 child->AddChild(grand_child.get());
4868 child->SetMaskLayer(mask_layer.get());
4869 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144870
ennea7b43c32015-06-18 20:01:334871 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284872
[email protected]fb661802013-03-25 01:59:324873 int nonexistent_id = -1;
jaydasikadb41a582016-03-28 20:48:214874 EXPECT_EQ(root.get(), host()->LayerById(root->id()));
4875 EXPECT_EQ(child.get(), host()->LayerById(child->id()));
4876 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
4877 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
4878 EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id()));
4879 EXPECT_FALSE(host()->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144880}
4881
[email protected]989386c2013-07-18 21:37:234882TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
jaydasikabf1875a2016-06-28 03:39:594883 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:324884 LayerImpl* child = AddChild<LayerImpl>(root);
4885 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]498ec6e0e2012-11-30 18:24:574886
danakje4fa7b72016-07-25 22:00:064887 root->SetBounds(gfx::Size(100, 100));
4888 child->SetBounds(gfx::Size(10, 10));
jaydasikaab317e02016-06-01 00:53:184889 child->test_properties()->opacity = 0.5f;
danakje4fa7b72016-07-25 22:00:064890 grand_child->SetBounds(gfx::Size(10, 10));
4891 grand_child->SetDrawsContent(true);
ajuma4711f4b12016-05-16 18:48:324892 ExecuteCalculateDrawProperties(root);
ennec1332992015-08-24 19:45:094893 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:574894}
4895
[email protected]989386c2013-07-18 21:37:234896TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164897 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:454898 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:564899 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:484900 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider,
4901 &shared_bitmap_manager, &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:164902 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:484903 std::unique_ptr<LayerImpl> root =
4904 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:064905 root->SetBounds(gfx::Size(100, 100));
[email protected]f90fc412013-03-30 20:13:164906 root->SetDrawsContent(true);
4907
danakj60bc3bc2016-04-09 00:24:484908 std::unique_ptr<LayerImpl> child =
4909 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:064910 child->SetBounds(gfx::Size(50, 50));
[email protected]f90fc412013-03-30 20:13:164911 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:184912 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:164913
jaydasika9cb21c772016-05-10 22:37:084914 const int child_id = child->id();
jaydasika89f7b5a2016-06-22 02:08:394915 root->test_properties()->AddChild(std::move(child));
jaydasika9cb21c772016-05-10 22:37:084916 root->SetHasRenderSurface(true);
4917 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:594918 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
jaydasika4340ea02016-06-06 19:44:264919 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
vollickef2ae922016-06-29 17:54:274920
[email protected]f90fc412013-03-30 20:13:164921 // Add opacity animation.
loyso9556c732016-03-11 07:54:584922 scoped_refptr<AnimationTimeline> timeline =
4923 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
4924 host_impl.animation_host()->AddAnimationTimeline(timeline);
vollickef2ae922016-06-29 17:54:274925 host_impl.pending_tree()->SetElementIdsForTesting();
loyso968163c92016-01-04 23:18:484926
vollickef2ae922016-06-29 17:54:274927 ElementId child_element_id =
4928 host_impl.pending_tree()->LayerById(child_id)->element_id();
4929
4930 AddOpacityTransitionToElementWithPlayer(child_element_id, timeline, 10.0,
4931 0.0f, 1.0f, false);
[email protected]f90fc412013-03-30 20:13:164932
[email protected]c0ae06c12013-06-24 18:32:194933 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534934 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:384935 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534936 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574937 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:164938
4939 // We should have one render surface and two layers. The child
4940 // layer should be included even though it is transparent.
4941 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:054942 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:074943
4944 // If the root itself is hidden, the child should not be drawn even if it has
4945 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:184946 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054947 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:074948 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:074949 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:384950 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:074951 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574952 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:074953
jaydasika0c2fd472016-03-24 01:26:054954 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:064955 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:054956 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:074957 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014958 EXPECT_FALSE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404959
4960 // A layer should be drawn and it should contribute to drawn surface when
4961 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:184962 root_layer->test_properties()->opacity = 1.0f;
4963 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:054964 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:404965 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:404966 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:384967 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:404968 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:574969 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:404970
jaydasika0c2fd472016-03-24 01:26:054971 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
4972 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:404973 node = tree.Node(child_ptr->effect_tree_index());
trchendba8b1502016-07-08 09:47:014974 EXPECT_TRUE(node->is_drawn);
jaydasikae99e83e2016-01-29 19:35:404975 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:064976
4977 // But if the opacity of the layer remains 0 after activation, it should not
4978 // be drawn.
4979 host_impl.ActivateSyncTree();
danakj0da42ca62016-07-01 19:42:334980 LayerImpl* active_root = host_impl.active_tree()->LayerById(root_layer->id());
jaydasika8185d302016-04-14 15:20:064981 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
4982
4983 EffectTree& active_effect_tree =
4984 host_impl.active_tree()->property_trees()->effect_tree;
4985 EXPECT_TRUE(active_effect_tree.needs_update());
4986
4987 ExecuteCalculateDrawProperties(active_root);
4988
4989 node = active_effect_tree.Node(active_child->effect_tree_index());
trchendba8b1502016-07-08 09:47:014990 EXPECT_FALSE(node->is_drawn);
jaydasika8185d302016-04-14 15:20:064991 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
4992 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:164993}
4994
danakj3f76ace2014-11-18 16:56:004995using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:264996class LCDTextTest : public LayerTreeHostCommonTestBase,
4997 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:364998 public:
4999 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:225000 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
5001 host_impl_(LCDTextTestLayerTreeSettings(),
5002 &task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:165003 &shared_bitmap_manager_,
danakj59931942016-07-26 22:11:295004 &task_graph_runner_) {}
enneaf5bda32015-02-19 01:27:365005
loyso968163c92016-01-04 23:18:485006 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
5007
[email protected]fb661802013-03-25 01:59:325008 protected:
sunxd5a7a4032016-06-01 18:49:225009 LayerTreeSettings LCDTextTestLayerTreeSettings() {
danakj59931942016-07-26 22:11:295010 LayerTreeSettings settings = VerifyTreeCalcsLayerTreeSettings();
sunxd5a7a4032016-06-01 18:49:225011
5012 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
5013 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
5014 settings.can_use_lcd_text = can_use_lcd_text_;
5015 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
sunxd5a7a4032016-06-01 18:49:225016 return settings;
5017 }
5018
dcheng93a52eb2014-12-23 02:14:235019 void SetUp() override {
loyso9556c732016-03-11 07:54:585020 timeline_ =
5021 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5022 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:485023
danakj60bc3bc2016-04-09 00:24:485024 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:365025 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:485026 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:365027 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:485028 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:365029 LayerImpl::Create(host_impl_.active_tree(), 3);
5030
5031 // Stash raw pointers to look at later.
5032 root_ = root_ptr.get();
5033 child_ = child_ptr.get();
5034 grand_child_ = grand_child_ptr.get();
5035
jaydasika89f7b5a2016-06-22 02:08:395036 child_->test_properties()->AddChild(std::move(grand_child_ptr));
5037 root_->test_properties()->AddChild(std::move(child_ptr));
jaydasikabf1875a2016-06-28 03:39:595038 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595039
vollickef2ae922016-06-29 17:54:275040 host_impl_.active_tree()->SetElementIdsForTesting();
5041
fmalita51b5e202014-11-18 20:11:505042 root_->SetContentsOpaque(true);
5043 child_->SetContentsOpaque(true);
5044 grand_child_->SetContentsOpaque(true);
5045
jaydasika3f930c12015-06-30 15:18:255046 root_->SetDrawsContent(true);
5047 child_->SetDrawsContent(true);
5048 grand_child_->SetDrawsContent(true);
5049
danakje4fa7b72016-07-25 22:00:065050 root_->SetBounds(gfx::Size(1, 1));
5051 child_->SetBounds(gfx::Size(1, 1));
5052 grand_child_->SetBounds(gfx::Size(1, 1));
5053
5054 child_->test_properties()->force_render_surface =
5055 std::tr1::get<2>(GetParam());
[email protected]fb661802013-03-25 01:59:325056 }
[email protected]10aabcc32012-12-13 09:18:595057
[email protected]fb661802013-03-25 01:59:325058 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005059 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365060
khushalsagarb64b360d2015-10-21 19:25:165061 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:365062 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475063 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365064 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485065 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365066
danakj59931942016-07-26 22:11:295067 LayerImpl* root_ = nullptr;
5068 LayerImpl* child_ = nullptr;
5069 LayerImpl* grand_child_ = nullptr;
[email protected]10aabcc32012-12-13 09:18:595070};
5071
[email protected]fb661802013-03-25 01:59:325072TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005073 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5074 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5075
[email protected]fb661802013-03-25 01:59:325076 // Case 1: Identity transform.
danakj59931942016-07-26 22:11:295077 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225078 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5079 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5080 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595081
[email protected]fb661802013-03-25 01:59:325082 // Case 2: Integral translation.
5083 gfx::Transform integral_translation;
5084 integral_translation.Translate(1.0, 2.0);
5085 child_->SetTransform(integral_translation);
jaydasika3f930c12015-06-30 15:18:255086 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295087 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225088 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5089 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5090 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595091
[email protected]fb661802013-03-25 01:59:325092 // Case 3: Non-integral translation.
5093 gfx::Transform non_integral_translation;
5094 non_integral_translation.Translate(1.5, 2.5);
5095 child_->SetTransform(non_integral_translation);
jaydasika3f930c12015-06-30 15:18:255096 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295097 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225098 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5099 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5100 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595101
[email protected]fb661802013-03-25 01:59:325102 // Case 4: Rotation.
5103 gfx::Transform rotation;
5104 rotation.Rotate(10.0);
5105 child_->SetTransform(rotation);
jaydasika3f930c12015-06-30 15:18:255106 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295107 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225108 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5109 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5110 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595111
[email protected]fb661802013-03-25 01:59:325112 // Case 5: Scale.
5113 gfx::Transform scale;
5114 scale.Scale(2.0, 2.0);
5115 child_->SetTransform(scale);
jaydasika3f930c12015-06-30 15:18:255116 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295117 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225118 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5119 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5120 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595121
[email protected]fb661802013-03-25 01:59:325122 // Case 6: Skew.
5123 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105124 skew.Skew(10.0, 0.0);
[email protected]fb661802013-03-25 01:59:325125 child_->SetTransform(skew);
jaydasika3f930c12015-06-30 15:18:255126 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
danakj59931942016-07-26 22:11:295127 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225128 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5129 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5130 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595131
[email protected]fb661802013-03-25 01:59:325132 // Case 7: Translucent.
danakjf78fb272016-07-26 19:06:155133 child_->SetTransform(gfx::Transform());
jaydasika3f930c12015-06-30 15:18:255134 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185135 child_->test_properties()->opacity = 0.5f;
danakj59931942016-07-26 22:11:295136 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225137 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5138 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5139 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595140
[email protected]fb661802013-03-25 01:59:325141 // Case 8: Sanity check: restore transform and opacity.
danakjf78fb272016-07-26 19:06:155142 child_->SetTransform(gfx::Transform());
jaydasika3f930c12015-06-30 15:18:255143 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185144 child_->test_properties()->opacity = 1.f;
danakj59931942016-07-26 22:11:295145 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225146 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5147 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5148 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505149
5150 // Case 9: Non-opaque content.
5151 child_->SetContentsOpaque(false);
danakj59931942016-07-26 22:11:295152 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225153 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5154 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5155 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505156
5157 // Case 10: Sanity check: restore content opaqueness.
5158 child_->SetContentsOpaque(true);
danakj59931942016-07-26 22:11:295159 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225160 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5161 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5162 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595163}
5164
[email protected]fd9a3b6d2013-08-03 00:46:175165TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005166 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335167 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005168
[email protected]fb661802013-03-25 01:59:325169 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
danakj59931942016-07-26 22:11:295170 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225171 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5172 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5173 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595174
[email protected]fb661802013-03-25 01:59:325175 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:185176 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:255177 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
vollickef2ae922016-06-29 17:54:275178
5179 SetElementIdsForTesting();
5180
5181 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5182 10.0, 0.9f, 0.1f, false);
danakj59931942016-07-26 22:11:295183 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
fmalitafcd926a2015-05-13 20:19:335184 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:225185 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5186 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5187 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335188}
5189
5190TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5191 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5192 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5193
5194 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
danakj59931942016-07-26 22:11:295195 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
sunxd5a7a4032016-06-01 18:49:225196 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5197 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5198 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
vollickef2ae922016-06-29 17:54:275199 SetElementIdsForTesting();
fmalitafcd926a2015-05-13 20:19:335200
5201 // Mark contents non-opaque within the first animation frame.
5202 child_->SetContentsOpaque(false);
vollickef2ae922016-06-29 17:54:275203 AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(),
5204 10.0, 0.9f, 0.1f, false);
danakj59931942016-07-26 22:11:295205 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr);
fmalitafcd926a2015-05-13 20:19:335206 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:225207 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5208 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5209 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595210}
5211
5212INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5213 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005214 testing::Combine(testing::Bool(),
5215 testing::Bool(),
5216 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595217
[email protected]989386c2013-07-18 21:37:235218TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165219 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455220 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565221 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165222 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565223 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195224 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195225
danakj60bc3bc2016-04-09 00:24:485226 std::unique_ptr<LayerImpl> root =
5227 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065228 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195229 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065230 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195231
danakj60bc3bc2016-04-09 00:24:485232 std::unique_ptr<LayerImpl> child =
5233 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065234 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195235 child->SetDrawsContent(true);
5236
danakj60bc3bc2016-04-09 00:24:485237 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195238 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065239 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195240 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355241 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195242
jaydasika89f7b5a2016-06-22 02:08:395243 child->test_properties()->AddChild(std::move(grand_child));
5244 root->test_properties()->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005245 root->SetHasRenderSurface(true);
jaydasikabf1875a2016-06-28 03:39:595246 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195247
5248 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535249 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385250 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535251 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575252 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195253
5254 // We should have one render surface and two layers. The grand child has
5255 // hidden itself.
5256 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055257 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5258 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5259 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195260}
5261
[email protected]989386c2013-07-18 21:37:235262TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165263 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455264 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565265 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165266 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565267 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195268 host_impl.CreatePendingTree();
[email protected]c0ae06c12013-06-24 18:32:195269
danakj60bc3bc2016-04-09 00:24:485270 std::unique_ptr<LayerImpl> root =
5271 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065272 root->SetBounds(gfx::Size(50, 50));
[email protected]c0ae06c12013-06-24 18:32:195273 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095274 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195275
danakj60bc3bc2016-04-09 00:24:485276 std::unique_ptr<LayerImpl> child =
5277 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065278 child->SetBounds(gfx::Size(40, 40));
[email protected]c0ae06c12013-06-24 18:32:195279 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355280 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195281
danakj60bc3bc2016-04-09 00:24:485282 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195283 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065284 grand_child->SetBounds(gfx::Size(30, 30));
[email protected]c0ae06c12013-06-24 18:32:195285 grand_child->SetDrawsContent(true);
5286
jaydasika89f7b5a2016-06-22 02:08:395287 child->test_properties()->AddChild(std::move(grand_child));
5288 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:595289 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195290
5291 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535292 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385293 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535294 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575295 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195296
5297 // We should have one render surface and one layers. The child has
5298 // hidden itself and the grand child.
5299 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095300 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5301 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195302}
5303
danakj60bc3bc2016-04-09 00:24:485304void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455305
[email protected]989386c2013-07-18 21:37:235306TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165307 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455308 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565309 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165310 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565311 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455312 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455313
danakj60bc3bc2016-04-09 00:24:485314 std::unique_ptr<LayerImpl> root =
5315 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065316 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305317 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095318 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455319
danakj60bc3bc2016-04-09 00:24:485320 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305321 LayerImpl::Create(host_impl.pending_tree(), 2);
danakje4fa7b72016-07-25 22:00:065322 copy_grand_parent->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305323 copy_grand_parent->SetDrawsContent(true);
5324 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455325
danakj60bc3bc2016-04-09 00:24:485326 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305327 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065328 copy_parent->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305329 copy_parent->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065330 copy_parent->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305331 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455332
danakj60bc3bc2016-04-09 00:24:485333 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305334 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065335 copy_request->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305336 copy_request->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065337 copy_request->test_properties()->force_render_surface = true;
weiliangc51fb255d2015-07-24 15:32:305338 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455339
danakj60bc3bc2016-04-09 00:24:485340 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305341 LayerImpl::Create(host_impl.pending_tree(), 5);
danakje4fa7b72016-07-25 22:00:065342 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305343 copy_child->SetDrawsContent(true);
5344 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455345
danakj60bc3bc2016-04-09 00:24:485346 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405347 LayerImpl::Create(host_impl.pending_tree(), 6);
danakje4fa7b72016-07-25 22:00:065348 copy_grand_child->SetBounds(gfx::Size(20, 20));
5349 copy_grand_child->SetDrawsContent(true);
jaydasika86654512016-01-27 17:05:075350 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5351
danakj60bc3bc2016-04-09 00:24:485352 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075353 LayerImpl::Create(host_impl.pending_tree(), 7);
danakje4fa7b72016-07-25 22:00:065354 copy_grand_parent_sibling_before->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305355 copy_grand_parent_sibling_before->SetDrawsContent(true);
5356 LayerImpl* copy_grand_parent_sibling_before_layer =
5357 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535358
danakj60bc3bc2016-04-09 00:24:485359 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075360 LayerImpl::Create(host_impl.pending_tree(), 8);
danakje4fa7b72016-07-25 22:00:065361 copy_grand_parent_sibling_after->SetBounds(gfx::Size(40, 40));
weiliangc51fb255d2015-07-24 15:32:305362 copy_grand_parent_sibling_after->SetDrawsContent(true);
5363 LayerImpl* copy_grand_parent_sibling_after_layer =
5364 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535365
jaydasika89f7b5a2016-06-22 02:08:395366 copy_child->test_properties()->AddChild(std::move(copy_grand_child));
5367 copy_request->test_properties()->AddChild(std::move(copy_child));
5368 copy_parent->test_properties()->AddChild(std::move(copy_request));
5369 copy_grand_parent->test_properties()->AddChild(std::move(copy_parent));
5370 root->test_properties()->AddChild(
5371 std::move(copy_grand_parent_sibling_before));
5372 root->test_properties()->AddChild(std::move(copy_grand_parent));
5373 root->test_properties()->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasikabf1875a2016-06-28 03:39:595374 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285375
[email protected]30fe19ff2013-07-04 00:54:455376 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075377 // hidden subtree on copy_layer. Also hide the copy grand child and its
5378 // subtree.
jaydasika5121caa82016-05-05 15:43:355379 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5380 copy_grand_parent_sibling_before_layer->test_properties()
5381 ->hide_layer_and_subtree = true;
5382 copy_grand_parent_sibling_after_layer->test_properties()
5383 ->hide_layer_and_subtree = true;
5384 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305385
ajumae6f541b2016-05-31 16:50:505386 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305387 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455388
weiliangc51fb255d2015-07-24 15:32:305389 LayerImplList render_surface_layer_list;
5390 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385391 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535392 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575393 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455394
jaydasika2411692c2016-03-23 01:56:095395 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025396 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5397 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5398 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535399
jaydasika86654512016-01-27 17:05:075400 // We should have four render surfaces, one for the root, one for the grand
5401 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455402 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075403 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095404 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075405 EXPECT_EQ(copy_grand_parent_layer->id(),
5406 render_surface_layer_list.at(1)->id());
5407 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5408 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455409
jaydasika86654512016-01-27 17:05:075410 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095411 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5412 EXPECT_EQ(root_layer->id(),
5413 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075414 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095415 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455416
[email protected]7392c7b2014-02-07 08:28:285417 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455418 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305419 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455420 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065421 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455422
5423 // The copy_layer's render surface should have two contributing layers.
5424 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5425 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235426 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305427 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235428 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075429
5430 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5431 // but the copy_layer and copy_child should be drawn for the copy request.
5432 // copy grand child should not be drawn as its hidden even in the copy
5433 // request.
ajumae4af47062016-05-24 23:59:045434 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095435 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075436 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015437 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075438 node = tree.Node(copy_parent_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015439 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075440 node = tree.Node(copy_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015441 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075442 node = tree.Node(copy_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015443 EXPECT_TRUE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075444 node = tree.Node(copy_grand_child_layer->effect_tree_index());
trchendba8b1502016-07-08 09:47:015445 EXPECT_FALSE(node->is_drawn);
jaydasika86654512016-01-27 17:05:075446
5447 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5448 // actually hidden.
5449 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455450}
5451
[email protected]989386c2013-07-18 21:37:235452TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165453 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455454 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565455 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165456 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565457 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455458 host_impl.CreatePendingTree();
[email protected]30fe19ff2013-07-04 00:54:455459
danakj60bc3bc2016-04-09 00:24:485460 std::unique_ptr<LayerImpl> root =
5461 LayerImpl::Create(host_impl.pending_tree(), 1);
danakje4fa7b72016-07-25 22:00:065462 root->SetBounds(gfx::Size(50, 50));
weiliangc51fb255d2015-07-24 15:32:305463 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455464
danakj60bc3bc2016-04-09 00:24:485465 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305466 LayerImpl::Create(host_impl.pending_tree(), 2);
weiliangc51fb255d2015-07-24 15:32:305467 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455468 copy_parent->SetMasksToBounds(true);
5469
danakj60bc3bc2016-04-09 00:24:485470 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305471 LayerImpl::Create(host_impl.pending_tree(), 3);
danakje4fa7b72016-07-25 22:00:065472 copy_layer->SetBounds(gfx::Size(30, 30));
weiliangc51fb255d2015-07-24 15:32:305473 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065474 copy_layer->test_properties()->force_render_surface = true;
[email protected]30fe19ff2013-07-04 00:54:455475
danakj60bc3bc2016-04-09 00:24:485476 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305477 LayerImpl::Create(host_impl.pending_tree(), 4);
danakje4fa7b72016-07-25 22:00:065478 copy_child->SetBounds(gfx::Size(20, 20));
weiliangc51fb255d2015-07-24 15:32:305479 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455480
ajumae6f541b2016-05-31 16:50:505481 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305482 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455483
jaydasika89f7b5a2016-06-22 02:08:395484 copy_layer->test_properties()->AddChild(std::move(copy_child));
5485 copy_parent->test_properties()->AddChild(std::move(copy_layer));
5486 root->test_properties()->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305487
5488 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055489 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:595490 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305491 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385492 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535493 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575494 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455495
xjze19f76402015-11-06 21:48:445496 // We should have two render surface, as the others are clipped out.
5497 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055498 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455499
xjze19f76402015-11-06 21:48:445500 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455501 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055502 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5503 EXPECT_EQ(root_layer->id(),
5504 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455505}
5506
weiliangcde7e0c32016-06-15 15:02:415507TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
jaydasikabf1875a2016-06-28 03:39:595508 LayerImpl* root = root_layer_for_testing();
danakje4fa7b72016-07-25 22:00:065509 root->SetBounds(gfx::Size(50, 50));
weiliangcde7e0c32016-06-15 15:02:415510 root->SetDrawsContent(true);
5511 root->SetMasksToBounds(true);
5512
5513 LayerImpl* copy_layer = AddChild<LayerImpl>(root);
danakje4fa7b72016-07-25 22:00:065514 copy_layer->SetBounds(gfx::Size(100, 100));
weiliangcde7e0c32016-06-15 15:02:415515 copy_layer->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065516 copy_layer->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415517
5518 LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065519 copy_child->SetPosition(gfx::PointF(40.f, 40.f));
5520 copy_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415521 copy_child->SetDrawsContent(true);
5522
5523 LayerImpl* copy_clip = AddChild<LayerImpl>(copy_layer);
danakje4fa7b72016-07-25 22:00:065524 copy_clip->SetBounds(gfx::Size(55, 55));
weiliangcde7e0c32016-06-15 15:02:415525 copy_clip->SetMasksToBounds(true);
5526
5527 LayerImpl* copy_clipped_child = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065528 copy_clipped_child->SetPosition(gfx::PointF(40.f, 40.f));
5529 copy_clipped_child->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415530 copy_clipped_child->SetDrawsContent(true);
5531
5532 LayerImpl* copy_surface = AddChild<LayerImpl>(copy_clip);
danakje4fa7b72016-07-25 22:00:065533 copy_surface->SetPosition(gfx::PointF(45.f, 45.f));
5534 copy_surface->SetBounds(gfx::Size(20, 20));
weiliangcde7e0c32016-06-15 15:02:415535 copy_surface->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065536 copy_surface->test_properties()->force_render_surface = true;
weiliangcde7e0c32016-06-15 15:02:415537
5538 copy_layer->test_properties()->copy_requests.push_back(
5539 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5540
weiliangce22ce842016-07-04 23:31:535541 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415542 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535543 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415544
5545 EXPECT_EQ(gfx::Rect(100, 100), copy_layer->visible_layer_rect());
5546 EXPECT_EQ(gfx::Rect(20, 20), copy_child->visible_layer_rect());
5547 EXPECT_EQ(gfx::Rect(15, 15), copy_clipped_child->visible_layer_rect());
5548 EXPECT_EQ(gfx::Rect(10, 10), copy_surface->visible_layer_rect());
5549
5550 // Case 2: When the non root copy request layer is clipped.
5551 copy_layer->SetBounds(gfx::Size(50, 50));
5552 copy_layer->SetMasksToBounds(true);
weiliangce22ce842016-07-04 23:31:535553 copy_layer->test_properties()->copy_requests.push_back(
5554 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
weiliangcde7e0c32016-06-15 15:02:415555 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5556
weiliangce22ce842016-07-04 23:31:535557 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415558 ExecuteCalculateDrawProperties(root);
weiliangce22ce842016-07-04 23:31:535559 DCHECK(copy_layer->test_properties()->copy_requests.empty());
weiliangcde7e0c32016-06-15 15:02:415560
5561 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5562 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5563 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5564 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangc296dd9f2016-07-05 14:59:515565
5566 // Case 3: When there is device scale factor.
5567 float device_scale_factor = 2.f;
5568 copy_layer->test_properties()->copy_requests.push_back(
5569 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5570
5571 DCHECK(!copy_layer->test_properties()->copy_requests.empty());
5572 ExecuteCalculateDrawProperties(root, device_scale_factor);
5573 DCHECK(copy_layer->test_properties()->copy_requests.empty());
5574
5575 EXPECT_EQ(gfx::Rect(50, 50), copy_layer->visible_layer_rect());
5576 EXPECT_EQ(gfx::Rect(10, 10), copy_child->visible_layer_rect());
5577 EXPECT_EQ(gfx::Rect(10, 10), copy_clipped_child->visible_layer_rect());
5578 EXPECT_EQ(gfx::Rect(5, 5), copy_surface->visible_layer_rect());
weiliangcde7e0c32016-06-15 15:02:415579}
5580
[email protected]11a07b102013-07-24 17:33:195581TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
jaydasikabf1875a2016-06-28 03:39:595582 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:145583 LayerImpl* surface = AddChild<LayerImpl>(root);
5584 LayerImpl* surface_child = AddChild<LayerImpl>(surface);
5585
danakje4fa7b72016-07-25 22:00:065586 root->SetBounds(gfx::Size(50, 50));
jaydasika6f972de2016-04-07 16:16:145587 root->SetDrawsContent(true);
danakje4fa7b72016-07-25 22:00:065588 surface->SetPosition(gfx::PointF(-10, 20));
5589 surface->test_properties()->force_render_surface = true;
5590 surface_child->SetBounds(gfx::Size(50, 50));
jaydasika6f972de2016-04-07 16:16:145591 surface_child->SetDrawsContent(true);
jaydasika6f972de2016-04-07 16:16:145592 ExecuteCalculateDrawProperties(root);
[email protected]11a07b102013-07-24 17:33:195593
danakj64767d902015-06-19 00:10:435594 // The visible_layer_rect for the |surface_child| should not be clipped by
[email protected]11a07b102013-07-24 17:33:195595 // the viewport.
jaydasika6f972de2016-04-07 16:16:145596 EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect());
[email protected]11a07b102013-07-24 17:33:195597}
5598
[email protected]420fdf6e2013-08-26 20:36:385599TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5600 // Ensure that a transform between the layer and its render surface is not a
5601 // problem. Constructs the following layer tree.
5602 //
5603 // root (a render surface)
5604 // + render_surface
5605 // + clip_parent (scaled)
5606 // + intervening_clipping_layer
5607 // + clip_child
5608 //
5609 // The render surface should be resized correctly and the clip child should
5610 // inherit the right clip rect.
jaydasikabf1875a2016-06-28 03:39:595611 LayerImpl* root = root_layer_for_testing();
enne70aa712d2015-07-28 22:46:315612 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5613 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285614 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315615 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285616 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315617 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5618 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565619 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485620 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315621 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565622 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385623
5624 intervening->SetMasksToBounds(true);
5625 clip_parent->SetMasksToBounds(true);
5626
[email protected]420fdf6e2013-08-26 20:36:385627 gfx::Transform scale_transform;
5628 scale_transform.Scale(2, 2);
5629
danakjf78fb272016-07-26 19:06:155630 root->SetBounds(gfx::Size(50, 50));
5631 render_surface->SetBounds(gfx::Size(10, 10));
5632 render_surface->test_properties()->force_render_surface = true;
5633 clip_parent->SetTransform(scale_transform);
5634 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5635 clip_parent->SetBounds(gfx::Size(10, 10));
5636 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5637 intervening->SetBounds(gfx::Size(5, 5));
5638 clip_child->SetPosition(gfx::PointF(1.f, 1.f));
5639 clip_child->SetBounds(gfx::Size(10, 10));
enne70aa712d2015-07-28 22:46:315640 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385641
5642 ASSERT_TRUE(root->render_surface());
5643 ASSERT_TRUE(render_surface->render_surface());
5644
5645 // Ensure that we've inherited our clip parent's clip and weren't affected
5646 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145647 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5648 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5649 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385650
5651 // Ensure that the render surface reports a content rect that has been grown
5652 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145653 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5654 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385655
5656 // The above check implies the two below, but they nicely demonstrate that
5657 // we've grown, despite the intervening layer's clip.
5658 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5659 render_surface->render_surface()->content_rect()));
5660 ASSERT_FALSE(intervening->clip_rect().Contains(
5661 render_surface->render_surface()->content_rect()));
5662}
5663
5664TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5665 // Ensure that intervening render surfaces are not a problem in the basic
5666 // case. In the following tree, both render surfaces should be resized to
5667 // accomodate for the clip child, despite an intervening clip.
5668 //
5669 // root (a render surface)
5670 // + clip_parent (masks to bounds)
5671 // + render_surface1 (sets opacity)
5672 // + intervening (masks to bounds)
5673 // + render_surface2 (also sets opacity)
5674 // + clip_child
5675 //
jaydasikabf1875a2016-06-28 03:39:595676 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235677 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5678 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5679 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5680 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5681 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365682 render_surface1->SetDrawsContent(true);
5683 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235684 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385685
jaydasika1c0a27d42016-04-28 01:54:565686 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385687
5688 intervening->SetMasksToBounds(true);
5689 clip_parent->SetMasksToBounds(true);
5690
[email protected]420fdf6e2013-08-26 20:36:385691 gfx::Transform translation_transform;
5692 translation_transform.Translate(2, 2);
5693
danakjf78fb272016-07-26 19:06:155694 root->SetBounds(gfx::Size(50, 50));
5695 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5696 clip_parent->SetBounds(gfx::Size(40, 40));
5697 render_surface1->SetBounds(gfx::Size(10, 10));
5698 render_surface1->test_properties()->force_render_surface = true;
5699 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5700 intervening->SetBounds(gfx::Size(5, 5));
5701 render_surface2->SetBounds(gfx::Size(10, 10));
5702 render_surface2->test_properties()->force_render_surface = true;
5703 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5704 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235705 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385706
5707 EXPECT_TRUE(root->render_surface());
5708 EXPECT_TRUE(render_surface1->render_surface());
5709 EXPECT_TRUE(render_surface2->render_surface());
5710
5711 // Since the render surfaces could have expanded, they should not clip (their
5712 // bounds would no longer be reliable). We should resort to layer clipping
5713 // in this case.
jaydasika6f972de2016-04-07 16:16:145714 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5715 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385716 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145717 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5718 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385719 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5720
5721 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145722 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385723 EXPECT_TRUE(render_surface1->is_clipped());
5724
5725 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145726 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385727 EXPECT_TRUE(render_surface2->is_clipped());
5728
5729 // The content rects of both render surfaces should both have expanded to
5730 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145731 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5732 render_surface1->render_surface()->content_rect());
5733 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5734 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385735
5736 // The clip child should have inherited the clip parent's clip (projected to
5737 // the right space, of course), and should have the correctly sized visible
5738 // content rect.
jaydasika6f972de2016-04-07 16:16:145739 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5740 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385741 EXPECT_TRUE(clip_child->is_clipped());
5742}
5743
5744TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5745 // Ensure that intervening render surfaces are not a problem, even if there
5746 // is a scroll involved. Note, we do _not_ have to consider any other sort
5747 // of transform.
5748 //
5749 // root (a render surface)
5750 // + clip_parent (masks to bounds)
5751 // + render_surface1 (sets opacity)
5752 // + intervening (masks to bounds AND scrolls)
5753 // + render_surface2 (also sets opacity)
5754 // + clip_child
5755 //
jaydasikabf1875a2016-06-28 03:39:595756 LayerImpl* root = root_layer_for_testing();
weiliangcd6a836d2015-07-28 21:20:235757 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5758 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5759 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5760 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5761 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365762 render_surface1->SetDrawsContent(true);
5763 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235764 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385765
jaydasika1c0a27d42016-04-28 01:54:565766 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385767
5768 intervening->SetMasksToBounds(true);
5769 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235770 intervening->SetScrollClipLayer(clip_parent->id());
5771 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385772
5773 gfx::Transform translation_transform;
5774 translation_transform.Translate(2, 2);
5775
danakjf78fb272016-07-26 19:06:155776 root->SetBounds(gfx::Size(50, 50));
5777 clip_parent->SetTransform(translation_transform);
5778 clip_parent->SetPosition(gfx::PointF(1.f, 1.f));
5779 clip_parent->SetBounds(gfx::Size(40, 40));
5780 render_surface1->SetBounds(gfx::Size(10, 10));
5781 render_surface1->test_properties()->force_render_surface = true;
5782 intervening->SetPosition(gfx::PointF(1.f, 1.f));
5783 intervening->SetBounds(gfx::Size(5, 5));
5784 render_surface2->SetBounds(gfx::Size(10, 10));
5785 render_surface2->test_properties()->force_render_surface = true;
5786 clip_child->SetPosition(gfx::PointF(-10.f, -10.f));
5787 clip_child->SetBounds(gfx::Size(60, 60));
weiliangcd6a836d2015-07-28 21:20:235788 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385789
5790 EXPECT_TRUE(root->render_surface());
5791 EXPECT_TRUE(render_surface1->render_surface());
5792 EXPECT_TRUE(render_surface2->render_surface());
5793
5794 // Since the render surfaces could have expanded, they should not clip (their
5795 // bounds would no longer be reliable). We should resort to layer clipping
5796 // in this case.
jaydasika6f972de2016-04-07 16:16:145797 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5798 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385799 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145800 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5801 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385802 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5803
5804 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145805 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385806 EXPECT_TRUE(render_surface1->is_clipped());
5807
5808 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145809 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385810 EXPECT_TRUE(render_surface2->is_clipped());
5811
5812 // The content rects of both render surfaces should both have expanded to
5813 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145814 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5815 render_surface1->render_surface()->content_rect());
5816 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
5817 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385818
5819 // The clip child should have inherited the clip parent's clip (projected to
5820 // the right space, of course), and should have the correctly sized visible
5821 // content rect.
jaydasika6f972de2016-04-07 16:16:145822 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
5823 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385824 EXPECT_TRUE(clip_child->is_clipped());
5825}
5826
5827TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5828 // Ensures that descendants of the clip child inherit the correct clip.
5829 //
5830 // root (a render surface)
5831 // + clip_parent (masks to bounds)
5832 // + intervening (masks to bounds)
5833 // + clip_child
5834 // + child
5835 //
jaydasikabf1875a2016-06-28 03:39:595836 LayerImpl* root = root_layer_for_testing();
enne2d0d8e62015-08-18 18:29:175837 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5838 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5839 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5840 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365841 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175842 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385843
jaydasika1c0a27d42016-04-28 01:54:565844 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155845 clip_parent->test_properties()->clip_children =
5846 base::MakeUnique<std::set<LayerImpl*>>();
5847 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385848
danakjf78fb272016-07-26 19:06:155849 root->SetBounds(gfx::Size(50, 50));
5850 clip_parent->SetBounds(gfx::Size(40, 40));
[email protected]420fdf6e2013-08-26 20:36:385851 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:155852 intervening->SetBounds(gfx::Size(5, 5));
5853 intervening->SetMasksToBounds(true);
5854 clip_child->SetBounds(gfx::Size(60, 60));
5855 child->SetBounds(gfx::Size(60, 60));
[email protected]420fdf6e2013-08-26 20:36:385856
enne2d0d8e62015-08-18 18:29:175857 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385858
5859 EXPECT_TRUE(root->render_surface());
5860
5861 // Neither the clip child nor its descendant should have inherited the clip
5862 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145863 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385864 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145865 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385866 EXPECT_TRUE(child->is_clipped());
5867}
5868
5869TEST_F(LayerTreeHostCommonTest,
5870 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5871 // Ensures that non-descendant clip children in the tree do not affect
5872 // render surfaces.
5873 //
5874 // root (a render surface)
5875 // + clip_parent (masks to bounds)
5876 // + render_surface1
5877 // + clip_child
5878 // + render_surface2
5879 // + non_clip_child
5880 //
5881 // In this example render_surface2 should be unaffected by clip_child.
jaydasikabf1875a2016-06-28 03:39:595882 LayerImpl* root = root_layer_for_testing();
enneb441cdd2015-07-28 22:47:505883 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5884 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
enneb441cdd2015-07-28 22:47:505885 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
enneb441cdd2015-07-28 22:47:505886 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
enneb441cdd2015-07-28 22:47:505887 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
[email protected]420fdf6e2013-08-26 20:36:385888
jaydasika1c0a27d42016-04-28 01:54:565889 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:155890 clip_parent->test_properties()->clip_children =
5891 base::MakeUnique<std::set<LayerImpl*>>();
5892 clip_parent->test_properties()->clip_children->insert(clip_child);
[email protected]420fdf6e2013-08-26 20:36:385893
5894 clip_parent->SetMasksToBounds(true);
5895 render_surface1->SetMasksToBounds(true);
5896
danakjf78fb272016-07-26 19:06:155897 render_surface1->SetDrawsContent(true);
5898 clip_child->SetDrawsContent(true);
5899 render_surface2->SetDrawsContent(true);
5900 non_clip_child->SetDrawsContent(true);
5901
5902 root->SetBounds(gfx::Size(15, 15));
5903 clip_parent->SetBounds(gfx::Size(10, 10));
5904 render_surface1->SetPosition(gfx::PointF(5, 5));
5905 render_surface1->SetBounds(gfx::Size(5, 5));
5906 render_surface1->test_properties()->force_render_surface = true;
5907 render_surface2->SetBounds(gfx::Size(5, 5));
5908 render_surface2->test_properties()->force_render_surface = true;
5909 clip_child->SetPosition(gfx::PointF(-1, 1));
5910 clip_child->SetBounds(gfx::Size(10, 10));
5911 non_clip_child->SetBounds(gfx::Size(5, 5));
[email protected]420fdf6e2013-08-26 20:36:385912
enneb441cdd2015-07-28 22:47:505913 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385914
5915 EXPECT_TRUE(root->render_surface());
5916 EXPECT_TRUE(render_surface1->render_surface());
5917 EXPECT_TRUE(render_surface2->render_surface());
5918
jaydasika6f972de2016-04-07 16:16:145919 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385920 EXPECT_TRUE(render_surface1->is_clipped());
5921
5922 // The render surface should not clip (it has unclipped descendants), instead
5923 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:145924 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5925 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385926 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5927
jaydasika0d98ba92015-11-17 05:17:285928 // That said, it should have grown to accomodate the unclipped descendant and
5929 // its own size.
jaydasika6f972de2016-04-07 16:16:145930 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
5931 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385932
5933 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:145934 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
5935 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385936 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:425937 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:385938
5939 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:145940 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
5941 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385942
5943 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:215944 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
5945 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:385946}
5947
weiliangc9ced1592015-11-17 19:04:375948TEST_F(LayerTreeHostCommonTest,
5949 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5950 // Verifies that Render Surfaces are created at the edge of rendering context.
5951
jaydasikabf1875a2016-06-28 03:39:595952 LayerImpl* root = root_layer_for_testing();
weiliangcc154ce22015-12-09 03:39:265953 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
5954 LayerImpl* child2 = AddChild<LayerImpl>(child1);
5955 LayerImpl* child3 = AddChild<LayerImpl>(child2);
5956 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375957
weiliangc9ced1592015-11-17 19:04:375958 gfx::Size bounds(100, 100);
5959
danakjf78fb272016-07-26 19:06:155960 root->SetBounds(bounds);
5961 child1->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265962 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:155963 child1->Set3dSortingContextId(1);
5964 child1->test_properties()->should_flatten_transform = false;
5965 child2->SetBounds(bounds);
weiliangcc154ce22015-12-09 03:39:265966 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375967 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:155968 child3->SetBounds(bounds);
5969 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:375970 child3->Set3dSortingContextId(1);
weiliangcc154ce22015-12-09 03:39:265971 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
weiliangc9ced1592015-11-17 19:04:375972
5973 // Verify which render surfaces were created.
5974 EXPECT_TRUE(root->has_render_surface());
5975 EXPECT_FALSE(child1->has_render_surface());
5976 EXPECT_TRUE(child2->has_render_surface());
5977 EXPECT_FALSE(child3->has_render_surface());
5978}
5979
[email protected]45948712013-09-27 02:46:485980TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:165981 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455982 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565983 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165984 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565985 &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:265986
danakj60bc3bc2016-04-09 00:24:485987 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:485988 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:485989 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:485990 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:485991 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:485992 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:485993 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:485994 LayerImpl::Create(host_impl.active_tree(), 12345678);
5995
[email protected]45948712013-09-27 02:46:485996 gfx::Size bounds(100, 100);
danakjf78fb272016-07-26 19:06:155997
5998 root->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:485999 root->SetDrawsContent(true);
6000
6001 // This layer structure normally forces render surface due to preserves3d
6002 // behavior.
danakjf78fb272016-07-26 19:06:156003 child1->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:486004 child1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156005 child1->Set3dSortingContextId(1);
6006 child1->test_properties()->should_flatten_transform = false;
6007 child2->SetBounds(bounds);
[email protected]45948712013-09-27 02:46:486008 child2->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:286009 child2->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:156010 child3->SetBounds(bounds);
6011 child3->SetDrawsContent(true);
[email protected]a9d4d4f2014-06-19 06:49:286012 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:576013
jaydasika89f7b5a2016-06-22 02:08:396014 child2->test_properties()->AddChild(std::move(child3));
6015 child1->test_properties()->AddChild(std::move(child2));
6016 root->test_properties()->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:056017 LayerImpl* root_layer = root.get();
jaydasikabf1875a2016-06-28 03:39:596018 root_layer->layer_tree_impl()->SetRootLayerForTesting(std::move(root));
[email protected]45948712013-09-27 02:46:486019
6020 {
6021 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:056022 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:486023 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386024 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486025 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:576026 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486027
6028 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026029
6030 int count_represents_target_render_surface = 0;
6031 int count_represents_contributing_render_surface = 0;
6032 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516033 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6034 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026035 it != end; ++it) {
6036 if (it.represents_target_render_surface())
6037 count_represents_target_render_surface++;
6038 if (it.represents_contributing_render_surface())
6039 count_represents_contributing_render_surface++;
6040 if (it.represents_itself())
6041 count_represents_itself++;
6042 }
6043
6044 // Two render surfaces.
6045 EXPECT_EQ(2, count_represents_target_render_surface);
6046 // Second render surface contributes to root render surface.
6047 EXPECT_EQ(1, count_represents_contributing_render_surface);
6048 // All 4 layers represent itself.
6049 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486050 }
6051
6052 {
6053 LayerImplList render_surface_layer_list;
6054 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386055 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486056 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:576057 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486058
6059 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026060
6061 int count_represents_target_render_surface = 0;
6062 int count_represents_contributing_render_surface = 0;
6063 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516064 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6065 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026066 it != end; ++it) {
6067 if (it.represents_target_render_surface())
6068 count_represents_target_render_surface++;
6069 if (it.represents_contributing_render_surface())
6070 count_represents_contributing_render_surface++;
6071 if (it.represents_itself())
6072 count_represents_itself++;
6073 }
6074
6075 // Only root layer has a render surface.
6076 EXPECT_EQ(1, count_represents_target_render_surface);
6077 // No layer contributes a render surface to root render surface.
6078 EXPECT_EQ(0, count_represents_contributing_render_surface);
6079 // All 4 layers represent itself.
6080 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486081 }
6082}
6083
[email protected]a9aa60a82013-08-29 04:28:266084TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
jaydasikabf1875a2016-06-28 03:39:596085 LayerImpl* root = root_layer_for_testing();
jaydasikae00c8a42016-01-28 20:18:336086 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6087 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6088 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6089 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
6090 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
danakjf78fb272016-07-26 19:06:156091
jaydasikae00c8a42016-01-28 20:18:336092 child1->SetDrawsContent(true);
6093 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266094
danakjf78fb272016-07-26 19:06:156095 root->SetBounds(gfx::Size(50, 50));
[email protected]a9d4d4f2014-06-19 06:49:286096 root->Set3dSortingContextId(1);
danakjf78fb272016-07-26 19:06:156097 root->test_properties()->should_flatten_transform = false;
6098 back_facing->SetBounds(gfx::Size(50, 50));
jaydasikae00c8a42016-01-28 20:18:336099 back_facing->Set3dSortingContextId(1);
jaydasikaca2605e2016-04-23 02:52:526100 back_facing->test_properties()->should_flatten_transform = false;
danakjf78fb272016-07-26 19:06:156101 render_surface1->SetBounds(gfx::Size(30, 30));
6102 render_surface1->Set3dSortingContextId(1);
6103 render_surface1->test_properties()->should_flatten_transform = false;
6104 render_surface1->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366105 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156106 render_surface2->SetBounds(gfx::Size(30, 30));
6107 // Different context from the rest.
jaydasikae00c8a42016-01-28 20:18:336108 render_surface2->Set3dSortingContextId(2);
danakjf78fb272016-07-26 19:06:156109 render_surface2->test_properties()->should_flatten_transform = false;
6110 render_surface2->test_properties()->force_render_surface = true;
jaydasika6b5a32bf2016-04-22 21:56:366111 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156112 child1->SetBounds(gfx::Size(20, 20));
6113 child2->SetBounds(gfx::Size(20, 20));
[email protected]a9aa60a82013-08-29 04:28:266114
enne03b0e9a2015-06-19 00:08:026115 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266116
jaydasikae00c8a42016-01-28 20:18:336117 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
6118 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
6119 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6120 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026121 ->at(0)
6122 ->render_surface()
6123 ->layer_list()
6124 .size());
6125 EXPECT_EQ(1u, render_surface_layer_list_impl()
6126 ->at(1)
6127 ->render_surface()
6128 ->layer_list()
6129 .size());
[email protected]a9aa60a82013-08-29 04:28:266130
danakjf78fb272016-07-26 19:06:156131 gfx::Transform rotation_transform;
[email protected]a9aa60a82013-08-29 04:28:266132 rotation_transform.RotateAboutXAxis(180.0);
6133
jaydasikae00c8a42016-01-28 20:18:336134 back_facing->SetTransform(rotation_transform);
jaydasika5aa88b82015-11-10 01:48:036135 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266136
enne03b0e9a2015-06-19 00:08:026137 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266138
jaydasikae00c8a42016-01-28 20:18:336139 // render_surface1 is in the same 3d rendering context as back_facing and is
6140 // not double sided, so it should not be in RSLL. render_surface2 is also not
6141 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6142 // context.
6143 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6144 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026145 ->at(0)
6146 ->render_surface()
6147 ->layer_list()
6148 .size());
[email protected]a9aa60a82013-08-29 04:28:266149}
6150
ajumaaa0d3862015-11-09 22:24:466151TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
jaydasikabf1875a2016-06-28 03:39:596152 LayerImpl* root = root_layer_for_testing();
ajumaaa0d3862015-11-09 22:24:466153 LayerImpl* child = AddChild<LayerImpl>(root);
6154 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumaaa0d3862015-11-09 22:24:466155
danakjf78fb272016-07-26 19:06:156156 root->SetBounds(gfx::Size(50, 50));
6157 root->test_properties()->should_flatten_transform = false;
6158 child->SetBounds(gfx::Size(30, 30));
jaydasika6b5a32bf2016-04-22 21:56:366159 child->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156160 child->test_properties()->should_flatten_transform = false;
6161 grand_child->SetBounds(gfx::Size(20, 20));
6162 grand_child->SetDrawsContent(true);
ajumaaa0d3862015-11-09 22:24:466163 grand_child->SetUseParentBackfaceVisibility(true);
danakjf78fb272016-07-26 19:06:156164 grand_child->test_properties()->should_flatten_transform = false;
ajumaaa0d3862015-11-09 22:24:466165 ExecuteCalculateDrawProperties(root);
6166
6167 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6168 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6169 ->at(0)
6170 ->render_surface()
6171 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556172
6173 // As all layers have identity transform, we shouldn't check for backface
6174 // visibility.
6175 EXPECT_FALSE(root->should_check_backface_visibility());
6176 EXPECT_FALSE(child->should_check_backface_visibility());
6177 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6178 // As there are no 3d rendering contexts, all layers should use their local
6179 // transform for backface visibility.
6180 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6181 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6182 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6183
danakjf78fb272016-07-26 19:06:156184 gfx::Transform rotation_transform;
ajumaaa0d3862015-11-09 22:24:466185 rotation_transform.RotateAboutXAxis(180.0);
6186
6187 child->SetTransform(rotation_transform);
jaydasika62bd3dd2016-02-04 18:52:556188 child->Set3dSortingContextId(1);
6189 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466190 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6191
6192 ExecuteCalculateDrawProperties(root);
6193 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6194 EXPECT_EQ(0u, render_surface_layer_list_impl()
6195 ->at(0)
6196 ->render_surface()
6197 ->layer_list()
6198 .size());
jaydasika62bd3dd2016-02-04 18:52:556199
6200 // We should check for backface visibilty of child as it has a rotation
6201 // transform. We should also check for grand_child as it uses the backface
6202 // visibility of its parent.
6203 EXPECT_FALSE(root->should_check_backface_visibility());
6204 EXPECT_TRUE(child->should_check_backface_visibility());
6205 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6206 // child uses its local transform for backface visibility as it is the root of
6207 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6208 // the root, but it derives its backface visibility from its parent which uses
6209 // its local transform.
6210 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6211 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6212 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6213
6214 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366215 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556216 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6217
6218 ExecuteCalculateDrawProperties(root);
6219 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6220 EXPECT_EQ(0u, render_surface_layer_list_impl()
6221 ->at(0)
6222 ->render_surface()
6223 ->layer_list()
6224 .size());
6225
6226 // We should check the backface visibility of child as it has a rotation
6227 // transform and for grand_child as it is in a 3d rendering context and not
6228 // the root of it.
6229 EXPECT_FALSE(root->should_check_backface_visibility());
6230 EXPECT_TRUE(child->should_check_backface_visibility());
6231 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6232 // grand_child is in an existing 3d rendering context, so it should not use
6233 // local transform for backface visibility.
6234 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6235 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6236 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466237}
6238
sunxd59dd7da2016-05-19 20:07:476239TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
jaydasikabf1875a2016-06-28 03:39:596240 LayerImpl* root = root_layer_for_testing();
sunxd59dd7da2016-05-19 20:07:476241 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6242 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6243 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6244
sunxd59dd7da2016-05-19 20:07:476245 gfx::Transform rotate_about_y;
6246 rotate_about_y.RotateAboutYAxis(180.0);
sunxd59dd7da2016-05-19 20:07:476247
danakjf78fb272016-07-26 19:06:156248 root->SetBounds(gfx::Size(50, 50));
6249 root->Set3dSortingContextId(1);
6250 root->test_properties()->should_flatten_transform = false;
6251 back_facing->SetTransform(rotate_about_y);
6252 back_facing->SetBounds(gfx::Size(50, 50));
6253 back_facing->Set3dSortingContextId(1);
6254 back_facing->test_properties()->should_flatten_transform = false;
6255 render_surface1->SetBounds(gfx::Size(30, 30));
6256 render_surface1->Set3dSortingContextId(1);
6257 render_surface1->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476258 render_surface1->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156259 render_surface1->test_properties()->force_render_surface = true;
6260 render_surface2->SetBounds(gfx::Size(30, 30));
6261 render_surface2->Set3dSortingContextId(1);
6262 render_surface2->test_properties()->should_flatten_transform = false;
sunxd59dd7da2016-05-19 20:07:476263 render_surface2->test_properties()->double_sided = false;
danakjf78fb272016-07-26 19:06:156264 render_surface2->test_properties()->force_render_surface = true;
sunxd59dd7da2016-05-19 20:07:476265 ExecuteCalculateDrawProperties(root);
6266
6267 const EffectTree& tree =
6268 root->layer_tree_impl()->property_trees()->effect_tree;
6269 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016270 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476271 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016272 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476273
danakjf78fb272016-07-26 19:06:156274 back_facing->OnTransformAnimated(gfx::Transform());
sunxd59dd7da2016-05-19 20:07:476275 render_surface2->OnTransformAnimated(rotate_about_y);
6276 ExecuteCalculateDrawProperties(root);
6277 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016278 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476279 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016280 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476281
6282 render_surface1->OnTransformAnimated(rotate_about_y);
6283 ExecuteCalculateDrawProperties(root);
6284 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
trchendba8b1502016-07-08 09:47:016285 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476286 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
trchendba8b1502016-07-08 09:47:016287 ->hidden_by_backface_visibility);
sunxd59dd7da2016-05-19 20:07:476288}
6289
[email protected]995708c52013-10-17 20:52:596290TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6291 // Checks that the simple case (being clipped by a scroll parent that would
6292 // have been processed before you anyhow) results in the right clips.
6293 //
6294 // + root
6295 // + scroll_parent_border
6296 // | + scroll_parent_clip
6297 // | + scroll_parent
6298 // + scroll_child
6299 //
jaydasikabf1875a2016-06-28 03:39:596300 LayerImpl* root = root_layer_for_testing();
enne085b48a2015-08-18 17:54:486301 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6302 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6303 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6304 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596305
enne085b48a2015-08-18 17:54:486306 scroll_parent->SetDrawsContent(true);
6307 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596308 scroll_parent_clip->SetMasksToBounds(true);
6309
jaydasika1c0a27d42016-04-28 01:54:566310 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156311 scroll_parent->test_properties()->scroll_children =
6312 base::MakeUnique<std::set<LayerImpl*>>();
6313 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596314
danakjf78fb272016-07-26 19:06:156315 root->SetBounds(gfx::Size(50, 50));
6316 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6317 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6318 scroll_parent->SetBounds(gfx::Size(50, 50));
6319 scroll_child->SetBounds(gfx::Size(50, 50));
enne085b48a2015-08-18 17:54:486320 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596321
6322 EXPECT_TRUE(root->render_surface());
6323
jaydasika6f972de2016-04-07 16:16:146324 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596325 EXPECT_TRUE(scroll_child->is_clipped());
6326}
6327
jaydasika8ccff3d2016-01-20 19:51:306328TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6329 // Tests the computation of draw transform for the scroll child when its
6330 // target is different from its scroll parent's target.
jaydasikabf1875a2016-06-28 03:39:596331 LayerImpl* root = root_layer_for_testing();
jaydasika8ccff3d2016-01-20 19:51:306332 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6333 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6334 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6335 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6336
6337 scroll_parent->SetDrawsContent(true);
6338 scroll_child->SetDrawsContent(true);
6339
jaydasika1c0a27d42016-04-28 01:54:566340 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156341 scroll_parent->test_properties()->scroll_children =
6342 base::MakeUnique<std::set<LayerImpl*>>();
6343 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
jaydasika8ccff3d2016-01-20 19:51:306344
danakjf78fb272016-07-26 19:06:156345 root->SetBounds(gfx::Size(50, 50));
6346 scroll_child_target->SetBounds(gfx::Size(50, 50));
6347 scroll_child_target->test_properties()->force_render_surface = true;
6348 scroll_child->SetBounds(gfx::Size(50, 50));
6349 scroll_parent_target->SetPosition(gfx::PointF(10, 10));
6350 scroll_parent_target->SetBounds(gfx::Size(50, 50));
jaydasika2489a442016-01-29 02:26:006351 scroll_parent_target->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156352 scroll_parent_target->test_properties()->force_render_surface = true;
6353 scroll_parent->SetBounds(gfx::Size(50, 50));
jaydasika8ccff3d2016-01-20 19:51:306354
jaydasika2489a442016-01-29 02:26:006355 float device_scale_factor = 1.5f;
6356 LayerImplList render_surface_layer_list_impl;
jaydasika2489a442016-01-29 02:26:006357 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakjf78fb272016-07-26 19:06:156358 root, root->bounds(), gfx::Transform(), &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006359 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576360 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006361
weiliangc1da3fb892016-03-14 20:23:526362 EXPECT_EQ(scroll_child->effect_tree_index(),
6363 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006364 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6365 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6366 gfx::Transform scale;
6367 scale.Scale(1.5f, 1.5f);
weiliangcc3517722016-06-28 22:52:026368 EXPECT_TRANSFORMATION_MATRIX_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306369}
6370
[email protected]08bdf1b2014-04-16 23:23:296371TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
jaydasikabf1875a2016-06-28 03:39:596372 LayerImpl* root = root_layer_for_testing();
enneca33fed2015-07-27 18:22:196373 LayerImpl* parent = AddChildToRoot<LayerImpl>();
enneca33fed2015-07-27 18:22:196374 LayerImpl* child = AddChild<LayerImpl>(parent);
danakjf78fb272016-07-26 19:06:156375
6376 root->SetBounds(gfx::Size(50, 50));
6377 root->SetDrawsContent(true);
6378 root->Set3dSortingContextId(1);
6379 parent->SetBounds(gfx::Size(30, 30));
6380 parent->SetDrawsContent(true);
6381 parent->Set3dSortingContextId(1);
6382 parent->test_properties()->force_render_surface = true;
6383 child->SetBounds(gfx::Size(20, 20));
enneca33fed2015-07-27 18:22:196384 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156385 child->Set3dSortingContextId(1);
6386 child->test_properties()->force_render_surface = true;
enneca33fed2015-07-27 18:22:196387 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296388
enneca33fed2015-07-27 18:22:196389 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296390
6391 gfx::Transform singular_transform;
6392 singular_transform.Scale3d(
6393 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6394
6395 child->SetTransform(singular_transform);
6396
sunxd71aea3e2016-04-01 23:48:056397 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196398 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296399
enneca33fed2015-07-27 18:22:196400 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296401
6402 // Ensure that the entire subtree under a layer with singular transform does
6403 // not get rendered.
6404 parent->SetTransform(singular_transform);
danakjf78fb272016-07-26 19:06:156405 child->SetTransform(gfx::Transform());
[email protected]08bdf1b2014-04-16 23:23:296406
sunxd71aea3e2016-04-01 23:48:056407 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196408 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296409
enneca33fed2015-07-27 18:22:196410 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296411}
6412
[email protected]995708c52013-10-17 20:52:596413TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6414 // Checks that clipping by a scroll parent that follows you in paint order
6415 // still results in correct clipping.
6416 //
6417 // + root
[email protected]995708c52013-10-17 20:52:596418 // + scroll_parent_border
6419 // + scroll_parent_clip
6420 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026421 // + scroll_child
[email protected]995708c52013-10-17 20:52:596422 //
jaydasikabf1875a2016-06-28 03:39:596423 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026424 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6425 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6426 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6427 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596428
enne03b0e9a2015-06-19 00:08:026429 scroll_parent->SetDrawsContent(true);
6430 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596431
danakjf78fb272016-07-26 19:06:156432 root->SetBounds(gfx::Size(50, 50));
6433 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6434 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
[email protected]995708c52013-10-17 20:52:596435 scroll_parent_clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:156436 scroll_parent->SetBounds(gfx::Size(50, 50));
6437 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596438
jaydasika1c0a27d42016-04-28 01:54:566439 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156440 scroll_parent->test_properties()->scroll_children =
6441 base::MakeUnique<std::set<LayerImpl*>>();
6442 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
[email protected]995708c52013-10-17 20:52:596443
enne03b0e9a2015-06-19 00:08:026444 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596445
6446 EXPECT_TRUE(root->render_surface());
6447
jaydasika6f972de2016-04-07 16:16:146448 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596449 EXPECT_TRUE(scroll_child->is_clipped());
6450}
6451
6452TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6453 // Checks that clipping by a scroll parent and scroll grandparent that follow
6454 // you in paint order still results in correct clipping.
6455 //
6456 // + root
6457 // + scroll_child
6458 // + scroll_parent_border
6459 // | + scroll_parent_clip
6460 // | + scroll_parent
6461 // + scroll_grandparent_border
6462 // + scroll_grandparent_clip
6463 // + scroll_grandparent
6464 //
jaydasikabf1875a2016-06-28 03:39:596465 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026466 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6467 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6468 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6469 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6470 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6471 LayerImpl* scroll_grandparent_clip =
6472 AddChild<LayerImpl>(scroll_grandparent_border);
6473 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596474
enne03b0e9a2015-06-19 00:08:026475 scroll_parent->SetDrawsContent(true);
6476 scroll_grandparent->SetDrawsContent(true);
6477 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596478
6479 scroll_parent_clip->SetMasksToBounds(true);
6480 scroll_grandparent_clip->SetMasksToBounds(true);
6481
jaydasika1c0a27d42016-04-28 01:54:566482 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156483 scroll_parent->test_properties()->scroll_children =
6484 base::MakeUnique<std::set<LayerImpl*>>();
6485 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386486
jaydasika1c0a27d42016-04-28 01:54:566487 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156488 scroll_grandparent->test_properties()->scroll_children =
6489 base::MakeUnique<std::set<LayerImpl*>>();
6490 scroll_grandparent->test_properties()->scroll_children->insert(
6491 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596492
danakjf78fb272016-07-26 19:06:156493 root->SetBounds(gfx::Size(50, 50));
6494 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6495 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6496 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6497 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6498 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6499 scroll_parent->SetBounds(gfx::Size(50, 50));
6500 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596501
enne03b0e9a2015-06-19 00:08:026502 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596503
6504 EXPECT_TRUE(root->render_surface());
6505
jaydasika6f972de2016-04-07 16:16:146506 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596507 EXPECT_TRUE(scroll_child->is_clipped());
6508
6509 // Despite the fact that we visited the above layers out of order to get the
6510 // correct clip, the layer lists should be unaffected.
6511 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026512 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6513 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6514 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596515}
6516
6517TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6518 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226519 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596520 // + root
6521 // + scroll_child
6522 // + scroll_parent_border
6523 // + scroll_parent_clip
6524 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026525 // + render_surface2
[email protected]995708c52013-10-17 20:52:596526 // + scroll_grandparent_border
6527 // + scroll_grandparent_clip
6528 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026529 // + render_surface1
[email protected]995708c52013-10-17 20:52:596530 //
jaydasikabf1875a2016-06-28 03:39:596531 LayerImpl* root = root_layer_for_testing();
enne03b0e9a2015-06-19 00:08:026532 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596533
enne03b0e9a2015-06-19 00:08:026534 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6535 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596536
enne03b0e9a2015-06-19 00:08:026537 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6538 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6539 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6540 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6541 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6542 LayerImpl* scroll_grandparent_clip =
6543 AddChild<LayerImpl>(scroll_grandparent_border);
6544 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6545 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596546
enne03b0e9a2015-06-19 00:08:026547 scroll_parent->SetDrawsContent(true);
6548 render_surface1->SetDrawsContent(true);
6549 scroll_grandparent->SetDrawsContent(true);
6550 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596551
6552 scroll_parent_clip->SetMasksToBounds(true);
6553 scroll_grandparent_clip->SetMasksToBounds(true);
6554
jaydasika1c0a27d42016-04-28 01:54:566555 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakjf78fb272016-07-26 19:06:156556 scroll_parent->test_properties()->scroll_children =
6557 base::MakeUnique<std::set<LayerImpl*>>();
6558 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajuma9af2e92b2015-06-29 22:26:386559
jaydasika1c0a27d42016-04-28 01:54:566560 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
danakjf78fb272016-07-26 19:06:156561 scroll_grandparent->test_properties()->scroll_children =
6562 base::MakeUnique<std::set<LayerImpl*>>();
6563 scroll_grandparent->test_properties()->scroll_children->insert(
6564 scroll_parent_border);
[email protected]995708c52013-10-17 20:52:596565
danakjf78fb272016-07-26 19:06:156566 root->SetBounds(gfx::Size(50, 50));
6567 scroll_grandparent_border->SetBounds(gfx::Size(40, 40));
6568 scroll_grandparent_clip->SetBounds(gfx::Size(20, 20));
6569 scroll_grandparent->SetBounds(gfx::Size(50, 50));
6570 render_surface1->SetBounds(gfx::Size(50, 50));
6571 render_surface1->test_properties()->force_render_surface = true;
6572 scroll_parent_border->SetBounds(gfx::Size(40, 40));
6573 scroll_parent_clip->SetBounds(gfx::Size(30, 30));
6574 scroll_parent->SetBounds(gfx::Size(50, 50));
6575 render_surface2->SetBounds(gfx::Size(50, 50));
6576 render_surface2->test_properties()->force_render_surface = true;
6577 scroll_child->SetBounds(gfx::Size(50, 50));
[email protected]995708c52013-10-17 20:52:596578
enne03b0e9a2015-06-19 00:08:026579 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596580
6581 EXPECT_TRUE(root->render_surface());
6582
jaydasika6f972de2016-04-07 16:16:146583 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596584 EXPECT_TRUE(scroll_child->is_clipped());
6585
6586 // Despite the fact that we had to process the layers out of order to get the
6587 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026588 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6589 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6590 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6591 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6592 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6593 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6594 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596595}
6596
ajuma0b10f942015-03-21 07:45:536597TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6598 // Ensures that when we have a render surface between a fixed position layer
6599 // and its container, we compute the fixed position layer's draw transform
6600 // with respect to that intervening render surface, not with respect to its
6601 // container's render target.
6602 //
6603 // + root
6604 // + render_surface
6605 // + fixed
ajuma737b2702015-05-06 01:18:376606 // + child
ajuma0b10f942015-03-21 07:45:536607 //
jaydasikabf1875a2016-06-28 03:39:596608 LayerImpl* root = root_layer_for_testing();
sunxdfd920f3f2016-04-05 16:17:516609 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6610 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6611 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536612
jaydasika6b5a32bf2016-04-22 21:56:366613 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526614 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536615
6616 LayerPositionConstraint constraint;
6617 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526618 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536619
danakjf78fb272016-07-26 19:06:156620 root->SetBounds(gfx::Size(50, 50));
6621 render_surface->SetPosition(gfx::PointF(7.f, 9.f));
6622 render_surface->SetBounds(gfx::Size(50, 50));
6623 render_surface->SetDrawsContent(true);
6624 fixed->SetPosition(gfx::PointF(10.f, 15.f));
6625 fixed->SetBounds(gfx::Size(50, 50));
6626 fixed->SetDrawsContent(true);
6627 child->SetPosition(gfx::PointF(1.f, 2.f));
6628 child->SetBounds(gfx::Size(50, 50));
6629 child->SetDrawsContent(true);
sunxdfd920f3f2016-04-05 16:17:516630 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536631
jaydasikabaede2d92016-07-20 00:34:326632 TransformTree& transform_tree =
sunxdfd920f3f2016-04-05 16:17:516633 host_impl()->active_tree()->property_trees()->transform_tree;
jaydasikabaede2d92016-07-20 00:34:326634 EffectTree& effect_tree =
6635 host_impl()->active_tree()->property_trees()->effect_tree;
ennef6903532015-08-18 05:10:156636
ajuma737b2702015-05-06 01:18:376637 gfx::Transform expected_fixed_draw_transform;
6638 expected_fixed_draw_transform.Translate(10.f, 15.f);
weiliangcc3517722016-06-28 22:52:026639 EXPECT_TRANSFORMATION_MATRIX_EQ(
6640 expected_fixed_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326641 draw_property_utils::DrawTransform(fixed, transform_tree, effect_tree));
ajuma0b10f942015-03-21 07:45:536642
ajuma737b2702015-05-06 01:18:376643 gfx::Transform expected_fixed_screen_space_transform;
6644 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
weiliangcc3517722016-06-28 22:52:026645 EXPECT_TRANSFORMATION_MATRIX_EQ(
6646 expected_fixed_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326647 draw_property_utils::ScreenSpaceTransform(fixed, transform_tree));
ajuma737b2702015-05-06 01:18:376648
6649 gfx::Transform expected_child_draw_transform;
6650 expected_child_draw_transform.Translate(11.f, 17.f);
weiliangcc3517722016-06-28 22:52:026651 EXPECT_TRANSFORMATION_MATRIX_EQ(
6652 expected_child_draw_transform,
jaydasikabaede2d92016-07-20 00:34:326653 draw_property_utils::DrawTransform(child, transform_tree, effect_tree));
ajuma737b2702015-05-06 01:18:376654
6655 gfx::Transform expected_child_screen_space_transform;
6656 expected_child_screen_space_transform.Translate(18.f, 26.f);
weiliangcc3517722016-06-28 22:52:026657 EXPECT_TRANSFORMATION_MATRIX_EQ(
6658 expected_child_screen_space_transform,
jaydasikabaede2d92016-07-20 00:34:326659 draw_property_utils::ScreenSpaceTransform(child, transform_tree));
ajuma0b10f942015-03-21 07:45:536660}
6661
[email protected]d81752b2013-10-25 08:32:236662TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6663 // This test verifies that a scrolling layer that gets snapped to
6664 // integer coordinates doesn't move a fixed position child.
6665 //
6666 // + root
6667 // + container
6668 // + scroller
6669 // + fixed
6670 //
khushalsagarb64b360d2015-10-21 19:25:166671 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456672 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566673 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166674 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566675 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236676 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486677 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426678 LayerImpl::Create(host_impl.active_tree(), 1);
6679 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486680 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236681 LayerImpl::Create(host_impl.active_tree(), 2);
6682 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486683 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236684 LayerImpl::Create(host_impl.active_tree(), 3);
6685 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486686 std::unique_ptr<LayerImpl> fixed =
6687 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236688 LayerImpl* fixed_layer = fixed.get();
6689
jaydasikaca2605e2016-04-23 02:52:526690 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236691
6692 LayerPositionConstraint constraint;
6693 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526694 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236695
[email protected]adeda572014-01-31 00:49:476696 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236697
[email protected]d81752b2013-10-25 08:32:236698 gfx::Transform container_transform;
6699 container_transform.Translate3d(10.0, 20.0, 0.0);
6700 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6701
danakjf78fb272016-07-26 19:06:156702 root->SetBounds(gfx::Size(50, 50));
6703 container->SetTransform(container_transform);
6704 container->SetBounds(gfx::Size(40, 40));
jaydasika0d98ba92015-11-17 05:17:286705 container->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156706 scroller->SetBounds(gfx::Size(30, 30));
jaydasika0d98ba92015-11-17 05:17:286707 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156708 fixed->SetBounds(gfx::Size(50, 50));
jaydasika0d98ba92015-11-17 05:17:286709 fixed->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:156710
jaydasika89f7b5a2016-06-22 02:08:396711 scroller->test_properties()->AddChild(std::move(fixed));
6712 container->test_properties()->AddChild(std::move(scroller));
6713 root->test_properties()->AddChild(std::move(container));
danakj74af409e2016-07-01 00:41:486714 root->layer_tree_impl()->SetRootLayerForTesting(std::move(root_ptr));
6715 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]d81752b2013-10-25 08:32:236716
6717 // Rounded to integers already.
6718 {
[email protected]d81752b2013-10-25 08:32:236719 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426720 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236721
6722 LayerImplList render_surface_layer_list;
6723 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386724 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:426725 root->layer_tree_impl()
6726 ->property_trees()
6727 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576728 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236729
6730 EXPECT_TRANSFORMATION_MATRIX_EQ(
6731 container_layer->draw_properties().screen_space_transform,
6732 fixed_layer->draw_properties().screen_space_transform);
6733 EXPECT_VECTOR_EQ(
6734 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6735 container_offset);
6736 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6737 .screen_space_transform.To2dTranslation(),
6738 container_offset - scroll_delta);
6739 }
6740
6741 // Scroll delta requiring rounding.
6742 {
[email protected]d81752b2013-10-25 08:32:236743 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426744 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236745
6746 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6747
6748 LayerImplList render_surface_layer_list;
6749 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386750 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576751 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236752
6753 EXPECT_TRANSFORMATION_MATRIX_EQ(
6754 container_layer->draw_properties().screen_space_transform,
6755 fixed_layer->draw_properties().screen_space_transform);
6756 EXPECT_VECTOR_EQ(
6757 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6758 container_offset);
6759 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6760 .screen_space_transform.To2dTranslation(),
6761 container_offset - rounded_scroll_delta);
6762 }
[email protected]cf15ad7b2014-04-02 03:59:266763
6764 // Scale is applied earlier in the tree.
6765 {
sunxdb7e79432016-03-09 21:13:426766 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:266767 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286768 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:266769 container_layer->SetTransform(scaled_container_transform);
danakj74af409e2016-07-01 00:41:486770
jaydasika0d98ba92015-11-17 05:17:286771 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]cf15ad7b2014-04-02 03:59:266772
6773 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:426774 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:266775
6776 LayerImplList render_surface_layer_list;
6777 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386778 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576779 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:266780
6781 EXPECT_TRANSFORMATION_MATRIX_EQ(
6782 container_layer->draw_properties().screen_space_transform,
6783 fixed_layer->draw_properties().screen_space_transform);
6784 EXPECT_VECTOR_EQ(
6785 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6786 container_offset);
6787
6788 container_layer->SetTransform(container_transform);
6789 }
[email protected]d81752b2013-10-25 08:32:236790}
6791
miletus2c78036b2015-01-29 20:52:376792TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:506793 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6794 // This test verifies that a scrolling layer whose screen space transform is
6795 // animating doesn't get snapped to integer coordinates.
6796 //
6797 // + root
6798 // + animated layer
6799 // + surface
6800 // + container
6801 // + scroller
6802 //
jaydasikabf1875a2016-06-28 03:39:596803 LayerImpl* root = root_layer_for_testing();
ajuma5e8e40d2015-07-31 01:50:506804 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6805 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6806 LayerImpl* container = AddChild<LayerImpl>(surface);
6807 LayerImpl* scroller = AddChild<LayerImpl>(container);
ajuma5e8e40d2015-07-31 01:50:506808
ajuma5e8e40d2015-07-31 01:50:506809 gfx::Transform start_scale;
6810 start_scale.Scale(1.5f, 1.5f);
danakjf78fb272016-07-26 19:06:156811
6812 root->SetBounds(gfx::Size(50, 50));
6813 animated_layer->SetTransform(start_scale);
6814 animated_layer->SetBounds(gfx::Size(50, 50));
6815 surface->SetBounds(gfx::Size(50, 50));
6816 surface->test_properties()->force_render_surface = true;
6817 container->SetBounds(gfx::Size(50, 50));
6818 scroller->SetBounds(gfx::Size(100, 100));
6819 scroller->SetScrollClipLayer(container->id());
6820 scroller->SetDrawsContent(true);
ajuma5e8e40d2015-07-31 01:50:506821
6822 gfx::Transform end_scale;
6823 end_scale.Scale(2.f, 2.f);
6824 TransformOperations start_operations;
6825 start_operations.AppendMatrix(start_scale);
6826 TransformOperations end_operations;
6827 end_operations.AppendMatrix(end_scale);
vollickef2ae922016-06-29 17:54:276828 SetElementIdsForTesting();
6829
6830 AddAnimatedTransformToElementWithPlayer(animated_layer->element_id(),
6831 timeline_impl(), 1.0,
6832 start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:506833 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:426834 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:506835
6836 ExecuteCalculateDrawProperties(root);
6837
6838 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6839 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446840 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506841}
6842
sunxd8a9a60982016-07-29 18:46:566843TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) {
6844 // This test verifies that a scrolling child of a scrolling layer doesn't get
6845 // snapped to integer coordinates.
6846 //
6847 // + root
6848 // + container
6849 // + scroller
6850 // + scroll_child
6851 //
6852 scoped_refptr<Layer> root = Layer::Create();
6853 scoped_refptr<Layer> container = Layer::Create();
6854 scoped_refptr<Layer> scroller = Layer::Create();
6855 scoped_refptr<Layer> scroll_child = Layer::Create();
6856 root->AddChild(container);
6857 root->AddChild(scroll_child);
6858 container->AddChild(scroller);
6859 host()->SetRootLayer(root);
6860
6861 scroller->SetScrollClipLayerId(container->id());
6862 scroll_child->SetScrollParent(scroller.get());
6863
6864 gfx::Transform rotate;
6865 rotate.RotateAboutYAxis(30);
6866 root->SetBounds(gfx::Size(50, 50));
6867 container->SetBounds(gfx::Size(50, 50));
6868 scroller->SetBounds(gfx::Size(100, 100));
6869 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6870 scroll_child->SetBounds(gfx::Size(10, 10));
6871 scroll_child->SetTransform(rotate);
6872
6873 ExecuteCalculateDrawProperties(root.get());
6874
6875 host()->host_impl()->CreatePendingTree();
6876 host()->CommitAndCreatePendingTree();
6877 host()->host_impl()->ActivateSyncTree();
6878 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6879
6880 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6881 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6882 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id());
6883 gfx::Vector2dF scroll_delta(5.f, 9.f);
6884 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6885
6886 ExecuteCalculateDrawProperties(root_impl);
6887
6888 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6889 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6890 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6891
6892 gfx::Transform expected_scroll_child_screen_space_transform;
6893 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f);
6894 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30);
6895 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform,
6896 scroll_child_impl->ScreenSpaceTransform());
6897}
6898
6899TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) {
6900 // This test verifies that a fixed pos child of a scrolling layer doesn't get
6901 // snapped to integer coordinates.
6902 //
6903 // + root
6904 // + container
6905 // + scroller
6906 // + fixed_pos
6907 //
6908 scoped_refptr<Layer> root = Layer::Create();
6909 scoped_refptr<Layer> container = Layer::Create();
6910 scoped_refptr<Layer> scroller = Layer::Create();
6911 scoped_refptr<Layer> fixed_pos = Layer::Create();
6912
6913 scroller->SetIsContainerForFixedPositionLayers(true);
6914
6915 root->AddChild(container);
6916 container->AddChild(scroller);
6917 scroller->AddChild(fixed_pos);
6918 host()->SetRootLayer(root);
6919
6920 LayerPositionConstraint fixed_position;
6921 fixed_position.set_is_fixed_position(true);
6922 scroller->SetScrollClipLayerId(container->id());
6923 fixed_pos->SetPositionConstraint(fixed_position);
6924
6925 root->SetBounds(gfx::Size(50, 50));
6926 container->SetBounds(gfx::Size(50, 50));
6927 scroller->SetBounds(gfx::Size(100, 100));
6928 scroller->SetPosition(gfx::PointF(10.3f, 10.3f));
6929 fixed_pos->SetBounds(gfx::Size(10, 10));
6930
6931 ExecuteCalculateDrawProperties(root.get());
6932
6933 host()->host_impl()->CreatePendingTree();
6934 host()->CommitAndCreatePendingTree();
6935 host()->host_impl()->ActivateSyncTree();
6936 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree();
6937
6938 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id());
6939 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id());
6940 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id());
6941 gfx::Vector2dF scroll_delta(5.f, 9.f);
6942 SetScrollOffsetDelta(scroller_impl, scroll_delta);
6943
6944 ExecuteCalculateDrawProperties(root_impl);
6945
6946 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f);
6947 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation,
6948 scroller_impl->ScreenSpaceTransform().To2dTranslation());
6949
6950 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f,
6951 10.3f);
6952 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation,
6953 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation());
6954}
6955
[email protected]1c3626e2014-04-09 17:49:226956class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
6957 public:
danakj60bc3bc2016-04-09 00:24:486958 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:226959 LayerTreeImpl* tree_impl,
6960 int id) {
danakj60bc3bc2016-04-09 00:24:486961 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:226962 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
6963 }
6964
dcheng716bedf2014-10-21 09:51:086965 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:226966
[email protected]1c3626e2014-04-09 17:49:226967 private:
6968 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
6969 int id)
[email protected]a57cb8b12014-06-13 18:15:376970 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:226971 SetDrawsContent(true);
6972 }
[email protected]1c3626e2014-04-09 17:49:226973};
6974
6975TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:166976 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:226977 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566978 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:486979 LayerTreeSettings settings = host()->settings();
ajumab4a846f22015-08-24 19:13:446980 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:166981 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
6982 &shared_bitmap_manager, &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:486983 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:226984 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:486985 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:226986 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:486987 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:226988 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:486989 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:226990 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
6991
6992 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
6993 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
6994 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:096995 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:226996
danakjf78fb272016-07-26 19:06:156997 grand_parent->SetBounds(gfx::Size(1, 2));
6998 parent->SetBounds(gfx::Size(1, 2));
6999 child->SetBounds(gfx::Size(1, 2));
7000 grand_child->SetBounds(gfx::Size(1, 2));
7001
jaydasika89f7b5a2016-06-22 02:08:397002 child->test_properties()->AddChild(std::move(grand_child));
7003 parent->test_properties()->AddChild(std::move(child));
7004 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597005 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
sunxd71aea3e2016-04-01 23:48:057006
jaydasika2411692c2016-03-23 01:56:097007 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227008
7009 // No layers have animations.
sunxdf468675e2016-06-30 23:56:187010 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7011 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7012 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7013 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227014
sunxdf468675e2016-06-30 23:56:187015 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7016 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7017 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7018 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037019
[email protected]1c3626e2014-04-09 17:49:227020 TransformOperations translation;
7021 translation.AppendTranslate(1.f, 2.f, 3.f);
7022
loyso968163c92016-01-04 23:18:487023 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587024 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7025 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487026
vollickef2ae922016-06-29 17:54:277027 host_impl.active_tree()->SetElementIdsForTesting();
7028 AddAnimatedTransformToElementWithPlayer(parent_raw->element_id(), timeline,
7029 1.0, TransformOperations(),
7030 translation);
[email protected]1c3626e2014-04-09 17:49:227031
7032 // No layers have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187033 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7034 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7035 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7036 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227037
sunxdf468675e2016-06-30 23:56:187038 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7039 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7040 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7041 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037042
[email protected]1c3626e2014-04-09 17:49:227043 TransformOperations scale;
7044 scale.AppendScale(5.f, 4.f, 3.f);
7045
vollickef2ae922016-06-29 17:54:277046 AddAnimatedTransformToElementWithPlayer(child_raw->element_id(), timeline,
7047 1.0, TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297048 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097049 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227050
7051 // Only |child| has a scale-affecting animation.
sunxdf468675e2016-06-30 23:56:187052 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7053 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7054 EXPECT_EQ(5.f, GetMaximumAnimationScale(child_raw));
7055 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227056
sunxdf468675e2016-06-30 23:56:187057 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7058 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7059 EXPECT_EQ(1.f, GetStartingAnimationScale(child_raw));
7060 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037061
vollickef2ae922016-06-29 17:54:277062 AddAnimatedTransformToElementWithPlayer(grand_parent_raw->element_id(),
7063 timeline, 1.0, TransformOperations(),
7064 scale);
jaydasika2411692c2016-03-23 01:56:097065 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7066 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227067
7068 // |grand_parent| and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187069 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7070 EXPECT_EQ(5.f, GetMaximumAnimationScale(parent_raw));
[email protected]1c3626e2014-04-09 17:49:227071 // We don't support combining animated scales from two nodes; 0.f means
7072 // that the maximum scale could not be computed.
sunxdf468675e2016-06-30 23:56:187073 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7074 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227075
sunxdf468675e2016-06-30 23:56:187076 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7077 EXPECT_EQ(1.f, GetStartingAnimationScale(parent_raw));
7078 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7079 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037080
vollickef2ae922016-06-29 17:54:277081 AddAnimatedTransformToElementWithPlayer(parent_raw->element_id(), timeline,
7082 1.0, TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297083 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097084 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227085
7086 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
sunxdf468675e2016-06-30 23:56:187087 EXPECT_EQ(5.f, GetMaximumAnimationScale(grand_parent_raw));
7088 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7089 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7090 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227091
sunxdf468675e2016-06-30 23:56:187092 EXPECT_EQ(1.f, GetStartingAnimationScale(grand_parent_raw));
7093 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7094 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7095 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037096
vollickef2ae922016-06-29 17:54:277097 AbortAnimationsOnElementWithPlayer(grand_parent_raw->element_id(), timeline,
7098 TargetProperty::TRANSFORM);
7099 AbortAnimationsOnElementWithPlayer(parent_raw->element_id(), timeline,
7100 TargetProperty::TRANSFORM);
7101 AbortAnimationsOnElementWithPlayer(child_raw->element_id(), timeline,
7102 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227103
7104 TransformOperations perspective;
7105 perspective.AppendPerspective(10.f);
7106
vollickef2ae922016-06-29 17:54:277107 AddAnimatedTransformToElementWithPlayer(child_raw->element_id(), timeline,
7108 1.0, TransformOperations(),
7109 perspective);
ajumab4a846f22015-08-24 19:13:447110 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097111 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227112
7113 // |child| has a scale-affecting animation but computing the maximum of this
7114 // animation is not supported.
sunxdf468675e2016-06-30 23:56:187115 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7116 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7117 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7118 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227119
sunxdf468675e2016-06-30 23:56:187120 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7121 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7122 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7123 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037124
vollickef2ae922016-06-29 17:54:277125 AbortAnimationsOnElementWithPlayer(child_raw->element_id(), timeline,
7126 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227127 gfx::Transform scale_matrix;
7128 scale_matrix.Scale(1.f, 2.f);
jaydasika2411692c2016-03-23 01:56:097129 grand_parent_raw->SetTransform(scale_matrix);
[email protected]1c3626e2014-04-09 17:49:227130 parent_raw->SetTransform(scale_matrix);
jaydasika2411692c2016-03-23 01:56:097131 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487132
vollickef2ae922016-06-29 17:54:277133 AddAnimatedTransformToElementWithPlayer(parent_raw->element_id(), timeline,
7134 1.0, TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097135 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227136
7137 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7138 // animation with maximum scale 5.f.
sunxdf468675e2016-06-30 23:56:187139 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7140 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7141 EXPECT_EQ(10.f, GetMaximumAnimationScale(child_raw));
7142 EXPECT_EQ(10.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227143
sunxdf468675e2016-06-30 23:56:187144 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7145 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7146 EXPECT_EQ(2.f, GetStartingAnimationScale(child_raw));
7147 EXPECT_EQ(2.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037148
[email protected]1c3626e2014-04-09 17:49:227149 gfx::Transform perspective_matrix;
7150 perspective_matrix.ApplyPerspectiveDepth(2.f);
7151 child_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097152 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7153 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227154
7155 // |child| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187156 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7157 EXPECT_EQ(10.f, GetMaximumAnimationScale(parent_raw));
7158 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7159 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227160
sunxdf468675e2016-06-30 23:56:187161 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7162 EXPECT_EQ(2.f, GetStartingAnimationScale(parent_raw));
7163 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7164 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037165
[email protected]1c3626e2014-04-09 17:49:227166 parent_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097167 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7168 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227169
7170 // |parent| and |child| have transforms that are neither translations nor
7171 // scales.
sunxdf468675e2016-06-30 23:56:187172 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7173 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7174 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7175 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227176
sunxdf468675e2016-06-30 23:56:187177 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7178 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7179 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7180 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037181
danakjf78fb272016-07-26 19:06:157182 parent_raw->SetTransform(gfx::Transform());
7183 child_raw->SetTransform(gfx::Transform());
jaydasika2411692c2016-03-23 01:56:097184 grand_parent_raw->SetTransform(perspective_matrix);
7185 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227186
jaydasika2411692c2016-03-23 01:56:097187 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227188
7189 // |grand_parent| has a transform that's neither a translation nor a scale.
sunxdf468675e2016-06-30 23:56:187190 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_parent_raw));
7191 EXPECT_EQ(0.f, GetMaximumAnimationScale(parent_raw));
7192 EXPECT_EQ(0.f, GetMaximumAnimationScale(child_raw));
7193 EXPECT_EQ(0.f, GetMaximumAnimationScale(grand_child_raw));
ajuma052892e2015-08-21 14:39:037194
sunxdf468675e2016-06-30 23:56:187195 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_parent_raw));
7196 EXPECT_EQ(0.f, GetStartingAnimationScale(parent_raw));
7197 EXPECT_EQ(0.f, GetStartingAnimationScale(child_raw));
7198 EXPECT_EQ(0.f, GetStartingAnimationScale(grand_child_raw));
[email protected]1c3626e2014-04-09 17:49:227199}
7200
danakj59931942016-07-26 22:11:297201static void GatherDrawnLayers(const LayerImplList* rsll,
[email protected]390bb1ff2014-05-09 17:14:407202 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517203 for (LayerIterator it = LayerIterator::Begin(rsll),
7204 end = LayerIterator::End(rsll);
7205 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407206 LayerImpl* layer = *it;
7207 if (it.represents_itself())
7208 drawn_layers->insert(layer);
7209
7210 if (!it.represents_contributing_render_surface())
7211 continue;
7212
ajuma1d4026a32016-06-14 13:18:507213 if (layer->render_surface()->MaskLayer())
7214 drawn_layers->insert(layer->render_surface()->MaskLayer());
7215 if (layer->render_surface()->ReplicaMaskLayer())
7216 drawn_layers->insert(layer->render_surface()->ReplicaMaskLayer());
[email protected]390bb1ff2014-05-09 17:14:407217 }
7218}
7219
7220TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167221 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407222 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567223 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167224 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567225 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407226
danakj60bc3bc2016-04-09 00:24:487227 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407228 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487229 std::unique_ptr<LayerImpl> parent =
7230 LayerImpl::Create(host_impl.active_tree(), 3);
7231 std::unique_ptr<LayerImpl> child =
7232 LayerImpl::Create(host_impl.active_tree(), 5);
7233 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407234 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487235 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407236 LayerImpl::Create(host_impl.active_tree(), 9);
7237
7238 LayerImpl* grand_parent_raw = grand_parent.get();
7239 LayerImpl* parent_raw = parent.get();
7240 LayerImpl* child_raw = child.get();
7241 LayerImpl* grand_child1_raw = grand_child1.get();
7242 LayerImpl* grand_child2_raw = grand_child2.get();
7243
danakjf78fb272016-07-26 19:06:157244 grand_parent->SetBounds(gfx::Size(1, 2));
7245 parent->SetBounds(gfx::Size(1, 2));
7246 child->SetBounds(gfx::Size(1, 2));
7247 grand_child1->SetBounds(gfx::Size(1, 2));
7248 grand_child2->SetBounds(gfx::Size(1, 2));
7249
jaydasika89f7b5a2016-06-22 02:08:397250 child->test_properties()->AddChild(std::move(grand_child1));
7251 child->test_properties()->AddChild(std::move(grand_child2));
7252 parent->test_properties()->AddChild(std::move(child));
7253 grand_parent->test_properties()->AddChild(std::move(parent));
jaydasikabf1875a2016-06-28 03:39:597254 host_impl.active_tree()->SetRootLayerForTesting(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407255
[email protected]390bb1ff2014-05-09 17:14:407256 // Start with nothing being drawn.
7257 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407258
ajuma0adb5902016-04-28 16:32:387259 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7260 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7261 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7262 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7263 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407264
7265 std::set<LayerImpl*> expected;
7266 std::set<LayerImpl*> actual;
7267 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7268 EXPECT_EQ(expected, actual);
7269
7270 // If we force render surface, but none of the layers are in the layer list,
7271 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007272 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127273 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407274
7275 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407276
ajuma0adb5902016-04-28 16:32:387277 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7278 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7279 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7280 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7281 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407282
7283 expected.clear();
7284 actual.clear();
7285 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7286 EXPECT_EQ(expected, actual);
7287
7288 // However, if we say that this layer also draws content, it will appear in
7289 // RSLL.
7290 grand_child1_raw->SetDrawsContent(true);
7291
7292 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407293
ajuma0adb5902016-04-28 16:32:387294 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7295 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7296 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7297 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7298 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407299
7300 expected.clear();
7301 expected.insert(grand_child1_raw);
7302
7303 actual.clear();
7304 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7305 EXPECT_EQ(expected, actual);
7306
7307 // Now child is forced to have a render surface, and one if its children draws
7308 // content.
7309 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007310 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127311 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007312 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407313 grand_child2_raw->SetDrawsContent(true);
7314
7315 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407316
ajuma0adb5902016-04-28 16:32:387317 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7318 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7319 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7320 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7321 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407322
7323 expected.clear();
7324 expected.insert(grand_child2_raw);
7325
7326 actual.clear();
7327 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7328 EXPECT_EQ(expected, actual);
7329
7330 // Add a mask layer to child.
ajuma1d4026a32016-06-14 13:18:507331 child_raw->test_properties()->SetMaskLayer(
7332 LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047333 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407334
7335 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407336
ajuma0adb5902016-04-28 16:32:387337 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7338 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7339 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507340 EXPECT_TRUE(child_raw->test_properties()
7341 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387342 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7343 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407344
7345 expected.clear();
7346 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507347 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407348
7349 expected.clear();
7350 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507351 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407352
7353 actual.clear();
7354 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7355 EXPECT_EQ(expected, actual);
7356
7357 // Add replica mask layer.
danakj60bc3bc2016-04-09 00:24:487358 std::unique_ptr<LayerImpl> replica_layer =
[email protected]390bb1ff2014-05-09 17:14:407359 LayerImpl::Create(host_impl.active_tree(), 20);
ajuma1d4026a32016-06-14 13:18:507360 replica_layer->test_properties()->SetMaskLayer(
7361 LayerImpl::Create(host_impl.active_tree(), 21));
7362 child_raw->test_properties()->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597363 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407364
7365 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407366
ajuma0adb5902016-04-28 16:32:387367 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7368 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7369 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507370 EXPECT_TRUE(child_raw->test_properties()
7371 ->mask_layer->is_drawn_render_surface_layer_list_member());
7372 EXPECT_TRUE(child_raw->test_properties()
7373 ->replica_layer->test_properties()
7374 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387375 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7376 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407377
7378 expected.clear();
7379 expected.insert(grand_child2_raw);
ajuma1d4026a32016-06-14 13:18:507380 expected.insert(child_raw->test_properties()->mask_layer);
7381 expected.insert(child_raw->test_properties()
7382 ->replica_layer->test_properties()
7383 ->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407384
7385 actual.clear();
7386 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7387 EXPECT_EQ(expected, actual);
7388
ajuma1d4026a32016-06-14 13:18:507389 child_raw->test_properties()->SetReplicaLayer(nullptr);
7390 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407391
7392 // With nothing drawing, we should have no layers.
7393 grand_child2_raw->SetDrawsContent(false);
7394
7395 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407396
ajuma0adb5902016-04-28 16:32:387397 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7398 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7399 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507400 EXPECT_FALSE(child_raw->test_properties()
7401 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387402 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7403 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407404
7405 expected.clear();
7406 actual.clear();
7407 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7408 EXPECT_EQ(expected, actual);
7409
7410 // Child itself draws means that we should have the child and the mask in the
7411 // list.
7412 child_raw->SetDrawsContent(true);
7413
7414 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407415
ajuma0adb5902016-04-28 16:32:387416 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7417 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7418 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
ajuma1d4026a32016-06-14 13:18:507419 EXPECT_TRUE(child_raw->test_properties()
7420 ->mask_layer->is_drawn_render_surface_layer_list_member());
ajuma0adb5902016-04-28 16:32:387421 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7422 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407423
7424 expected.clear();
7425 expected.insert(child_raw);
ajuma1d4026a32016-06-14 13:18:507426 expected.insert(child_raw->test_properties()->mask_layer);
[email protected]390bb1ff2014-05-09 17:14:407427 actual.clear();
7428 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7429 EXPECT_EQ(expected, actual);
7430
ajuma1d4026a32016-06-14 13:18:507431 child_raw->test_properties()->SetMaskLayer(nullptr);
jaydasikad36e7fa2015-07-14 15:15:047432 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407433
7434 // Now everyone's a member!
7435 grand_parent_raw->SetDrawsContent(true);
7436 parent_raw->SetDrawsContent(true);
7437 child_raw->SetDrawsContent(true);
7438 grand_child1_raw->SetDrawsContent(true);
7439 grand_child2_raw->SetDrawsContent(true);
7440
7441 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407442
ajuma0adb5902016-04-28 16:32:387443 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7444 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
7445 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
7446 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7447 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407448
7449 expected.clear();
7450 expected.insert(grand_parent_raw);
7451 expected.insert(parent_raw);
7452 expected.insert(child_raw);
7453 expected.insert(grand_child1_raw);
7454 expected.insert(grand_child2_raw);
7455
7456 actual.clear();
7457 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7458 EXPECT_EQ(expected, actual);
7459}
[email protected]18e69652014-06-13 12:50:587460
7461TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167462 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587463 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567464 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487465 LayerTreeSettings settings = host()->settings();
enne637715732015-07-07 02:05:267466 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167467 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7468 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587469
danakj60bc3bc2016-04-09 00:24:487470 std::unique_ptr<LayerImpl> root =
7471 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:587472 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:487473 std::unique_ptr<LayerImpl> child1 =
7474 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:587475 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:487476 std::unique_ptr<LayerImpl> child2 =
7477 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:587478 LayerImpl* child2_layer = child2.get();
7479
danakjf78fb272016-07-26 19:06:157480 gfx::Transform scale_transform_child1, scale_transform_child2;
[email protected]18e69652014-06-13 12:50:587481 scale_transform_child1.Scale(2, 3);
7482 scale_transform_child2.Scale(4, 5);
7483
danakjf78fb272016-07-26 19:06:157484 root->SetBounds(gfx::Size(1, 1));
7485 root->SetDrawsContent(true);
7486 child1_layer->SetTransform(scale_transform_child1);
7487 child1_layer->SetBounds(gfx::Size(1, 1));
7488 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587489
ajuma1d4026a32016-06-14 13:18:507490 child1_layer->test_properties()->SetMaskLayer(
7491 LayerImpl::Create(host_impl.active_tree(), 4));
[email protected]18e69652014-06-13 12:50:587492
danakj60bc3bc2016-04-09 00:24:487493 std::unique_ptr<LayerImpl> replica_layer =
[email protected]18e69652014-06-13 12:50:587494 LayerImpl::Create(host_impl.active_tree(), 5);
ajuma1d4026a32016-06-14 13:18:507495 replica_layer->test_properties()->SetMaskLayer(
7496 LayerImpl::Create(host_impl.active_tree(), 6));
7497 child1_layer->test_properties()->SetReplicaLayer(std::move(replica_layer));
danakjf78fb272016-07-26 19:06:157498
7499 root->test_properties()->AddChild(std::move(child1));
7500 root->test_properties()->AddChild(std::move(child2));
7501 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7502 host_impl.active_tree()->SetElementIdsForTesting();
[email protected]18e69652014-06-13 12:50:587503
7504 ExecuteCalculateDrawProperties(root_layer);
7505
7506 TransformOperations scale;
7507 scale.AppendScale(5.f, 8.f, 3.f);
7508
loyso9556c732016-03-11 07:54:587509 scoped_refptr<AnimationTimeline> timeline =
7510 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7511 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487512
danakjf78fb272016-07-26 19:06:157513 child2_layer->SetTransform(scale_transform_child2);
7514 child2_layer->SetBounds(gfx::Size(1, 1));
jaydasika0d98ba92015-11-17 05:17:287515 child2_layer->SetDrawsContent(true);
vollickef2ae922016-06-29 17:54:277516 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
7517 1.0, TransformOperations(), scale);
7518
jaydasika2411692c2016-03-23 01:56:097519 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587520 ExecuteCalculateDrawProperties(root_layer);
7521
enne637715732015-07-07 02:05:267522 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7523 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
ajuma1d4026a32016-06-14 13:18:507524 EXPECT_FLOAT_EQ(
7525 3.f,
7526 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267527 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587528
sunxdf468675e2016-06-30 23:56:187529 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7530 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7531 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587532
[email protected]18e69652014-06-13 12:50:587533 // Changing page-scale would affect ideal_contents_scale and
7534 // maximum_animation_contents_scale.
7535
7536 float page_scale_factor = 3.f;
7537 float device_scale_factor = 1.0f;
7538 std::vector<LayerImpl*> render_surface_layer_list;
7539 gfx::Size device_viewport_size =
7540 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7541 root_layer->bounds().height() * device_scale_factor);
7542 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387543 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:587544
7545 inputs.page_scale_factor = page_scale_factor;
7546 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117547 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:577548 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587549
enne637715732015-07-07 02:05:267550 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7551 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587552 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267553 9.f,
ajuma1d4026a32016-06-14 13:18:507554 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
7555 EXPECT_FLOAT_EQ(9.f, child1_layer->test_properties()
7556 ->replica_layer->test_properties()
7557 ->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267558 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587559
sunxdf468675e2016-06-30 23:56:187560 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7561 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7562 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
[email protected]18e69652014-06-13 12:50:587563
[email protected]18e69652014-06-13 12:50:587564 // Changing device-scale would affect ideal_contents_scale and
7565 // maximum_animation_contents_scale.
7566
7567 device_scale_factor = 4.0f;
7568 inputs.device_scale_factor = device_scale_factor;
7569 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097570 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:577571 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587572
enne637715732015-07-07 02:05:267573 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7574 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587575 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267576 36.f,
ajuma1d4026a32016-06-14 13:18:507577 child1_layer->test_properties()->mask_layer->GetIdealContentsScale());
7578 EXPECT_FLOAT_EQ(36.f, child1_layer->test_properties()
7579 ->replica_layer->test_properties()
7580 ->mask_layer->GetIdealContentsScale());
enne637715732015-07-07 02:05:267581 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587582
sunxdf468675e2016-06-30 23:56:187583 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7584 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7585 EXPECT_FLOAT_EQ(96.f, GetMaximumAnimationScale(child2_layer));
7586}
7587
7588TEST_F(LayerTreeHostCommonTest, AnimationScales) {
7589 FakeImplTaskRunnerProvider task_runner_provider;
7590 TestSharedBitmapManager shared_bitmap_manager;
7591 TestTaskGraphRunner task_graph_runner;
7592 LayerTreeSettings settings = host()->settings();
7593 settings.layer_transforms_should_scale_layer_contents = true;
7594 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7595 &shared_bitmap_manager, &task_graph_runner);
7596
7597 std::unique_ptr<LayerImpl> root =
7598 LayerImpl::Create(host_impl.active_tree(), 1);
7599 LayerImpl* root_layer = root.get();
7600 std::unique_ptr<LayerImpl> child1 =
7601 LayerImpl::Create(host_impl.active_tree(), 2);
7602 LayerImpl* child1_layer = child1.get();
7603 std::unique_ptr<LayerImpl> child2 =
7604 LayerImpl::Create(host_impl.active_tree(), 3);
7605 LayerImpl* child2_layer = child2.get();
7606
7607 root->test_properties()->AddChild(std::move(child1));
7608 child1_layer->test_properties()->AddChild(std::move(child2));
7609 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7610
7611 host_impl.active_tree()->SetElementIdsForTesting();
7612
danakjf78fb272016-07-26 19:06:157613 gfx::Transform scale_transform_child1, scale_transform_child2;
sunxdf468675e2016-06-30 23:56:187614 scale_transform_child1.Scale(2, 3);
7615 scale_transform_child2.Scale(4, 5);
7616
danakjf78fb272016-07-26 19:06:157617 root_layer->SetBounds(gfx::Size(1, 1));
7618 child1_layer->SetTransform(scale_transform_child1);
7619 child1_layer->SetBounds(gfx::Size(1, 1));
7620 child2_layer->SetTransform(scale_transform_child2);
7621 child2_layer->SetBounds(gfx::Size(1, 1));
sunxdf468675e2016-06-30 23:56:187622
7623 TransformOperations scale;
7624 scale.AppendScale(5.f, 8.f, 3.f);
7625
7626 scoped_refptr<AnimationTimeline> timeline =
7627 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7628 host_impl.animation_host()->AddAnimationTimeline(timeline);
7629
7630 AddAnimatedTransformToElementWithPlayer(child2_layer->element_id(), timeline,
7631 1.0, TransformOperations(), scale);
7632
sunxdf468675e2016-06-30 23:56:187633 // Correctly computes animation scale when rebuilding property trees.
7634 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
7635 ExecuteCalculateDrawProperties(root_layer);
7636
7637 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7638 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child1_layer));
7639 EXPECT_FLOAT_EQ(24.f, GetMaximumAnimationScale(child2_layer));
7640
7641 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
7642 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child1_layer));
7643 EXPECT_FLOAT_EQ(3.f, GetStartingAnimationScale(child2_layer));
7644
7645 // Correctly updates animation scale when layer property changes.
danakjf78fb272016-07-26 19:06:157646 child1_layer->SetTransform(gfx::Transform());
sunxdf468675e2016-06-30 23:56:187647 child1_layer->UpdatePropertyTreeTransform();
7648 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = false;
7649 ExecuteCalculateDrawProperties(root_layer);
7650 EXPECT_FLOAT_EQ(8.f, GetMaximumAnimationScale(child2_layer));
7651 EXPECT_FLOAT_EQ(1.f, GetStartingAnimationScale(child2_layer));
7652
7653 // Do not update animation scale if already updated.
7654 host_impl.active_tree()->property_trees()->SetAnimationScalesForTesting(
7655 child2_layer->transform_tree_index(), 100.f, 100.f);
7656 EXPECT_FLOAT_EQ(100.f, GetMaximumAnimationScale(child2_layer));
7657 EXPECT_FLOAT_EQ(100.f, GetStartingAnimationScale(child2_layer));
7658}
7659
7660TEST_F(LayerTreeHostCommonTest,
7661 AnimationScaleWhenLayerTransformShouldNotScaleLayerBounds) {
7662 // Returns empty scale if layer_transforms_should_scale_layer_contents is
7663 // false.
7664 FakeImplTaskRunnerProvider task_runner_provider;
7665 TestSharedBitmapManager shared_bitmap_manager;
7666 TestTaskGraphRunner task_graph_runner;
7667 LayerTreeSettings settings = host()->settings();
7668 settings.layer_transforms_should_scale_layer_contents = false;
7669 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7670 &shared_bitmap_manager, &task_graph_runner);
7671
7672 std::unique_ptr<LayerImpl> root =
7673 LayerImpl::Create(host_impl.active_tree(), 1);
7674 LayerImpl* root_layer = root.get();
7675 std::unique_ptr<LayerImpl> child =
7676 LayerImpl::Create(host_impl.active_tree(), 2);
7677 LayerImpl* child_layer = child.get();
7678
7679 root->test_properties()->AddChild(std::move(child));
7680 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
7681
7682 host_impl.active_tree()->SetElementIdsForTesting();
7683
danakjf78fb272016-07-26 19:06:157684 gfx::Transform scale_transform_child;
sunxdf468675e2016-06-30 23:56:187685 scale_transform_child.Scale(4, 5);
7686
danakjf78fb272016-07-26 19:06:157687 root_layer->SetBounds(gfx::Size(1, 1));
7688 child_layer->SetTransform(scale_transform_child);
7689 child_layer->SetBounds(gfx::Size(1, 1));
7690
sunxdf468675e2016-06-30 23:56:187691 TransformOperations scale;
7692 scale.AppendScale(5.f, 8.f, 3.f);
7693
7694 scoped_refptr<AnimationTimeline> timeline =
7695 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7696 host_impl.animation_host()->AddAnimationTimeline(timeline);
7697
7698 AddAnimatedTransformToElementWithPlayer(child_layer->element_id(), timeline,
7699 1.0, TransformOperations(), scale);
7700
sunxdf468675e2016-06-30 23:56:187701 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
7702 ExecuteCalculateDrawProperties(root_layer);
7703
7704 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(root_layer));
7705 EXPECT_FLOAT_EQ(0.f, GetMaximumAnimationScale(child_layer));
7706
7707 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(root_layer));
7708 EXPECT_FLOAT_EQ(0.f, GetStartingAnimationScale(child_layer));
[email protected]18e69652014-06-13 12:50:587709}
7710
danakjf6069db2014-09-13 00:46:477711TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:597712 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:147713 LayerImpl* clip = AddChild<LayerImpl>(root);
7714 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:477715
danakjf78fb272016-07-26 19:06:157716 root->SetBounds(gfx::Size(768 / 2, 3000));
jaydasika6f972de2016-04-07 16:16:147717 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:157718 clip->SetBounds(gfx::Size(768 / 2, 10000));
danakjf6069db2014-09-13 00:46:477719 clip->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:157720 content->SetBounds(gfx::Size(768 / 2, 10000));
jaydasika6f972de2016-04-07 16:16:147721 content->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:157722 content->test_properties()->force_render_surface = true;
danakjf6069db2014-09-13 00:46:477723
7724 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:147725 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:147726 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
danakjf78fb272016-07-26 19:06:157727 root, device_viewport_size, gfx::Transform(),
ajuma0adb5902016-04-28 16:32:387728 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:477729 inputs.device_scale_factor = 2.f;
7730 inputs.page_scale_factor = 1.f;
danakj59931942016-07-26 22:11:297731 inputs.page_scale_layer = nullptr;
sunxdb365de02016-04-28 20:32:577732 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:477733
7734 // Layers in the root render surface have their visible content rect clipped
7735 // by the viewport.
jaydasika6f972de2016-04-07 16:16:147736 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:477737
7738 // Layers drawing to a child render surface should still have their visible
7739 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:147740 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:477741}
7742
timav599f4359d2014-12-05 00:12:227743TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:167744 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:227745 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567746 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167747 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567748 &task_graph_runner);
timav599f4359d2014-12-05 00:12:227749
7750 // Set two layers: the root layer clips it's child,
7751 // the child draws its content.
7752
7753 gfx::Size root_size = gfx::Size(300, 500);
7754
7755 // Sublayer should be bigger than the root enlarged by bounds_delta.
7756 gfx::Size sublayer_size = gfx::Size(300, 1000);
7757
7758 // Device viewport accomidated the root and the top controls.
7759 gfx::Size device_viewport_size = gfx::Size(300, 600);
timav599f4359d2014-12-05 00:12:227760
miletus8bd08a622015-06-16 18:44:527761 host_impl.SetViewportSize(device_viewport_size);
jaydasikabf1875a2016-06-28 03:39:597762 host_impl.active_tree()->SetRootLayerForTesting(
timav599f4359d2014-12-05 00:12:227763 LayerImpl::Create(host_impl.active_tree(), 1));
7764
jaydasikabf1875a2016-06-28 03:39:597765 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing();
danakjf78fb272016-07-26 19:06:157766 root->SetBounds(root_size);
timav599f4359d2014-12-05 00:12:227767 root->SetMasksToBounds(true);
7768
jaydasika89f7b5a2016-06-22 02:08:397769 root->test_properties()->AddChild(
7770 LayerImpl::Create(host_impl.active_tree(), 2));
timav599f4359d2014-12-05 00:12:227771
jaydasikafc66cfb2016-06-10 04:34:227772 LayerImpl* sublayer = root->test_properties()->children[0];
danakjf78fb272016-07-26 19:06:157773 sublayer->SetBounds(sublayer_size);
timav599f4359d2014-12-05 00:12:227774 sublayer->SetDrawsContent(true);
7775
danakj74af409e2016-07-01 00:41:487776 host_impl.active_tree()->BuildPropertyTreesForTesting();
7777
timav599f4359d2014-12-05 00:12:227778 LayerImplList layer_impl_list;
7779 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387780 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:227781
sunxdb365de02016-04-28 20:32:577782 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:437783 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:227784
7785 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:577786 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:227787
7788 gfx::Rect affected_by_delta(0, 0, root_size.width(),
7789 root_size.height() + 50);
danakj64767d902015-06-19 00:10:437790 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:227791}
7792
ajumadd2802e72015-06-30 20:28:297793TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:317794 scoped_refptr<Layer> root = Layer::Create();
7795 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
7796 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
7797 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
7798 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:297799
7800 root->AddChild(inner_viewport_container_layer);
7801 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
7802 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
7803 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
7804
7805 inner_viewport_scroll_layer->SetScrollClipLayerId(
7806 inner_viewport_container_layer->id());
7807 outer_viewport_scroll_layer->SetScrollClipLayerId(
7808 outer_viewport_container_layer->id());
7809
7810 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7811 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7812
7813 host()->SetRootLayer(root);
7814 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
7815 outer_viewport_scroll_layer);
7816
loyso0940d412016-03-14 01:30:317817 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
7818 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:297819
7820 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
7821 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
7822
7823 LayerPositionConstraint fixed_to_right;
7824 fixed_to_right.set_is_fixed_position(true);
7825 fixed_to_right.set_is_fixed_to_right_edge(true);
7826
7827 fixed_to_inner->SetPositionConstraint(fixed_to_right);
7828 fixed_to_outer->SetPositionConstraint(fixed_to_right);
7829
7830 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7831
7832 TransformTree& transform_tree = host()->property_trees()->transform_tree;
7833 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7834 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7835
7836 LayerPositionConstraint fixed_to_left;
7837 fixed_to_left.set_is_fixed_position(true);
7838 fixed_to_inner->SetPositionConstraint(fixed_to_left);
7839
7840 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7841 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7842 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7843
7844 fixed_to_outer->SetPositionConstraint(fixed_to_left);
7845
7846 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7847 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7848 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7849}
7850
vollick7d83b452015-02-24 20:18:067851TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
loyso0940d412016-03-14 01:30:317852 scoped_refptr<Layer> root = Layer::Create();
vollick7d83b452015-02-24 20:18:067853 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:317854 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick7d83b452015-02-24 20:18:067855
7856 root->AddChild(animated);
ennea7b43c32015-06-18 20:01:337857 host()->SetRootLayer(root);
vollickef2ae922016-06-29 17:54:277858 host()->SetElementIdsForTesting();
7859
danakjf78fb272016-07-26 19:06:157860 root->SetBounds(gfx::Size(100, 100));
vollick7d83b452015-02-24 20:18:067861 root->SetMasksToBounds(true);
jaydasika6b5a32bf2016-04-22 21:56:367862 root->SetForceRenderSurfaceForTesting(true);
vollick7d83b452015-02-24 20:18:067863 animated->SetOpacity(0.f);
danakjf78fb272016-07-26 19:06:157864 animated->SetBounds(gfx::Size(20, 20));
vollick7d83b452015-02-24 20:18:067865
vollickef2ae922016-06-29 17:54:277866 AddOpacityTransitionToElementWithPlayer(animated->element_id(), timeline(),
7867 10.0, 0.f, 1.f, false);
enne601f2ef12015-05-19 18:20:177868 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:067869
jaydasika74bf516f2016-04-01 19:48:157870 EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty());
vollick7d83b452015-02-24 20:18:067871}
7872
ajumaa92fdc12015-03-31 22:47:417873TEST_F(LayerTreeHostCommonTest,
7874 VisibleContentRectForAnimatedLayerWithSingularTransform) {
loyso0940d412016-03-14 01:30:317875 scoped_refptr<Layer> root = Layer::Create();
7876 scoped_refptr<Layer> clip = Layer::Create();
ajumaa92fdc12015-03-31 22:47:417877 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:317878 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:417879 scoped_refptr<LayerWithForcedDrawsContent> surface =
loyso0940d412016-03-14 01:30:317880 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:417881 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loyso0940d412016-03-14 01:30:317882 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:417883
7884 root->AddChild(clip);
7885 clip->AddChild(animated);
7886 animated->AddChild(surface);
7887 surface->AddChild(descendant_of_animation);
7888
ennea7b43c32015-06-18 20:01:337889 host()->SetRootLayer(root);
vollickef2ae922016-06-29 17:54:277890 host()->SetElementIdsForTesting();
7891
ajumaa92fdc12015-03-31 22:47:417892 gfx::Transform uninvertible_matrix;
7893 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
7894
danakjf78fb272016-07-26 19:06:157895 root->SetBounds(gfx::Size(100, 100));
7896 clip->SetBounds(gfx::Size(10, 10));
7897 clip->SetMasksToBounds(true);
7898 animated->SetTransform(uninvertible_matrix);
7899 animated->SetBounds(gfx::Size(120, 120));
7900 surface->SetBounds(gfx::Size(100, 100));
7901 surface->SetForceRenderSurfaceForTesting(true);
7902 descendant_of_animation->SetBounds(gfx::Size(200, 200));
ajumaa92fdc12015-03-31 22:47:417903
7904 TransformOperations start_transform_operations;
7905 start_transform_operations.AppendMatrix(uninvertible_matrix);
7906 TransformOperations end_transform_operations;
7907
vollickef2ae922016-06-29 17:54:277908 SetElementIdsForTesting();
7909 AddAnimatedTransformToElementWithPlayer(animated->element_id(), timeline(),
7910 10.0, start_transform_operations,
7911 end_transform_operations);
enne601f2ef12015-05-19 18:20:177912 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:417913
7914 // The animated layer has a singular transform and maps to a non-empty rect in
7915 // clipped target space, so is treated as fully visible.
jaydasika74bf516f2016-04-01 19:48:157916 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:417917
7918 // The singular transform on |animated| is flattened when inherited by
7919 // |surface|, and this happens to make it invertible.
jaydasika74bf516f2016-04-01 19:48:157920 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing());
7921 EXPECT_EQ(gfx::Rect(2, 2),
7922 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:417923
7924 gfx::Transform zero_matrix;
7925 zero_matrix.Scale3d(0.f, 0.f, 0.f);
danakjf78fb272016-07-26 19:06:157926 animated->SetTransform(zero_matrix);
enne601f2ef12015-05-19 18:20:177927 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:417928
7929 // The animated layer maps to the empty rect in clipped target space, so is
7930 // treated as having an empty visible rect.
jaydasika74bf516f2016-04-01 19:48:157931 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:417932
7933 // This time, flattening does not make |animated|'s transform invertible. This
7934 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:347935 // |surface| and layers that draw into it as having empty visible rect.
jaydasika74bf516f2016-04-01 19:48:157936 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing());
7937 EXPECT_EQ(gfx::Rect(),
7938 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:417939}
7940
ajuma20384bf2016-07-22 13:26:157941// Verify that having animated opacity but current opacity 1 still creates
7942// a render surface.
7943TEST_F(LayerTreeHostCommonTest, AnimatedOpacityCreatesRenderSurface) {
7944 LayerImpl* root = root_layer_for_testing();
7945 LayerImpl* child = AddChild<LayerImpl>(root);
7946 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma20384bf2016-07-22 13:26:157947
danakjf78fb272016-07-26 19:06:157948 root->SetBounds(gfx::Size(50, 50));
7949 child->SetBounds(gfx::Size(50, 50));
7950 child->SetDrawsContent(true);
7951 grandchild->SetBounds(gfx::Size(50, 50));
7952 grandchild->SetDrawsContent(true);
ajuma20384bf2016-07-22 13:26:157953
7954 SetElementIdsForTesting();
7955 AddOpacityTransitionToElementWithPlayer(child->element_id(), timeline_impl(),
7956 10.0, 1.f, 0.2f, false);
7957 ExecuteCalculateDrawProperties(root);
7958
7959 EXPECT_EQ(1.f, child->Opacity());
7960 EXPECT_TRUE(root->has_render_surface());
7961 EXPECT_TRUE(child->has_render_surface());
7962 EXPECT_FALSE(grandchild->has_render_surface());
7963}
7964
enne92f2f6d92015-02-25 23:13:317965// Verify that having an animated filter (but no current filter, as these
7966// are mutually exclusive) correctly creates a render surface.
7967TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:597968 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:327969 LayerImpl* child = AddChild<LayerImpl>(root);
7970 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:317971
danakjf78fb272016-07-26 19:06:157972 root->SetBounds(gfx::Size(50, 50));
7973 child->SetBounds(gfx::Size(50, 50));
7974 grandchild->SetBounds(gfx::Size(50, 50));
enne92f2f6d92015-02-25 23:13:317975
vollickef2ae922016-06-29 17:54:277976 SetElementIdsForTesting();
7977 AddAnimatedFilterToElementWithPlayer(child->element_id(), timeline_impl(),
7978 10.0, 0.1f, 0.2f);
ajuma4711f4b12016-05-16 18:48:327979 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:317980
ennec1332992015-08-24 19:45:097981 EXPECT_TRUE(root->has_render_surface());
7982 EXPECT_TRUE(child->has_render_surface());
7983 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:317984
ajumacb2b74432016-07-21 19:11:157985 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
7986 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
enne92f2f6d92015-02-25 23:13:317987
7988 EXPECT_FALSE(root->FilterIsAnimating());
7989 EXPECT_TRUE(child->FilterIsAnimating());
7990 EXPECT_FALSE(grandchild->FilterIsAnimating());
7991}
7992
ajuma315a4782015-07-24 21:16:347993// Verify that having a filter animation with a delayed start time creates a
7994// render surface.
7995TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
jaydasikabf1875a2016-06-28 03:39:597996 LayerImpl* root = root_layer_for_testing();
ajuma4711f4b12016-05-16 18:48:327997 LayerImpl* child = AddChild<LayerImpl>(root);
7998 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:347999
danakjf78fb272016-07-26 19:06:158000 root->SetBounds(gfx::Size(50, 50));
8001 child->SetBounds(gfx::Size(50, 50));
8002 grandchild->SetBounds(gfx::Size(50, 50));
ajuma315a4782015-07-24 21:16:348003
vollickef2ae922016-06-29 17:54:278004 SetElementIdsForTesting();
8005
danakj60bc3bc2016-04-09 00:24:488006 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348007 KeyframedFilterAnimationCurve::Create());
8008 FilterOperations start_filters;
8009 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8010 FilterOperations end_filters;
8011 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8012 curve->AddKeyframe(
8013 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8014 curve->AddKeyframe(FilterKeyframe::Create(
8015 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488016 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308017 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558018 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348019 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348020
vollickef2ae922016-06-29 17:54:278021 AddAnimationToElementWithPlayer(child->element_id(), timeline_impl(),
8022 std::move(animation));
ajuma4711f4b12016-05-16 18:48:328023 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348024
ennec1332992015-08-24 19:45:098025 EXPECT_TRUE(root->has_render_surface());
8026 EXPECT_TRUE(child->has_render_surface());
8027 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348028
ajumacb2b74432016-07-21 19:11:158029 EXPECT_TRUE(root->render_surface()->Filters().IsEmpty());
8030 EXPECT_TRUE(child->render_surface()->Filters().IsEmpty());
ajuma315a4782015-07-24 21:16:348031
8032 EXPECT_FALSE(root->FilterIsAnimating());
8033 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8034 EXPECT_FALSE(child->FilterIsAnimating());
8035 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8036 EXPECT_FALSE(grandchild->FilterIsAnimating());
8037 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8038}
8039
vollick0120eb22015-03-02 03:07:348040// Ensures that the property tree code accounts for offsets between fixed
8041// position layers and their respective containers.
8042TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasikabf1875a2016-06-28 03:39:598043 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148044 LayerImpl* child = AddChild<LayerImpl>(root);
8045 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348046
danakjf78fb272016-07-26 19:06:158047 root->SetBounds(gfx::Size(50, 50));
vollick0120eb22015-03-02 03:07:348048 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528049 root->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158050 child->SetPosition(gfx::PointF(1000, 1000));
8051 child->SetBounds(gfx::Size(50, 50));
8052 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8053 grandchild->SetBounds(gfx::Size(50, 50));
8054 grandchild->SetDrawsContent(true);
8055
vollick0120eb22015-03-02 03:07:348056 LayerPositionConstraint constraint;
8057 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528058 grandchild->test_properties()->position_constraint = constraint;
vollick0120eb22015-03-02 03:07:348059
jaydasika6f972de2016-04-07 16:16:148060 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348061
jaydasika6f972de2016-04-07 16:16:148062 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348063}
8064
ajuma0178b522015-07-02 21:08:418065// Ensures that the property tree code accounts for offsets between fixed
8066// position containers and their transform tree parents, when a fixed position
8067// layer's container is its layer tree parent, but this parent doesn't have its
8068// own transform tree node.
8069TEST_F(LayerTreeHostCommonTest,
8070 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasikabf1875a2016-06-28 03:39:598071 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148072 LayerImpl* child = AddChild<LayerImpl>(root);
8073 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418074
danakjf78fb272016-07-26 19:06:158075 root->SetBounds(gfx::Size(50, 50));
ajuma0178b522015-07-02 21:08:418076 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158077 root->test_properties()->is_container_for_fixed_position_layers = true;
8078 child->SetPosition(gfx::PointF(1000, 1000));
8079 child->SetBounds(gfx::Size(50, 50));
jaydasikaca2605e2016-04-23 02:52:528080 child->test_properties()->is_container_for_fixed_position_layers = true;
danakjf78fb272016-07-26 19:06:158081 grandchild->SetPosition(gfx::PointF(-1000, -1000));
8082 grandchild->SetBounds(gfx::Size(50, 50));
8083 grandchild->SetDrawsContent(true);
8084
ajuma0178b522015-07-02 21:08:418085 LayerPositionConstraint constraint;
8086 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528087 grandchild->test_properties()->position_constraint = constraint;
ajuma0178b522015-07-02 21:08:418088
jaydasika6f972de2016-04-07 16:16:148089 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418090
jaydasika6f972de2016-04-07 16:16:148091 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418092}
8093
vollick8c824742015-03-20 22:21:088094TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasikabf1875a2016-06-28 03:39:598095 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148096 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8097 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088098 gfx::Transform translate_z;
8099 translate_z.Translate3d(0, 0, 10);
8100
danakjf78fb272016-07-26 19:06:158101 root->SetBounds(gfx::Size(800, 800));
jaydasikaca2605e2016-04-23 02:52:528102 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088103
danakjf78fb272016-07-26 19:06:158104 frame_clip->SetPosition(gfx::PointF(500, 100));
8105 frame_clip->SetBounds(gfx::Size(100, 100));
vollick8c824742015-03-20 22:21:088106 frame_clip->SetMasksToBounds(true);
8107
danakjf78fb272016-07-26 19:06:158108 fixed->SetBounds(gfx::Size(1000, 1000));
8109 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088110
8111 LayerPositionConstraint constraint;
8112 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528113 fixed->test_properties()->position_constraint = constraint;
vollick8c824742015-03-20 22:21:088114
jaydasika6f972de2016-04-07 16:16:148115 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088116
8117 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148118 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088119}
8120
vollick06ca3e832015-03-31 19:37:128121TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasikabf1875a2016-06-28 03:39:598122 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148123 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8124 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8125 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8126
danakjf78fb272016-07-26 19:06:158127 root->SetBounds(gfx::Size(800, 800));
jaydasika6f972de2016-04-07 16:16:148128 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158129 root->test_properties()->is_container_for_fixed_position_layers = true;
8130 frame_clip->SetPosition(gfx::PointF(500, 100));
8131 frame_clip->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148132 frame_clip->SetMasksToBounds(true);
8133 frame_clip->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158134 scroller->SetBounds(gfx::Size(1000, 1000));
jaydasika6f972de2016-04-07 16:16:148135 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8136 scroller->SetScrollClipLayer(frame_clip->id());
8137 scroller->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158138 fixed->SetPosition(gfx::PointF(100, 100));
8139 fixed->SetBounds(gfx::Size(50, 50));
8140 fixed->SetMasksToBounds(true);
8141 fixed->SetDrawsContent(true);
8142 fixed->test_properties()->force_render_surface = true;
vollick06ca3e832015-03-31 19:37:128143
8144 LayerPositionConstraint constraint;
8145 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528146 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128147
jaydasika6f972de2016-04-07 16:16:148148 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128149
8150 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148151 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128152}
8153
vollick5057e1e2015-04-17 19:12:328154TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
vollick5057e1e2015-04-17 19:12:328155 gfx::Transform translate;
8156 gfx::Transform rotate;
8157
8158 translate.Translate(10, 10);
8159 rotate.Rotate(45);
8160
loyso0940d412016-03-14 01:30:318161 scoped_refptr<Layer> root = Layer::Create();
danakjf78fb272016-07-26 19:06:158162 root->SetBounds(gfx::Size(800, 800));
vollick5057e1e2015-04-17 19:12:328163 root->SetIsContainerForFixedPositionLayers(true);
8164
ennea7b43c32015-06-18 20:01:338165 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328166
enne601f2ef12015-05-19 18:20:178167 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338168 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328169
8170 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338171 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328172
8173 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338174 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328175}
8176
ajumab0e0c1c2015-04-23 00:29:238177TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasikabf1875a2016-06-28 03:39:598178 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148179 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238180
ajumab0e0c1c2015-04-23 00:29:238181 gfx::Transform scale_matrix;
8182 scale_matrix.Scale(2.f, 2.f);
ajumab0e0c1c2015-04-23 00:29:238183
danakjf78fb272016-07-26 19:06:158184 root->SetBounds(gfx::Size(100, 100));
jaydasika6f972de2016-04-07 16:16:148185 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158186 child->SetTransform(scale_matrix);
8187 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148188 child->SetDrawsContent(true);
8189
8190 ExecuteCalculateDrawProperties(root);
8191 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238192
jaydasika38be7a822016-04-21 16:07:068193 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238194
jaydasika6f972de2016-04-07 16:16:148195 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8196 ExecuteCalculateDrawProperties(root);
8197 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238198}
8199
ajumaf09db8962015-04-24 21:55:348200TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasikabf1875a2016-06-28 03:39:598201 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148202 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8203 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348204
ajumaf09db8962015-04-24 21:55:348205 gfx::Transform scale;
8206 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:158207
8208 root->SetBounds(gfx::Size(50, 50));
8209 scroll_child->SetTransform(scale);
8210 scroll_child->SetBounds(gfx::Size(40, 40));
8211 scroll_child->SetDrawsContent(true);
8212 scroll_parent->SetBounds(gfx::Size(30, 30));
8213 scroll_parent->SetDrawsContent(true);
8214
8215 scroll_child->test_properties()->scroll_parent = scroll_parent;
8216 scroll_parent->test_properties()->scroll_children =
8217 base::MakeUnique<std::set<LayerImpl*>>();
8218 scroll_parent->test_properties()->scroll_children->insert(scroll_child);
ajumaf09db8962015-04-24 21:55:348219
jaydasika6f972de2016-04-07 16:16:148220 ExecuteCalculateDrawProperties(root);
8221 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348222
8223 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148224 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8225 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8226 ExecuteCalculateDrawProperties(root);
8227 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348228}
8229
danakj60bc3bc2016-04-09 00:24:488230static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128231
sunxded58688e2016-01-11 21:01:028232TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8233 // If the layer has a node in effect_tree, the return value of
8234 // num_copy_requests_in_target_subtree() must be equal to the actual number
8235 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8236 // to be the value of its nearest ancestor that owns an effect node and
8237 // greater than or equal to the actual number of copy requests in the
8238 // sub-layer_tree.
8239
loyso0940d412016-03-14 01:30:318240 scoped_refptr<Layer> root = Layer::Create();
8241 scoped_refptr<Layer> child1 = Layer::Create();
8242 scoped_refptr<Layer> child2 = Layer::Create();
8243 scoped_refptr<Layer> grandchild = Layer::Create();
8244 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028245
8246 root->AddChild(child1);
8247 root->AddChild(child2);
8248 child1->AddChild(grandchild);
8249 grandchild->AddChild(greatgrandchild);
8250 host()->SetRootLayer(root);
8251
8252 child1->RequestCopyOfOutput(
8253 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8254 greatgrandchild->RequestCopyOfOutput(
8255 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8256 child2->SetOpacity(0.f);
8257 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8258
8259 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8260 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8261 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8262 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8263 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8264}
8265
vollick2175fae82015-04-27 21:18:128266TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
loyso0940d412016-03-14 01:30:318267 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328268 FakeContentLayerClient client;
8269 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128270 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318271 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128272 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318273 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258274 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318275 FakePictureLayer::Create(&client));
danakjf78fb272016-07-26 19:06:158276
8277 root->SetBounds(gfx::Size(100, 100));
8278 child->SetBounds(gfx::Size(10, 10));
8279 grandchild->SetBounds(gfx::Size(10, 10));
8280 greatgrandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128281
8282 root->AddChild(child);
8283 child->AddChild(grandchild);
8284 grandchild->AddChild(greatgrandchild);
ennea7b43c32015-06-18 20:01:338285 host()->SetRootLayer(root);
vollickef2ae922016-06-29 17:54:278286 host()->SetElementIdsForTesting();
8287
vollick2175fae82015-04-27 21:18:128288 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178289 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158290 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128291
8292 // Now we will reset the visible rect from property trees for the grandchild,
8293 // and we will configure |child| in several ways that should force the subtree
8294 // to be skipped. The visible content rect for |grandchild| should, therefore,
8295 // remain empty.
weiliangcc97575c2016-03-03 18:34:278296 grandchild->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:128297 gfx::Transform singular;
8298 singular.matrix().set(0, 0, 0);
8299
8300 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178301 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158302 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
danakjf78fb272016-07-26 19:06:158303 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128304
8305 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178306 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158307 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128308 child->SetHideLayerAndSubtree(false);
8309
ajuma315a4782015-07-24 21:16:348310 gfx::Transform zero_z_scale;
8311 zero_z_scale.Scale3d(1, 1, 0);
8312 child->SetTransform(zero_z_scale);
8313
8314 // Add a transform animation with a start delay. Now, even though |child| has
8315 // a singular transform, the subtree should still get processed.
8316 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488317 std::unique_ptr<Animation> animation = Animation::Create(
8318 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308319 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558320 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348321 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278322 AddAnimationToElementWithPlayer(child->element_id(), timeline(),
8323 std::move(animation));
ajuma315a4782015-07-24 21:16:348324 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158325 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278326 grandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348327
vollickef2ae922016-06-29 17:54:278328 RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
8329 animation_id);
danakjf78fb272016-07-26 19:06:158330 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128331 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178332 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158333 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128334
8335 // Now, even though child has zero opacity, we will configure |grandchild| and
8336 // |greatgrandchild| in several ways that should force the subtree to be
8337 // processed anyhow.
jaydasika86654512016-01-27 17:05:078338 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128339 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:178340 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158341 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278342 greatgrandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348343
8344 // Add an opacity animation with a start delay.
8345 animation_id = 1;
8346 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488347 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308348 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558349 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348350 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
vollickef2ae922016-06-29 17:54:278351 AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
8352 std::move(animation));
ajuma315a4782015-07-24 21:16:348353 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158354 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128355}
8356
sunxd71aea3e2016-04-01 23:48:058357TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168358 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128359 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568360 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168361 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568362 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128363
danakj60bc3bc2016-04-09 00:24:488364 std::unique_ptr<LayerImpl> root =
8365 LayerImpl::Create(host_impl.active_tree(), 1);
8366 std::unique_ptr<LayerImpl> child =
8367 LayerImpl::Create(host_impl.active_tree(), 2);
8368 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:128369 LayerImpl::Create(host_impl.active_tree(), 3);
8370
danakj60bc3bc2016-04-09 00:24:488371 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:258372 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128373
danakjf78fb272016-07-26 19:06:158374 root->SetBounds(gfx::Size(100, 100));
8375 child->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128376 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158377 grandchild->SetBounds(gfx::Size(10, 10));
vollick2175fae82015-04-27 21:18:128378 grandchild->SetDrawsContent(true);
8379 greatgrandchild->SetDrawsContent(true);
8380
jaydasika2411692c2016-03-23 01:56:098381 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128382 LayerImpl* child_ptr = child.get();
8383 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128384
jaydasika89f7b5a2016-06-22 02:08:398385 child->test_properties()->AddChild(std::move(grandchild));
8386 root->test_properties()->AddChild(std::move(child));
jaydasikabf1875a2016-06-28 03:39:598387 host_impl.active_tree()->SetRootLayerForTesting(std::move(root));
vollick2175fae82015-04-27 21:18:128388
vollickef2ae922016-06-29 17:54:278389 host_impl.active_tree()->SetElementIdsForTesting();
8390
vollick2175fae82015-04-27 21:18:128391 // Check the non-skipped case.
sunxd71aea3e2016-04-01 23:48:058392 // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8393 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128394
8395 // Now we will reset the visible rect from property trees for the grandchild,
8396 // and we will configure |child| in several ways that should force the subtree
8397 // to be skipped. The visible content rect for |grandchild| should, therefore,
8398 // remain empty.
weiliangcc97575c2016-03-03 18:34:278399 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058400
vollick2175fae82015-04-27 21:18:128401 gfx::Transform singular;
8402 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058403 // This line is used to make the results of skipping and not skipping layers
8404 // different.
8405 singular.matrix().set(0, 1, 1);
8406
8407 gfx::Transform rotate;
8408 rotate.Rotate(90);
8409
8410 gfx::Transform rotate_back_and_translate;
8411 rotate_back_and_translate.RotateAboutYAxis(180);
8412 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128413
8414 child_ptr->SetTransform(singular);
sunxd71aea3e2016-04-01 23:48:058415 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098416 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278417 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
danakjf78fb272016-07-26 19:06:158418 child_ptr->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128419
jaydasika5121caa82016-05-05 15:43:358420 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika2411692c2016-03-23 01:56:098421 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278422 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358423 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128424
jaydasikaab317e02016-06-01 00:53:188425 child_ptr->OnOpacityAnimated(0.f);
jaydasika2411692c2016-03-23 01:56:098426 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278427 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188428 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:128429
sunxd71aea3e2016-04-01 23:48:058430 root_ptr->SetTransform(singular);
8431 // Force transform tree to have a node for child, so that ancestor's
8432 // invertible transform can be tested.
8433 child_ptr->SetTransform(rotate);
8434 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8435 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8436 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
danakjf78fb272016-07-26 19:06:158437 root_ptr->SetTransform(gfx::Transform());
8438 child_ptr->SetTransform(gfx::Transform());
sunxd71aea3e2016-04-01 23:48:058439
jaydasikaab317e02016-06-01 00:53:188440 root_ptr->test_properties()->opacity = 0.f;
8441 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:058442 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8443 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8444 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188445 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058446
jaydasikaab317e02016-06-01 00:53:188447 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:128448 // Now, even though child has zero opacity, we will configure |grandchild| and
8449 // |greatgrandchild| in several ways that should force the subtree to be
8450 // processed anyhow.
ajumae6f541b2016-05-31 16:50:508451 grandchild_ptr->test_properties()->copy_requests.push_back(
8452 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:098453 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8454 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278455 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:508456
8457 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:188458 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058459
8460 // A double sided render surface with backface visible should not be skipped
8461 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8462 child_ptr->SetHasRenderSurface(true);
jaydasika6b5a32bf2016-04-22 21:56:368463 child_ptr->test_properties()->double_sided = true;
sunxd71aea3e2016-04-01 23:48:058464 child_ptr->SetTransform(rotate_back_and_translate);
8465 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8466 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8467 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
danakjf78fb272016-07-26 19:06:158468 child_ptr->SetTransform(gfx::Transform());
sunxd71aea3e2016-04-01 23:48:058469
danakj60bc3bc2016-04-09 00:24:488470 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058471 KeyframedTransformAnimationCurve::Create());
8472 TransformOperations start;
8473 start.AppendTranslate(1.f, 2.f, 3.f);
8474 gfx::Transform transform;
8475 transform.Scale3d(1.0, 2.0, 3.0);
8476 TransformOperations operation;
8477 operation.AppendMatrix(transform);
8478 curve->AddKeyframe(
8479 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8480 curve->AddKeyframe(TransformKeyframe::Create(
8481 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:488482 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:058483 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8484 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588485 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278486 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:058487 host_impl.active_tree()
8488 ->animation_host()
vollickef2ae922016-06-29 17:54:278489 ->GetElementAnimationsForElementId(root_ptr->element_id())
sunxd71aea3e2016-04-01 23:48:058490 ->AddAnimation(std::move(transform_animation));
8491 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8492 child_ptr->SetScrollClipLayer(root_ptr->id());
8493 root_ptr->SetTransform(singular);
8494 child_ptr->SetTransform(singular);
8495 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8496 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:278497 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058498
loysofb69174e2016-04-27 00:58:588499 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278500 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:058501}
8502
jaydasikaf187b06b2016-04-11 23:30:278503TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
jaydasikabf1875a2016-06-28 03:39:598504 LayerImpl* root = root_layer_for_testing();
jaydasikaf187b06b2016-04-11 23:30:278505 LayerImpl* child = AddChild<LayerImpl>(root);
8506 LayerImpl* grand_child = AddChild<LayerImpl>(child);
8507
vollickef2ae922016-06-29 17:54:278508 SetElementIdsForTesting();
jaydasikaf187b06b2016-04-11 23:30:278509
8510 gfx::Transform singular;
8511 singular.matrix().set(0, 0, 0);
8512 singular.matrix().set(0, 1, 1);
8513
danakjf78fb272016-07-26 19:06:158514 root->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278515 child->SetTransform(singular);
danakjf78fb272016-07-26 19:06:158516 child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278517 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158518 grand_child->SetBounds(gfx::Size(10, 10));
jaydasikaf187b06b2016-04-11 23:30:278519 grand_child->SetDrawsContent(true);
8520
danakj25c52c32016-04-12 21:51:088521 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:278522 KeyframedTransformAnimationCurve::Create());
8523 TransformOperations start;
8524 start.AppendTranslate(1.f, 2.f, 3.f);
8525 gfx::Transform transform;
8526 transform.Scale3d(1.0, 2.0, 3.0);
8527 TransformOperations operation;
8528 operation.AppendMatrix(transform);
8529 curve->AddKeyframe(
8530 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8531 curve->AddKeyframe(TransformKeyframe::Create(
8532 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:088533 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:278534 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8535 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588536 host_impl()->active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278537 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:278538 host_impl()
8539 ->active_tree()
8540 ->animation_host()
vollickef2ae922016-06-29 17:54:278541 ->GetElementAnimationsForElementId(grand_child->element_id())
jaydasikaf187b06b2016-04-11 23:30:278542 ->AddAnimation(std::move(transform_animation));
8543
8544 ExecuteCalculateDrawProperties(root);
8545 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
8546 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
8547
loysofb69174e2016-04-27 00:58:588548 host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278549 grand_child->element_id(), player.get());
jaydasikaf187b06b2016-04-11 23:30:278550}
8551
sunxd71aea3e2016-04-01 23:48:058552TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8553 FakeImplTaskRunnerProvider task_runner_provider;
8554 TestSharedBitmapManager shared_bitmap_manager;
8555 TestTaskGraphRunner task_graph_runner;
8556 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
8557 &task_graph_runner);
8558
sunxd71aea3e2016-04-01 23:48:058559 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:488560 std::unique_ptr<LayerImpl> root =
8561 LayerImpl::Create(host_impl.pending_tree(), 1);
8562 std::unique_ptr<LayerImpl> child =
8563 LayerImpl::Create(host_impl.pending_tree(), 2);
8564 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:058565 LayerImpl::Create(host_impl.pending_tree(), 3);
8566
danakj60bc3bc2016-04-09 00:24:488567 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:058568 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8569
danakjf78fb272016-07-26 19:06:158570 root->SetBounds(gfx::Size(100, 100));
8571 child->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058572 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158573 grandchild->SetBounds(gfx::Size(10, 10));
sunxd71aea3e2016-04-01 23:48:058574 grandchild->SetDrawsContent(true);
8575 greatgrandchild->SetDrawsContent(true);
8576
sunxd71aea3e2016-04-01 23:48:058577 LayerImpl* root_ptr = root.get();
8578 LayerImpl* grandchild_ptr = grandchild.get();
8579
jaydasika89f7b5a2016-06-22 02:08:398580 child->test_properties()->AddChild(std::move(grandchild));
8581 root->test_properties()->AddChild(std::move(child));
sunxd71aea3e2016-04-01 23:48:058582
jaydasikabf1875a2016-06-28 03:39:598583 host_impl.pending_tree()->SetRootLayerForTesting(std::move(root));
vollickef2ae922016-06-29 17:54:278584 host_impl.pending_tree()->SetElementIdsForTesting();
sunxd71aea3e2016-04-01 23:48:058585
8586 // Check the non-skipped case.
8587 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8588 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8589
danakj60bc3bc2016-04-09 00:24:488590 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058591 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:498592 std::unique_ptr<TimingFunction> func =
8593 CubicBezierTimingFunction::CreatePreset(
8594 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:058595 curve->AddKeyframe(
8596 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
8597 curve->AddKeyframe(
8598 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:488599 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:058600 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
8601 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588602 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278603 root_ptr->element_id(), player.get());
sunxd71aea3e2016-04-01 23:48:058604 host_impl.active_tree()
8605 ->animation_host()
vollickef2ae922016-06-29 17:54:278606 ->GetElementAnimationsForElementId(root_ptr->element_id())
sunxd71aea3e2016-04-01 23:48:058607 ->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:188608 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:058609 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8610 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8611 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8612 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8613
loysofb69174e2016-04-27 00:58:588614 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
vollickef2ae922016-06-29 17:54:278615 root_ptr->element_id(), player.get());
vollick2175fae82015-04-27 21:18:128616}
8617
8618TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
jaydasikabf1875a2016-06-28 03:39:598619 LayerImpl* root = root_layer_for_testing();
jaydasika6f972de2016-04-07 16:16:148620 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:128621
danakjf78fb272016-07-26 19:06:158622 root->SetBounds(gfx::Size(100, 100));
8623 child->SetBounds(gfx::Size(10, 10));
jaydasika6f972de2016-04-07 16:16:148624 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:128625
jaydasika6f972de2016-04-07 16:16:148626 ExecuteCalculateDrawProperties(root);
8627 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:278628 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:128629
jaydasika5121caa82016-05-05 15:43:358630 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:148631 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8632 ExecuteCalculateDrawProperties(root);
8633 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358634 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128635
8636 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:148637 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8638 ExecuteCalculateDrawProperties(root);
8639 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128640 child->SetBounds(gfx::Size(10, 10));
8641
8642 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:368643 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:128644 rotate.RotateAboutXAxis(180.f);
8645 child->SetTransform(rotate);
jaydasika6f972de2016-04-07 16:16:148646 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8647 ExecuteCalculateDrawProperties(root);
8648 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:368649 child->test_properties()->double_sided = true;
danakjf78fb272016-07-26 19:06:158650 child->SetTransform(gfx::Transform());
vollick2175fae82015-04-27 21:18:128651
jaydasikaab317e02016-06-01 00:53:188652 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:148653 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8654 ExecuteCalculateDrawProperties(root);
8655 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128656}
8657
jaydasika3d10aa62015-05-06 17:50:448658TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
8659 // Ensure that the treewalk in LayerTreeHostCommom::
8660 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:318661 scoped_refptr<Layer> root = Layer::Create();
8662 scoped_refptr<Layer> parent = Layer::Create();
8663 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:448664
danakjf78fb272016-07-26 19:06:158665 root->SetBounds(gfx::Size(100, 100));
8666 parent->SetBounds(gfx::Size(100, 100));
8667 child->SetBounds(gfx::Size(100, 100));
jaydasika3d10aa62015-05-06 17:50:448668 child->SetClipParent(root.get());
8669
danakjf78fb272016-07-26 19:06:158670 root->AddChild(parent);
8671 parent->AddChild(child);
ennea7b43c32015-06-18 20:01:338672 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:448673
jaydasika3d10aa62015-05-06 17:50:448674 child->RequestCopyOfOutput(
8675 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:028676
8677 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8678 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
8679
8680 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
8681 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8682 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:448683}
8684
vollick692444f2015-05-20 15:39:148685TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
danakjf78fb272016-07-26 19:06:158686 scoped_refptr<Layer> root = Layer::Create();
8687 root->SetBounds(gfx::Size(800, 800));
8688
vollick692444f2015-05-20 15:39:148689 gfx::Transform translate_z;
8690 translate_z.Translate3d(0, 0, 10);
8691
loyso0940d412016-03-14 01:30:318692 scoped_refptr<Layer> child = Layer::Create();
danakjf78fb272016-07-26 19:06:158693 child->SetTransform(translate_z);
8694 child->SetBounds(gfx::Size(100, 100));
vollick692444f2015-05-20 15:39:148695
8696 root->AddChild(child);
8697
ennea7b43c32015-06-18 20:01:338698 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:148699
8700 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8701 EXPECT_NE(-1, child->transform_tree_index());
8702
8703 child->RemoveFromParent();
8704
8705 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8706 EXPECT_EQ(-1, child->transform_tree_index());
8707}
8708
jaydasika67d7989e2015-08-06 21:55:348709TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
8710 // Ensure that a Clip Node is added when a render surface applies clip.
jaydasikabf1875a2016-06-28 03:39:598711 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:348712 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
8713 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
8714 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
8715 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
8716
jaydasika67d7989e2015-08-06 21:55:348717 // This transform should be a significant one so that a transform node is
8718 // formed for it.
8719 gfx::Transform transform1;
8720 transform1.RotateAboutYAxis(45);
8721 transform1.RotateAboutXAxis(30);
8722 // This transform should be a 3d transform as we want the render surface
8723 // to flatten the transform
8724 gfx::Transform transform2;
8725 transform2.Translate3d(10, 10, 10);
8726
danakjf78fb272016-07-26 19:06:158727 root->SetBounds(gfx::Size(30, 30));
8728 significant_transform->SetTransform(transform1);
8729 significant_transform->SetBounds(gfx::Size(30, 30));
8730 layer_clips_subtree->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:348731 layer_clips_subtree->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158732 layer_clips_subtree->test_properties()->force_render_surface = true;
8733 render_surface->SetTransform(transform2);
8734 render_surface->SetBounds(gfx::Size(30, 30));
8735 render_surface->test_properties()->force_render_surface = true;
8736 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:348737 test_layer->SetDrawsContent(true);
8738
jaydasika67d7989e2015-08-06 21:55:348739 ExecuteCalculateDrawProperties(root);
8740
ajumae4af47062016-05-24 23:59:048741 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:348742 root->layer_tree_impl()->property_trees()->transform_tree;
8743 TransformNode* transform_node =
8744 transform_tree.Node(significant_transform->transform_tree_index());
8745 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
8746
weiliangcc154ce22015-12-09 03:39:268747 EXPECT_TRUE(root->has_render_surface());
8748 EXPECT_FALSE(significant_transform->has_render_surface());
8749 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
8750 EXPECT_TRUE(render_surface->has_render_surface());
8751 EXPECT_FALSE(test_layer->has_render_surface());
8752
ajumae4af47062016-05-24 23:59:048753 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:348754 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
trchendba8b1502016-07-08 09:47:018755 EXPECT_FALSE(clip_node->applies_local_clip);
weiliangcd15784432016-06-07 17:57:338756 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:348757}
8758
8759TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
8760 // Ensure that when parent clip node's transform is an ancestor of current
8761 // clip node's target, clip is 'projected' from parent space to current
8762 // target space and visible rects are calculated correctly.
jaydasikabf1875a2016-06-28 03:39:598763 LayerImpl* root = root_layer_for_testing();
jaydasika67d7989e2015-08-06 21:55:348764 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
8765 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
8766 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
8767
jaydasika67d7989e2015-08-06 21:55:348768 gfx::Transform transform;
8769 transform.RotateAboutYAxis(45);
danakjf78fb272016-07-26 19:06:158770
8771 root->SetBounds(gfx::Size(30, 30));
8772 clip_layer->SetTransform(transform);
8773 clip_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:348774 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158775 target_layer->SetTransform(transform);
8776 target_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:348777 target_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158778 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika67d7989e2015-08-06 21:55:348779 test_layer->SetDrawsContent(true);
8780
jaydasika67d7989e2015-08-06 21:55:348781 ExecuteCalculateDrawProperties(root);
8782
weiliangcc97575c2016-03-03 18:34:278783 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:348784}
8785
jaydasika7d5c1ed2015-08-14 14:27:028786TEST_F(LayerTreeHostCommonTest,
8787 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
8788 // Ensure clip rect is calculated correctly when render surface has unclipped
8789 // descendants.
jaydasikabf1875a2016-06-28 03:39:598790 LayerImpl* root = root_layer_for_testing();
jaydasika7d5c1ed2015-08-14 14:27:028791 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8792 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
8793 LayerImpl* render_surface =
8794 AddChild<LayerImpl>(between_clip_parent_and_child);
8795 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
8796
weiliangcbb2e8642016-03-04 00:24:428797 gfx::Transform translate;
8798 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:028799
danakjf78fb272016-07-26 19:06:158800 root->SetBounds(gfx::Size(30, 30));
8801 clip_parent->SetTransform(translate);
8802 clip_parent->SetBounds(gfx::Size(30, 30));
weiliangcbb2e8642016-03-04 00:24:428803 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158804 between_clip_parent_and_child->SetTransform(translate);
8805 between_clip_parent_and_child->SetBounds(gfx::Size(30, 30));
8806 render_surface->SetBounds(gfx::Size(30, 30));
8807 render_surface->test_properties()->force_render_surface = true;
8808 test_layer->SetBounds(gfx::Size(30, 30));
jaydasika7d5c1ed2015-08-14 14:27:028809 test_layer->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158810
jaydasika1c0a27d42016-04-28 01:54:568811 render_surface->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:158812 clip_parent->test_properties()->clip_children =
8813 base::MakeUnique<std::set<LayerImpl*>>();
8814 clip_parent->test_properties()->clip_children->insert(render_surface);
jaydasika7d5c1ed2015-08-14 14:27:028815
8816 ExecuteCalculateDrawProperties(root);
8817
weiliangcbb2e8642016-03-04 00:24:428818 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:258819 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:568820 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
8821 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:028822}
8823
jaydasika571dd2cf2015-09-25 20:55:428824TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:088825 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
8826 // Ensure that the visible layer rect of a descendant of a surface with
8827 // unclipped descendants is computed correctly, when the surface doesn't apply
8828 // a clip.
jaydasikabf1875a2016-06-28 03:39:598829 LayerImpl* root = root_layer_for_testing();
ajuma01734dd02015-10-07 01:22:088830 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8831 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
8832 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
8833 LayerImpl* child = AddChild<LayerImpl>(render_surface);
8834
danakjf78fb272016-07-26 19:06:158835 root->SetBounds(gfx::Size(30, 10));
8836 clip_parent->SetBounds(gfx::Size(30, 30));
8837 render_surface->SetBounds(gfx::Size(10, 15));
8838 render_surface->test_properties()->force_render_surface = true;
8839 clip_child->SetBounds(gfx::Size(10, 10));
ajuma01734dd02015-10-07 01:22:088840 clip_child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158841 child->SetBounds(gfx::Size(40, 40));
ajuma01734dd02015-10-07 01:22:088842 child->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158843
jaydasika1c0a27d42016-04-28 01:54:568844 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:158845 clip_parent->test_properties()->clip_children =
8846 base::MakeUnique<std::set<LayerImpl*>>();
8847 clip_parent->test_properties()->clip_children->insert(clip_child);
ajuma01734dd02015-10-07 01:22:088848
8849 ExecuteCalculateDrawProperties(root);
8850 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
8851}
8852
8853TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:428854 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
jaydasikabf1875a2016-06-28 03:39:598855 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:428856 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8857 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
8858 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
8859 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
8860 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
8861
danakjf78fb272016-07-26 19:06:158862 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:428863 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158864 clip_parent->SetBounds(gfx::Size(30, 30));
8865 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:428866 render_surface->SetMasksToBounds(true);
8867 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158868 render_surface->test_properties()->force_render_surface = true;
8869 test_layer1->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:428870 test_layer1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158871 clip_child->SetBounds(gfx::Size(50, 50));
8872 clip_child->SetDrawsContent(true);
8873 test_layer2->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:428874 test_layer2->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:428875
danakjf78fb272016-07-26 19:06:158876 clip_child->test_properties()->clip_parent = clip_parent;
8877 clip_parent->test_properties()->clip_children =
8878 base::MakeUnique<std::set<LayerImpl*>>();
8879 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika571dd2cf2015-09-25 20:55:428880
8881 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:568882 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
8883 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:428884 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
8885 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
8886}
8887
ajumae2b7a5c2015-09-30 21:41:428888TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
jaydasikabf1875a2016-06-28 03:39:598889 LayerImpl* root = root_layer_for_testing();
ajumae2b7a5c2015-09-30 21:41:428890 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8891 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
8892 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
8893
danakjf78fb272016-07-26 19:06:158894 root->SetBounds(gfx::Size(50, 50));
8895 clip_parent->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:428896 clip_parent->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158897 render_surface->SetBounds(gfx::Size(30, 30));
8898 render_surface->test_properties()->force_render_surface = true;
ajumae2b7a5c2015-09-30 21:41:428899 render_surface->SetMasksToBounds(true);
8900 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:158901 clip_child->SetBounds(gfx::Size(50, 50));
ajumae2b7a5c2015-09-30 21:41:428902 clip_child->SetDrawsContent(true);
8903
jaydasika1c0a27d42016-04-28 01:54:568904 clip_child->test_properties()->clip_parent = clip_parent;
danakjf78fb272016-07-26 19:06:158905 clip_parent->test_properties()->clip_children =
8906 base::MakeUnique<std::set<LayerImpl*>>();
8907 clip_parent->test_properties()->clip_children->insert(clip_child);
ajumae2b7a5c2015-09-30 21:41:428908
8909 ExecuteCalculateDrawProperties(root);
8910
8911 // The clip child should inherit its clip parent's clipping state, not its
8912 // tree parent's clipping state.
8913 EXPECT_FALSE(clip_parent->is_clipped());
8914 EXPECT_TRUE(render_surface->is_clipped());
8915 EXPECT_FALSE(clip_child->is_clipped());
8916}
8917
jaydasika77a4a072015-10-20 21:47:278918TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
8919 // Tests the value of render surface content rect when we have multiple types
8920 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
8921 // clipped surfaces.
jaydasikabf1875a2016-06-28 03:39:598922 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:278923 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
8924 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
8925 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
8926 LayerImpl* unclipped_desc_surface2 =
8927 AddChild<LayerImpl>(unclipped_desc_surface);
8928 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
8929 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
8930
danakjf78fb272016-07-26 19:06:158931 root->SetBounds(gfx::Size(80, 80));
8932 unclipped_surface->SetBounds(gfx::Size(50, 50));
jaydasika77a4a072015-10-20 21:47:278933 unclipped_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158934 unclipped_surface->SetDrawsContent(true);
8935 unclipped_surface->test_properties()->force_render_surface = true;
8936 clip_parent->SetBounds(gfx::Size(50, 50));
8937 clip_parent->SetMasksToBounds(true);
8938 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:278939 unclipped_desc_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158940 unclipped_desc_surface->SetDrawsContent(true);
8941 unclipped_desc_surface->test_properties()->force_render_surface = true;
8942 unclipped_desc_surface2->SetBounds(gfx::Size(60, 60));
8943 unclipped_desc_surface2->SetDrawsContent(true);
8944 unclipped_desc_surface2->test_properties()->force_render_surface = true;
8945 clip_child->SetBounds(gfx::Size(100, 100));
8946 clipped_surface->SetBounds(gfx::Size(70, 70));
8947 clipped_surface->SetDrawsContent(true);
8948 clipped_surface->test_properties()->force_render_surface = true;
8949
8950 clip_child->test_properties()->clip_parent = clip_parent;
8951 clip_parent->test_properties()->clip_children =
8952 base::MakeUnique<std::set<LayerImpl*>>();
8953 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:278954
8955 ExecuteCalculateDrawProperties(root);
8956 EXPECT_EQ(gfx::Rect(50, 50),
8957 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:568958 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:278959 unclipped_desc_surface->render_surface()->content_rect());
8960 EXPECT_EQ(gfx::Rect(50, 50),
8961 unclipped_desc_surface2->render_surface()->content_rect());
8962 EXPECT_EQ(gfx::Rect(50, 50),
8963 clipped_surface->render_surface()->content_rect());
8964}
8965
8966TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
8967 // Tests the value of render surface content rect when we have a layer that
8968 // clips between the clip parent's target and clip child's target.
jaydasikabf1875a2016-06-28 03:39:598969 LayerImpl* root = root_layer_for_testing();
jaydasika77a4a072015-10-20 21:47:278970 LayerImpl* surface = AddChildToRoot<LayerImpl>();
8971 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
8972 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
8973 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
8974 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
8975
jaydasika77a4a072015-10-20 21:47:278976 gfx::Transform translate;
8977 translate.Translate(10, 10);
danakjf78fb272016-07-26 19:06:158978
8979 root->SetBounds(gfx::Size(100, 100));
8980 surface->SetBounds(gfx::Size(100, 100));
jaydasika77a4a072015-10-20 21:47:278981 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158982 surface->test_properties()->force_render_surface = true;
8983 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika77a4a072015-10-20 21:47:278984 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:158985 clip_parent->SetBounds(gfx::Size(50, 50));
8986 unclipped_desc_surface->SetTransform(translate);
8987 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
8988 unclipped_desc_surface->SetDrawsContent(true);
8989 unclipped_desc_surface->test_properties()->force_render_surface = true;
8990 clip_child->SetBounds(gfx::Size(100, 100));
8991 clip_child->SetDrawsContent(true);
8992
8993 clip_child->test_properties()->clip_parent = clip_parent;
8994 clip_parent->test_properties()->clip_children =
8995 base::MakeUnique<std::set<LayerImpl*>>();
8996 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika77a4a072015-10-20 21:47:278997
8998 ExecuteCalculateDrawProperties(root);
8999
9000 EXPECT_EQ(gfx::Rect(10, 10),
9001 unclipped_desc_surface->render_surface()->content_rect());
9002}
9003
jaydasika2c8c2872015-10-21 23:28:219004TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
jaydasikabf1875a2016-06-28 03:39:599005 LayerImpl* root = root_layer_for_testing();
jaydasika2c8c2872015-10-21 23:28:219006 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9007 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9008 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9009 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9010 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9011
jaydasika2c8c2872015-10-21 23:28:219012
jaydasika2c8c2872015-10-21 23:28:219013 gfx::Transform scale;
9014 scale.Scale(2, 2);
danakjf78fb272016-07-26 19:06:159015
9016 root->SetBounds(gfx::Size(100, 100));
9017 surface->SetTransform(scale);
9018 surface->SetBounds(gfx::Size(100, 100));
jaydasika2c8c2872015-10-21 23:28:219019 surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159020 surface->test_properties()->force_render_surface = true;
9021 clip_layer->SetBounds(gfx::Size(20, 20));
jaydasika2c8c2872015-10-21 23:28:219022 clip_layer->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159023 clip_parent->SetBounds(gfx::Size(50, 50));
9024 unclipped_desc_surface->SetBounds(gfx::Size(100, 100));
9025 unclipped_desc_surface->SetDrawsContent(true);
9026 unclipped_desc_surface->test_properties()->force_render_surface = true;
9027 clip_child->SetBounds(gfx::Size(100, 100));
9028 clip_child->SetDrawsContent(true);
9029
9030 clip_child->test_properties()->clip_parent = clip_parent;
9031 clip_parent->test_properties()->clip_children =
9032 base::MakeUnique<std::set<LayerImpl*>>();
9033 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasika2c8c2872015-10-21 23:28:219034
9035 ExecuteCalculateDrawProperties(root);
9036
9037 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9038}
9039
jaydasika60f85862015-10-01 20:36:149040TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
jaydasikabf1875a2016-06-28 03:39:599041 LayerImpl* root = root_layer_for_testing();
jaydasika60f85862015-10-01 20:36:149042 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9043 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9044
jaydasika86654512016-01-27 17:05:079045 gfx::Transform translation;
9046 translation.Translate(10, 10);
jaydasika60f85862015-10-01 20:36:149047
danakjf78fb272016-07-26 19:06:159048 root->SetBounds(gfx::Size(30, 30));
9049 render_surface->SetBounds(gfx::Size(30, 30));
jaydasika60f85862015-10-01 20:36:149050 render_surface->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159051 render_surface->test_properties()->force_render_surface = true;
9052 test_layer->SetTransform(translation);
9053 test_layer->SetBounds(gfx::Size(20, 20));
jaydasika60f85862015-10-01 20:36:149054 test_layer->SetDrawsContent(true);
dtapuskaee0b6982016-01-29 15:14:489055 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
danakjf78fb272016-07-26 19:06:159056 test_layer->test_properties()->opacity = 0.f;
jaydasika60f85862015-10-01 20:36:149057
9058 ExecuteCalculateDrawProperties(root);
weiliangcc3517722016-06-28 22:52:029059 EXPECT_TRANSFORMATION_MATRIX_EQ(translation,
9060 test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149061}
9062
jaydasikae4910fa22015-10-09 00:52:099063TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
jaydasikabf1875a2016-06-28 03:39:599064 LayerImpl* root = root_layer_for_testing();
jaydasikae4910fa22015-10-09 00:52:099065 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9066 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9067 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9068
danakjf78fb272016-07-26 19:06:159069 root->SetBounds(gfx::Size(30, 30));
9070 clip_parent->SetBounds(gfx::Size(40, 40));
jaydasikae4910fa22015-10-09 00:52:099071 clip_parent->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159072 render_surface->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099073 render_surface->SetMasksToBounds(true);
9074 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159075 render_surface->test_properties()->force_render_surface = true;
9076 clip_child->SetBounds(gfx::Size(50, 50));
jaydasikae4910fa22015-10-09 00:52:099077 clip_child->SetDrawsContent(true);
jaydasikae4910fa22015-10-09 00:52:099078
danakjf78fb272016-07-26 19:06:159079 clip_child->test_properties()->clip_parent = clip_parent;
9080 clip_parent->test_properties()->clip_children =
9081 base::MakeUnique<std::set<LayerImpl*>>();
9082 clip_parent->test_properties()->clip_children->insert(clip_child);
jaydasikae4910fa22015-10-09 00:52:099083
9084 ExecuteCalculateDrawProperties(root);
9085 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9086}
9087
jaydasika571dd2cf2015-09-25 20:55:429088TEST_F(LayerTreeHostCommonTest,
9089 LayerClipRectLargerThanClippingRenderSurfaceRect) {
jaydasikabf1875a2016-06-28 03:39:599090 LayerImpl* root = root_layer_for_testing();
jaydasika571dd2cf2015-09-25 20:55:429091 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9092 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
danakjf78fb272016-07-26 19:06:159093
9094 root->SetBounds(gfx::Size(30, 30));
jaydasika571dd2cf2015-09-25 20:55:429095 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369096 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159097 render_surface->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429098 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369099 render_surface->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159100 render_surface->test_properties()->force_render_surface = true;
9101 test_layer->SetBounds(gfx::Size(50, 50));
jaydasika571dd2cf2015-09-25 20:55:429102 test_layer->SetMasksToBounds(true);
9103 test_layer->SetDrawsContent(true);
9104 ExecuteCalculateDrawProperties(root);
9105
9106 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9107 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9108 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9109}
9110
jaydasikab5504ca2015-12-18 23:41:559111TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9112 // Tests that subtree is hidden is updated.
jaydasikabf1875a2016-06-28 03:39:599113 LayerImpl* root = root_layer_for_testing();
jaydasikab5504ca2015-12-18 23:41:559114 LayerImpl* hidden = AddChild<LayerImpl>(root);
9115 LayerImpl* test = AddChild<LayerImpl>(hidden);
9116
danakjf78fb272016-07-26 19:06:159117 root->SetBounds(gfx::Size(30, 30));
9118 hidden->SetBounds(gfx::Size(30, 30));
9119 hidden->test_properties()->force_render_surface = true;
jaydasika5121caa82016-05-05 15:43:359120 hidden->test_properties()->hide_layer_and_subtree = true;
danakjf78fb272016-07-26 19:06:159121 test->SetBounds(gfx::Size(30, 30));
9122 test->test_properties()->force_render_surface = true;
9123
jaydasikab5504ca2015-12-18 23:41:559124 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079125 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559126
jaydasika5121caa82016-05-05 15:43:359127 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559128 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9129 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079130 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559131}
9132
jaydasikac0137282015-10-01 15:50:309133TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
jaydasikabf1875a2016-06-28 03:39:599134 LayerImpl* root = root_layer_for_testing();
jaydasikac0137282015-10-01 15:50:309135 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9136 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9137 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9138
danakjf78fb272016-07-26 19:06:159139 root->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309140 root->SetMasksToBounds(true);
danakjf78fb272016-07-26 19:06:159141 render_surface1->SetPosition(gfx::PointF(10, 10));
9142 render_surface1->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309143 render_surface1->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159144 render_surface1->test_properties()->force_render_surface = true;
9145 render_surface2->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309146 render_surface2->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159147 render_surface2->test_properties()->force_render_surface = true;
9148 clip_child->SetBounds(gfx::Size(30, 30));
jaydasikac0137282015-10-01 15:50:309149
danakjf78fb272016-07-26 19:06:159150 clip_child->test_properties()->clip_parent = root;
9151 root->test_properties()->clip_children =
9152 base::MakeUnique<std::set<LayerImpl*>>();
9153 root->test_properties()->clip_children->insert(clip_child);
9154
jaydasikac0137282015-10-01 15:50:309155 ExecuteCalculateDrawProperties(root);
9156
9157 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379158 // A clip node is created for every render surface and for layers that have
9159 // local clip. So, here it should be craeted for every layer.
9160 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309161}
9162
ajumadb6216f2c2016-06-07 21:44:059163TEST_F(LayerTreeHostCommonTest, MaskLayerDrawProperties) {
9164 // Tests that a mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599165 LayerImpl* root = root_layer_for_testing();
jaydasika224bca02015-12-18 02:37:099166 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509167 child->test_properties()->SetMaskLayer(
9168 LayerImpl::Create(root->layer_tree_impl(), 100));
9169 LayerImpl* mask = child->test_properties()->mask_layer;
jaydasika224bca02015-12-18 02:37:099170
jaydasika224bca02015-12-18 02:37:099171 gfx::Transform transform;
9172 transform.Translate(10, 10);
9173
danakjf78fb272016-07-26 19:06:159174 root->SetBounds(gfx::Size(40, 40));
jaydasika224bca02015-12-18 02:37:099175 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159176 child->SetTransform(transform);
9177 child->SetBounds(gfx::Size(30, 30));
jaydasika224bca02015-12-18 02:37:099178 child->SetDrawsContent(false);
danakjf78fb272016-07-26 19:06:159179 mask->SetBounds(gfx::Size(20, 20));
jaydasika224bca02015-12-18 02:37:099180 ExecuteCalculateDrawProperties(root);
9181
ajumadb6216f2c2016-06-07 21:44:059182 // The render surface created for the mask has no contributing content, so the
9183 // mask isn't a drawn RSLL member. This means it has an empty visible rect,
9184 // but its screen space transform can still be computed correctly on-demand.
ajuma1d4026a32016-06-14 13:18:509185 EXPECT_FALSE(mask->is_drawn_render_surface_layer_list_member());
9186 EXPECT_EQ(gfx::Rect(), mask->visible_layer_rect());
9187 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059188
9189 // Make the child's render surface have contributing content.
9190 child->SetDrawsContent(true);
9191 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9192 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509193 EXPECT_TRUE(mask->is_drawn_render_surface_layer_list_member());
9194 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
9195 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059196
jaydasika224bca02015-12-18 02:37:099197 transform.Translate(10, 10);
9198 child->SetTransform(transform);
jaydasika224bca02015-12-18 02:37:099199 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9200 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509201 EXPECT_TRANSFORMATION_MATRIX_EQ(transform, mask->ScreenSpaceTransform());
9202 EXPECT_EQ(gfx::Rect(20, 20), mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:059203}
9204
9205TEST_F(LayerTreeHostCommonTest, ReplicaMaskLayerDrawProperties) {
9206 // Tests that a replica mask layer's draw properties are computed correctly.
jaydasikabf1875a2016-06-28 03:39:599207 LayerImpl* root = root_layer_for_testing();
ajumadb6216f2c2016-06-07 21:44:059208 LayerImpl* child = AddChild<LayerImpl>(root);
ajuma1d4026a32016-06-14 13:18:509209 child->test_properties()->SetReplicaLayer(
9210 LayerImpl::Create(root->layer_tree_impl(), 100));
9211 LayerImpl* replica = child->test_properties()->replica_layer;
jaydasikaf419bf72016-06-15 10:21:219212 replica->test_properties()->parent = child;
ajuma1d4026a32016-06-14 13:18:509213 replica->test_properties()->SetMaskLayer(
ajumadb6216f2c2016-06-07 21:44:059214 LayerImpl::Create(root->layer_tree_impl(), 200));
ajuma1d4026a32016-06-14 13:18:509215 LayerImpl* replica_mask = replica->test_properties()->mask_layer;
ajumadb6216f2c2016-06-07 21:44:059216
ajumadb6216f2c2016-06-07 21:44:059217 gfx::Transform transform;
9218 transform.Translate(10, 10);
9219
9220 gfx::PointF replica_position(3.f, 3.f);
9221
danakjf78fb272016-07-26 19:06:159222 root->SetBounds(gfx::Size(40, 40));
ajumadb6216f2c2016-06-07 21:44:059223 root->SetDrawsContent(true);
danakjf78fb272016-07-26 19:06:159224 child->SetTransform(transform);
9225 child->SetBounds(gfx::Size(30, 30));
9226 replica->SetPosition(replica_position);
9227 replica_mask->SetBounds(gfx::Size(20, 20));
9228
ajumadb6216f2c2016-06-07 21:44:059229 ExecuteCalculateDrawProperties(root);
9230
9231 // The render surface created for the replica has no contributing content, so
9232 // the replica's mask isn't a drawn RSLL member. This means it has an empty
9233 // visible rect, but its screen space transform can still be computed
9234 // correctly on-demand.
ajuma1d4026a32016-06-14 13:18:509235 EXPECT_FALSE(replica_mask->is_drawn_render_surface_layer_list_member());
9236 EXPECT_EQ(gfx::Rect(), replica_mask->visible_layer_rect());
ajumadb6216f2c2016-06-07 21:44:059237
9238 gfx::Transform expected_screen_space_transform = transform;
9239 expected_screen_space_transform.Translate(replica_position.x(),
9240 replica_position.y());
9241
ajuma1d4026a32016-06-14 13:18:509242 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
9243 replica_mask->ScreenSpaceTransform());
ajumadb6216f2c2016-06-07 21:44:059244
9245 // Make the child's render surface have contributing content.
9246 child->SetDrawsContent(true);
9247 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9248 ExecuteCalculateDrawProperties(root);
ajuma1d4026a32016-06-14 13:18:509249 EXPECT_TRUE(replica_mask->is_drawn_render_surface_layer_list_member());
9250 EXPECT_EQ(gfx::Rect(20, 20), replica_mask->visible_layer_rect());
9251 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
9252 replica_mask->ScreenSpaceTransform());
jaydasika224bca02015-12-18 02:37:099253}
9254
jaydasikaf62311f2016-04-20 14:38:459255TEST_F(LayerTreeHostCommonTest,
9256 SublayerScaleWithTransformNodeBetweenTwoTargets) {
jaydasikabf1875a2016-06-28 03:39:599257 LayerImpl* root = root_layer_for_testing();
jaydasikaf62311f2016-04-20 14:38:459258 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9259 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9260 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9261 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
jaydasikaf62311f2016-04-20 14:38:459262
9263 gfx::Transform scale;
9264 scale.Scale(2.f, 2.f);
danakjf78fb272016-07-26 19:06:159265
9266 root->SetBounds(gfx::Size(30, 30));
9267 render_surface1->SetTransform(scale);
9268 render_surface1->SetBounds(gfx::Size(30, 30));
9269 render_surface1->test_properties()->force_render_surface = true;
9270 between_targets->SetBounds(gfx::Size(30, 30));
9271 render_surface2->SetBounds(gfx::Size(30, 30));
9272 render_surface2->test_properties()->force_render_surface = true;
9273 test_layer->SetBounds(gfx::Size(30, 30));
9274 test_layer->SetDrawsContent(true);
9275
jaydasikaf62311f2016-04-20 14:38:459276 // We want layer between the two targets to create a clip node and transform
9277 // node but it shouldn't create a render surface.
9278 between_targets->SetMasksToBounds(true);
9279 between_targets->Set3dSortingContextId(2);
9280
9281 ExecuteCalculateDrawProperties(root);
9282
9283 TransformTree& tree =
9284 root->layer_tree_impl()->property_trees()->transform_tree;
9285 TransformNode* node = tree.Node(render_surface1->transform_tree_index());
jaydasika6be761602016-07-18 20:11:439286 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459287
9288 node = tree.Node(between_targets->transform_tree_index());
jaydasika6be761602016-07-18 20:11:439289 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f));
jaydasikaf62311f2016-04-20 14:38:459290
9291 node = tree.Node(render_surface2->transform_tree_index());
jaydasika6be761602016-07-18 20:11:439292 EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f));
jaydasikaf62311f2016-04-20 14:38:459293
9294 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9295}
9296
jaydasika5160e672015-10-15 15:25:149297TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
jaydasikabf1875a2016-06-28 03:39:599298 LayerImpl* root = root_layer_for_testing();
jaydasika5160e672015-10-15 15:25:149299 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059300 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149301
sunxd71aea3e2016-04-01 23:48:059302 child->SetDrawsContent(true);
9303 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149304
9305 gfx::Transform large_transform;
9306 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9307 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9308 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9309 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9310
danakjf78fb272016-07-26 19:06:159311 root->SetBounds(gfx::Size(30, 30));
9312 render_surface1->SetBounds(gfx::Size(30, 30));
9313 render_surface1->test_properties()->force_render_surface = true;
9314
sunxd71aea3e2016-04-01 23:48:059315 // TODO(sunxd): we make child have no render surface, because if the
9316 // child has one, the large transform applied to child will result in NaNs in
9317 // the draw_transform of the render_surface, thus make draw property updates
9318 // skip the child layer. We need further investigation into this to know
9319 // what exactly happens here.
danakjf78fb272016-07-26 19:06:159320 child->SetTransform(large_transform);
9321 child->SetBounds(gfx::Size(30, 30));
jaydasika5160e672015-10-15 15:25:149322
9323 ExecuteCalculateDrawProperties(root);
9324
jaydasika5160e672015-10-15 15:25:149325 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:059326 render_surface1->render_surface()->DrawableContentRect());
9327
9328 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9329 std::isnan(child->DrawTransform().matrix().get(0, 0));
9330 EXPECT_TRUE(is_inf_or_nan);
9331
9332 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9333 std::isnan(child->DrawTransform().matrix().get(1, 1));
9334 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149335
danakj59931942016-07-26 22:11:299336 // The root layer should be in the RenderSurfaceLayerListImpl.
9337 const auto* rsll = render_surface_layer_list_impl();
9338 EXPECT_NE(std::find(rsll->begin(), rsll->end(), root), rsll->end());
jaydasika5160e672015-10-15 15:25:149339}
9340
jaydasika8d6efe2e2016-05-17 15:37:219341TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
jaydasika8d6efe2e2016-05-17 15:37:219342 scoped_refptr<Layer> root = Layer::Create();
9343 scoped_refptr<LayerWithForcedDrawsContent> child =
9344 make_scoped_refptr(new LayerWithForcedDrawsContent());
9345 root->AddChild(child);
jaydasika8d6efe2e2016-05-17 15:37:219346 host()->SetRootLayer(root);
9347
danakjf78fb272016-07-26 19:06:159348 root->SetBounds(gfx::Size(100, 100));
9349 child->SetBounds(gfx::Size(20, 20));
jaydasika8d6efe2e2016-05-17 15:37:219350 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9351
9352 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9353 // property trees as a new effect node will be created.
9354 child->SetOpacity(0.5f);
9355 PropertyTrees* property_trees = host()->property_trees();
9356 EXPECT_TRUE(property_trees->needs_rebuild);
9357
9358 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9359 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9360 property_trees->effect_id_to_index_map.end());
9361
9362 // child already has an effect node. Changing its opacity shouldn't trigger
9363 // a property trees rebuild.
9364 child->SetOpacity(0.8f);
9365 property_trees = host()->property_trees();
9366 EXPECT_FALSE(property_trees->needs_rebuild);
9367
9368 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9369 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9370 property_trees->effect_id_to_index_map.end());
9371
9372 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
9373 // property trees as the effect node may no longer be needed.
9374 child->SetOpacity(1.f);
9375 property_trees = host()->property_trees();
9376 EXPECT_TRUE(property_trees->needs_rebuild);
9377
9378 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9379 EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()),
9380 property_trees->effect_id_to_index_map.end());
9381}
9382
jaydasika9cb21c772016-05-10 22:37:089383TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
jaydasika9cb21c772016-05-10 22:37:089384 scoped_refptr<Layer> root = Layer::Create();
9385 scoped_refptr<LayerWithForcedDrawsContent> animated =
9386 make_scoped_refptr(new LayerWithForcedDrawsContent());
9387 root->AddChild(animated);
jaydasika9cb21c772016-05-10 22:37:089388 host()->SetRootLayer(root);
vollickef2ae922016-06-29 17:54:279389 host()->SetElementIdsForTesting();
9390
danakjf78fb272016-07-26 19:06:159391 root->SetBounds(gfx::Size(100, 100));
jaydasika9cb21c772016-05-10 22:37:089392 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159393 animated->SetBounds(gfx::Size(20, 20));
jaydasika9cb21c772016-05-10 22:37:089394 animated->SetOpacity(0.f);
9395
9396 scoped_refptr<AnimationPlayer> player =
9397 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9398 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279399
9400 player->AttachElement(animated->element_id());
jaydasika9cb21c772016-05-10 22:37:089401
9402 int animation_id = 0;
9403 std::unique_ptr<Animation> animation = Animation::Create(
9404 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
9405 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559406 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:089407 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9408 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279409 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9410 std::move(animation));
jaydasika9cb21c772016-05-10 22:37:089411
9412 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9413
9414 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree;
9415 EffectNode* node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019416 EXPECT_FALSE(node->is_currently_animating_opacity);
9417 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089418
9419 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
9420 root->layer_tree_host()->AnimateLayers(
9421 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9422 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019423 EXPECT_TRUE(node->is_currently_animating_opacity);
9424 EXPECT_TRUE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089425
9426 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
9427 node = tree.Node(animated->effect_tree_index());
trchendba8b1502016-07-08 09:47:019428 EXPECT_FALSE(node->is_currently_animating_opacity);
9429 EXPECT_FALSE(node->has_potential_opacity_animation);
jaydasika9cb21c772016-05-10 22:37:089430}
9431
jaydasika6c3404e92016-05-19 02:40:369432TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
jaydasika6c3404e92016-05-19 02:40:369433 scoped_refptr<Layer> root = Layer::Create();
9434 scoped_refptr<LayerWithForcedDrawsContent> animated =
9435 make_scoped_refptr(new LayerWithForcedDrawsContent());
9436 root->AddChild(animated);
jaydasika6c3404e92016-05-19 02:40:369437 host()->SetRootLayer(root);
vollickef2ae922016-06-29 17:54:279438 host()->SetElementIdsForTesting();
9439
danakjf78fb272016-07-26 19:06:159440 root->SetBounds(gfx::Size(100, 100));
jaydasika6c3404e92016-05-19 02:40:369441 root->SetForceRenderSurfaceForTesting(true);
danakjf78fb272016-07-26 19:06:159442 animated->SetBounds(gfx::Size(20, 20));
jaydasika6c3404e92016-05-19 02:40:369443
9444 scoped_refptr<AnimationPlayer> player =
9445 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9446 timeline()->AttachPlayer(player);
vollickef2ae922016-06-29 17:54:279447 player->AttachElement(animated->element_id());
jaydasika6c3404e92016-05-19 02:40:369448
9449 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
9450 KeyframedTransformAnimationCurve::Create());
9451 TransformOperations start;
9452 start.AppendTranslate(1.f, 2.f, 3.f);
9453 gfx::Transform transform;
9454 transform.Scale3d(1.0, 2.0, 3.0);
9455 TransformOperations operation;
9456 operation.AppendMatrix(transform);
9457 curve->AddKeyframe(
9458 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9459 curve->AddKeyframe(TransformKeyframe::Create(
9460 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
9461 std::unique_ptr<Animation> animation(
9462 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9463 animation->set_fill_mode(Animation::FillMode::NONE);
9464 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9465 Animation* animation_ptr = animation.get();
vollickef2ae922016-06-29 17:54:279466 AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
9467 std::move(animation));
jaydasika6c3404e92016-05-19 02:40:369468
9469 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9470
9471 TransformTree& tree =
9472 root->layer_tree_host()->property_trees()->transform_tree;
9473 TransformNode* node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019474 EXPECT_FALSE(node->is_currently_animating);
9475 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369476
9477 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
9478 root->layer_tree_host()->AnimateLayers(
9479 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9480 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019481 EXPECT_TRUE(node->is_currently_animating);
9482 EXPECT_TRUE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369483
9484 player->AbortAnimations(TargetProperty::TRANSFORM,
9485 false /*needs_completion*/);
9486 node = tree.Node(animated->transform_tree_index());
trchendba8b1502016-07-08 09:47:019487 EXPECT_FALSE(node->is_currently_animating);
9488 EXPECT_FALSE(node->has_potential_animation);
jaydasika6c3404e92016-05-19 02:40:369489}
9490
khushalsagar37694212016-01-15 20:46:489491TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9492 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9493 scroll.layer_id = 2;
9494 scroll.scroll_delta = gfx::Vector2d(5, 10);
9495
9496 proto::ScrollUpdateInfo proto;
9497 scroll.ToProtobuf(&proto);
9498 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9499 new_scroll.FromProtobuf(proto);
9500
9501 EXPECT_EQ(scroll, new_scroll);
9502}
9503
9504TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9505 ScrollAndScaleSet scroll_and_scale_set;
9506
9507 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9508 scroll1.layer_id = 1;
9509 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9510 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9511 scroll2.layer_id = 2;
9512 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9513 scroll_and_scale_set.scrolls.push_back(scroll1);
9514 scroll_and_scale_set.scrolls.push_back(scroll2);
9515
9516 scroll_and_scale_set.page_scale_delta = 0.3f;
9517 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
9518 scroll_and_scale_set.top_controls_delta = 0.9f;
9519
9520 proto::ScrollAndScaleSet proto;
9521 scroll_and_scale_set.ToProtobuf(&proto);
9522 ScrollAndScaleSet new_scroll_and_scale_set;
9523 new_scroll_and_scale_set.FromProtobuf(proto);
9524
9525 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
9526}
9527
sunxdea1df782016-01-28 00:12:339528TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9529 // Test the behavior of scroll tree builder
9530 // Topology:
sunxdcfccd1b32016-02-11 00:54:209531 // +root1(1)[inner_viewport_container_layer]
9532 // +-page_scale_layer
9533 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9534 // scrollable, inner_viewport_scroll_layer]
9535 // +------child6(6)[kScrollbarScrolling]
9536 // +--------grand_child10(10)[kScrollbarScrolling]
9537 // +----parent3(3)
9538 // +------child7(7)[scrollable]
9539 // +------child8(8)[scroll_parent=7]
9540 // +--------grand_child11(11)[scrollable]
9541 // +----parent4(4)
9542 // +------child9(9)
9543 // +--------grand_child12(12)
9544 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339545 //
9546 // Expected scroll tree topology:
9547 // +property_tree_root---owner:-1
9548 // +--root---owner:1, id:1
9549 // +----node---owner:2, id:2
9550 // +------node---owner:6, id:3
9551 // +----node---owner:7, id:4
9552 // +------node---owner:11, id:5
9553 // +----node---owner:5, id:6
9554 //
9555 // Extra check:
9556 // scroll_tree_index() of:
9557 // grand_child10:3
9558 // parent3:1
9559 // child8:4
9560 // parent4:1
9561 // child9:1
9562 // grand_child12:1
loyso0940d412016-03-14 01:30:319563 scoped_refptr<Layer> root1 = Layer::Create();
9564 scoped_refptr<Layer> page_scale_layer = Layer::Create();
9565 scoped_refptr<Layer> parent2 = Layer::Create();
9566 scoped_refptr<Layer> parent3 = Layer::Create();
9567 scoped_refptr<Layer> parent4 = Layer::Create();
9568 scoped_refptr<Layer> parent5 = Layer::Create();
9569 scoped_refptr<Layer> child6 = Layer::Create();
9570 scoped_refptr<Layer> child7 = Layer::Create();
9571 scoped_refptr<Layer> child8 = Layer::Create();
9572 scoped_refptr<Layer> child9 = Layer::Create();
9573 scoped_refptr<Layer> grand_child10 = Layer::Create();
9574 scoped_refptr<Layer> grand_child11 = Layer::Create();
9575 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:339576
sunxdcfccd1b32016-02-11 00:54:209577 root1->AddChild(page_scale_layer);
9578 page_scale_layer->AddChild(parent2);
9579 page_scale_layer->AddChild(parent3);
9580 page_scale_layer->AddChild(parent4);
9581 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:339582 parent2->AddChild(child6);
9583 parent3->AddChild(child7);
9584 parent3->AddChild(child8);
9585 parent4->AddChild(child9);
9586 child6->AddChild(grand_child10);
9587 child8->AddChild(grand_child11);
9588 child9->AddChild(grand_child12);
9589 host()->SetRootLayer(root1);
9590
9591 parent2->AddMainThreadScrollingReasons(
9592 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:489593 parent2->AddMainThreadScrollingReasons(
9594 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339595 parent2->SetScrollClipLayerId(root1->id());
9596 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:489597 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339598 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:489599 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339600
sunxdcfccd1b32016-02-11 00:54:209601 child7->SetScrollClipLayerId(parent3->id());
9602
sunxdea1df782016-01-28 00:12:339603 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:209604 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:339605
9606 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:209607 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:339608
danakj59931942016-07-26 22:11:299609 host()->RegisterViewportLayers(nullptr, page_scale_layer, parent2, nullptr);
sunxdea1df782016-01-28 00:12:339610 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get());
9611
9612 const int kInvalidPropertyTreeNodeId = -1;
9613 const int kRootPropertyTreeNodeId = 0;
9614
9615 // Property tree root
ajumae4af47062016-05-24 23:59:049616 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:109617 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:209618 property_trees.is_main_thread = true;
9619 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:049620 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:339621 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
9622 property_tree_root->id = kRootPropertyTreeNodeId;
9623 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
9624 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
trchendba8b1502016-07-08 09:47:019625 property_tree_root->scrollable = false;
9626 property_tree_root->main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:489627 MainThreadScrollingReason::kNotScrollingOnMain;
trchendba8b1502016-07-08 09:47:019628 property_tree_root->contains_non_fast_scrollable_region = false;
9629 property_tree_root->transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:339630
9631 // The node owned by root1
9632 ScrollNode scroll_root1;
9633 scroll_root1.id = 1;
9634 scroll_root1.owner_id = root1->id();
trchendba8b1502016-07-08 09:47:019635 scroll_root1.user_scrollable_horizontal = true;
9636 scroll_root1.user_scrollable_vertical = true;
9637 scroll_root1.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:339638 expected_scroll_tree.Insert(scroll_root1, 0);
9639
9640 // The node owned by parent2
9641 ScrollNode scroll_parent2;
9642 scroll_parent2.id = 2;
9643 scroll_parent2.owner_id = parent2->id();
trchendba8b1502016-07-08 09:47:019644 scroll_parent2.scrollable = true;
9645 scroll_parent2.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:489646 parent2->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:019647 scroll_parent2.scroll_clip_layer_bounds = root1->bounds();
9648 scroll_parent2.bounds = parent2->bounds();
9649 scroll_parent2.max_scroll_offset_affected_by_page_scale = true;
9650 scroll_parent2.is_inner_viewport_scroll_layer = true;
9651 scroll_parent2.user_scrollable_horizontal = true;
9652 scroll_parent2.user_scrollable_vertical = true;
9653 scroll_parent2.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:339654 expected_scroll_tree.Insert(scroll_parent2, 1);
9655
9656 // The node owned by child6
9657 ScrollNode scroll_child6;
9658 scroll_child6.id = 3;
9659 scroll_child6.owner_id = child6->id();
trchendba8b1502016-07-08 09:47:019660 scroll_child6.main_thread_scrolling_reasons =
sunxd29f17bf422016-02-03 02:47:489661 child6->main_thread_scrolling_reasons();
trchendba8b1502016-07-08 09:47:019662 scroll_child6.should_flatten = true;
9663 scroll_child6.user_scrollable_horizontal = true;
9664 scroll_child6.user_scrollable_vertical = true;
9665 scroll_child6.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:339666 expected_scroll_tree.Insert(scroll_child6, 2);
9667
9668 // The node owned by child7, child7 also owns a transform node
9669 ScrollNode scroll_child7;
9670 scroll_child7.id = 4;
9671 scroll_child7.owner_id = child7->id();
trchendba8b1502016-07-08 09:47:019672 scroll_child7.scrollable = true;
9673 scroll_child7.scroll_clip_layer_bounds = parent3->bounds();
9674 scroll_child7.bounds = child7->bounds();
9675 scroll_child7.user_scrollable_horizontal = true;
9676 scroll_child7.user_scrollable_vertical = true;
9677 scroll_child7.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:339678 expected_scroll_tree.Insert(scroll_child7, 1);
9679
9680 // The node owned by grand_child11, grand_child11 also owns a transform node
9681 ScrollNode scroll_grand_child11;
9682 scroll_grand_child11.id = 5;
9683 scroll_grand_child11.owner_id = grand_child11->id();
trchendba8b1502016-07-08 09:47:019684 scroll_grand_child11.scrollable = true;
9685 scroll_grand_child11.user_scrollable_horizontal = true;
9686 scroll_grand_child11.user_scrollable_vertical = true;
9687 scroll_grand_child11.transform_id = grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:339688 expected_scroll_tree.Insert(scroll_grand_child11, 4);
9689
9690 // The node owned by parent5
9691 ScrollNode scroll_parent5;
9692 scroll_parent5.id = 8;
9693 scroll_parent5.owner_id = parent5->id();
trchendba8b1502016-07-08 09:47:019694 scroll_parent5.contains_non_fast_scrollable_region = true;
9695 scroll_parent5.bounds = gfx::Size(10, 10);
9696 scroll_parent5.should_flatten = true;
9697 scroll_parent5.user_scrollable_horizontal = true;
9698 scroll_parent5.user_scrollable_vertical = true;
9699 scroll_parent5.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:339700 expected_scroll_tree.Insert(scroll_parent5, 1);
9701
sunxdc044b11a2016-03-16 16:23:209702 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
9703 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
9704 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
9705 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:339706 expected_scroll_tree.set_needs_update(false);
9707
9708 EXPECT_EQ(expected_scroll_tree, scroll_tree);
9709
9710 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:209711 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:339712 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
9713 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
9714 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
9715 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
9716 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
9717 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
9718}
9719
[email protected]ba565742012-11-10 09:29:489720} // namespace
9721} // namespace cc