blob: 6234d87a3bc215491a69a343a45541d85314e527 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 The Chromium Authors. All rights reserved.
2// 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
danakj6496cba2014-10-16 01:31:087#include <algorithm>
[email protected]995708c52013-10-17 20:52:598#include <set>
9
[email protected]95e4e1a02013-03-18 07:09:0910#include "cc/animation/layer_animation_controller.h"
[email protected]1c3626e2014-04-09 17:49:2211#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5212#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5213#include "cc/layers/content_layer.h"
14#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5215#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5916#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5217#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4018#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2819#include "cc/layers/render_surface.h"
20#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4521#include "cc/output/copy_output_request.h"
22#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0323#include "cc/test/animation_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4524#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2825#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4526#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5927#include "cc/test/fake_picture_layer.h"
28#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0329#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2830#include "cc/test/layer_tree_host_common_test.h"
[email protected]556fd292013-03-18 08:03:0431#include "cc/trees/layer_tree_impl.h"
32#include "cc/trees/proxy.h"
33#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1834#include "testing/gmock/include/gmock/gmock.h"
35#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2036#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3737#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0038#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1439
[email protected]ba565742012-11-10 09:29:4840namespace cc {
[email protected]94f206c12012-08-25 00:09:1441namespace {
42
[email protected]96baf3e2012-10-22 23:09:5543class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3244 public:
[email protected]35322352014-08-08 01:36:2045 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:1446
dcheng716bedf2014-10-21 09:51:0847 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4748
[email protected]fb661802013-03-25 01:59:3249 private:
dcheng716bedf2014-10-21 09:51:0850 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1451};
52
[email protected]fb661802013-03-25 01:59:3253bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4454
[email protected]96baf3e2012-10-22 23:09:5555class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3256 public:
57 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0858 ~MockContentLayerClient() override {}
schenney0154bfa2015-02-05 19:46:4959 void PaintContents(SkCanvas* canvas,
60 const gfx::Rect& clip,
61 PaintingControlSetting picture_control) override {}
ajuma5e77f7d42014-11-27 14:19:1462 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
63 const gfx::Rect& clip,
schenney0154bfa2015-02-05 19:46:4964 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1465 NOTIMPLEMENTED();
66 return DisplayItemList::Create();
67 }
dcheng716bedf2014-10-21 09:51:0868 bool FillsBoundsCompletely() const override { return false; }
[email protected]f34a24232012-09-20 22:59:5569};
70
sohan.jyotie3bd6192014-10-13 07:13:5971scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer(
72 ContentLayerClient* delegate) {
73 scoped_refptr<FakePictureLayer> to_return =
74 FakePictureLayer::Create(delegate);
75 to_return->SetIsDrawable(true);
76 return to_return;
77}
78
[email protected]fb661802013-03-25 01:59:3279scoped_refptr<ContentLayer> CreateDrawableContentLayer(
80 ContentLayerClient* delegate) {
81 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
82 to_return->SetIsDrawable(true);
83 return to_return;
[email protected]f34a24232012-09-20 22:59:5584}
85
[email protected]989386c2013-07-18 21:37:2386#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
87 do { \
88 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
89 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4790 } while (false)
91
sohan.jyotie3bd6192014-10-13 07:13:5992#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
93 do { \
94 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \
95 } while (false)
96
[email protected]989386c2013-07-18 21:37:2397TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:3298 // Sanity check: For layers positioned at zero, with zero size,
99 // and with identity transforms, then the draw transform,
100 // screen space transform, and the hierarchy passed on to children
101 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14102
[email protected]fb661802013-03-25 01:59:32103 scoped_refptr<Layer> parent = Layer::Create();
104 scoped_refptr<Layer> child = Layer::Create();
105 scoped_refptr<Layer> grand_child = Layer::Create();
106 parent->AddChild(child);
107 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14108
enne2097cab2014-09-25 20:16:31109 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28110 host->SetRootLayer(parent);
111
[email protected]fb661802013-03-25 01:59:32112 gfx::Transform identity_matrix;
113 SetLayerPropertiesForTesting(parent.get(),
114 identity_matrix,
[email protected]a2566412014-06-05 03:14:20115 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32116 gfx::PointF(),
117 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57118 true,
[email protected]fb661802013-03-25 01:59:32119 false);
120 SetLayerPropertiesForTesting(child.get(),
121 identity_matrix,
[email protected]a2566412014-06-05 03:14:20122 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32123 gfx::PointF(),
124 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57125 true,
[email protected]fb661802013-03-25 01:59:32126 false);
127 SetLayerPropertiesForTesting(grand_child.get(),
128 identity_matrix,
[email protected]a2566412014-06-05 03:14:20129 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32130 gfx::PointF(),
131 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57132 true,
[email protected]fb661802013-03-25 01:59:32133 false);
[email protected]94f206c12012-08-25 00:09:14134
[email protected]fb661802013-03-25 01:59:32135 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14136
[email protected]fb661802013-03-25 01:59:32137 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
138 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
139 child->screen_space_transform());
140 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
141 grand_child->draw_transform());
142 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
143 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14144}
145
[email protected]f9e56702014-06-13 01:19:59146TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
147 scoped_refptr<Layer> parent = Layer::Create();
148 scoped_refptr<Layer> child = Layer::Create();
149 scoped_refptr<Layer> grand_child = Layer::Create();
150 parent->AddChild(child);
151 child->AddChild(grand_child);
152
enne2097cab2014-09-25 20:16:31153 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]f9e56702014-06-13 01:19:59154 host->SetRootLayer(parent);
155
156 gfx::Transform identity_matrix;
157 SetLayerPropertiesForTesting(parent.get(),
158 identity_matrix,
159 gfx::Point3F(),
160 gfx::PointF(),
161 gfx::Size(100, 100),
162 true,
163 false);
164 SetLayerPropertiesForTesting(child.get(),
165 identity_matrix,
166 gfx::Point3F(),
167 gfx::PointF(10, 10),
168 gfx::Size(100, 100),
169 true,
170 false);
171 // This would have previously caused us to skip our subtree, but this would be
172 // wrong; we need up-to-date draw properties to do hit testing on the layers
173 // with handlers.
174 child->SetOpacity(0.f);
175 SetLayerPropertiesForTesting(grand_child.get(),
176 identity_matrix,
177 gfx::Point3F(),
178 gfx::PointF(10, 10),
179 gfx::Size(100, 100),
180 true,
181 false);
182 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
183
184 ExecuteCalculateDrawProperties(parent.get());
185
186 // Check that we've computed draw properties for the subtree rooted at
187 // |child|.
188 EXPECT_FALSE(child->draw_transform().IsIdentity());
189 EXPECT_FALSE(grand_child->draw_transform().IsIdentity());
190}
191
[email protected]989386c2013-07-18 21:37:23192TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32193 gfx::Transform identity_matrix;
194 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14195
[email protected]fb661802013-03-25 01:59:32196 scoped_refptr<Layer> root = Layer::Create();
197 SetLayerPropertiesForTesting(root.get(),
198 identity_matrix,
[email protected]a2566412014-06-05 03:14:20199 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32200 gfx::PointF(),
201 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57202 true,
[email protected]fb661802013-03-25 01:59:32203 false);
204 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42205
enne2097cab2014-09-25 20:16:31206 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28207 host->SetRootLayer(root);
208
[email protected]fb661802013-03-25 01:59:32209 // Case 2: Setting the bounds of the layer should not affect either the draw
210 // transform or the screenspace transform.
211 gfx::Transform translation_to_center;
212 translation_to_center.Translate(5.0, 6.0);
213 SetLayerPropertiesForTesting(layer.get(),
214 identity_matrix,
[email protected]a2566412014-06-05 03:14:20215 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32216 gfx::PointF(),
217 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57218 true,
[email protected]fb661802013-03-25 01:59:32219 false);
220 ExecuteCalculateDrawProperties(root.get());
221 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
223 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14224
[email protected]fb661802013-03-25 01:59:32225 // Case 3: The anchor point by itself (without a layer transform) should have
226 // no effect on the transforms.
227 SetLayerPropertiesForTesting(layer.get(),
228 identity_matrix,
[email protected]a2566412014-06-05 03:14:20229 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32230 gfx::PointF(),
231 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57232 true,
[email protected]fb661802013-03-25 01:59:32233 false);
234 ExecuteCalculateDrawProperties(root.get());
235 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
236 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
237 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14238
[email protected]fb661802013-03-25 01:59:32239 // Case 4: A change in actual position affects both the draw transform and
240 // screen space transform.
241 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05242 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32243 SetLayerPropertiesForTesting(layer.get(),
244 identity_matrix,
[email protected]a2566412014-06-05 03:14:20245 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32246 gfx::PointF(0.f, 1.2f),
247 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57248 true,
[email protected]fb661802013-03-25 01:59:32249 false);
250 ExecuteCalculateDrawProperties(root.get());
251 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
253 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14254
[email protected]fb661802013-03-25 01:59:32255 // Case 5: In the correct sequence of transforms, the layer transform should
256 // pre-multiply the translation_to_center. This is easily tested by using a
257 // scale transform, because scale and translation are not commutative.
258 gfx::Transform layer_transform;
259 layer_transform.Scale3d(2.0, 2.0, 1.0);
260 SetLayerPropertiesForTesting(layer.get(),
261 layer_transform,
[email protected]a2566412014-06-05 03:14:20262 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32263 gfx::PointF(),
264 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57265 true,
[email protected]fb661802013-03-25 01:59:32266 false);
267 ExecuteCalculateDrawProperties(root.get());
268 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
269 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
270 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14271
[email protected]fb661802013-03-25 01:59:32272 // Case 6: The layer transform should occur with respect to the anchor point.
273 gfx::Transform translation_to_anchor;
274 translation_to_anchor.Translate(5.0, 0.0);
275 gfx::Transform expected_result =
276 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
277 SetLayerPropertiesForTesting(layer.get(),
278 layer_transform,
[email protected]a2566412014-06-05 03:14:20279 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32280 gfx::PointF(),
281 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57282 true,
[email protected]fb661802013-03-25 01:59:32283 false);
284 ExecuteCalculateDrawProperties(root.get());
285 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
286 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
287 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14288
[email protected]fb661802013-03-25 01:59:32289 // Case 7: Verify that position pre-multiplies the layer transform. The
290 // current implementation of CalculateDrawProperties does this implicitly, but
291 // it is still worth testing to detect accidental regressions.
292 expected_result = position_transform * translation_to_anchor *
293 layer_transform * Inverse(translation_to_anchor);
294 SetLayerPropertiesForTesting(layer.get(),
295 layer_transform,
[email protected]a2566412014-06-05 03:14:20296 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32297 gfx::PointF(0.f, 1.2f),
298 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57299 true,
[email protected]fb661802013-03-25 01:59:32300 false);
301 ExecuteCalculateDrawProperties(root.get());
302 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
303 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
304 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14305}
306
[email protected]989386c2013-07-18 21:37:23307TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13308 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32309 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01310 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32311 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
312 -kScrollOffset.y());
313 const float kPageScale = 0.888f;
314 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20315
[email protected]fb661802013-03-25 01:59:32316 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45317 TestSharedBitmapManager shared_bitmap_manager;
318 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]657b24c2013-03-06 09:01:20319
[email protected]fb661802013-03-25 01:59:32320 gfx::Transform identity_matrix;
321 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
322 LayerImpl::Create(host_impl.active_tree(), 1));
323 LayerImpl* sublayer = sublayer_scoped_ptr.get();
324 sublayer->SetContentsScale(kPageScale * kDeviceScale,
325 kPageScale * kDeviceScale);
awoloszyne83f28c2014-12-22 15:40:00326 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
327 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32328 false);
[email protected]657b24c2013-03-06 09:01:20329
[email protected]adeda572014-01-31 00:49:47330 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32331 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47332 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00333 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
334 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32335 false);
[email protected]adeda572014-01-31 00:49:47336 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
337 LayerImpl::Create(host_impl.active_tree(), 4));
338 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
339
340 scroll_layer->SetScrollClipLayer(clip_layer->id());
341 clip_layer->SetBounds(
342 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
343 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
344 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32345 scroll_layer->SetScrollDelta(kScrollDelta);
346 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32347 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47348 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
349 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
aeliasf998da82015-02-03 01:40:51350 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20351
[email protected]fb661802013-03-25 01:59:32352 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00353 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
354 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32355 false);
[email protected]adeda572014-01-31 00:49:47356 root->AddChild(clip_layer_scoped_ptr.Pass());
awoloszyne83f28c2014-12-22 15:40:00357 root->SetHasRenderSurface(true);
[email protected]657b24c2013-03-06 09:01:20358
[email protected]f2136262013-04-26 21:10:19359 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32360 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32361 gfx::Transform expected_transform = identity_matrix;
362 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
363 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
364 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
365 MathUtil::Round(sub_layer_screen_position.y()));
366 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
367 sublayer->draw_transform());
368 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
369 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20370
[email protected]fb661802013-03-25 01:59:32371 gfx::Transform arbitrary_translate;
372 const float kTranslateX = 10.6f;
373 const float kTranslateY = 20.6f;
374 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00375 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
376 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
377 true, false, false);
[email protected]f2136262013-04-26 21:10:19378 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32379 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32380 expected_transform.MakeIdentity();
381 expected_transform.Translate(
382 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
383 sub_layer_screen_position.x()),
384 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
385 sub_layer_screen_position.y()));
386 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
387 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20388}
389
[email protected]989386c2013-07-18 21:37:23390TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32391 gfx::Transform identity_matrix;
392 scoped_refptr<Layer> root = Layer::Create();
393 scoped_refptr<Layer> parent = Layer::Create();
394 scoped_refptr<Layer> child = Layer::Create();
395 scoped_refptr<Layer> grand_child = Layer::Create();
396 root->AddChild(parent);
397 parent->AddChild(child);
398 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14399
enne2097cab2014-09-25 20:16:31400 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28401 host->SetRootLayer(root);
402
[email protected]fb661802013-03-25 01:59:32403 // One-time setup of root layer
404 SetLayerPropertiesForTesting(root.get(),
405 identity_matrix,
[email protected]a2566412014-06-05 03:14:20406 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32407 gfx::PointF(),
408 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57409 true,
[email protected]fb661802013-03-25 01:59:32410 false);
[email protected]ecc12622012-10-30 20:45:42411
[email protected]fb661802013-03-25 01:59:32412 // Case 1: parent's anchor point should not affect child or grand_child.
413 SetLayerPropertiesForTesting(parent.get(),
414 identity_matrix,
[email protected]a2566412014-06-05 03:14:20415 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32416 gfx::PointF(),
417 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57418 true,
[email protected]fb661802013-03-25 01:59:32419 false);
420 SetLayerPropertiesForTesting(child.get(),
421 identity_matrix,
[email protected]a2566412014-06-05 03:14:20422 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32423 gfx::PointF(),
424 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57425 true,
[email protected]fb661802013-03-25 01:59:32426 false);
427 SetLayerPropertiesForTesting(grand_child.get(),
428 identity_matrix,
[email protected]a2566412014-06-05 03:14:20429 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32430 gfx::PointF(),
431 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57432 true,
[email protected]fb661802013-03-25 01:59:32433 false);
434 ExecuteCalculateDrawProperties(root.get());
435 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
436 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
437 child->screen_space_transform());
438 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
439 grand_child->draw_transform());
440 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
441 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14442
[email protected]fb661802013-03-25 01:59:32443 // Case 2: parent's position affects child and grand_child.
444 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05445 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32446 SetLayerPropertiesForTesting(parent.get(),
447 identity_matrix,
[email protected]a2566412014-06-05 03:14:20448 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32449 gfx::PointF(0.f, 1.2f),
450 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57451 true,
[email protected]fb661802013-03-25 01:59:32452 false);
453 SetLayerPropertiesForTesting(child.get(),
454 identity_matrix,
[email protected]a2566412014-06-05 03:14:20455 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32456 gfx::PointF(),
457 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57458 true,
[email protected]fb661802013-03-25 01:59:32459 false);
460 SetLayerPropertiesForTesting(grand_child.get(),
461 identity_matrix,
[email protected]a2566412014-06-05 03:14:20462 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32463 gfx::PointF(),
464 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57465 true,
[email protected]fb661802013-03-25 01:59:32466 false);
467 ExecuteCalculateDrawProperties(root.get());
468 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
469 child->draw_transform());
470 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
471 child->screen_space_transform());
472 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
473 grand_child->draw_transform());
474 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
475 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14476
[email protected]fb661802013-03-25 01:59:32477 // Case 3: parent's local transform affects child and grandchild
478 gfx::Transform parent_layer_transform;
479 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
480 gfx::Transform parent_translation_to_anchor;
481 parent_translation_to_anchor.Translate(2.5, 3.0);
482 gfx::Transform parent_composite_transform =
483 parent_translation_to_anchor * parent_layer_transform *
484 Inverse(parent_translation_to_anchor);
485 SetLayerPropertiesForTesting(parent.get(),
486 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20487 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32488 gfx::PointF(),
489 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57490 true,
[email protected]fb661802013-03-25 01:59:32491 false);
492 SetLayerPropertiesForTesting(child.get(),
493 identity_matrix,
[email protected]a2566412014-06-05 03:14:20494 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32495 gfx::PointF(),
496 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57497 true,
[email protected]fb661802013-03-25 01:59:32498 false);
499 SetLayerPropertiesForTesting(grand_child.get(),
500 identity_matrix,
[email protected]a2566412014-06-05 03:14:20501 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32502 gfx::PointF(),
503 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57504 true,
[email protected]fb661802013-03-25 01:59:32505 false);
506 ExecuteCalculateDrawProperties(root.get());
507 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
508 child->draw_transform());
509 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
510 child->screen_space_transform());
511 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
512 grand_child->draw_transform());
513 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
514 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14515}
516
[email protected]989386c2013-07-18 21:37:23517TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32518 scoped_refptr<Layer> root = Layer::Create();
519 scoped_refptr<Layer> parent = Layer::Create();
520 scoped_refptr<Layer> child = Layer::Create();
521 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
522 make_scoped_refptr(new LayerWithForcedDrawsContent());
523 root->AddChild(parent);
524 parent->AddChild(child);
525 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14526
enne2097cab2014-09-25 20:16:31527 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28528 host->SetRootLayer(root);
529
[email protected]fb661802013-03-25 01:59:32530 // One-time setup of root layer
531 gfx::Transform identity_matrix;
532 SetLayerPropertiesForTesting(root.get(),
533 identity_matrix,
[email protected]a2566412014-06-05 03:14:20534 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32535 gfx::PointF(),
536 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57537 true,
[email protected]fb661802013-03-25 01:59:32538 false);
[email protected]ecc12622012-10-30 20:45:42539
[email protected]fb661802013-03-25 01:59:32540 // Child is set up so that a new render surface should be created.
541 child->SetOpacity(0.5f);
542 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14543
[email protected]fb661802013-03-25 01:59:32544 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05545 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32546 gfx::Transform parent_translation_to_anchor;
547 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44548
[email protected]fb661802013-03-25 01:59:32549 gfx::Transform parent_composite_transform =
550 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39551 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32552 gfx::Vector2dF parent_composite_scale =
553 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
554 1.f);
555 gfx::Transform surface_sublayer_transform;
556 surface_sublayer_transform.Scale(parent_composite_scale.x(),
557 parent_composite_scale.y());
558 gfx::Transform surface_sublayer_composite_transform =
559 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14560
[email protected]fb661802013-03-25 01:59:32561 // Child's render surface should not exist yet.
562 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14563
[email protected]fb661802013-03-25 01:59:32564 SetLayerPropertiesForTesting(parent.get(),
565 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20566 gfx::Point3F(25.0f, 30.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32567 gfx::PointF(),
568 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57569 true,
[email protected]fb661802013-03-25 01:59:32570 false);
571 SetLayerPropertiesForTesting(child.get(),
572 identity_matrix,
[email protected]a2566412014-06-05 03:14:20573 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32574 gfx::PointF(),
575 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57576 true,
[email protected]fb661802013-03-25 01:59:32577 false);
578 SetLayerPropertiesForTesting(grand_child.get(),
579 identity_matrix,
[email protected]a2566412014-06-05 03:14:20580 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32581 gfx::PointF(),
582 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57583 true,
[email protected]fb661802013-03-25 01:59:32584 false);
585 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14586
[email protected]fb661802013-03-25 01:59:32587 // Render surface should have been created now.
588 ASSERT_TRUE(child->render_surface());
Daniel Chengeea98042014-08-26 00:28:10589 ASSERT_EQ(child.get(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14590
[email protected]fb661802013-03-25 01:59:32591 // The child layer's draw transform should refer to its new render surface.
592 // The screen-space transform, however, should still refer to the root.
593 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
594 child->draw_transform());
595 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
596 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14597
[email protected]fb661802013-03-25 01:59:32598 // Because the grand_child is the only drawable content, the child's render
599 // surface will tighten its bounds to the grand_child. The scale at which the
600 // surface's subtree is drawn must be removed from the composite transform.
601 EXPECT_TRANSFORMATION_MATRIX_EQ(
602 surface_sublayer_composite_transform,
603 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14604
[email protected]fb661802013-03-25 01:59:32605 // The screen space is the same as the target since the child surface draws
606 // into the root.
607 EXPECT_TRANSFORMATION_MATRIX_EQ(
608 surface_sublayer_composite_transform,
609 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14610}
611
[email protected]989386c2013-07-18 21:37:23612TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32613 scoped_refptr<Layer> root = Layer::Create();
614 scoped_refptr<Layer> parent = Layer::Create();
615 scoped_refptr<Layer> child = Layer::Create();
616 scoped_refptr<Layer> child_replica = Layer::Create();
617 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
618 make_scoped_refptr(new LayerWithForcedDrawsContent());
619 root->AddChild(parent);
620 parent->AddChild(child);
621 child->AddChild(grand_child);
622 child->SetReplicaLayer(child_replica.get());
623
enne2097cab2014-09-25 20:16:31624 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28625 host->SetRootLayer(root);
626
[email protected]fb661802013-03-25 01:59:32627 // One-time setup of root layer
628 gfx::Transform identity_matrix;
629 SetLayerPropertiesForTesting(root.get(),
630 identity_matrix,
[email protected]a2566412014-06-05 03:14:20631 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32632 gfx::PointF(),
633 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57634 true,
[email protected]fb661802013-03-25 01:59:32635 false);
636
637 // Child is set up so that a new render surface should be created.
638 child->SetOpacity(0.5f);
639
640 gfx::Transform parent_layer_transform;
641 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
642 gfx::Transform parent_translation_to_anchor;
643 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32644 gfx::Transform parent_composite_transform =
645 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39646 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32647 gfx::Transform replica_layer_transform;
648 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
649 gfx::Vector2dF parent_composite_scale =
650 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
651 1.f);
652 gfx::Transform surface_sublayer_transform;
653 surface_sublayer_transform.Scale(parent_composite_scale.x(),
654 parent_composite_scale.y());
655 gfx::Transform replica_composite_transform =
656 parent_composite_transform * replica_layer_transform *
657 Inverse(surface_sublayer_transform);
vollick51ed1a22014-12-17 02:03:00658 child_replica->SetIsDrawable(true);
[email protected]fb661802013-03-25 01:59:32659 // Child's render surface should not exist yet.
660 ASSERT_FALSE(child->render_surface());
661
662 SetLayerPropertiesForTesting(parent.get(),
663 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20664 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32665 gfx::PointF(),
666 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57667 true,
[email protected]fb661802013-03-25 01:59:32668 false);
669 SetLayerPropertiesForTesting(child.get(),
670 identity_matrix,
[email protected]a2566412014-06-05 03:14:20671 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32672 gfx::PointF(),
673 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57674 true,
[email protected]fb661802013-03-25 01:59:32675 false);
676 SetLayerPropertiesForTesting(grand_child.get(),
677 identity_matrix,
[email protected]a2566412014-06-05 03:14:20678 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32679 gfx::PointF(-0.5f, -0.5f),
680 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57681 true,
[email protected]fb661802013-03-25 01:59:32682 false);
683 SetLayerPropertiesForTesting(child_replica.get(),
684 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20685 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32686 gfx::PointF(),
687 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57688 true,
[email protected]fb661802013-03-25 01:59:32689 false);
690 ExecuteCalculateDrawProperties(root.get());
691
692 // Render surface should have been created now.
693 ASSERT_TRUE(child->render_surface());
Daniel Chengeea98042014-08-26 00:28:10694 ASSERT_EQ(child.get(), child->render_target());
[email protected]fb661802013-03-25 01:59:32695
696 EXPECT_TRANSFORMATION_MATRIX_EQ(
697 replica_composite_transform,
698 child->render_target()->render_surface()->replica_draw_transform());
699 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57700 child->render_target()
701 ->render_surface()
[email protected]fb661802013-03-25 01:59:32702 ->replica_screen_space_transform());
703}
704
[email protected]989386c2013-07-18 21:37:23705TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32706 // This test creates a more complex tree and verifies it all at once. This
707 // covers the following cases:
708 // - layers that are described w.r.t. a render surface: should have draw
709 // transforms described w.r.t. that surface
710 // - A render surface described w.r.t. an ancestor render surface: should
711 // have a draw transform described w.r.t. that ancestor surface
712 // - Replicas of a render surface are described w.r.t. the replica's
713 // transform around its anchor, along with the surface itself.
714 // - Sanity check on recursion: verify transforms of layers described w.r.t.
715 // a render surface that is described w.r.t. an ancestor render surface.
716 // - verifying that each layer has a reference to the correct render surface
717 // and render target values.
718
719 scoped_refptr<Layer> root = Layer::Create();
720 scoped_refptr<Layer> parent = Layer::Create();
721 scoped_refptr<Layer> render_surface1 = Layer::Create();
722 scoped_refptr<Layer> render_surface2 = Layer::Create();
723 scoped_refptr<Layer> child_of_root = Layer::Create();
724 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
725 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
726 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
727 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
728 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
729 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
730 make_scoped_refptr(new LayerWithForcedDrawsContent());
731 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
732 make_scoped_refptr(new LayerWithForcedDrawsContent());
733 root->AddChild(parent);
734 parent->AddChild(render_surface1);
735 parent->AddChild(child_of_root);
736 render_surface1->AddChild(child_of_rs1);
737 render_surface1->AddChild(render_surface2);
738 render_surface2->AddChild(child_of_rs2);
739 child_of_root->AddChild(grand_child_of_root);
740 child_of_rs1->AddChild(grand_child_of_rs1);
741 child_of_rs2->AddChild(grand_child_of_rs2);
742 render_surface1->SetReplicaLayer(replica_of_rs1.get());
743 render_surface2->SetReplicaLayer(replica_of_rs2.get());
744
enne2097cab2014-09-25 20:16:31745 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28746 host->SetRootLayer(root);
747
[email protected]fb661802013-03-25 01:59:32748 // In combination with descendant draws content, opacity != 1 forces the layer
749 // to have a new render surface.
750 render_surface1->SetOpacity(0.5f);
751 render_surface2->SetOpacity(0.33f);
752
753 // One-time setup of root layer
754 gfx::Transform identity_matrix;
755 SetLayerPropertiesForTesting(root.get(),
756 identity_matrix,
[email protected]a2566412014-06-05 03:14:20757 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32758 gfx::PointF(),
759 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57760 true,
[email protected]fb661802013-03-25 01:59:32761 false);
762
763 // All layers in the tree are initialized with an anchor at .25 and a size of
764 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39765 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32766 gfx::Transform translation_to_anchor;
767 translation_to_anchor.Translate(2.5, 0.0);
768 gfx::Transform layer_transform;
769 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32770 gfx::Transform replica_layer_transform;
771 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
772
773 gfx::Transform A =
774 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32775 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
776 Inverse(translation_to_anchor);
777
778 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39779 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32780 gfx::Transform surface1_sublayer_transform;
781 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
782 surface1_parent_transform_scale.y());
783
784 // SS1 = transform given to the subtree of render_surface1
785 gfx::Transform SS1 = surface1_sublayer_transform;
786 // S1 = transform to move from render_surface1 pixels to the layer space of
787 // the owning layer
788 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
789
790 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39791 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32792 gfx::Transform surface2_sublayer_transform;
793 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
794 surface2_parent_transform_scale.y());
795
796 // SS2 = transform given to the subtree of render_surface2
797 gfx::Transform SS2 = surface2_sublayer_transform;
798 // S2 = transform to move from render_surface2 pixels to the layer space of
799 // the owning layer
800 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
801
802 SetLayerPropertiesForTesting(parent.get(),
803 layer_transform,
[email protected]a2566412014-06-05 03:14:20804 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32805 gfx::PointF(),
806 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57807 true,
[email protected]fb661802013-03-25 01:59:32808 false);
809 SetLayerPropertiesForTesting(render_surface1.get(),
810 layer_transform,
[email protected]a2566412014-06-05 03:14:20811 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32812 gfx::PointF(),
813 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57814 true,
[email protected]fb661802013-03-25 01:59:32815 false);
816 SetLayerPropertiesForTesting(render_surface2.get(),
817 layer_transform,
[email protected]a2566412014-06-05 03:14:20818 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32819 gfx::PointF(),
820 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57821 true,
[email protected]fb661802013-03-25 01:59:32822 false);
823 SetLayerPropertiesForTesting(child_of_root.get(),
824 layer_transform,
[email protected]a2566412014-06-05 03:14:20825 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32826 gfx::PointF(),
827 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57828 true,
[email protected]fb661802013-03-25 01:59:32829 false);
830 SetLayerPropertiesForTesting(child_of_rs1.get(),
831 layer_transform,
[email protected]a2566412014-06-05 03:14:20832 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32833 gfx::PointF(),
834 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57835 true,
[email protected]fb661802013-03-25 01:59:32836 false);
837 SetLayerPropertiesForTesting(child_of_rs2.get(),
838 layer_transform,
[email protected]a2566412014-06-05 03:14:20839 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32840 gfx::PointF(),
841 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57842 true,
[email protected]fb661802013-03-25 01:59:32843 false);
844 SetLayerPropertiesForTesting(grand_child_of_root.get(),
845 layer_transform,
[email protected]a2566412014-06-05 03:14:20846 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32847 gfx::PointF(),
848 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57849 true,
[email protected]fb661802013-03-25 01:59:32850 false);
851 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
852 layer_transform,
[email protected]a2566412014-06-05 03:14:20853 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32854 gfx::PointF(),
855 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57856 true,
[email protected]fb661802013-03-25 01:59:32857 false);
858 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
859 layer_transform,
[email protected]a2566412014-06-05 03:14:20860 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32861 gfx::PointF(),
862 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57863 true,
[email protected]fb661802013-03-25 01:59:32864 false);
865 SetLayerPropertiesForTesting(replica_of_rs1.get(),
866 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20867 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32868 gfx::PointF(),
869 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57870 true,
[email protected]fb661802013-03-25 01:59:32871 false);
872 SetLayerPropertiesForTesting(replica_of_rs2.get(),
873 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20874 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32875 gfx::PointF(),
876 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57877 true,
[email protected]fb661802013-03-25 01:59:32878 false);
879
880 ExecuteCalculateDrawProperties(root.get());
881
882 // Only layers that are associated with render surfaces should have an actual
883 // RenderSurface() value.
884 ASSERT_TRUE(root->render_surface());
885 ASSERT_FALSE(child_of_root->render_surface());
886 ASSERT_FALSE(grand_child_of_root->render_surface());
887
888 ASSERT_TRUE(render_surface1->render_surface());
889 ASSERT_FALSE(child_of_rs1->render_surface());
890 ASSERT_FALSE(grand_child_of_rs1->render_surface());
891
892 ASSERT_TRUE(render_surface2->render_surface());
893 ASSERT_FALSE(child_of_rs2->render_surface());
894 ASSERT_FALSE(grand_child_of_rs2->render_surface());
895
896 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:10897 EXPECT_EQ(root.get(), parent->render_target());
898 EXPECT_EQ(root.get(), child_of_root->render_target());
899 EXPECT_EQ(root.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32900
Daniel Chengeea98042014-08-26 00:28:10901 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
902 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
903 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32904
Daniel Chengeea98042014-08-26 00:28:10905 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
906 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
907 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32908
909 // Verify layer draw transforms note that draw transforms are described with
910 // respect to the nearest ancestor render surface but screen space transforms
911 // are described with respect to the root.
912 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:39913 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
914 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32915 grand_child_of_root->draw_transform());
916
917 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:39918 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
919 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:32920 grand_child_of_rs1->draw_transform());
921
922 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:39923 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
924 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:32925 grand_child_of_rs2->draw_transform());
926
927 // Verify layer screen-space transforms
928 //
929 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39930 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32931 child_of_root->screen_space_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39933 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32934
[email protected]baf64d062014-02-16 22:10:39935 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32936 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39937 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32938 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39939 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32940 grand_child_of_rs1->screen_space_transform());
941
[email protected]baf64d062014-02-16 22:10:39942 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32943 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39944 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32945 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39946 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:32947 grand_child_of_rs2->screen_space_transform());
948
949 // Verify render surface transforms.
950 //
951 // Draw transform of render surface 1 is described with respect to root.
952 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39953 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32954 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39955 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32956 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39957 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32958 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39959 A * R * S1,
[email protected]fb661802013-03-25 01:59:32960 render_surface1->render_surface()->replica_screen_space_transform());
961 // Draw transform of render surface 2 is described with respect to render
962 // surface 1.
963 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39964 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32965 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39966 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32967 render_surface2->render_surface()->replica_draw_transform());
968 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39969 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32970 render_surface2->render_surface()->screen_space_transform());
971 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39972 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32973 render_surface2->render_surface()->replica_screen_space_transform());
974
975 // Sanity check. If these fail there is probably a bug in the test itself. It
976 // is expected that we correctly set up transforms so that the y-component of
977 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:26978 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
979 EXPECT_FLOAT_EQ(2.0,
980 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32981 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26982 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32983
[email protected]803f6b52013-09-12 00:51:26984 EXPECT_FLOAT_EQ(2.0,
985 render_surface1->screen_space_transform().matrix().get(1, 3));
986 EXPECT_FLOAT_EQ(3.0,
987 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32988 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26989 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32990
[email protected]803f6b52013-09-12 00:51:26991 EXPECT_FLOAT_EQ(3.0,
992 render_surface2->screen_space_transform().matrix().get(1, 3));
993 EXPECT_FLOAT_EQ(4.0,
994 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32995 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26996 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32997}
998
[email protected]989386c2013-07-18 21:37:23999TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321000 // For layers that flatten their subtree, there should be an orthographic
1001 // projection (for x and y values) in the middle of the transform sequence.
1002 // Note that the way the code is currently implemented, it is not expected to
1003 // use a canonical orthographic projection.
1004
1005 scoped_refptr<Layer> root = Layer::Create();
1006 scoped_refptr<Layer> child = Layer::Create();
1007 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1008 make_scoped_refptr(new LayerWithForcedDrawsContent());
1009
1010 gfx::Transform rotation_about_y_axis;
1011 rotation_about_y_axis.RotateAboutYAxis(30.0);
1012
1013 const gfx::Transform identity_matrix;
1014 SetLayerPropertiesForTesting(root.get(),
1015 identity_matrix,
[email protected]a2566412014-06-05 03:14:201016 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321017 gfx::PointF(),
1018 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571019 true,
[email protected]fb661802013-03-25 01:59:321020 false);
1021 SetLayerPropertiesForTesting(child.get(),
1022 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201023 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321024 gfx::PointF(),
1025 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571026 true,
[email protected]fb661802013-03-25 01:59:321027 false);
1028 SetLayerPropertiesForTesting(grand_child.get(),
1029 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201030 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321031 gfx::PointF(),
1032 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571033 true,
[email protected]fb661802013-03-25 01:59:321034 false);
1035
1036 root->AddChild(child);
1037 child->AddChild(grand_child);
1038 child->SetForceRenderSurface(true);
1039
enne2097cab2014-09-25 20:16:311040 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281041 host->SetRootLayer(root);
1042
[email protected]fb661802013-03-25 01:59:321043 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571044 ASSERT_TRUE(root->should_flatten_transform());
1045 ASSERT_TRUE(child->should_flatten_transform());
1046 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321047
1048 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1049 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1050 gfx::Transform expected_grand_child_draw_transform =
1051 rotation_about_y_axis; // draws onto child's render surface
1052 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1053 flattened_rotation_about_y.FlattenTo2d();
1054 gfx::Transform expected_grand_child_screen_space_transform =
1055 flattened_rotation_about_y * rotation_about_y_axis;
1056
1057 ExecuteCalculateDrawProperties(root.get());
1058
1059 // The child's draw transform should have been taken by its surface.
1060 ASSERT_TRUE(child->render_surface());
1061 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1062 child->render_surface()->draw_transform());
1063 EXPECT_TRANSFORMATION_MATRIX_EQ(
1064 expected_child_screen_space_transform,
1065 child->render_surface()->screen_space_transform());
1066 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1067 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1068 child->screen_space_transform());
1069 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1070 grand_child->draw_transform());
1071 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1072 grand_child->screen_space_transform());
1073}
1074
[email protected]989386c2013-07-18 21:37:231075TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321076 // A layer that is empty in one axis, but not the other, was accidentally
1077 // skipping a necessary translation. Without that translation, the coordinate
1078 // space of the layer's draw transform is incorrect.
1079 //
1080 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1081 // but if that layer becomes a render surface, then its draw transform is
1082 // implicitly inherited by the rest of the subtree, which then is positioned
1083 // incorrectly as a result.
1084
1085 scoped_refptr<Layer> root = Layer::Create();
1086 scoped_refptr<Layer> child = Layer::Create();
1087 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1088 make_scoped_refptr(new LayerWithForcedDrawsContent());
1089
1090 // The child height is zero, but has non-zero width that should be accounted
1091 // for while computing draw transforms.
1092 const gfx::Transform identity_matrix;
1093 SetLayerPropertiesForTesting(root.get(),
1094 identity_matrix,
[email protected]a2566412014-06-05 03:14:201095 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321096 gfx::PointF(),
1097 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571098 true,
[email protected]fb661802013-03-25 01:59:321099 false);
1100 SetLayerPropertiesForTesting(child.get(),
1101 identity_matrix,
[email protected]a2566412014-06-05 03:14:201102 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321103 gfx::PointF(),
1104 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571105 true,
[email protected]fb661802013-03-25 01:59:321106 false);
1107 SetLayerPropertiesForTesting(grand_child.get(),
1108 identity_matrix,
[email protected]a2566412014-06-05 03:14:201109 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321110 gfx::PointF(),
1111 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571112 true,
[email protected]fb661802013-03-25 01:59:321113 false);
1114
1115 root->AddChild(child);
1116 child->AddChild(grand_child);
1117 child->SetForceRenderSurface(true);
1118
enne2097cab2014-09-25 20:16:311119 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281120 host->SetRootLayer(root);
1121
[email protected]fb661802013-03-25 01:59:321122 ExecuteCalculateDrawProperties(root.get());
1123
1124 ASSERT_TRUE(child->render_surface());
1125 // This is the real test, the rest are sanity checks.
1126 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1127 child->render_surface()->draw_transform());
1128 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1129 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1130 grand_child->draw_transform());
1131}
1132
[email protected]989386c2013-07-18 21:37:231133TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321134 // Transformations applied at the root of the tree should be forwarded
1135 // to child layers instead of applied to the root RenderSurface.
1136 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291137 scoped_refptr<LayerWithForcedDrawsContent> root =
1138 new LayerWithForcedDrawsContent;
1139 scoped_refptr<LayerWithForcedDrawsContent> child =
1140 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471141 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321142 root->AddChild(child);
1143
enne2097cab2014-09-25 20:16:311144 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281145 host->SetRootLayer(root);
1146
[email protected]f224cc92013-06-06 23:23:321147 SetLayerPropertiesForTesting(root.get(),
1148 identity_matrix,
[email protected]a2566412014-06-05 03:14:201149 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321150 gfx::PointF(),
1151 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571152 true,
[email protected]f224cc92013-06-06 23:23:321153 false);
1154 SetLayerPropertiesForTesting(child.get(),
1155 identity_matrix,
[email protected]a2566412014-06-05 03:14:201156 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321157 gfx::PointF(),
1158 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571159 true,
[email protected]f224cc92013-06-06 23:23:321160 false);
1161
[email protected]f224cc92013-06-06 23:23:321162 gfx::Transform translate;
1163 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231164 {
1165 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531166 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221167 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531168 inputs.can_adjust_raster_scales = true;
1169 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231170 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1171 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1172 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201173 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1174 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231175 }
[email protected]f224cc92013-06-06 23:23:321176
1177 gfx::Transform scale;
1178 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231179 {
1180 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531181 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221182 root.get(), root->bounds(), scale, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531183 inputs.can_adjust_raster_scales = true;
1184 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231185 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1186 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1187 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201188 EXPECT_EQ(2.f, root->draw_properties().device_scale_factor);
1189 EXPECT_EQ(2.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231190 }
[email protected]f224cc92013-06-06 23:23:321191
1192 gfx::Transform rotate;
1193 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231194 {
1195 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531196 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221197 root.get(), root->bounds(), rotate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531198 inputs.can_adjust_raster_scales = true;
1199 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231200 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1201 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1202 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201203 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1204 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231205 }
[email protected]f224cc92013-06-06 23:23:321206
1207 gfx::Transform composite;
1208 composite.ConcatTransform(translate);
1209 composite.ConcatTransform(scale);
1210 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231211 {
1212 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531213 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221214 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531215 inputs.can_adjust_raster_scales = true;
1216 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231217 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1218 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1219 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1220 }
[email protected]f224cc92013-06-06 23:23:321221
[email protected]9781afa2013-07-17 23:15:321222 // Verify it composes correctly with device scale.
1223 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231224
1225 {
1226 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531227 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221228 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531229 inputs.device_scale_factor = device_scale_factor;
1230 inputs.can_adjust_raster_scales = true;
1231 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231232 gfx::Transform device_scaled_translate = translate;
1233 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1234 EXPECT_EQ(device_scaled_translate,
1235 root->draw_properties().target_space_transform);
1236 EXPECT_EQ(device_scaled_translate,
1237 child->draw_properties().target_space_transform);
1238 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201239 EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor);
1240 EXPECT_EQ(device_scale_factor,
1241 child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231242 }
[email protected]9781afa2013-07-17 23:15:321243
1244 // Verify it composes correctly with page scale.
1245 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231246
1247 {
1248 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531249 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221250 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531251 inputs.page_scale_factor = page_scale_factor;
1252 inputs.page_scale_application_layer = root.get();
1253 inputs.can_adjust_raster_scales = true;
1254 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231255 gfx::Transform page_scaled_translate = translate;
1256 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1257 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1258 EXPECT_EQ(page_scaled_translate,
1259 child->draw_properties().target_space_transform);
1260 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201261 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1262 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231263 }
[email protected]9781afa2013-07-17 23:15:321264
[email protected]f224cc92013-06-06 23:23:321265 // Verify that it composes correctly with transforms directly on root layer.
1266 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231267
1268 {
1269 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531270 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221271 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531272 inputs.can_adjust_raster_scales = true;
1273 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231274 gfx::Transform compositeSquared = composite;
1275 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261276 EXPECT_TRANSFORMATION_MATRIX_EQ(
1277 compositeSquared, root->draw_properties().target_space_transform);
1278 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391279 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231280 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1281 }
[email protected]f224cc92013-06-06 23:23:321282}
1283
[email protected]989386c2013-07-18 21:37:231284TEST_F(LayerTreeHostCommonTest,
1285 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321286 scoped_refptr<Layer> parent = Layer::Create();
1287 scoped_refptr<Layer> render_surface1 = Layer::Create();
1288 scoped_refptr<LayerWithForcedDrawsContent> child =
1289 make_scoped_refptr(new LayerWithForcedDrawsContent());
1290
enne2097cab2014-09-25 20:16:311291 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281292 host->SetRootLayer(parent);
1293
[email protected]fb661802013-03-25 01:59:321294 const gfx::Transform identity_matrix;
1295 SetLayerPropertiesForTesting(parent.get(),
1296 identity_matrix,
[email protected]a2566412014-06-05 03:14:201297 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321298 gfx::PointF(),
1299 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571300 true,
[email protected]fb661802013-03-25 01:59:321301 false);
1302 SetLayerPropertiesForTesting(render_surface1.get(),
1303 identity_matrix,
[email protected]a2566412014-06-05 03:14:201304 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321305 gfx::PointF(),
1306 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571307 true,
[email protected]fb661802013-03-25 01:59:321308 false);
1309 SetLayerPropertiesForTesting(child.get(),
1310 identity_matrix,
[email protected]a2566412014-06-05 03:14:201311 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321312 gfx::PointF(30.f, 30.f),
1313 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571314 true,
[email protected]fb661802013-03-25 01:59:321315 false);
1316
1317 parent->AddChild(render_surface1);
1318 parent->SetMasksToBounds(true);
1319 render_surface1->AddChild(child);
1320 render_surface1->SetForceRenderSurface(true);
1321
[email protected]989386c2013-07-18 21:37:231322 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531323 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1324 parent.get(),
1325 parent->bounds(),
1326 gfx::Transform(),
1327 &render_surface_layer_list);
1328 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321329
1330 // The child layer's content is entirely outside the parent's clip rect, so
1331 // the intermediate render surface should not be listed here, even if it was
1332 // forced to be created. Render surfaces without children or visible content
1333 // are unexpected at draw time (e.g. we might try to create a content texture
1334 // of size 0).
1335 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321336 EXPECT_EQ(1U, render_surface_layer_list.size());
1337}
1338
[email protected]989386c2013-07-18 21:37:231339TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321340 scoped_refptr<Layer> parent = Layer::Create();
1341 scoped_refptr<Layer> render_surface1 = Layer::Create();
1342 scoped_refptr<LayerWithForcedDrawsContent> child =
1343 make_scoped_refptr(new LayerWithForcedDrawsContent());
1344
enne2097cab2014-09-25 20:16:311345 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281346 host->SetRootLayer(parent);
1347
[email protected]fb661802013-03-25 01:59:321348 const gfx::Transform identity_matrix;
1349 SetLayerPropertiesForTesting(render_surface1.get(),
1350 identity_matrix,
[email protected]a2566412014-06-05 03:14:201351 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321352 gfx::PointF(),
1353 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571354 true,
[email protected]fb661802013-03-25 01:59:321355 false);
1356 SetLayerPropertiesForTesting(child.get(),
1357 identity_matrix,
[email protected]a2566412014-06-05 03:14:201358 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321359 gfx::PointF(),
1360 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571361 true,
[email protected]fb661802013-03-25 01:59:321362 false);
1363
1364 parent->AddChild(render_surface1);
1365 render_surface1->AddChild(child);
1366 render_surface1->SetForceRenderSurface(true);
1367 render_surface1->SetOpacity(0.f);
1368
[email protected]989386c2013-07-18 21:37:231369 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531370 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1371 parent.get(), parent->bounds(), &render_surface_layer_list);
1372 inputs.can_adjust_raster_scales = true;
1373 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321374
1375 // Since the layer is transparent, render_surface1->render_surface() should
1376 // not have gotten added anywhere. Also, the drawable content rect should not
1377 // have been extended by the children.
1378 ASSERT_TRUE(parent->render_surface());
1379 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1380 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231381 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321382 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1383}
1384
rosca948d29d2014-11-09 10:25:131385TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1386 scoped_refptr<Layer> parent = Layer::Create();
1387 scoped_refptr<LayerWithForcedDrawsContent> child =
1388 make_scoped_refptr(new LayerWithForcedDrawsContent());
1389
1390 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1391 host->SetRootLayer(parent);
1392
1393 const gfx::Transform identity_matrix;
1394 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1395 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1396 gfx::PointF(), gfx::Size(10, 10), true, false);
1397
1398 parent->AddChild(child);
1399 child->SetBlendMode(blend_mode);
1400
1401 RenderSurfaceLayerList render_surface_layer_list;
1402 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1403 parent.get(), parent->bounds(), &render_surface_layer_list);
1404 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1405
1406 // Since the child layer has a blend mode other than normal, it should get
1407 // its own render surface. Also, layer's draw_properties should contain the
1408 // default blend mode, since the render surface becomes responsible for
1409 // applying the blend mode.
1410 ASSERT_TRUE(child->render_surface());
1411 EXPECT_EQ(1U, child->render_surface()->layer_list().size());
1412 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode);
1413}
1414
[email protected]989386c2013-07-18 21:37:231415TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321416 scoped_refptr<Layer> parent = Layer::Create();
1417 scoped_refptr<Layer> render_surface1 = Layer::Create();
1418 scoped_refptr<LayerWithForcedDrawsContent> child =
1419 make_scoped_refptr(new LayerWithForcedDrawsContent());
1420 render_surface1->SetForceRenderSurface(true);
1421
enne2097cab2014-09-25 20:16:311422 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281423 host->SetRootLayer(parent);
1424
[email protected]fb661802013-03-25 01:59:321425 const gfx::Transform identity_matrix;
1426 SetLayerPropertiesForTesting(parent.get(),
1427 identity_matrix,
[email protected]a2566412014-06-05 03:14:201428 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321429 gfx::PointF(),
1430 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571431 true,
[email protected]fb661802013-03-25 01:59:321432 false);
1433 SetLayerPropertiesForTesting(render_surface1.get(),
1434 identity_matrix,
[email protected]a2566412014-06-05 03:14:201435 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321436 gfx::PointF(),
1437 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571438 true,
[email protected]fb661802013-03-25 01:59:321439 false);
1440 SetLayerPropertiesForTesting(child.get(),
1441 identity_matrix,
[email protected]a2566412014-06-05 03:14:201442 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321443 gfx::PointF(),
1444 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571445 true,
[email protected]fb661802013-03-25 01:59:321446 false);
1447
1448 parent->AddChild(render_surface1);
1449 render_surface1->AddChild(child);
1450
1451 // Sanity check before the actual test
1452 EXPECT_FALSE(parent->render_surface());
1453 EXPECT_FALSE(render_surface1->render_surface());
1454
[email protected]989386c2013-07-18 21:37:231455 {
1456 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531457 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1458 parent.get(), parent->bounds(), &render_surface_layer_list);
1459 inputs.can_adjust_raster_scales = true;
1460 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321461
[email protected]989386c2013-07-18 21:37:231462 // The root layer always creates a render surface
1463 EXPECT_TRUE(parent->render_surface());
1464 EXPECT_TRUE(render_surface1->render_surface());
1465 EXPECT_EQ(2U, render_surface_layer_list.size());
1466 }
[email protected]fb661802013-03-25 01:59:321467
[email protected]989386c2013-07-18 21:37:231468 {
1469 RenderSurfaceLayerList render_surface_layer_list;
1470 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531471 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1472 parent.get(), parent->bounds(), &render_surface_layer_list);
1473 inputs.can_adjust_raster_scales = true;
1474 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231475 EXPECT_TRUE(parent->render_surface());
1476 EXPECT_FALSE(render_surface1->render_surface());
1477 EXPECT_EQ(1U, render_surface_layer_list.size());
1478 }
[email protected]fb661802013-03-25 01:59:321479}
1480
[email protected]989386c2013-07-18 21:37:231481TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321482 // The entire subtree of layers that are outside the clip rect should be
1483 // culled away, and should not affect the render_surface_layer_list.
1484 //
1485 // The test tree is set up as follows:
1486 // - all layers except the leaf_nodes are forced to be a new render surface
1487 // that have something to draw.
1488 // - parent is a large container layer.
1489 // - child has masksToBounds=true to cause clipping.
1490 // - grand_child is positioned outside of the child's bounds
1491 // - great_grand_child is also kept outside child's bounds.
1492 //
1493 // In this configuration, grand_child and great_grand_child are completely
1494 // outside the clip rect, and they should never get scheduled on the list of
1495 // render surfaces.
1496 //
1497
1498 const gfx::Transform identity_matrix;
1499 scoped_refptr<Layer> parent = Layer::Create();
1500 scoped_refptr<Layer> child = Layer::Create();
1501 scoped_refptr<Layer> grand_child = Layer::Create();
1502 scoped_refptr<Layer> great_grand_child = Layer::Create();
1503 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1504 make_scoped_refptr(new LayerWithForcedDrawsContent());
1505 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1506 make_scoped_refptr(new LayerWithForcedDrawsContent());
1507 parent->AddChild(child);
1508 child->AddChild(grand_child);
1509 grand_child->AddChild(great_grand_child);
1510
enne2097cab2014-09-25 20:16:311511 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281512 host->SetRootLayer(parent);
1513
[email protected]fb661802013-03-25 01:59:321514 // leaf_node1 ensures that parent and child are kept on the
1515 // render_surface_layer_list, even though grand_child and great_grand_child
1516 // should be clipped.
1517 child->AddChild(leaf_node1);
1518 great_grand_child->AddChild(leaf_node2);
1519
1520 SetLayerPropertiesForTesting(parent.get(),
1521 identity_matrix,
[email protected]a2566412014-06-05 03:14:201522 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321523 gfx::PointF(),
1524 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571525 true,
[email protected]fb661802013-03-25 01:59:321526 false);
1527 SetLayerPropertiesForTesting(child.get(),
1528 identity_matrix,
[email protected]a2566412014-06-05 03:14:201529 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321530 gfx::PointF(),
1531 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571532 true,
[email protected]fb661802013-03-25 01:59:321533 false);
1534 SetLayerPropertiesForTesting(grand_child.get(),
1535 identity_matrix,
[email protected]a2566412014-06-05 03:14:201536 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321537 gfx::PointF(45.f, 45.f),
1538 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571539 true,
[email protected]fb661802013-03-25 01:59:321540 false);
1541 SetLayerPropertiesForTesting(great_grand_child.get(),
1542 identity_matrix,
[email protected]a2566412014-06-05 03:14:201543 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321544 gfx::PointF(),
1545 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571546 true,
[email protected]fb661802013-03-25 01:59:321547 false);
1548 SetLayerPropertiesForTesting(leaf_node1.get(),
1549 identity_matrix,
[email protected]a2566412014-06-05 03:14:201550 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321551 gfx::PointF(),
1552 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571553 true,
[email protected]fb661802013-03-25 01:59:321554 false);
1555 SetLayerPropertiesForTesting(leaf_node2.get(),
1556 identity_matrix,
[email protected]a2566412014-06-05 03:14:201557 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321558 gfx::PointF(),
1559 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571560 true,
[email protected]fb661802013-03-25 01:59:321561 false);
1562
1563 child->SetMasksToBounds(true);
1564 child->SetOpacity(0.4f);
1565 child->SetForceRenderSurface(true);
1566 grand_child->SetOpacity(0.5f);
1567 great_grand_child->SetOpacity(0.4f);
1568
[email protected]989386c2013-07-18 21:37:231569 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531570 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1571 parent.get(), parent->bounds(), &render_surface_layer_list);
1572 inputs.can_adjust_raster_scales = true;
1573 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321574
1575 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231576 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1577 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321578}
1579
[email protected]989386c2013-07-18 21:37:231580TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321581 // When a render surface has a clip rect, it is used to clip the content rect
1582 // of the surface. When the render surface is animating its transforms, then
1583 // the content rect's position in the clip rect is not defined on the main
1584 // thread, and its content rect should not be clipped.
1585
1586 // The test tree is set up as follows:
1587 // - parent is a container layer that masksToBounds=true to cause clipping.
1588 // - child is a render surface, which has a clip rect set to the bounds of
1589 // the parent.
1590 // - grand_child is a render surface, and the only visible content in child.
1591 // It is positioned outside of the clip rect from parent.
1592
1593 // In this configuration, grand_child should be outside the clipped
1594 // content rect of the child, making grand_child not appear in the
1595 // render_surface_layer_list. However, when we place an animation on the
1596 // child, this clipping should be avoided and we should keep the grand_child
1597 // in the render_surface_layer_list.
1598
1599 const gfx::Transform identity_matrix;
1600 scoped_refptr<Layer> parent = Layer::Create();
1601 scoped_refptr<Layer> child = Layer::Create();
1602 scoped_refptr<Layer> grand_child = Layer::Create();
1603 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1604 make_scoped_refptr(new LayerWithForcedDrawsContent());
1605 parent->AddChild(child);
1606 child->AddChild(grand_child);
1607 grand_child->AddChild(leaf_node);
1608
enne2097cab2014-09-25 20:16:311609 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281610 host->SetRootLayer(parent);
1611
[email protected]fb661802013-03-25 01:59:321612 SetLayerPropertiesForTesting(parent.get(),
1613 identity_matrix,
[email protected]a2566412014-06-05 03:14:201614 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321615 gfx::PointF(),
1616 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571617 true,
[email protected]fb661802013-03-25 01:59:321618 false);
1619 SetLayerPropertiesForTesting(child.get(),
1620 identity_matrix,
[email protected]a2566412014-06-05 03:14:201621 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321622 gfx::PointF(),
1623 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571624 true,
[email protected]fb661802013-03-25 01:59:321625 false);
1626 SetLayerPropertiesForTesting(grand_child.get(),
1627 identity_matrix,
[email protected]a2566412014-06-05 03:14:201628 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321629 gfx::PointF(200.f, 200.f),
1630 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571631 true,
[email protected]fb661802013-03-25 01:59:321632 false);
1633 SetLayerPropertiesForTesting(leaf_node.get(),
1634 identity_matrix,
[email protected]a2566412014-06-05 03:14:201635 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321636 gfx::PointF(),
1637 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571638 true,
[email protected]fb661802013-03-25 01:59:321639 false);
1640
1641 parent->SetMasksToBounds(true);
1642 child->SetOpacity(0.4f);
1643 child->SetForceRenderSurface(true);
1644 grand_child->SetOpacity(0.4f);
1645 grand_child->SetForceRenderSurface(true);
1646
[email protected]989386c2013-07-18 21:37:231647 {
1648 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531649 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1650 parent.get(), parent->bounds(), &render_surface_layer_list);
1651 inputs.can_adjust_raster_scales = true;
1652 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321653
[email protected]989386c2013-07-18 21:37:231654 // Without an animation, we should cull child and grand_child from the
1655 // render_surface_layer_list.
1656 ASSERT_EQ(1U, render_surface_layer_list.size());
1657 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1658 }
[email protected]fb661802013-03-25 01:59:321659
1660 // Now put an animating transform on child.
1661 AddAnimatedTransformToController(
1662 child->layer_animation_controller(), 10.0, 30, 0);
1663
[email protected]989386c2013-07-18 21:37:231664 {
1665 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531666 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1667 parent.get(), parent->bounds(), &render_surface_layer_list);
1668 inputs.can_adjust_raster_scales = true;
1669 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321670
[email protected]989386c2013-07-18 21:37:231671 // With an animating transform, we should keep child and grand_child in the
1672 // render_surface_layer_list.
1673 ASSERT_EQ(3U, render_surface_layer_list.size());
1674 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1675 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1676 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1677 }
[email protected]fb661802013-03-25 01:59:321678}
1679
[email protected]989386c2013-07-18 21:37:231680TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321681 // Layer's IsClipped() property is set to true when:
1682 // - the layer clips its subtree, e.g. masks to bounds,
1683 // - the layer is clipped by an ancestor that contributes to the same
1684 // render target,
1685 // - a surface is clipped by an ancestor that contributes to the same
1686 // render target.
1687 //
1688 // In particular, for a layer that owns a render surface:
1689 // - the render surface inherits any clip from ancestors, and does NOT
1690 // pass that clipped status to the layer itself.
1691 // - but if the layer itself masks to bounds, it is considered clipped
1692 // and propagates the clip to the subtree.
1693
1694 const gfx::Transform identity_matrix;
1695 scoped_refptr<Layer> root = Layer::Create();
1696 scoped_refptr<Layer> parent = Layer::Create();
1697 scoped_refptr<Layer> child1 = Layer::Create();
1698 scoped_refptr<Layer> child2 = Layer::Create();
1699 scoped_refptr<Layer> grand_child = Layer::Create();
1700 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1701 make_scoped_refptr(new LayerWithForcedDrawsContent());
1702 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1703 make_scoped_refptr(new LayerWithForcedDrawsContent());
1704 root->AddChild(parent);
1705 parent->AddChild(child1);
1706 parent->AddChild(child2);
1707 child1->AddChild(grand_child);
1708 child2->AddChild(leaf_node2);
1709 grand_child->AddChild(leaf_node1);
1710
enne2097cab2014-09-25 20:16:311711 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281712 host->SetRootLayer(root);
1713
[email protected]fb661802013-03-25 01:59:321714 child2->SetForceRenderSurface(true);
1715
1716 SetLayerPropertiesForTesting(root.get(),
1717 identity_matrix,
[email protected]a2566412014-06-05 03:14:201718 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321719 gfx::PointF(),
1720 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571721 true,
[email protected]fb661802013-03-25 01:59:321722 false);
1723 SetLayerPropertiesForTesting(parent.get(),
1724 identity_matrix,
[email protected]a2566412014-06-05 03:14:201725 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321726 gfx::PointF(),
1727 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571728 true,
[email protected]fb661802013-03-25 01:59:321729 false);
1730 SetLayerPropertiesForTesting(child1.get(),
1731 identity_matrix,
[email protected]a2566412014-06-05 03:14:201732 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321733 gfx::PointF(),
1734 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571735 true,
[email protected]fb661802013-03-25 01:59:321736 false);
1737 SetLayerPropertiesForTesting(child2.get(),
1738 identity_matrix,
[email protected]a2566412014-06-05 03:14:201739 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321740 gfx::PointF(),
1741 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571742 true,
[email protected]fb661802013-03-25 01:59:321743 false);
1744 SetLayerPropertiesForTesting(grand_child.get(),
1745 identity_matrix,
[email protected]a2566412014-06-05 03:14:201746 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321747 gfx::PointF(),
1748 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571749 true,
[email protected]fb661802013-03-25 01:59:321750 false);
1751 SetLayerPropertiesForTesting(leaf_node1.get(),
1752 identity_matrix,
[email protected]a2566412014-06-05 03:14:201753 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321754 gfx::PointF(),
1755 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571756 true,
[email protected]fb661802013-03-25 01:59:321757 false);
1758 SetLayerPropertiesForTesting(leaf_node2.get(),
1759 identity_matrix,
[email protected]a2566412014-06-05 03:14:201760 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321761 gfx::PointF(),
1762 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571763 true,
[email protected]fb661802013-03-25 01:59:321764 false);
1765
[email protected]989386c2013-07-18 21:37:231766 // Case 1: nothing is clipped except the root render surface.
1767 {
1768 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531769 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1770 root.get(), parent->bounds(), &render_surface_layer_list);
1771 inputs.can_adjust_raster_scales = true;
1772 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321773
[email protected]989386c2013-07-18 21:37:231774 ASSERT_TRUE(root->render_surface());
1775 ASSERT_TRUE(child2->render_surface());
1776
1777 EXPECT_FALSE(root->is_clipped());
1778 EXPECT_TRUE(root->render_surface()->is_clipped());
1779 EXPECT_FALSE(parent->is_clipped());
1780 EXPECT_FALSE(child1->is_clipped());
1781 EXPECT_FALSE(child2->is_clipped());
1782 EXPECT_FALSE(child2->render_surface()->is_clipped());
1783 EXPECT_FALSE(grand_child->is_clipped());
1784 EXPECT_FALSE(leaf_node1->is_clipped());
1785 EXPECT_FALSE(leaf_node2->is_clipped());
1786 }
[email protected]fb661802013-03-25 01:59:321787
1788 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1789 // surface are clipped. But layers that contribute to child2's surface are
1790 // not clipped explicitly because child2's surface already accounts for
1791 // that clip.
[email protected]989386c2013-07-18 21:37:231792 {
1793 RenderSurfaceLayerList render_surface_layer_list;
1794 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531795 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1796 root.get(), parent->bounds(), &render_surface_layer_list);
1797 inputs.can_adjust_raster_scales = true;
1798 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321799
[email protected]989386c2013-07-18 21:37:231800 ASSERT_TRUE(root->render_surface());
1801 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321802
[email protected]989386c2013-07-18 21:37:231803 EXPECT_FALSE(root->is_clipped());
1804 EXPECT_TRUE(root->render_surface()->is_clipped());
1805 EXPECT_TRUE(parent->is_clipped());
1806 EXPECT_TRUE(child1->is_clipped());
1807 EXPECT_FALSE(child2->is_clipped());
1808 EXPECT_TRUE(child2->render_surface()->is_clipped());
1809 EXPECT_TRUE(grand_child->is_clipped());
1810 EXPECT_TRUE(leaf_node1->is_clipped());
1811 EXPECT_FALSE(leaf_node2->is_clipped());
1812 }
[email protected]fb661802013-03-25 01:59:321813
1814 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1815 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231816 {
1817 RenderSurfaceLayerList render_surface_layer_list;
1818 parent->SetMasksToBounds(false);
1819 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531820 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1821 root.get(), parent->bounds(), &render_surface_layer_list);
1822 inputs.can_adjust_raster_scales = true;
1823 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321824
[email protected]989386c2013-07-18 21:37:231825 ASSERT_TRUE(root->render_surface());
1826 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321827
[email protected]989386c2013-07-18 21:37:231828 EXPECT_FALSE(root->is_clipped());
1829 EXPECT_TRUE(root->render_surface()->is_clipped());
1830 EXPECT_FALSE(parent->is_clipped());
1831 EXPECT_FALSE(child1->is_clipped());
1832 EXPECT_TRUE(child2->is_clipped());
1833 EXPECT_FALSE(child2->render_surface()->is_clipped());
1834 EXPECT_FALSE(grand_child->is_clipped());
1835 EXPECT_FALSE(leaf_node1->is_clipped());
1836 EXPECT_TRUE(leaf_node2->is_clipped());
1837 }
[email protected]fb661802013-03-25 01:59:321838}
1839
[email protected]fd9a3b6d2013-08-03 00:46:171840TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321841 // Verify that layers get the appropriate DrawableContentRect when their
1842 // parent masksToBounds is true.
1843 //
1844 // grand_child1 - completely inside the region; DrawableContentRect should
1845 // be the layer rect expressed in target space.
1846 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1847 // will be the intersection of layer bounds and the mask region.
1848 // grand_child3 - partially clipped and masksToBounds; the
1849 // DrawableContentRect will still be the intersection of layer bounds and
1850 // the mask region.
1851 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1852 // be empty.
1853 //
1854
1855 const gfx::Transform identity_matrix;
1856 scoped_refptr<Layer> parent = Layer::Create();
1857 scoped_refptr<Layer> child = Layer::Create();
1858 scoped_refptr<Layer> grand_child1 = Layer::Create();
1859 scoped_refptr<Layer> grand_child2 = Layer::Create();
1860 scoped_refptr<Layer> grand_child3 = Layer::Create();
1861 scoped_refptr<Layer> grand_child4 = Layer::Create();
1862
1863 parent->AddChild(child);
1864 child->AddChild(grand_child1);
1865 child->AddChild(grand_child2);
1866 child->AddChild(grand_child3);
1867 child->AddChild(grand_child4);
1868
enne2097cab2014-09-25 20:16:311869 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281870 host->SetRootLayer(parent);
1871
[email protected]fb661802013-03-25 01:59:321872 SetLayerPropertiesForTesting(parent.get(),
1873 identity_matrix,
[email protected]a2566412014-06-05 03:14:201874 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321875 gfx::PointF(),
1876 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571877 true,
[email protected]fb661802013-03-25 01:59:321878 false);
1879 SetLayerPropertiesForTesting(child.get(),
1880 identity_matrix,
[email protected]a2566412014-06-05 03:14:201881 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321882 gfx::PointF(),
1883 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571884 true,
[email protected]fb661802013-03-25 01:59:321885 false);
1886 SetLayerPropertiesForTesting(grand_child1.get(),
1887 identity_matrix,
[email protected]a2566412014-06-05 03:14:201888 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321889 gfx::PointF(5.f, 5.f),
1890 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571891 true,
[email protected]fb661802013-03-25 01:59:321892 false);
1893 SetLayerPropertiesForTesting(grand_child2.get(),
1894 identity_matrix,
[email protected]a2566412014-06-05 03:14:201895 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321896 gfx::PointF(15.f, 15.f),
1897 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571898 true,
[email protected]fb661802013-03-25 01:59:321899 false);
1900 SetLayerPropertiesForTesting(grand_child3.get(),
1901 identity_matrix,
[email protected]a2566412014-06-05 03:14:201902 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321903 gfx::PointF(15.f, 15.f),
1904 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571905 true,
[email protected]fb661802013-03-25 01:59:321906 false);
1907 SetLayerPropertiesForTesting(grand_child4.get(),
1908 identity_matrix,
[email protected]a2566412014-06-05 03:14:201909 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321910 gfx::PointF(45.f, 45.f),
1911 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571912 true,
[email protected]fb661802013-03-25 01:59:321913 false);
1914
1915 child->SetMasksToBounds(true);
1916 grand_child3->SetMasksToBounds(true);
1917
1918 // Force everyone to be a render surface.
1919 child->SetOpacity(0.4f);
1920 grand_child1->SetOpacity(0.5f);
1921 grand_child2->SetOpacity(0.5f);
1922 grand_child3->SetOpacity(0.5f);
1923 grand_child4->SetOpacity(0.5f);
1924
[email protected]989386c2013-07-18 21:37:231925 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531926 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1927 parent.get(), parent->bounds(), &render_surface_layer_list);
1928 inputs.can_adjust_raster_scales = true;
1929 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321930
hush6b614212014-12-04 22:37:321931 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
1932 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1933 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321934 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1935}
1936
[email protected]989386c2013-07-18 21:37:231937TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:321938 // Verify that render surfaces (and their layers) get the appropriate
1939 // clip rects when their parent masksToBounds is true.
1940 //
1941 // Layers that own render surfaces (at least for now) do not inherit any
1942 // clipping; instead the surface will enforce the clip for the entire subtree.
1943 // They may still have a clip rect of their own layer bounds, however, if
1944 // masksToBounds was true.
1945 const gfx::Transform identity_matrix;
1946 scoped_refptr<Layer> parent = Layer::Create();
1947 scoped_refptr<Layer> child = Layer::Create();
1948 scoped_refptr<Layer> grand_child1 = Layer::Create();
1949 scoped_refptr<Layer> grand_child2 = Layer::Create();
1950 scoped_refptr<Layer> grand_child3 = Layer::Create();
1951 scoped_refptr<Layer> grand_child4 = Layer::Create();
1952 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1953 make_scoped_refptr(new LayerWithForcedDrawsContent());
1954 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1955 make_scoped_refptr(new LayerWithForcedDrawsContent());
1956 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
1957 make_scoped_refptr(new LayerWithForcedDrawsContent());
1958 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
1959 make_scoped_refptr(new LayerWithForcedDrawsContent());
1960
1961 parent->AddChild(child);
1962 child->AddChild(grand_child1);
1963 child->AddChild(grand_child2);
1964 child->AddChild(grand_child3);
1965 child->AddChild(grand_child4);
1966
enne2097cab2014-09-25 20:16:311967 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281968 host->SetRootLayer(parent);
1969
[email protected]fb661802013-03-25 01:59:321970 // the leaf nodes ensure that these grand_children become render surfaces for
1971 // this test.
1972 grand_child1->AddChild(leaf_node1);
1973 grand_child2->AddChild(leaf_node2);
1974 grand_child3->AddChild(leaf_node3);
1975 grand_child4->AddChild(leaf_node4);
1976
1977 SetLayerPropertiesForTesting(parent.get(),
1978 identity_matrix,
[email protected]a2566412014-06-05 03:14:201979 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321980 gfx::PointF(),
1981 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571982 true,
[email protected]fb661802013-03-25 01:59:321983 false);
1984 SetLayerPropertiesForTesting(child.get(),
1985 identity_matrix,
[email protected]a2566412014-06-05 03:14:201986 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321987 gfx::PointF(),
1988 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571989 true,
[email protected]fb661802013-03-25 01:59:321990 false);
1991 SetLayerPropertiesForTesting(grand_child1.get(),
1992 identity_matrix,
[email protected]a2566412014-06-05 03:14:201993 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321994 gfx::PointF(5.f, 5.f),
1995 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571996 true,
[email protected]fb661802013-03-25 01:59:321997 false);
1998 SetLayerPropertiesForTesting(grand_child2.get(),
1999 identity_matrix,
[email protected]a2566412014-06-05 03:14:202000 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322001 gfx::PointF(15.f, 15.f),
2002 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572003 true,
[email protected]fb661802013-03-25 01:59:322004 false);
2005 SetLayerPropertiesForTesting(grand_child3.get(),
2006 identity_matrix,
[email protected]a2566412014-06-05 03:14:202007 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322008 gfx::PointF(15.f, 15.f),
2009 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572010 true,
[email protected]fb661802013-03-25 01:59:322011 false);
2012 SetLayerPropertiesForTesting(grand_child4.get(),
2013 identity_matrix,
[email protected]a2566412014-06-05 03:14:202014 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322015 gfx::PointF(45.f, 45.f),
2016 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572017 true,
[email protected]fb661802013-03-25 01:59:322018 false);
2019 SetLayerPropertiesForTesting(leaf_node1.get(),
2020 identity_matrix,
[email protected]a2566412014-06-05 03:14:202021 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322022 gfx::PointF(),
2023 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572024 true,
[email protected]fb661802013-03-25 01:59:322025 false);
2026 SetLayerPropertiesForTesting(leaf_node2.get(),
2027 identity_matrix,
[email protected]a2566412014-06-05 03:14:202028 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322029 gfx::PointF(),
2030 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572031 true,
[email protected]fb661802013-03-25 01:59:322032 false);
2033 SetLayerPropertiesForTesting(leaf_node3.get(),
2034 identity_matrix,
[email protected]a2566412014-06-05 03:14:202035 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322036 gfx::PointF(),
2037 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572038 true,
[email protected]fb661802013-03-25 01:59:322039 false);
2040 SetLayerPropertiesForTesting(leaf_node4.get(),
2041 identity_matrix,
[email protected]a2566412014-06-05 03:14:202042 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322043 gfx::PointF(),
2044 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572045 true,
[email protected]fb661802013-03-25 01:59:322046 false);
2047
2048 child->SetMasksToBounds(true);
2049 grand_child3->SetMasksToBounds(true);
2050 grand_child4->SetMasksToBounds(true);
2051
2052 // Force everyone to be a render surface.
2053 child->SetOpacity(0.4f);
2054 child->SetForceRenderSurface(true);
2055 grand_child1->SetOpacity(0.5f);
2056 grand_child1->SetForceRenderSurface(true);
2057 grand_child2->SetOpacity(0.5f);
2058 grand_child2->SetForceRenderSurface(true);
2059 grand_child3->SetOpacity(0.5f);
2060 grand_child3->SetForceRenderSurface(true);
2061 grand_child4->SetOpacity(0.5f);
2062 grand_child4->SetForceRenderSurface(true);
2063
[email protected]989386c2013-07-18 21:37:232064 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532065 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2066 parent.get(), parent->bounds(), &render_surface_layer_list);
2067 inputs.can_adjust_raster_scales = true;
2068 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322069 ASSERT_TRUE(grand_child1->render_surface());
2070 ASSERT_TRUE(grand_child2->render_surface());
2071 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322072
2073 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2074 // masksToBounds.
hush6b614212014-12-04 22:37:322075 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2076 grand_child1->render_surface()->clip_rect());
2077 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2078 grand_child2->render_surface()->clip_rect());
2079 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2080 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322081}
2082
[email protected]989386c2013-07-18 21:37:232083TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322084 scoped_refptr<Layer> parent = Layer::Create();
2085 scoped_refptr<Layer> render_surface1 = Layer::Create();
2086 scoped_refptr<Layer> render_surface2 = Layer::Create();
2087 scoped_refptr<Layer> child_of_root = Layer::Create();
2088 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2089 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2090 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2091 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2092 make_scoped_refptr(new LayerWithForcedDrawsContent());
2093 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2094 make_scoped_refptr(new LayerWithForcedDrawsContent());
2095 parent->AddChild(render_surface1);
2096 parent->AddChild(child_of_root);
2097 render_surface1->AddChild(child_of_rs1);
2098 render_surface1->AddChild(render_surface2);
2099 render_surface2->AddChild(child_of_rs2);
2100 child_of_root->AddChild(grand_child_of_root);
2101 child_of_rs1->AddChild(grand_child_of_rs1);
2102 child_of_rs2->AddChild(grand_child_of_rs2);
2103
enne2097cab2014-09-25 20:16:312104 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282105 host->SetRootLayer(parent);
2106
[email protected]fb661802013-03-25 01:59:322107 // Make our render surfaces.
2108 render_surface1->SetForceRenderSurface(true);
2109 render_surface2->SetForceRenderSurface(true);
2110
2111 gfx::Transform layer_transform;
2112 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322113
2114 SetLayerPropertiesForTesting(parent.get(),
2115 layer_transform,
[email protected]a2566412014-06-05 03:14:202116 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322117 gfx::PointF(2.5f, 0.f),
2118 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572119 true,
[email protected]fb661802013-03-25 01:59:322120 false);
2121 SetLayerPropertiesForTesting(render_surface1.get(),
2122 layer_transform,
[email protected]a2566412014-06-05 03:14:202123 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322124 gfx::PointF(2.5f, 0.f),
2125 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572126 true,
[email protected]fb661802013-03-25 01:59:322127 false);
2128 SetLayerPropertiesForTesting(render_surface2.get(),
2129 layer_transform,
[email protected]a2566412014-06-05 03:14:202130 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322131 gfx::PointF(2.5f, 0.f),
2132 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572133 true,
[email protected]fb661802013-03-25 01:59:322134 false);
2135 SetLayerPropertiesForTesting(child_of_root.get(),
2136 layer_transform,
[email protected]a2566412014-06-05 03:14:202137 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322138 gfx::PointF(2.5f, 0.f),
2139 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572140 true,
[email protected]fb661802013-03-25 01:59:322141 false);
2142 SetLayerPropertiesForTesting(child_of_rs1.get(),
2143 layer_transform,
[email protected]a2566412014-06-05 03:14:202144 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322145 gfx::PointF(2.5f, 0.f),
2146 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572147 true,
[email protected]fb661802013-03-25 01:59:322148 false);
2149 SetLayerPropertiesForTesting(child_of_rs2.get(),
2150 layer_transform,
[email protected]a2566412014-06-05 03:14:202151 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322152 gfx::PointF(2.5f, 0.f),
2153 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572154 true,
[email protected]fb661802013-03-25 01:59:322155 false);
2156 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2157 layer_transform,
[email protected]a2566412014-06-05 03:14:202158 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322159 gfx::PointF(2.5f, 0.f),
2160 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572161 true,
[email protected]fb661802013-03-25 01:59:322162 false);
2163 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2164 layer_transform,
[email protected]a2566412014-06-05 03:14:202165 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322166 gfx::PointF(2.5f, 0.f),
2167 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572168 true,
[email protected]fb661802013-03-25 01:59:322169 false);
2170 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2171 layer_transform,
[email protected]a2566412014-06-05 03:14:202172 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322173 gfx::PointF(2.5f, 0.f),
2174 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572175 true,
[email protected]fb661802013-03-25 01:59:322176 false);
2177
2178 // Put an animated opacity on the render surface.
2179 AddOpacityTransitionToController(
2180 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2181
2182 // Also put an animated opacity on a layer without descendants.
2183 AddOpacityTransitionToController(
2184 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2185
2186 // Put a transform animation on the render surface.
2187 AddAnimatedTransformToController(
2188 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2189
2190 // Also put transform animations on grand_child_of_root, and
2191 // grand_child_of_rs2
2192 AddAnimatedTransformToController(
2193 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2194 AddAnimatedTransformToController(
2195 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2196
2197 ExecuteCalculateDrawProperties(parent.get());
2198
2199 // Only layers that are associated with render surfaces should have an actual
2200 // RenderSurface() value.
2201 ASSERT_TRUE(parent->render_surface());
2202 ASSERT_FALSE(child_of_root->render_surface());
2203 ASSERT_FALSE(grand_child_of_root->render_surface());
2204
2205 ASSERT_TRUE(render_surface1->render_surface());
2206 ASSERT_FALSE(child_of_rs1->render_surface());
2207 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2208
2209 ASSERT_TRUE(render_surface2->render_surface());
2210 ASSERT_FALSE(child_of_rs2->render_surface());
2211 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2212
2213 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:102214 EXPECT_EQ(parent.get(), parent->render_target());
2215 EXPECT_EQ(parent.get(), child_of_root->render_target());
2216 EXPECT_EQ(parent.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322217
Daniel Chengeea98042014-08-26 00:28:102218 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
2219 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
2220 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322221
Daniel Chengeea98042014-08-26 00:28:102222 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
2223 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
2224 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322225
2226 // Verify draw_opacity_is_animating values
2227 EXPECT_FALSE(parent->draw_opacity_is_animating());
2228 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2229 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2230 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2231 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2232 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2233 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2234 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2235 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2236 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2237 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2238
2239 // Verify draw_transform_is_animating values
2240 EXPECT_FALSE(parent->draw_transform_is_animating());
2241 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2242 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2243 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2244 EXPECT_FALSE(render_surface1->render_surface()
2245 ->target_surface_transforms_are_animating());
2246 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2247 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2248 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2249 EXPECT_TRUE(render_surface2->render_surface()
2250 ->target_surface_transforms_are_animating());
2251 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2252 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2253
2254 // Verify screen_space_transform_is_animating values
2255 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2256 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2257 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2258 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2259 EXPECT_FALSE(render_surface1->render_surface()
2260 ->screen_space_transforms_are_animating());
2261 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2262 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2263 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2264 EXPECT_TRUE(render_surface2->render_surface()
2265 ->screen_space_transforms_are_animating());
2266 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2267 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2268
2269 // Sanity check. If these fail there is probably a bug in the test itself.
2270 // It is expected that we correctly set up transforms so that the y-component
2271 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262272 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2273 EXPECT_FLOAT_EQ(2.0,
2274 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322275 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262276 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322277
[email protected]803f6b52013-09-12 00:51:262278 EXPECT_FLOAT_EQ(2.0,
2279 render_surface1->screen_space_transform().matrix().get(1, 3));
2280 EXPECT_FLOAT_EQ(3.0,
2281 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322282 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262283 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322284
[email protected]803f6b52013-09-12 00:51:262285 EXPECT_FLOAT_EQ(3.0,
2286 render_surface2->screen_space_transform().matrix().get(1, 3));
2287 EXPECT_FLOAT_EQ(4.0,
2288 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322289 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262290 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322291}
2292
[email protected]989386c2013-07-18 21:37:232293TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322294 // Test the calculateVisibleRect() function works correctly for identity
2295 // transforms.
2296
[email protected]2c7c6702013-03-26 03:14:052297 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322298 gfx::Transform layer_to_surface_transform;
2299
2300 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232301 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052302 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322303 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2304 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322305 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322306
2307 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052308 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322309 actual = LayerTreeHostCommon::CalculateVisibleRect(
2310 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2311 EXPECT_TRUE(actual.IsEmpty());
2312
2313 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052314 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2315 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322316 actual = LayerTreeHostCommon::CalculateVisibleRect(
2317 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322318 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322319}
2320
[email protected]989386c2013-07-18 21:37:232321TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322322 // Test the calculateVisibleRect() function works correctly for scaling
2323 // transforms.
2324
[email protected]2c7c6702013-03-26 03:14:052325 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2326 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322327 gfx::Transform layer_to_surface_transform;
2328
2329 // Case 1: Layer is contained within the surface.
2330 layer_to_surface_transform.MakeIdentity();
2331 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052332 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322333 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2334 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322335 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322336
2337 // Case 2: Layer is outside the surface rect.
2338 layer_to_surface_transform.MakeIdentity();
2339 layer_to_surface_transform.Translate(120.0, 120.0);
2340 actual = LayerTreeHostCommon::CalculateVisibleRect(
2341 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2342 EXPECT_TRUE(actual.IsEmpty());
2343
2344 // Case 3: Layer is partially overlapping the surface rect.
2345 layer_to_surface_transform.MakeIdentity();
2346 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052347 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322348 actual = LayerTreeHostCommon::CalculateVisibleRect(
2349 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322350 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322351}
2352
[email protected]989386c2013-07-18 21:37:232353TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322354 // Test the calculateVisibleRect() function works correctly for rotations
2355 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2356 // should return the g in the layer's space.
2357
[email protected]2c7c6702013-03-26 03:14:052358 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2359 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322360 gfx::Transform layer_to_surface_transform;
2361
2362 // Case 1: Layer is contained within the surface.
2363 layer_to_surface_transform.MakeIdentity();
2364 layer_to_surface_transform.Translate(50.0, 50.0);
2365 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052366 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322367 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2368 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322369 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322370
2371 // Case 2: Layer is outside the surface rect.
2372 layer_to_surface_transform.MakeIdentity();
2373 layer_to_surface_transform.Translate(-50.0, 0.0);
2374 layer_to_surface_transform.Rotate(45.0);
2375 actual = LayerTreeHostCommon::CalculateVisibleRect(
2376 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2377 EXPECT_TRUE(actual.IsEmpty());
2378
2379 // Case 3: The layer is rotated about its top-left corner. In surface space,
2380 // the layer is oriented diagonally, with the left half outside of the render
2381 // surface. In this case, the g should still be the entire layer
2382 // (remember the g is computed in layer space); both the top-left
2383 // and bottom-right corners of the layer are still visible.
2384 layer_to_surface_transform.MakeIdentity();
2385 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052386 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322387 actual = LayerTreeHostCommon::CalculateVisibleRect(
2388 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322389 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322390
2391 // Case 4: The layer is rotated about its top-left corner, and translated
2392 // upwards. In surface space, the layer is oriented diagonally, with only the
2393 // top corner of the surface overlapping the layer. In layer space, the render
2394 // surface overlaps the right side of the layer. The g should be
2395 // the layer's right half.
2396 layer_to_surface_transform.MakeIdentity();
2397 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2398 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052399 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322400 actual = LayerTreeHostCommon::CalculateVisibleRect(
2401 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322402 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322403}
2404
[email protected]989386c2013-07-18 21:37:232405TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322406 // Test that the calculateVisibleRect() function works correctly for 3d
2407 // transforms.
2408
[email protected]2c7c6702013-03-26 03:14:052409 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2410 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322411 gfx::Transform layer_to_surface_transform;
2412
2413 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2414 // degrees, should be fully contained in the render surface.
2415 layer_to_surface_transform.MakeIdentity();
2416 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052417 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322418 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2419 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322420 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322421
2422 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2423 // degrees, but shifted to the side so only the right-half the layer would be
2424 // visible on the surface.
2425 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262426 SkMScalar half_width_of_rotated_layer =
2427 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322428 layer_to_surface_transform.MakeIdentity();
2429 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232430 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2431 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052432 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322433 actual = LayerTreeHostCommon::CalculateVisibleRect(
2434 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322435 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322436}
2437
[email protected]989386c2013-07-18 21:37:232438TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322439 // Test the calculateVisibleRect() function works correctly when the layer has
2440 // a perspective projection onto the target surface.
2441
[email protected]2c7c6702013-03-26 03:14:052442 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2443 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322444 gfx::Transform layer_to_surface_transform;
2445
2446 // Case 1: Even though the layer is twice as large as the surface, due to
2447 // perspective foreshortening, the layer will fit fully in the surface when
2448 // its translated more than the perspective amount.
2449 layer_to_surface_transform.MakeIdentity();
2450
2451 // The following sequence of transforms applies the perspective about the
2452 // center of the surface.
2453 layer_to_surface_transform.Translate(50.0, 50.0);
2454 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2455 layer_to_surface_transform.Translate(-50.0, -50.0);
2456
2457 // This translate places the layer in front of the surface's projection plane.
2458 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2459
[email protected]2c7c6702013-03-26 03:14:052460 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322461 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2462 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322463 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322464
2465 // Case 2: same projection as before, except that the layer is also translated
2466 // to the side, so that only the right half of the layer should be visible.
2467 //
2468 // Explanation of expected result: The perspective ratio is (z distance
2469 // between layer and camera origin) / (z distance between projection plane and
2470 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2471 // move a layer by translating -50 units in projected surface units (so that
2472 // only half of it is visible), then we would need to translate by (-36 / 9) *
2473 // -50 == -200 in the layer's units.
2474 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232475 expected = gfx::Rect(gfx::Point(50, -50),
2476 gfx::Size(100, 200)); // The right half of the layer's
2477 // bounding rect.
[email protected]fb661802013-03-25 01:59:322478 actual = LayerTreeHostCommon::CalculateVisibleRect(
2479 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322480 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322481}
2482
[email protected]989386c2013-07-18 21:37:232483TEST_F(LayerTreeHostCommonTest,
2484 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322485 // There is currently no explicit concept of an orthographic projection plane
2486 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2487 // are technically behind the surface in an orthographic world should not be
2488 // clipped when they are flattened to the surface.
2489
[email protected]2c7c6702013-03-26 03:14:052490 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2491 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322492 gfx::Transform layer_to_surface_transform;
2493
2494 // This sequence of transforms effectively rotates the layer about the y-axis
2495 // at the center of the layer.
2496 layer_to_surface_transform.MakeIdentity();
2497 layer_to_surface_transform.Translate(50.0, 0.0);
2498 layer_to_surface_transform.RotateAboutYAxis(45.0);
2499 layer_to_surface_transform.Translate(-50.0, 0.0);
2500
[email protected]2c7c6702013-03-26 03:14:052501 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322502 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2503 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322504 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322505}
2506
[email protected]989386c2013-07-18 21:37:232507TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322508 // Test the calculateVisibleRect() function works correctly when projecting a
2509 // surface onto a layer, but the layer is partially behind the camera (not
2510 // just behind the projection plane). In this case, the cartesian coordinates
2511 // may seem to be valid, but actually they are not. The visible rect needs to
2512 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2513 // converting to cartesian coordinates.
2514
[email protected]2c7c6702013-03-26 03:14:052515 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232516 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322517 gfx::Transform layer_to_surface_transform;
2518
2519 // The layer is positioned so that the right half of the layer should be in
2520 // front of the camera, while the other half is behind the surface's
2521 // projection plane. The following sequence of transforms applies the
2522 // perspective and rotation about the center of the layer.
2523 layer_to_surface_transform.MakeIdentity();
2524 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2525 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2526 layer_to_surface_transform.RotateAboutYAxis(45.0);
2527
2528 // Sanity check that this transform does indeed cause w < 0 when applying the
2529 // transform, otherwise this code is not testing the intended scenario.
2530 bool clipped;
2531 MathUtil::MapQuad(layer_to_surface_transform,
2532 gfx::QuadF(gfx::RectF(layer_content_rect)),
2533 &clipped);
2534 ASSERT_TRUE(clipped);
2535
2536 int expected_x_position = 0;
2537 int expected_width = 10;
2538 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2539 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2540 EXPECT_EQ(expected_x_position, actual.x());
2541 EXPECT_EQ(expected_width, actual.width());
2542}
2543
[email protected]989386c2013-07-18 21:37:232544TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322545 // To determine visible rect in layer space, there needs to be an
2546 // un-projection from surface space to layer space. When the original
2547 // transform was a perspective projection that was clipped, it returns a rect
2548 // that encloses the clipped bounds. Un-projecting this new rect may require
2549 // clipping again.
2550
2551 // This sequence of transforms causes one corner of the layer to protrude
2552 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232553 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2554 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322555 gfx::Transform layer_to_surface_transform;
2556 layer_to_surface_transform.MakeIdentity();
2557 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2558 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2559 layer_to_surface_transform.RotateAboutYAxis(45.0);
2560 layer_to_surface_transform.RotateAboutXAxis(80.0);
2561
2562 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2563 // code is not testing the intended scenario.
2564 bool clipped;
2565 gfx::RectF clipped_rect =
2566 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2567 MathUtil::ProjectQuad(
2568 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2569 ASSERT_TRUE(clipped);
2570
2571 // Only the corner of the layer is not visible on the surface because of being
2572 // clipped. But, the net result of rounding visible region to an axis-aligned
2573 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052574 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322575 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2576 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322577 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322578}
2579
[email protected]989386c2013-07-18 21:37:232580TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322581 scoped_refptr<Layer> root = Layer::Create();
2582 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2583 make_scoped_refptr(new LayerWithForcedDrawsContent());
2584 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2585 make_scoped_refptr(new LayerWithForcedDrawsContent());
2586 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2587 make_scoped_refptr(new LayerWithForcedDrawsContent());
2588 root->AddChild(child1);
2589 root->AddChild(child2);
2590 root->AddChild(child3);
2591
enne2097cab2014-09-25 20:16:312592 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282593 host->SetRootLayer(root);
2594
[email protected]fb661802013-03-25 01:59:322595 gfx::Transform identity_matrix;
2596 SetLayerPropertiesForTesting(root.get(),
2597 identity_matrix,
[email protected]a2566412014-06-05 03:14:202598 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322599 gfx::PointF(),
2600 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572601 true,
[email protected]fb661802013-03-25 01:59:322602 false);
2603 SetLayerPropertiesForTesting(child1.get(),
2604 identity_matrix,
[email protected]a2566412014-06-05 03:14:202605 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322606 gfx::PointF(),
2607 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572608 true,
[email protected]fb661802013-03-25 01:59:322609 false);
2610 SetLayerPropertiesForTesting(child2.get(),
2611 identity_matrix,
[email protected]a2566412014-06-05 03:14:202612 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322613 gfx::PointF(75.f, 75.f),
2614 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572615 true,
[email protected]fb661802013-03-25 01:59:322616 false);
2617 SetLayerPropertiesForTesting(child3.get(),
2618 identity_matrix,
[email protected]a2566412014-06-05 03:14:202619 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322620 gfx::PointF(125.f, 125.f),
2621 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572622 true,
[email protected]fb661802013-03-25 01:59:322623 false);
2624
2625 ExecuteCalculateDrawProperties(root.get());
2626
hush6b614212014-12-04 22:37:322627 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2628 root->render_surface()->DrawableContentRect());
2629 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322630
2631 // Layers that do not draw content should have empty visible_content_rects.
hush6b614212014-12-04 22:37:322632 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322633
2634 // layer visible_content_rects are clipped by their target surface.
hush6b614212014-12-04 22:37:322635 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2636 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322637 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2638
2639 // layer drawable_content_rects are not clipped.
hush6b614212014-12-04 22:37:322640 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2641 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2642 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322643}
2644
[email protected]989386c2013-07-18 21:37:232645TEST_F(LayerTreeHostCommonTest,
2646 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322647 scoped_refptr<Layer> root = Layer::Create();
2648 scoped_refptr<Layer> child = Layer::Create();
2649 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2650 make_scoped_refptr(new LayerWithForcedDrawsContent());
2651 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2652 make_scoped_refptr(new LayerWithForcedDrawsContent());
2653 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2654 make_scoped_refptr(new LayerWithForcedDrawsContent());
2655 root->AddChild(child);
2656 child->AddChild(grand_child1);
2657 child->AddChild(grand_child2);
2658 child->AddChild(grand_child3);
2659
enne2097cab2014-09-25 20:16:312660 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282661 host->SetRootLayer(root);
2662
[email protected]fb661802013-03-25 01:59:322663 gfx::Transform identity_matrix;
2664 SetLayerPropertiesForTesting(root.get(),
2665 identity_matrix,
[email protected]a2566412014-06-05 03:14:202666 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322667 gfx::PointF(),
2668 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572669 true,
[email protected]fb661802013-03-25 01:59:322670 false);
2671 SetLayerPropertiesForTesting(child.get(),
2672 identity_matrix,
[email protected]a2566412014-06-05 03:14:202673 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322674 gfx::PointF(),
2675 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572676 true,
[email protected]fb661802013-03-25 01:59:322677 false);
2678 SetLayerPropertiesForTesting(grand_child1.get(),
2679 identity_matrix,
[email protected]a2566412014-06-05 03:14:202680 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322681 gfx::PointF(5.f, 5.f),
2682 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572683 true,
[email protected]fb661802013-03-25 01:59:322684 false);
2685 SetLayerPropertiesForTesting(grand_child2.get(),
2686 identity_matrix,
[email protected]a2566412014-06-05 03:14:202687 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322688 gfx::PointF(75.f, 75.f),
2689 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572690 true,
[email protected]fb661802013-03-25 01:59:322691 false);
2692 SetLayerPropertiesForTesting(grand_child3.get(),
2693 identity_matrix,
[email protected]a2566412014-06-05 03:14:202694 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322695 gfx::PointF(125.f, 125.f),
2696 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572697 true,
[email protected]fb661802013-03-25 01:59:322698 false);
2699
2700 child->SetMasksToBounds(true);
2701 ExecuteCalculateDrawProperties(root.get());
2702
2703 ASSERT_FALSE(child->render_surface());
2704
hush6b614212014-12-04 22:37:322705 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2706 root->render_surface()->DrawableContentRect());
2707 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322708
2709 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322710 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2711 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322712
2713 // All grandchild visible content rects should be clipped by child.
hush6b614212014-12-04 22:37:322714 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2715 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322716 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2717
2718 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322719 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2720 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322721 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2722}
2723
[email protected]989386c2013-07-18 21:37:232724TEST_F(LayerTreeHostCommonTest,
2725 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322726 scoped_refptr<Layer> root = Layer::Create();
2727 scoped_refptr<Layer> render_surface1 = Layer::Create();
2728 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2729 make_scoped_refptr(new LayerWithForcedDrawsContent());
2730 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2731 make_scoped_refptr(new LayerWithForcedDrawsContent());
2732 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2733 make_scoped_refptr(new LayerWithForcedDrawsContent());
2734 root->AddChild(render_surface1);
2735 render_surface1->AddChild(child1);
2736 render_surface1->AddChild(child2);
2737 render_surface1->AddChild(child3);
2738
enne2097cab2014-09-25 20:16:312739 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282740 host->SetRootLayer(root);
2741
[email protected]fb661802013-03-25 01:59:322742 gfx::Transform identity_matrix;
2743 SetLayerPropertiesForTesting(root.get(),
2744 identity_matrix,
[email protected]a2566412014-06-05 03:14:202745 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322746 gfx::PointF(),
2747 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572748 true,
[email protected]fb661802013-03-25 01:59:322749 false);
2750 SetLayerPropertiesForTesting(render_surface1.get(),
2751 identity_matrix,
[email protected]a2566412014-06-05 03:14:202752 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322753 gfx::PointF(),
2754 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572755 true,
[email protected]fb661802013-03-25 01:59:322756 false);
2757 SetLayerPropertiesForTesting(child1.get(),
2758 identity_matrix,
[email protected]a2566412014-06-05 03:14:202759 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322760 gfx::PointF(5.f, 5.f),
2761 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572762 true,
[email protected]fb661802013-03-25 01:59:322763 false);
2764 SetLayerPropertiesForTesting(child2.get(),
2765 identity_matrix,
[email protected]a2566412014-06-05 03:14:202766 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322767 gfx::PointF(75.f, 75.f),
2768 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572769 true,
[email protected]fb661802013-03-25 01:59:322770 false);
2771 SetLayerPropertiesForTesting(child3.get(),
2772 identity_matrix,
[email protected]a2566412014-06-05 03:14:202773 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322774 gfx::PointF(125.f, 125.f),
2775 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572776 true,
[email protected]fb661802013-03-25 01:59:322777 false);
2778
2779 render_surface1->SetForceRenderSurface(true);
2780 ExecuteCalculateDrawProperties(root.get());
2781
2782 ASSERT_TRUE(render_surface1->render_surface());
2783
hush6b614212014-12-04 22:37:322784 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2785 root->render_surface()->DrawableContentRect());
2786 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322787
2788 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322789 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2790 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322791
2792 // An unclipped surface grows its DrawableContentRect to include all drawable
2793 // regions of the subtree.
hush6b614212014-12-04 22:37:322794 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2795 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322796
2797 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:322798 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2799 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2800 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322801
hush6b614212014-12-04 22:37:322802 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2803 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2804 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322805}
2806
[email protected]989386c2013-07-18 21:37:232807TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:022808 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2809 scoped_refptr<Layer> root = Layer::Create();
2810 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2811 make_scoped_refptr(new LayerWithForcedDrawsContent());
2812 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2813 make_scoped_refptr(new LayerWithForcedDrawsContent());
2814 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2815 make_scoped_refptr(new LayerWithForcedDrawsContent());
2816 root->AddChild(child1);
2817 root->AddChild(child2);
2818 root->AddChild(child3);
2819
2820 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2821 host->SetRootLayer(root);
2822
2823 gfx::Transform identity_matrix;
2824 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2825 gfx::PointF(), gfx::Size(100, 100), true, false);
2826 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(),
2827 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2828 false);
2829 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(),
2830 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2831 false);
2832 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(),
2833 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2834 true, false);
2835
2836 RenderSurfaceLayerList render_surface_layer_list;
2837 // Now set the root render surface an empty clip.
2838 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2839 root.get(), gfx::Size(), &render_surface_layer_list);
2840
2841 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2842 ASSERT_TRUE(root->render_surface());
2843 EXPECT_FALSE(root->is_clipped());
2844
2845 gfx::Rect empty;
2846 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2847 EXPECT_TRUE(root->render_surface()->is_clipped());
2848
2849 // Visible content rect calculation will check if the target surface is
2850 // clipped or not. An empty clip rect does not indicate the render surface
2851 // is unclipped.
2852 EXPECT_EQ(empty, child1->visible_content_rect());
2853 EXPECT_EQ(empty, child2->visible_content_rect());
2854 EXPECT_EQ(empty, child3->visible_content_rect());
2855}
2856
2857TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:232858 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472859 scoped_refptr<Layer> root = Layer::Create();
2860 scoped_refptr<LayerWithForcedDrawsContent> child =
2861 make_scoped_refptr(new LayerWithForcedDrawsContent());
2862 root->AddChild(child);
2863
enne2097cab2014-09-25 20:16:312864 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282865 host->SetRootLayer(root);
2866
[email protected]630ddad2013-08-16 03:01:322867 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472868 gfx::Transform identity_matrix;
2869 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322870 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472871
2872 SetLayerPropertiesForTesting(root.get(),
2873 identity_matrix,
[email protected]a2566412014-06-05 03:14:202874 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472875 gfx::PointF(),
2876 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572877 true,
[email protected]451107a32013-04-10 05:12:472878 false);
2879 SetLayerPropertiesForTesting(child.get(),
2880 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202881 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472882 gfx::PointF(5.f, 5.f),
2883 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572884 true,
[email protected]451107a32013-04-10 05:12:472885 false);
2886
2887 ExecuteCalculateDrawProperties(root.get());
2888
2889 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2890 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322891
[email protected]08bdf1b2014-04-16 23:23:292892 // Case 2: a matrix with flattened z, uninvertible and not visible according
2893 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322894 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262895 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322896 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2897
2898 SetLayerPropertiesForTesting(child.get(),
2899 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202900 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322901 gfx::PointF(5.f, 5.f),
2902 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572903 true,
[email protected]630ddad2013-08-16 03:01:322904 false);
2905
2906 ExecuteCalculateDrawProperties(root.get());
2907
[email protected]08bdf1b2014-04-16 23:23:292908 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2909 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322910
[email protected]08bdf1b2014-04-16 23:23:292911 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322912 uninvertible_matrix.MakeIdentity();
2913 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262914 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322915 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2916
2917 SetLayerPropertiesForTesting(child.get(),
2918 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202919 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322920 gfx::PointF(5.f, 5.f),
2921 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572922 true,
[email protected]630ddad2013-08-16 03:01:322923 false);
2924
2925 ExecuteCalculateDrawProperties(root.get());
2926
2927 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292928 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472929}
2930
[email protected]989386c2013-07-18 21:37:232931TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:362932 SingularTransformDoesNotPreventClearingDrawProperties) {
2933 scoped_refptr<Layer> root = Layer::Create();
2934 scoped_refptr<LayerWithForcedDrawsContent> child =
2935 make_scoped_refptr(new LayerWithForcedDrawsContent());
2936 root->AddChild(child);
2937
enne2097cab2014-09-25 20:16:312938 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]e43c68b2014-05-01 05:10:362939 host->SetRootLayer(root);
2940
2941 gfx::Transform identity_matrix;
2942 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2943 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2944
2945 SetLayerPropertiesForTesting(root.get(),
2946 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202947 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:362948 gfx::PointF(),
2949 gfx::Size(100, 100),
2950 true,
2951 false);
2952 SetLayerPropertiesForTesting(child.get(),
2953 identity_matrix,
[email protected]a2566412014-06-05 03:14:202954 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:362955 gfx::PointF(5.f, 5.f),
2956 gfx::Size(50, 50),
2957 true,
2958 false);
2959
vollickeb194942014-09-12 17:45:272960 child->draw_properties().sorted_for_recursion = true;
[email protected]e43c68b2014-05-01 05:10:362961
2962 TransformOperations start_transform_operations;
2963 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2964
2965 TransformOperations end_transform_operations;
2966 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2967
2968 AddAnimatedTransformToLayer(
2969 root.get(), 10.0, start_transform_operations, end_transform_operations);
2970
2971 EXPECT_TRUE(root->TransformIsAnimating());
2972
2973 ExecuteCalculateDrawProperties(root.get());
2974
vollickeb194942014-09-12 17:45:272975 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
[email protected]e43c68b2014-05-01 05:10:362976}
2977
eroman822f0dc32015-02-27 22:12:262978TEST_F(LayerTreeHostCommonTest, WillSortAtContextBoundary) {
2979 // Creates a layer tree that looks as follows:
2980 // * root (sorting-context-id1)
2981 // * parent (sorting-context-id2)
2982 // * child1 (sorting-context-id2)
2983 // * child2 (sorting-context-id2)
2984 //
2985 // This test ensures that we sort at |parent| even though both it and root are
2986 // set to be 3d sorted.
2987 FakeImplProxy proxy;
2988 TestSharedBitmapManager shared_bitmap_manager;
2989 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
2990
2991 scoped_ptr<LayerImpl> root_ptr(LayerImpl::Create(host_impl.active_tree(), 1));
2992 LayerImpl* root = root_ptr.get();
2993 scoped_ptr<LayerImpl> parent_ptr(
2994 LayerImpl::Create(host_impl.active_tree(), 2));
2995 LayerImpl* parent = parent_ptr.get();
2996 scoped_ptr<LayerImpl> child1_ptr(
2997 LayerImpl::Create(host_impl.active_tree(), 3));
2998 LayerImpl* child1 = child1_ptr.get();
2999 scoped_ptr<LayerImpl> child2_ptr(
3000 LayerImpl::Create(host_impl.active_tree(), 4));
3001 LayerImpl* child2 = child2_ptr.get();
3002
3003 gfx::Transform identity_matrix;
3004 gfx::Transform below_matrix;
3005 below_matrix.Translate3d(0.f, 0.f, -10.f);
3006 gfx::Transform above_matrix;
3007 above_matrix.Translate3d(0.f, 0.f, 10.f);
3008
3009 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3010 gfx::PointF(), gfx::Size(100, 100), true, true,
3011 true);
3012 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3013 gfx::PointF(), gfx::Size(50, 50), true, true,
3014 true);
3015 SetLayerPropertiesForTesting(child1, above_matrix, gfx::Point3F(),
3016 gfx::PointF(), gfx::Size(50, 50), true, true,
3017 false);
3018 SetLayerPropertiesForTesting(child2, below_matrix, gfx::Point3F(),
3019 gfx::PointF(), gfx::Size(50, 50), true, true,
3020 false);
3021
3022 root->Set3dSortingContextId(3);
3023 root->SetDrawsContent(true);
3024 parent->Set3dSortingContextId(7);
3025 parent->SetDrawsContent(true);
3026 child1->Set3dSortingContextId(7);
3027 child1->SetDrawsContent(true);
3028 child2->Set3dSortingContextId(7);
3029 child2->SetDrawsContent(true);
3030
3031 parent->AddChild(child1_ptr.Pass());
3032 parent->AddChild(child2_ptr.Pass());
3033 root->AddChild(parent_ptr.Pass());
3034
3035 LayerImplList render_surface_layer_list;
3036 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
3037 root_ptr.get(), root->bounds(), &render_surface_layer_list);
3038 inputs.can_adjust_raster_scales = true;
3039 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3040
3041 EXPECT_TRUE(root->render_surface());
3042 EXPECT_EQ(2u, render_surface_layer_list.size());
3043
3044 EXPECT_EQ(3u, parent->render_surface()->layer_list().size());
3045 EXPECT_EQ(child2->id(), parent->render_surface()->layer_list().at(0)->id());
3046 EXPECT_EQ(parent->id(), parent->render_surface()->layer_list().at(1)->id());
3047 EXPECT_EQ(child1->id(), parent->render_surface()->layer_list().at(2)->id());
3048}
3049
[email protected]e43c68b2014-05-01 05:10:363050TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:063051 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
3052 scoped_refptr<Layer> root = Layer::Create();
3053
enne2097cab2014-09-25 20:16:313054 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]8dbc85c2014-05-03 03:21:063055 host->SetRootLayer(root);
3056
3057 gfx::Transform identity_matrix;
3058 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3059 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3060
3061 SetLayerPropertiesForTesting(root.get(),
3062 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203063 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:063064 gfx::PointF(),
3065 gfx::Size(100, 100),
3066 true,
3067 false);
3068
vollickeb194942014-09-12 17:45:273069 root->draw_properties().sorted_for_recursion = true;
[email protected]8dbc85c2014-05-03 03:21:063070
3071 EXPECT_FALSE(root->TransformIsAnimating());
3072
3073 ExecuteCalculateDrawProperties(root.get());
3074
vollickeb194942014-09-12 17:45:273075 EXPECT_FALSE(root->draw_properties().sorted_for_recursion);
[email protected]8dbc85c2014-05-03 03:21:063076}
3077
3078TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233079 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323080 scoped_refptr<Layer> root = Layer::Create();
3081 scoped_refptr<Layer> render_surface1 = Layer::Create();
3082 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3083 make_scoped_refptr(new LayerWithForcedDrawsContent());
3084 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3085 make_scoped_refptr(new LayerWithForcedDrawsContent());
3086 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3087 make_scoped_refptr(new LayerWithForcedDrawsContent());
3088 root->AddChild(render_surface1);
3089 render_surface1->AddChild(child1);
3090 render_surface1->AddChild(child2);
3091 render_surface1->AddChild(child3);
3092
enne2097cab2014-09-25 20:16:313093 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283094 host->SetRootLayer(root);
3095
[email protected]fb661802013-03-25 01:59:323096 gfx::Transform identity_matrix;
3097 SetLayerPropertiesForTesting(root.get(),
3098 identity_matrix,
[email protected]a2566412014-06-05 03:14:203099 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323100 gfx::PointF(),
3101 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573102 true,
[email protected]fb661802013-03-25 01:59:323103 false);
3104 SetLayerPropertiesForTesting(render_surface1.get(),
3105 identity_matrix,
[email protected]a2566412014-06-05 03:14:203106 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323107 gfx::PointF(),
3108 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573109 true,
[email protected]fb661802013-03-25 01:59:323110 false);
3111 SetLayerPropertiesForTesting(child1.get(),
3112 identity_matrix,
[email protected]a2566412014-06-05 03:14:203113 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323114 gfx::PointF(5.f, 5.f),
3115 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573116 true,
[email protected]fb661802013-03-25 01:59:323117 false);
3118 SetLayerPropertiesForTesting(child2.get(),
3119 identity_matrix,
[email protected]a2566412014-06-05 03:14:203120 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323121 gfx::PointF(75.f, 75.f),
3122 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573123 true,
[email protected]fb661802013-03-25 01:59:323124 false);
3125 SetLayerPropertiesForTesting(child3.get(),
3126 identity_matrix,
[email protected]a2566412014-06-05 03:14:203127 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323128 gfx::PointF(125.f, 125.f),
3129 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573130 true,
[email protected]fb661802013-03-25 01:59:323131 false);
3132
3133 root->SetMasksToBounds(true);
3134 render_surface1->SetForceRenderSurface(true);
3135 ExecuteCalculateDrawProperties(root.get());
3136
3137 ASSERT_TRUE(render_surface1->render_surface());
3138
hush6b614212014-12-04 22:37:323139 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3140 root->render_surface()->DrawableContentRect());
3141 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323142
3143 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323144 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3145 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323146
3147 // A clipped surface grows its DrawableContentRect to include all drawable
3148 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323149 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3150 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323151
3152 // All layers that draw content into the surface have their visible content
3153 // rect clipped by the surface clip rect.
hush6b614212014-12-04 22:37:323154 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3155 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323156 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3157
3158 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323159 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3160 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3161 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323162}
3163
[email protected]989386c2013-07-18 21:37:233164TEST_F(LayerTreeHostCommonTest,
3165 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323166 // Check that clipping does not propagate down surfaces.
3167 scoped_refptr<Layer> root = Layer::Create();
3168 scoped_refptr<Layer> render_surface1 = Layer::Create();
3169 scoped_refptr<Layer> render_surface2 = Layer::Create();
3170 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3171 make_scoped_refptr(new LayerWithForcedDrawsContent());
3172 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3173 make_scoped_refptr(new LayerWithForcedDrawsContent());
3174 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3175 make_scoped_refptr(new LayerWithForcedDrawsContent());
3176 root->AddChild(render_surface1);
3177 render_surface1->AddChild(render_surface2);
3178 render_surface2->AddChild(child1);
3179 render_surface2->AddChild(child2);
3180 render_surface2->AddChild(child3);
3181
enne2097cab2014-09-25 20:16:313182 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283183 host->SetRootLayer(root);
3184
[email protected]fb661802013-03-25 01:59:323185 gfx::Transform identity_matrix;
3186 SetLayerPropertiesForTesting(root.get(),
3187 identity_matrix,
[email protected]a2566412014-06-05 03:14:203188 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323189 gfx::PointF(),
3190 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573191 true,
[email protected]fb661802013-03-25 01:59:323192 false);
3193 SetLayerPropertiesForTesting(render_surface1.get(),
3194 identity_matrix,
[email protected]a2566412014-06-05 03:14:203195 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323196 gfx::PointF(),
3197 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573198 true,
[email protected]fb661802013-03-25 01:59:323199 false);
3200 SetLayerPropertiesForTesting(render_surface2.get(),
3201 identity_matrix,
[email protected]a2566412014-06-05 03:14:203202 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323203 gfx::PointF(),
3204 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573205 true,
[email protected]fb661802013-03-25 01:59:323206 false);
3207 SetLayerPropertiesForTesting(child1.get(),
3208 identity_matrix,
[email protected]a2566412014-06-05 03:14:203209 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323210 gfx::PointF(5.f, 5.f),
3211 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573212 true,
[email protected]fb661802013-03-25 01:59:323213 false);
3214 SetLayerPropertiesForTesting(child2.get(),
3215 identity_matrix,
[email protected]a2566412014-06-05 03:14:203216 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323217 gfx::PointF(75.f, 75.f),
3218 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573219 true,
[email protected]fb661802013-03-25 01:59:323220 false);
3221 SetLayerPropertiesForTesting(child3.get(),
3222 identity_matrix,
[email protected]a2566412014-06-05 03:14:203223 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323224 gfx::PointF(125.f, 125.f),
3225 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573226 true,
[email protected]fb661802013-03-25 01:59:323227 false);
3228
3229 root->SetMasksToBounds(true);
3230 render_surface1->SetForceRenderSurface(true);
3231 render_surface2->SetForceRenderSurface(true);
3232 ExecuteCalculateDrawProperties(root.get());
3233
3234 ASSERT_TRUE(render_surface1->render_surface());
3235 ASSERT_TRUE(render_surface2->render_surface());
3236
hush6b614212014-12-04 22:37:323237 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3238 root->render_surface()->DrawableContentRect());
3239 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323240
3241 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323242 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3243 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
3244 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323245
3246 // A clipped surface grows its DrawableContentRect to include all drawable
3247 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323248 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3249 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323250
3251 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3252 // is only implicitly clipped by render_surface1's content rect. So,
3253 // render_surface2 grows to enclose all drawable content of its subtree.
hush6b614212014-12-04 22:37:323254 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3255 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323256
3257 // All layers that draw content into render_surface2 think they are unclipped.
hush6b614212014-12-04 22:37:323258 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3259 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3260 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323261
3262 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323263 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3264 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3265 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323266}
3267
[email protected]989386c2013-07-18 21:37:233268TEST_F(LayerTreeHostCommonTest,
3269 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323270 // Layers that have non-axis aligned bounds (due to transforms) have an
3271 // expanded, axis-aligned DrawableContentRect and visible content rect.
3272
3273 scoped_refptr<Layer> root = Layer::Create();
3274 scoped_refptr<Layer> render_surface1 = Layer::Create();
3275 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3276 make_scoped_refptr(new LayerWithForcedDrawsContent());
3277 root->AddChild(render_surface1);
3278 render_surface1->AddChild(child1);
3279
enne2097cab2014-09-25 20:16:313280 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283281 host->SetRootLayer(root);
3282
[email protected]fb661802013-03-25 01:59:323283 gfx::Transform identity_matrix;
3284 gfx::Transform child_rotation;
3285 child_rotation.Rotate(45.0);
3286 SetLayerPropertiesForTesting(root.get(),
3287 identity_matrix,
[email protected]a2566412014-06-05 03:14:203288 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323289 gfx::PointF(),
3290 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573291 true,
[email protected]fb661802013-03-25 01:59:323292 false);
3293 SetLayerPropertiesForTesting(render_surface1.get(),
3294 identity_matrix,
[email protected]a2566412014-06-05 03:14:203295 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323296 gfx::PointF(),
3297 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573298 true,
[email protected]fb661802013-03-25 01:59:323299 false);
3300 SetLayerPropertiesForTesting(child1.get(),
3301 child_rotation,
[email protected]a2566412014-06-05 03:14:203302 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323303 gfx::PointF(25.f, 25.f),
3304 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573305 true,
[email protected]fb661802013-03-25 01:59:323306 false);
3307
3308 render_surface1->SetForceRenderSurface(true);
3309 ExecuteCalculateDrawProperties(root.get());
3310
3311 ASSERT_TRUE(render_surface1->render_surface());
3312
hush6b614212014-12-04 22:37:323313 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3314 root->render_surface()->DrawableContentRect());
3315 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323316
3317 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323318 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3319 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323320
3321 // The unclipped surface grows its DrawableContentRect to include all drawable
3322 // regions of the subtree.
3323 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3324 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263325 gfx::Rect(50 - diagonal_radius,
3326 50 - diagonal_radius,
3327 diagonal_radius * 2,
3328 diagonal_radius * 2);
hush6b614212014-12-04 22:37:323329 EXPECT_EQ(expected_surface_drawable_content,
3330 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323331
3332 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:323333 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3334 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323335}
3336
[email protected]989386c2013-07-18 21:37:233337TEST_F(LayerTreeHostCommonTest,
3338 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323339 // Layers that have non-axis aligned bounds (due to transforms) have an
3340 // expanded, axis-aligned DrawableContentRect and visible content rect.
3341
3342 scoped_refptr<Layer> root = Layer::Create();
3343 scoped_refptr<Layer> render_surface1 = Layer::Create();
3344 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3345 make_scoped_refptr(new LayerWithForcedDrawsContent());
3346 root->AddChild(render_surface1);
3347 render_surface1->AddChild(child1);
3348
enne2097cab2014-09-25 20:16:313349 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283350 host->SetRootLayer(root);
3351
[email protected]fb661802013-03-25 01:59:323352 gfx::Transform identity_matrix;
3353 gfx::Transform child_rotation;
3354 child_rotation.Rotate(45.0);
3355 SetLayerPropertiesForTesting(root.get(),
3356 identity_matrix,
[email protected]a2566412014-06-05 03:14:203357 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323358 gfx::PointF(),
3359 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573360 true,
[email protected]fb661802013-03-25 01:59:323361 false);
3362 SetLayerPropertiesForTesting(render_surface1.get(),
3363 identity_matrix,
[email protected]a2566412014-06-05 03:14:203364 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323365 gfx::PointF(),
3366 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573367 true,
[email protected]fb661802013-03-25 01:59:323368 false);
[email protected]a2566412014-06-05 03:14:203369
[email protected]fb661802013-03-25 01:59:323370 SetLayerPropertiesForTesting(child1.get(),
3371 child_rotation,
[email protected]a2566412014-06-05 03:14:203372 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323373 gfx::PointF(25.f, 25.f),
3374 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573375 true,
[email protected]fb661802013-03-25 01:59:323376 false);
3377
3378 root->SetMasksToBounds(true);
3379 render_surface1->SetForceRenderSurface(true);
3380 ExecuteCalculateDrawProperties(root.get());
3381
3382 ASSERT_TRUE(render_surface1->render_surface());
3383
3384 // The clipped surface clamps the DrawableContentRect that encloses the
3385 // rotated layer.
3386 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263387 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3388 50 - diagonal_radius,
3389 diagonal_radius * 2,
3390 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323391 gfx::Rect expected_surface_drawable_content =
3392 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
hush6b614212014-12-04 22:37:323393 EXPECT_EQ(expected_surface_drawable_content,
3394 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323395
3396 // On the clipped surface, only a quarter of the child1 is visible, but when
3397 // rotating it back to child1's content space, the actual enclosing rect ends
3398 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263399 //
3400 // Given the floating point math, this number is a little bit fuzzy.
hush6b614212014-12-04 22:37:323401 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323402
3403 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323404 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323405}
3406
[email protected]989386c2013-07-18 21:37:233407TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323408 MockContentLayerClient client;
3409
3410 scoped_refptr<Layer> root = Layer::Create();
sohan.jyotie3bd6192014-10-13 07:13:593411 scoped_refptr<FakePictureLayer> render_surface1 =
3412 CreateDrawablePictureLayer(&client);
3413 scoped_refptr<FakePictureLayer> render_surface2 =
3414 CreateDrawablePictureLayer(&client);
3415 scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client);
3416 scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client);
3417 scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client);
[email protected]fb661802013-03-25 01:59:323418 root->AddChild(render_surface1);
3419 render_surface1->AddChild(render_surface2);
3420 render_surface2->AddChild(child1);
3421 render_surface2->AddChild(child2);
3422 render_surface2->AddChild(child3);
3423
enne2097cab2014-09-25 20:16:313424 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283425 host->SetRootLayer(root);
3426
[email protected]fb661802013-03-25 01:59:323427 gfx::Transform identity_matrix;
3428 SetLayerPropertiesForTesting(root.get(),
3429 identity_matrix,
[email protected]a2566412014-06-05 03:14:203430 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323431 gfx::PointF(),
3432 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573433 true,
[email protected]fb661802013-03-25 01:59:323434 false);
3435 SetLayerPropertiesForTesting(render_surface1.get(),
3436 identity_matrix,
[email protected]a2566412014-06-05 03:14:203437 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323438 gfx::PointF(5.f, 5.f),
3439 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573440 true,
[email protected]fb661802013-03-25 01:59:323441 false);
3442 SetLayerPropertiesForTesting(render_surface2.get(),
3443 identity_matrix,
[email protected]a2566412014-06-05 03:14:203444 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323445 gfx::PointF(5.f, 5.f),
3446 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573447 true,
[email protected]fb661802013-03-25 01:59:323448 false);
3449 SetLayerPropertiesForTesting(child1.get(),
3450 identity_matrix,
[email protected]a2566412014-06-05 03:14:203451 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323452 gfx::PointF(5.f, 5.f),
3453 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573454 true,
[email protected]fb661802013-03-25 01:59:323455 false);
3456 SetLayerPropertiesForTesting(child2.get(),
3457 identity_matrix,
[email protected]a2566412014-06-05 03:14:203458 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323459 gfx::PointF(75.f, 75.f),
3460 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573461 true,
[email protected]fb661802013-03-25 01:59:323462 false);
3463 SetLayerPropertiesForTesting(child3.get(),
3464 identity_matrix,
[email protected]a2566412014-06-05 03:14:203465 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323466 gfx::PointF(125.f, 125.f),
3467 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573468 true,
[email protected]fb661802013-03-25 01:59:323469 false);
3470
3471 float device_scale_factor = 2.f;
3472
3473 root->SetMasksToBounds(true);
3474 render_surface1->SetForceRenderSurface(true);
3475 render_surface2->SetForceRenderSurface(true);
3476 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3477
3478 ASSERT_TRUE(render_surface1->render_surface());
3479 ASSERT_TRUE(render_surface2->render_surface());
3480
3481 // drawable_content_rects for all layers and surfaces are scaled by
3482 // device_scale_factor.
hush6b614212014-12-04 22:37:323483 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3484 root->render_surface()->DrawableContentRect());
3485 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3486 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3487 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323488
3489 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3490 // is only implicitly clipped by render_surface1.
hush6b614212014-12-04 22:37:323491 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3492 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323493
hush6b614212014-12-04 22:37:323494 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3495 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3496 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323497
3498 // The root layer does not actually draw content of its own.
hush6b614212014-12-04 22:37:323499 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323500
sohan.jyotie3bd6192014-10-13 07:13:593501 // All layer visible content rects are not expressed in content space of each
3502 // layer, so they are not scaled by the device_scale_factor.
hush6b614212014-12-04 22:37:323503 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect());
3504 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect());
3505 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3506 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3507 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323508}
3509
[email protected]989386c2013-07-18 21:37:233510TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323511 // Verify the behavior of back-face culling when there are no preserve-3d
3512 // layers. Note that 3d transforms still apply in this case, but they are
3513 // "flattened" to each parent layer according to current W3C spec.
3514
3515 const gfx::Transform identity_matrix;
3516 scoped_refptr<Layer> parent = Layer::Create();
3517 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3518 make_scoped_refptr(new LayerWithForcedDrawsContent());
3519 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3520 make_scoped_refptr(new LayerWithForcedDrawsContent());
3521 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3522 make_scoped_refptr(new LayerWithForcedDrawsContent());
3523 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3524 make_scoped_refptr(new LayerWithForcedDrawsContent());
3525 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233526 front_facing_child_of_front_facing_surface =
3527 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323528 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233529 back_facing_child_of_front_facing_surface =
3530 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323531 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233532 front_facing_child_of_back_facing_surface =
3533 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323534 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233535 back_facing_child_of_back_facing_surface =
3536 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323537
3538 parent->AddChild(front_facing_child);
3539 parent->AddChild(back_facing_child);
3540 parent->AddChild(front_facing_surface);
3541 parent->AddChild(back_facing_surface);
3542 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3543 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3544 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3545 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3546
enne2097cab2014-09-25 20:16:313547 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283548 host->SetRootLayer(parent);
3549
[email protected]fb661802013-03-25 01:59:323550 // Nothing is double-sided
3551 front_facing_child->SetDoubleSided(false);
3552 back_facing_child->SetDoubleSided(false);
3553 front_facing_surface->SetDoubleSided(false);
3554 back_facing_surface->SetDoubleSided(false);
3555 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3556 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3557 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3558 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3559
3560 gfx::Transform backface_matrix;
3561 backface_matrix.Translate(50.0, 50.0);
3562 backface_matrix.RotateAboutYAxis(180.0);
3563 backface_matrix.Translate(-50.0, -50.0);
3564
3565 // Having a descendant and opacity will force these to have render surfaces.
3566 front_facing_surface->SetOpacity(0.5f);
3567 back_facing_surface->SetOpacity(0.5f);
3568
3569 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3570 // these layers should blindly use their own local transforms to determine
3571 // back-face culling.
3572 SetLayerPropertiesForTesting(parent.get(),
3573 identity_matrix,
[email protected]a2566412014-06-05 03:14:203574 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323575 gfx::PointF(),
3576 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573577 true,
[email protected]fb661802013-03-25 01:59:323578 false);
3579 SetLayerPropertiesForTesting(front_facing_child.get(),
3580 identity_matrix,
[email protected]a2566412014-06-05 03:14:203581 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323582 gfx::PointF(),
3583 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573584 true,
[email protected]fb661802013-03-25 01:59:323585 false);
3586 SetLayerPropertiesForTesting(back_facing_child.get(),
3587 backface_matrix,
[email protected]a2566412014-06-05 03:14:203588 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323589 gfx::PointF(),
3590 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573591 true,
[email protected]fb661802013-03-25 01:59:323592 false);
3593 SetLayerPropertiesForTesting(front_facing_surface.get(),
3594 identity_matrix,
[email protected]a2566412014-06-05 03:14:203595 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323596 gfx::PointF(),
3597 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573598 true,
[email protected]fb661802013-03-25 01:59:323599 false);
3600 SetLayerPropertiesForTesting(back_facing_surface.get(),
3601 backface_matrix,
[email protected]a2566412014-06-05 03:14:203602 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323603 gfx::PointF(),
3604 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573605 true,
[email protected]fb661802013-03-25 01:59:323606 false);
3607 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3608 identity_matrix,
[email protected]a2566412014-06-05 03:14:203609 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323610 gfx::PointF(),
3611 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573612 true,
[email protected]fb661802013-03-25 01:59:323613 false);
3614 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3615 backface_matrix,
[email protected]a2566412014-06-05 03:14:203616 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323617 gfx::PointF(),
3618 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573619 true,
[email protected]fb661802013-03-25 01:59:323620 false);
3621 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3622 identity_matrix,
[email protected]a2566412014-06-05 03:14:203623 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323624 gfx::PointF(),
3625 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573626 true,
[email protected]fb661802013-03-25 01:59:323627 false);
3628 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3629 backface_matrix,
[email protected]a2566412014-06-05 03:14:203630 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323631 gfx::PointF(),
3632 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573633 true,
[email protected]fb661802013-03-25 01:59:323634 false);
3635
[email protected]989386c2013-07-18 21:37:233636 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533637 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3638 parent.get(), parent->bounds(), &render_surface_layer_list);
3639 inputs.can_adjust_raster_scales = true;
3640 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323641
3642 // Verify which render surfaces were created.
3643 EXPECT_FALSE(front_facing_child->render_surface());
3644 EXPECT_FALSE(back_facing_child->render_surface());
3645 EXPECT_TRUE(front_facing_surface->render_surface());
3646 EXPECT_TRUE(back_facing_surface->render_surface());
3647 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3648 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3649 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3650 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3651
3652 // Verify the render_surface_layer_list.
3653 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233654 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3655 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323656 // Even though the back facing surface LAYER gets culled, the other
3657 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233658 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323659
3660 // Verify root surface's layer list.
3661 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233662 3u,
3663 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3664 EXPECT_EQ(front_facing_child->id(),
3665 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573666 ->render_surface()
3667 ->layer_list()
3668 .at(0)
3669 ->id());
[email protected]989386c2013-07-18 21:37:233670 EXPECT_EQ(front_facing_surface->id(),
3671 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573672 ->render_surface()
3673 ->layer_list()
3674 .at(1)
3675 ->id());
[email protected]989386c2013-07-18 21:37:233676 EXPECT_EQ(back_facing_surface->id(),
3677 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573678 ->render_surface()
3679 ->layer_list()
3680 .at(2)
3681 ->id());
[email protected]fb661802013-03-25 01:59:323682
3683 // Verify front_facing_surface's layer list.
3684 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233685 2u,
3686 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3687 EXPECT_EQ(front_facing_surface->id(),
3688 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573689 ->render_surface()
3690 ->layer_list()
3691 .at(0)
3692 ->id());
[email protected]989386c2013-07-18 21:37:233693 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3694 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573695 ->render_surface()
3696 ->layer_list()
3697 .at(1)
3698 ->id());
[email protected]fb661802013-03-25 01:59:323699
3700 // Verify back_facing_surface's layer list; its own layer should be culled
3701 // from the surface list.
3702 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233703 1u,
3704 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3705 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3706 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573707 ->render_surface()
3708 ->layer_list()
3709 .at(0)
3710 ->id());
[email protected]fb661802013-03-25 01:59:323711}
3712
[email protected]989386c2013-07-18 21:37:233713TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323714 // Verify the behavior of back-face culling when preserves-3d transform style
3715 // is used.
3716
3717 const gfx::Transform identity_matrix;
3718 scoped_refptr<Layer> parent = Layer::Create();
3719 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3720 make_scoped_refptr(new LayerWithForcedDrawsContent());
3721 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3722 make_scoped_refptr(new LayerWithForcedDrawsContent());
3723 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3724 make_scoped_refptr(new LayerWithForcedDrawsContent());
3725 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3726 make_scoped_refptr(new LayerWithForcedDrawsContent());
3727 scoped_refptr<LayerWithForcedDrawsContent>
3728 front_facing_child_of_front_facing_surface =
3729 make_scoped_refptr(new LayerWithForcedDrawsContent());
3730 scoped_refptr<LayerWithForcedDrawsContent>
3731 back_facing_child_of_front_facing_surface =
3732 make_scoped_refptr(new LayerWithForcedDrawsContent());
3733 scoped_refptr<LayerWithForcedDrawsContent>
3734 front_facing_child_of_back_facing_surface =
3735 make_scoped_refptr(new LayerWithForcedDrawsContent());
3736 scoped_refptr<LayerWithForcedDrawsContent>
3737 back_facing_child_of_back_facing_surface =
3738 make_scoped_refptr(new LayerWithForcedDrawsContent());
3739 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3740 make_scoped_refptr(new LayerWithForcedDrawsContent());
3741 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3742 make_scoped_refptr(new LayerWithForcedDrawsContent());
3743
3744 parent->AddChild(front_facing_child);
3745 parent->AddChild(back_facing_child);
3746 parent->AddChild(front_facing_surface);
3747 parent->AddChild(back_facing_surface);
3748 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3749 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3750 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3751 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3752
enne2097cab2014-09-25 20:16:313753 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283754 host->SetRootLayer(parent);
3755
[email protected]fb661802013-03-25 01:59:323756 // Nothing is double-sided
3757 front_facing_child->SetDoubleSided(false);
3758 back_facing_child->SetDoubleSided(false);
3759 front_facing_surface->SetDoubleSided(false);
3760 back_facing_surface->SetDoubleSided(false);
3761 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3762 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3763 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3764 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3765
3766 gfx::Transform backface_matrix;
3767 backface_matrix.Translate(50.0, 50.0);
3768 backface_matrix.RotateAboutYAxis(180.0);
3769 backface_matrix.Translate(-50.0, -50.0);
3770
3771 // Opacity will not force creation of render surfaces in this case because of
3772 // the preserve-3d transform style. Instead, an example of when a surface
3773 // would be created with preserve-3d is when there is a replica layer.
3774 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3775 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3776
3777 // Each surface creates its own new 3d rendering context (as defined by W3C
3778 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3779 // rendering context should use the transform with respect to that context.
3780 // This 3d rendering context occurs when (a) parent's transform style is flat
3781 // and (b) the layer's transform style is preserve-3d.
3782 SetLayerPropertiesForTesting(parent.get(),
3783 identity_matrix,
[email protected]a2566412014-06-05 03:14:203784 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323785 gfx::PointF(),
3786 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573787 true,
[email protected]fb661802013-03-25 01:59:323788 false); // parent transform style is flat.
3789 SetLayerPropertiesForTesting(front_facing_child.get(),
3790 identity_matrix,
[email protected]a2566412014-06-05 03:14:203791 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323792 gfx::PointF(),
3793 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573794 true,
[email protected]fb661802013-03-25 01:59:323795 false);
3796 SetLayerPropertiesForTesting(back_facing_child.get(),
3797 backface_matrix,
[email protected]a2566412014-06-05 03:14:203798 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323799 gfx::PointF(),
3800 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573801 true,
[email protected]fb661802013-03-25 01:59:323802 false);
[email protected]56fffdd2014-02-11 19:50:573803 // surface transform style is preserve-3d.
3804 SetLayerPropertiesForTesting(front_facing_surface.get(),
3805 identity_matrix,
[email protected]a2566412014-06-05 03:14:203806 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573807 gfx::PointF(),
3808 gfx::Size(100, 100),
3809 false,
3810 true);
3811 // surface transform style is preserve-3d.
3812 SetLayerPropertiesForTesting(back_facing_surface.get(),
3813 backface_matrix,
[email protected]a2566412014-06-05 03:14:203814 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573815 gfx::PointF(),
3816 gfx::Size(100, 100),
3817 false,
3818 true);
[email protected]fb661802013-03-25 01:59:323819 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3820 identity_matrix,
[email protected]a2566412014-06-05 03:14:203821 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323822 gfx::PointF(),
3823 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573824 true,
3825 true);
[email protected]fb661802013-03-25 01:59:323826 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3827 backface_matrix,
[email protected]a2566412014-06-05 03:14:203828 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323829 gfx::PointF(),
3830 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573831 true,
3832 true);
[email protected]fb661802013-03-25 01:59:323833 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3834 identity_matrix,
[email protected]a2566412014-06-05 03:14:203835 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323836 gfx::PointF(),
3837 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573838 true,
3839 true);
[email protected]fb661802013-03-25 01:59:323840 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3841 backface_matrix,
[email protected]a2566412014-06-05 03:14:203842 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323843 gfx::PointF(),
3844 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573845 true,
3846 true);
[email protected]fb661802013-03-25 01:59:323847
[email protected]989386c2013-07-18 21:37:233848 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533849 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3850 parent.get(), parent->bounds(), &render_surface_layer_list);
3851 inputs.can_adjust_raster_scales = true;
3852 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323853
awoloszyne83f28c2014-12-22 15:40:003854 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:323855 EXPECT_FALSE(front_facing_child->render_surface());
3856 EXPECT_FALSE(back_facing_child->render_surface());
3857 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:003858 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3859 // We expect that a render_surface was created but not used.
3860 EXPECT_TRUE(back_facing_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323861 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3862 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3863 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3864 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3865
3866 // Verify the render_surface_layer_list. The back-facing surface should be
3867 // culled.
3868 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233869 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3870 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323871
3872 // Verify root surface's layer list.
3873 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233874 2u,
3875 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3876 EXPECT_EQ(front_facing_child->id(),
3877 render_surface_layer_list.at(0)
3878 ->render_surface()->layer_list().at(0)->id());
3879 EXPECT_EQ(front_facing_surface->id(),
3880 render_surface_layer_list.at(0)
3881 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323882
3883 // Verify front_facing_surface's layer list.
3884 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233885 2u,
3886 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3887 EXPECT_EQ(front_facing_surface->id(),
3888 render_surface_layer_list.at(1)
3889 ->render_surface()->layer_list().at(0)->id());
3890 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3891 render_surface_layer_list.at(1)
3892 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323893}
3894
[email protected]989386c2013-07-18 21:37:233895TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323896 // Verify that layers are appropriately culled when their back face is showing
3897 // and they are not double sided, while animations are going on.
3898 //
3899 // Layers that are animating do not get culled on the main thread, as their
3900 // transforms should be treated as "unknown" so we can not be sure that their
3901 // back face is really showing.
3902 const gfx::Transform identity_matrix;
3903 scoped_refptr<Layer> parent = Layer::Create();
3904 scoped_refptr<LayerWithForcedDrawsContent> child =
3905 make_scoped_refptr(new LayerWithForcedDrawsContent());
3906 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3907 make_scoped_refptr(new LayerWithForcedDrawsContent());
3908 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3909 make_scoped_refptr(new LayerWithForcedDrawsContent());
3910 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3911 make_scoped_refptr(new LayerWithForcedDrawsContent());
3912 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3913 make_scoped_refptr(new LayerWithForcedDrawsContent());
3914
3915 parent->AddChild(child);
3916 parent->AddChild(animating_surface);
3917 animating_surface->AddChild(child_of_animating_surface);
3918 parent->AddChild(animating_child);
3919 parent->AddChild(child2);
3920
enne2097cab2014-09-25 20:16:313921 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283922 host->SetRootLayer(parent);
3923
[email protected]fb661802013-03-25 01:59:323924 // Nothing is double-sided
3925 child->SetDoubleSided(false);
3926 child2->SetDoubleSided(false);
3927 animating_surface->SetDoubleSided(false);
3928 child_of_animating_surface->SetDoubleSided(false);
3929 animating_child->SetDoubleSided(false);
3930
3931 gfx::Transform backface_matrix;
3932 backface_matrix.Translate(50.0, 50.0);
3933 backface_matrix.RotateAboutYAxis(180.0);
3934 backface_matrix.Translate(-50.0, -50.0);
3935
3936 // Make our render surface.
3937 animating_surface->SetForceRenderSurface(true);
3938
3939 // Animate the transform on the render surface.
3940 AddAnimatedTransformToController(
3941 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3942 // This is just an animating layer, not a surface.
3943 AddAnimatedTransformToController(
3944 animating_child->layer_animation_controller(), 10.0, 30, 0);
3945
3946 SetLayerPropertiesForTesting(parent.get(),
3947 identity_matrix,
[email protected]a2566412014-06-05 03:14:203948 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323949 gfx::PointF(),
3950 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573951 true,
[email protected]fb661802013-03-25 01:59:323952 false);
3953 SetLayerPropertiesForTesting(child.get(),
3954 backface_matrix,
[email protected]a2566412014-06-05 03:14:203955 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323956 gfx::PointF(),
3957 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573958 true,
[email protected]fb661802013-03-25 01:59:323959 false);
3960 SetLayerPropertiesForTesting(animating_surface.get(),
3961 backface_matrix,
[email protected]a2566412014-06-05 03:14:203962 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323963 gfx::PointF(),
3964 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573965 true,
[email protected]fb661802013-03-25 01:59:323966 false);
3967 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3968 backface_matrix,
[email protected]a2566412014-06-05 03:14:203969 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323970 gfx::PointF(),
3971 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573972 true,
[email protected]fb661802013-03-25 01:59:323973 false);
3974 SetLayerPropertiesForTesting(animating_child.get(),
3975 backface_matrix,
[email protected]a2566412014-06-05 03:14:203976 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323977 gfx::PointF(),
3978 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573979 true,
[email protected]fb661802013-03-25 01:59:323980 false);
3981 SetLayerPropertiesForTesting(child2.get(),
3982 identity_matrix,
[email protected]a2566412014-06-05 03:14:203983 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323984 gfx::PointF(),
3985 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573986 true,
[email protected]fb661802013-03-25 01:59:323987 false);
3988
[email protected]989386c2013-07-18 21:37:233989 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533990 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3991 parent.get(), parent->bounds(), &render_surface_layer_list);
3992 inputs.can_adjust_raster_scales = true;
3993 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323994
3995 EXPECT_FALSE(child->render_surface());
3996 EXPECT_TRUE(animating_surface->render_surface());
3997 EXPECT_FALSE(child_of_animating_surface->render_surface());
3998 EXPECT_FALSE(animating_child->render_surface());
3999 EXPECT_FALSE(child2->render_surface());
4000
4001 // Verify that the animating_child and child_of_animating_surface were not
4002 // culled, but that child was.
4003 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234004 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4005 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324006
4007 // The non-animating child be culled from the layer list for the parent render
4008 // surface.
4009 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234010 3u,
4011 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4012 EXPECT_EQ(animating_surface->id(),
4013 render_surface_layer_list.at(0)
4014 ->render_surface()->layer_list().at(0)->id());
4015 EXPECT_EQ(animating_child->id(),
4016 render_surface_layer_list.at(0)
4017 ->render_surface()->layer_list().at(1)->id());
4018 EXPECT_EQ(child2->id(),
4019 render_surface_layer_list.at(0)
4020 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324021
4022 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234023 2u,
4024 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4025 EXPECT_EQ(animating_surface->id(),
4026 render_surface_layer_list.at(1)
4027 ->render_surface()->layer_list().at(0)->id());
4028 EXPECT_EQ(child_of_animating_surface->id(),
4029 render_surface_layer_list.at(1)
4030 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324031
4032 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4033
4034 // The animating layers should have a visible content rect that represents the
4035 // area of the front face that is within the viewport.
4036 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054037 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324038 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054039 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324040 // And layers in the subtree of the animating layer should have valid visible
4041 // content rects also.
[email protected]989386c2013-07-18 21:37:234042 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4043 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324044}
4045
[email protected]989386c2013-07-18 21:37:234046TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324047 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4048 // Verify the behavior of back-face culling for a render surface that is
4049 // created when it flattens its subtree, and its parent has preserves-3d.
4050
4051 const gfx::Transform identity_matrix;
4052 scoped_refptr<Layer> parent = Layer::Create();
4053 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4054 make_scoped_refptr(new LayerWithForcedDrawsContent());
4055 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4056 make_scoped_refptr(new LayerWithForcedDrawsContent());
4057 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4058 make_scoped_refptr(new LayerWithForcedDrawsContent());
4059 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4060 make_scoped_refptr(new LayerWithForcedDrawsContent());
4061
4062 parent->AddChild(front_facing_surface);
4063 parent->AddChild(back_facing_surface);
4064 front_facing_surface->AddChild(child1);
4065 back_facing_surface->AddChild(child2);
4066
enne2097cab2014-09-25 20:16:314067 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284068 host->SetRootLayer(parent);
4069
[email protected]fb661802013-03-25 01:59:324070 // RenderSurfaces are not double-sided
4071 front_facing_surface->SetDoubleSided(false);
4072 back_facing_surface->SetDoubleSided(false);
4073
4074 gfx::Transform backface_matrix;
4075 backface_matrix.Translate(50.0, 50.0);
4076 backface_matrix.RotateAboutYAxis(180.0);
4077 backface_matrix.Translate(-50.0, -50.0);
4078
4079 SetLayerPropertiesForTesting(parent.get(),
4080 identity_matrix,
[email protected]a2566412014-06-05 03:14:204081 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324082 gfx::PointF(),
4083 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574084 false,
4085 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324086 SetLayerPropertiesForTesting(front_facing_surface.get(),
4087 identity_matrix,
[email protected]a2566412014-06-05 03:14:204088 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324089 gfx::PointF(),
4090 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574091 true,
4092 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324093 SetLayerPropertiesForTesting(back_facing_surface.get(),
4094 backface_matrix,
[email protected]a2566412014-06-05 03:14:204095 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324096 gfx::PointF(),
4097 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574098 true,
4099 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324100 SetLayerPropertiesForTesting(child1.get(),
4101 identity_matrix,
[email protected]a2566412014-06-05 03:14:204102 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324103 gfx::PointF(),
4104 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574105 true,
[email protected]fb661802013-03-25 01:59:324106 false);
4107 SetLayerPropertiesForTesting(child2.get(),
4108 identity_matrix,
[email protected]a2566412014-06-05 03:14:204109 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324110 gfx::PointF(),
4111 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574112 true,
[email protected]fb661802013-03-25 01:59:324113 false);
4114
[email protected]a9d4d4f2014-06-19 06:49:284115 front_facing_surface->Set3dSortingContextId(1);
4116 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574117
[email protected]989386c2013-07-18 21:37:234118 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534119 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4120 parent.get(), parent->bounds(), &render_surface_layer_list);
4121 inputs.can_adjust_raster_scales = true;
4122 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324123
awoloszyne83f28c2014-12-22 15:40:004124 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:324125 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:004126
4127 // We expect the render surface to have been created, but remain unused.
4128 EXPECT_TRUE(back_facing_surface->render_surface());
4129 EXPECT_NE(back_facing_surface->render_target(),
4130 back_facing_surface); // because it should be culled
[email protected]fb661802013-03-25 01:59:324131 EXPECT_FALSE(child1->render_surface());
4132 EXPECT_FALSE(child2->render_surface());
4133
4134 // Verify the render_surface_layer_list. The back-facing surface should be
4135 // culled.
4136 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234137 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4138 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324139
4140 // Verify root surface's layer list.
4141 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234142 1u,
4143 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4144 EXPECT_EQ(front_facing_surface->id(),
4145 render_surface_layer_list.at(0)
4146 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324147
4148 // Verify front_facing_surface's layer list.
4149 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234150 2u,
4151 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4152 EXPECT_EQ(front_facing_surface->id(),
4153 render_surface_layer_list.at(1)
4154 ->render_surface()->layer_list().at(0)->id());
4155 EXPECT_EQ(child1->id(),
4156 render_surface_layer_list.at(1)
4157 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324158}
4159
[email protected]fb661802013-03-25 01:59:324160class NoScaleContentLayer : public ContentLayer {
4161 public:
4162 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
4163 return make_scoped_refptr(new NoScaleContentLayer(client));
4164 }
[email protected]94f206c12012-08-25 00:09:144165
dcheng716bedf2014-10-21 09:51:084166 void CalculateContentsScale(float ideal_contents_scale,
4167 float* contents_scale_x,
4168 float* contents_scale_y,
4169 gfx::Size* content_bounds) override {
[email protected]fb661802013-03-25 01:59:324170 // Skip over the ContentLayer to the base Layer class.
4171 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]fb661802013-03-25 01:59:324172 contents_scale_x,
4173 contents_scale_y,
4174 content_bounds);
4175 }
[email protected]94f206c12012-08-25 00:09:144176
[email protected]fb661802013-03-25 01:59:324177 protected:
4178 explicit NoScaleContentLayer(ContentLayerClient* client)
4179 : ContentLayer(client) {}
dcheng716bedf2014-10-21 09:51:084180 ~NoScaleContentLayer() override {}
[email protected]518ee582012-10-24 18:29:444181};
4182
[email protected]fb661802013-03-25 01:59:324183scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
4184 ContentLayerClient* delegate) {
4185 scoped_refptr<NoScaleContentLayer> to_return =
4186 NoScaleContentLayer::Create(delegate);
4187 to_return->SetIsDrawable(true);
4188 return to_return;
[email protected]518ee582012-10-24 18:29:444189}
4190
[email protected]989386c2013-07-18 21:37:234191TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324192 // Verify draw and screen space transforms of layers not in a surface.
4193 MockContentLayerClient delegate;
4194 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144195
sohan.jyotie3bd6192014-10-13 07:13:594196 scoped_refptr<FakePictureLayer> parent =
4197 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324198 SetLayerPropertiesForTesting(parent.get(),
4199 identity_matrix,
[email protected]a2566412014-06-05 03:14:204200 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324201 gfx::PointF(),
4202 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574203 false,
[email protected]fb661802013-03-25 01:59:324204 true);
[email protected]94f206c12012-08-25 00:09:144205
sohan.jyotie3bd6192014-10-13 07:13:594206 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324207 SetLayerPropertiesForTesting(child.get(),
4208 identity_matrix,
[email protected]a2566412014-06-05 03:14:204209 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324210 gfx::PointF(2.f, 2.f),
4211 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574212 false,
[email protected]fb661802013-03-25 01:59:324213 true);
[email protected]94f206c12012-08-25 00:09:144214
sohan.jyotie3bd6192014-10-13 07:13:594215 scoped_refptr<FakePictureLayer> child_empty =
4216 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324217 SetLayerPropertiesForTesting(child_empty.get(),
4218 identity_matrix,
[email protected]a2566412014-06-05 03:14:204219 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324220 gfx::PointF(2.f, 2.f),
4221 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574222 false,
[email protected]fb661802013-03-25 01:59:324223 true);
[email protected]f89f5632012-11-14 23:34:454224
[email protected]fb661802013-03-25 01:59:324225 parent->AddChild(child);
4226 parent->AddChild(child_empty);
[email protected]94f206c12012-08-25 00:09:144227
enne2097cab2014-09-25 20:16:314228 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284229 host->SetRootLayer(parent);
4230
[email protected]fb661802013-03-25 01:59:324231 float device_scale_factor = 2.5f;
4232 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:144233
[email protected]7aad55f2013-07-26 11:25:534234 RenderSurfaceLayerList render_surface_layer_list;
4235 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4236 parent.get(), parent->bounds(), &render_surface_layer_list);
4237 inputs.device_scale_factor = device_scale_factor;
4238 inputs.page_scale_factor = page_scale_factor;
4239 inputs.can_adjust_raster_scales = true;
4240 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444241
sohan.jyotie3bd6192014-10-13 07:13:594242 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4243 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4244 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty);
[email protected]94f206c12012-08-25 00:09:144245
[email protected]fb661802013-03-25 01:59:324246 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:144247
[email protected]fb661802013-03-25 01:59:324248 // Verify parent transforms
4249 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594250 expected_parent_transform.Scale(device_scale_factor * page_scale_factor,
4251 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324252 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4253 parent->screen_space_transform());
4254 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4255 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:144256
[email protected]fb661802013-03-25 01:59:324257 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054258 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:144259
[email protected]fb661802013-03-25 01:59:324260 gfx::RectF parent_draw_rect =
4261 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4262 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4263 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:144264
[email protected]2c7c6702013-03-26 03:14:054265 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324266 expected_parent_draw_rect.Scale(device_scale_factor);
4267 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4268 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144269
[email protected]fb661802013-03-25 01:59:324270 // Verify child and child_empty transforms. They should match.
4271 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594272 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4273 expected_child_transform.Translate(child->position().x(),
4274 child->position().y());
[email protected]fb661802013-03-25 01:59:324275 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4276 child->draw_transform());
4277 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4278 child->screen_space_transform());
4279 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4280 child_empty->draw_transform());
4281 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4282 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144283
[email protected]fb661802013-03-25 01:59:324284 // Verify results of transformed child and child_empty rects. They should
4285 // match.
[email protected]2c7c6702013-03-26 03:14:054286 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:144287
[email protected]fb661802013-03-25 01:59:324288 gfx::RectF child_draw_rect =
4289 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4290 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4291 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:144292
[email protected]fb661802013-03-25 01:59:324293 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
4294 child_empty->draw_transform(), child_content_bounds);
4295 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4296 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:454297
[email protected]fb661802013-03-25 01:59:324298 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4299 expected_child_draw_rect.Scale(device_scale_factor);
4300 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4301 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4302 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4303 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144304}
4305
[email protected]989386c2013-07-18 21:37:234306TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324307 // Verify draw and screen space transforms of layers in a surface.
4308 MockContentLayerClient delegate;
4309 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:094310
[email protected]fb661802013-03-25 01:59:324311 gfx::Transform perspective_matrix;
4312 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094313
[email protected]fb661802013-03-25 01:59:324314 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054315 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094316
[email protected]9781afa2013-07-17 23:15:324317 scoped_refptr<Layer> root = Layer::Create();
4318
sohan.jyotie3bd6192014-10-13 07:13:594319 scoped_refptr<FakePictureLayer> parent =
4320 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324321 SetLayerPropertiesForTesting(parent.get(),
4322 identity_matrix,
[email protected]a2566412014-06-05 03:14:204323 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324324 gfx::PointF(),
4325 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574326 false,
[email protected]fb661802013-03-25 01:59:324327 true);
[email protected]1b30e8e2012-12-21 02:59:094328
sohan.jyotie3bd6192014-10-13 07:13:594329 scoped_refptr<FakePictureLayer> perspective_surface =
4330 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324331 SetLayerPropertiesForTesting(perspective_surface.get(),
4332 perspective_matrix * scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204333 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324334 gfx::PointF(2.f, 2.f),
4335 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574336 false,
[email protected]fb661802013-03-25 01:59:324337 true);
[email protected]1b30e8e2012-12-21 02:59:094338
sohan.jyotie3bd6192014-10-13 07:13:594339 scoped_refptr<FakePictureLayer> scale_surface =
4340 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324341 SetLayerPropertiesForTesting(scale_surface.get(),
4342 scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204343 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324344 gfx::PointF(2.f, 2.f),
4345 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574346 false,
[email protected]fb661802013-03-25 01:59:324347 true);
[email protected]1b30e8e2012-12-21 02:59:094348
[email protected]fb661802013-03-25 01:59:324349 perspective_surface->SetForceRenderSurface(true);
4350 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:094351
[email protected]fb661802013-03-25 01:59:324352 parent->AddChild(perspective_surface);
4353 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:324354 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:094355
enne2097cab2014-09-25 20:16:314356 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284357 host->SetRootLayer(root);
4358
[email protected]fb661802013-03-25 01:59:324359 float device_scale_factor = 2.5f;
4360 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:094361
[email protected]7aad55f2013-07-26 11:25:534362 RenderSurfaceLayerList render_surface_layer_list;
4363 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4364 root.get(), parent->bounds(), &render_surface_layer_list);
4365 inputs.device_scale_factor = device_scale_factor;
4366 inputs.page_scale_factor = page_scale_factor;
Daniel Chengeea98042014-08-26 00:28:104367 inputs.page_scale_application_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534368 inputs.can_adjust_raster_scales = true;
4369 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:094370
sohan.jyotie3bd6192014-10-13 07:13:594371 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4372 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4373 perspective_surface);
4374 // Ideal scale is the max 2d scale component of the combined transform up to
4375 // the nearest render target. Here this includes the layer transform as well
4376 // as the device and page scale factors.
4377 gfx::Transform transform = scale_small_matrix;
4378 transform.Scale(device_scale_factor * page_scale_factor,
4379 device_scale_factor * page_scale_factor);
4380 gfx::Vector2dF scales =
4381 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4382 float max_2d_scale = std::max(scales.x(), scales.y());
4383 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4384
4385 // The ideal scale will draw 1:1 with its render target space along
4386 // the larger-scale axis.
4387 gfx::Vector2dF target_space_transform_scales =
4388 MathUtil::ComputeTransform2dScaleComponents(
4389 scale_surface->draw_properties().target_space_transform, 0.f);
4390 EXPECT_FLOAT_EQ(max_2d_scale,
4391 std::max(target_space_transform_scales.x(),
4392 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094393
[email protected]fb661802013-03-25 01:59:324394 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:094395
[email protected]fb661802013-03-25 01:59:324396 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594397 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4398 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324399 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4400 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094401
[email protected]fb661802013-03-25 01:59:324402 // The scale for the perspective surface is not known, so it is rendered 1:1
4403 // with the screen, and then scaled during drawing.
4404 gfx::Transform expected_perspective_surface_draw_transform;
4405 expected_perspective_surface_draw_transform.Translate(
4406 device_scale_factor * page_scale_factor *
4407 perspective_surface->position().x(),
4408 device_scale_factor * page_scale_factor *
4409 perspective_surface->position().y());
4410 expected_perspective_surface_draw_transform.PreconcatTransform(
4411 perspective_matrix);
4412 expected_perspective_surface_draw_transform.PreconcatTransform(
4413 scale_small_matrix);
4414 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594415 expected_perspective_surface_layer_draw_transform.Scale(
4416 device_scale_factor * page_scale_factor,
4417 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324418 EXPECT_TRANSFORMATION_MATRIX_EQ(
4419 expected_perspective_surface_draw_transform,
4420 perspective_surface->render_surface()->draw_transform());
4421 EXPECT_TRANSFORMATION_MATRIX_EQ(
4422 expected_perspective_surface_layer_draw_transform,
4423 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094424}
4425
sohan.jyotie3bd6192014-10-13 07:13:594426// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234427TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324428 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
4429 // Verify draw and screen space transforms of layers not in a surface.
4430 MockContentLayerClient delegate;
4431 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474432
[email protected]fb661802013-03-25 01:59:324433 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4434 SetLayerPropertiesForTesting(parent.get(),
4435 identity_matrix,
[email protected]a2566412014-06-05 03:14:204436 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324437 gfx::PointF(),
4438 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:574439 false,
[email protected]fb661802013-03-25 01:59:324440 true);
[email protected]904e9132012-11-01 00:12:474441
[email protected]fb661802013-03-25 01:59:324442 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
4443 SetLayerPropertiesForTesting(child.get(),
4444 identity_matrix,
[email protected]a2566412014-06-05 03:14:204445 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324446 gfx::PointF(),
4447 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574448 false,
[email protected]fb661802013-03-25 01:59:324449 true);
[email protected]904e9132012-11-01 00:12:474450
[email protected]fb661802013-03-25 01:59:324451 scoped_refptr<NoScaleContentLayer> child_no_scale =
4452 CreateNoScaleDrawableContentLayer(&delegate);
4453 SetLayerPropertiesForTesting(child_no_scale.get(),
4454 identity_matrix,
[email protected]a2566412014-06-05 03:14:204455 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324456 gfx::PointF(),
4457 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574458 false,
[email protected]fb661802013-03-25 01:59:324459 true);
[email protected]904e9132012-11-01 00:12:474460
[email protected]fb661802013-03-25 01:59:324461 parent->AddChild(child);
4462 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:474463
enne2097cab2014-09-25 20:16:314464 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284465 host->SetRootLayer(parent);
4466
[email protected]fb661802013-03-25 01:59:324467 float device_scale_factor = 1.7f;
4468 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:474469
[email protected]7aad55f2013-07-26 11:25:534470 RenderSurfaceLayerList render_surface_layer_list;
4471 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4472 parent.get(), parent->bounds(), &render_surface_layer_list);
4473 inputs.device_scale_factor = device_scale_factor;
4474 inputs.page_scale_factor = page_scale_factor;
4475 inputs.page_scale_application_layer = parent.get();
4476 inputs.can_adjust_raster_scales = true;
4477 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:474478
[email protected]fb661802013-03-25 01:59:324479 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4480 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4481 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:474482
[email protected]fb661802013-03-25 01:59:324483 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:474484
[email protected]fb661802013-03-25 01:59:324485 // Verify parent transforms
4486 gfx::Transform expected_parent_transform;
4487 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4488 parent->screen_space_transform());
4489 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4490 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:474491
[email protected]fb661802013-03-25 01:59:324492 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054493 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:474494
[email protected]fb661802013-03-25 01:59:324495 gfx::RectF parent_draw_rect =
4496 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4497 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4498 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:474499
[email protected]2c7c6702013-03-26 03:14:054500 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324501 expected_parent_draw_rect.Scale(device_scale_factor);
4502 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
4503 expected_parent_draw_rect.set_height(
4504 ceil(expected_parent_draw_rect.height()));
4505 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4506 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474507
[email protected]fb661802013-03-25 01:59:324508 // Verify child transforms
4509 gfx::Transform expected_child_transform;
4510 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4511 child->draw_transform());
4512 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4513 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474514
[email protected]fb661802013-03-25 01:59:324515 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:054516 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:474517
[email protected]fb661802013-03-25 01:59:324518 gfx::RectF child_draw_rect =
4519 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4520 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4521 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:474522
[email protected]2c7c6702013-03-26 03:14:054523 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:324524 expected_child_draw_rect.Scale(device_scale_factor);
4525 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
4526 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
4527 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4528 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474529
[email protected]fb661802013-03-25 01:59:324530 // Verify child_no_scale transforms
4531 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4532 // All transforms operate on content rects. The child's content rect
4533 // incorporates device scale, but the child_no_scale does not; add it here.
4534 expected_child_no_scale_transform.Scale(device_scale_factor,
4535 device_scale_factor);
4536 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4537 child_no_scale->draw_transform());
4538 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4539 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474540}
4541
sohan.jyotie3bd6192014-10-13 07:13:594542// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234543TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:324544 MockContentLayerClient delegate;
4545 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444546
[email protected]fb661802013-03-25 01:59:324547 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264548 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324549 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444550
[email protected]fb661802013-03-25 01:59:324551 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264552 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324553 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444554
[email protected]35a99a12013-05-09 23:52:294555 scoped_refptr<Layer> root = Layer::Create();
4556 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444557
[email protected]fb661802013-03-25 01:59:324558 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4559 SetLayerPropertiesForTesting(parent.get(),
4560 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204561 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324562 gfx::PointF(),
4563 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574564 false,
[email protected]fb661802013-03-25 01:59:324565 true);
[email protected]518ee582012-10-24 18:29:444566
[email protected]fb661802013-03-25 01:59:324567 scoped_refptr<ContentLayer> child_scale =
4568 CreateDrawableContentLayer(&delegate);
4569 SetLayerPropertiesForTesting(child_scale.get(),
4570 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204571 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324572 gfx::PointF(2.f, 2.f),
4573 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574574 false,
[email protected]fb661802013-03-25 01:59:324575 true);
[email protected]518ee582012-10-24 18:29:444576
[email protected]fb661802013-03-25 01:59:324577 scoped_refptr<ContentLayer> child_empty =
4578 CreateDrawableContentLayer(&delegate);
4579 SetLayerPropertiesForTesting(child_empty.get(),
4580 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204581 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324582 gfx::PointF(2.f, 2.f),
4583 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574584 false,
[email protected]fb661802013-03-25 01:59:324585 true);
[email protected]f89f5632012-11-14 23:34:454586
[email protected]fb661802013-03-25 01:59:324587 scoped_refptr<NoScaleContentLayer> child_no_scale =
4588 CreateNoScaleDrawableContentLayer(&delegate);
4589 SetLayerPropertiesForTesting(child_no_scale.get(),
4590 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204591 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324592 gfx::PointF(12.f, 12.f),
4593 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574594 false,
[email protected]fb661802013-03-25 01:59:324595 true);
[email protected]518ee582012-10-24 18:29:444596
[email protected]35a99a12013-05-09 23:52:294597 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444598
[email protected]fb661802013-03-25 01:59:324599 parent->AddChild(child_scale);
4600 parent->AddChild(child_empty);
4601 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:444602
enne2097cab2014-09-25 20:16:314603 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284604 host->SetRootLayer(root);
4605
[email protected]fb661802013-03-25 01:59:324606 float device_scale_factor = 2.5f;
4607 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:444608
[email protected]989386c2013-07-18 21:37:234609 {
4610 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534611 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224612 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534613 inputs.device_scale_factor = device_scale_factor;
4614 inputs.page_scale_factor = page_scale_factor;
4615 inputs.page_scale_application_layer = root.get();
4616 inputs.can_adjust_raster_scales = true;
4617 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444618
[email protected]989386c2013-07-18 21:37:234619 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4620 initial_parent_scale, parent);
4621 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4622 initial_parent_scale * initial_child_scale,
4623 child_scale);
4624 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4625 initial_parent_scale * initial_child_scale,
4626 child_empty);
4627 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:444628
[email protected]989386c2013-07-18 21:37:234629 // The parent is scaled up and shouldn't need to scale during draw. The
4630 // child that can scale its contents should also not need to scale during
4631 // draw. This shouldn't change if the child has empty bounds. The other
4632 // children should.
[email protected]803f6b52013-09-12 00:51:264633 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4634 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
4635 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
4636 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
4637 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
4638 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234639 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
4640 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264641 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:234642 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264643 initial_parent_scale * initial_child_scale,
4644 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234645 }
[email protected]518ee582012-10-24 18:29:444646
[email protected]fb661802013-03-25 01:59:324647 // If the device_scale_factor or page_scale_factor changes, then it should be
4648 // updated using the initial transform as the raster scale.
4649 device_scale_factor = 2.25f;
4650 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:444651
[email protected]989386c2013-07-18 21:37:234652 {
4653 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534654 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224655 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534656 inputs.device_scale_factor = device_scale_factor;
4657 inputs.page_scale_factor = page_scale_factor;
4658 inputs.page_scale_application_layer = root.get();
4659 inputs.can_adjust_raster_scales = true;
4660 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4661
4662 EXPECT_CONTENTS_SCALE_EQ(
4663 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:234664 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534665 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:234666 child_scale);
4667 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4668 initial_parent_scale * initial_child_scale,
4669 child_empty);
4670 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4671 }
[email protected]d0518202013-02-08 02:06:494672
[email protected]fb661802013-03-25 01:59:324673 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:264674 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324675 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
4676 second_child_scale / initial_child_scale);
4677 child_scale->SetTransform(child_scale_matrix);
4678 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:494679
[email protected]989386c2013-07-18 21:37:234680 {
4681 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534682 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224683 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534684 inputs.device_scale_factor = device_scale_factor;
4685 inputs.page_scale_factor = page_scale_factor;
4686 inputs.page_scale_application_layer = root.get();
4687 inputs.can_adjust_raster_scales = true;
4688 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494689
[email protected]989386c2013-07-18 21:37:234690 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4691 initial_parent_scale,
4692 parent);
4693 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4694 child_scale);
4695 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4696 child_empty);
4697 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4698 }
[email protected]d0518202013-02-08 02:06:494699
[email protected]fb661802013-03-25 01:59:324700 // If the device_scale_factor or page_scale_factor changes, then it should be
4701 // updated, but still using 1.0 as the raster scale.
4702 device_scale_factor = 2.75f;
4703 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:494704
[email protected]989386c2013-07-18 21:37:234705 {
4706 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534707 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224708 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534709 inputs.device_scale_factor = device_scale_factor;
4710 inputs.page_scale_factor = page_scale_factor;
4711 inputs.page_scale_application_layer = root.get();
4712 inputs.can_adjust_raster_scales = true;
4713 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494714
[email protected]989386c2013-07-18 21:37:234715 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4716 initial_parent_scale,
4717 parent);
4718 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4719 child_scale);
4720 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4721 child_empty);
4722 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4723 }
[email protected]518ee582012-10-24 18:29:444724}
4725
sohan.jyotie3bd6192014-10-13 07:13:594726// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234727TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:594728 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:324729 MockContentLayerClient delegate;
4730 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:214731
[email protected]fb661802013-03-25 01:59:324732 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264733 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324734 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:214735
[email protected]fb661802013-03-25 01:59:324736 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264737 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324738 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:214739
[email protected]35a99a12013-05-09 23:52:294740 scoped_refptr<Layer> root = Layer::Create();
4741 root->SetBounds(gfx::Size(100, 100));
4742
[email protected]fb661802013-03-25 01:59:324743 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4744 SetLayerPropertiesForTesting(parent.get(),
4745 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204746 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324747 gfx::PointF(),
4748 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574749 false,
[email protected]fb661802013-03-25 01:59:324750 true);
[email protected]11ec92972012-11-10 03:06:214751
[email protected]fb661802013-03-25 01:59:324752 scoped_refptr<ContentLayer> child_scale =
4753 CreateDrawableContentLayer(&delegate);
4754 SetLayerPropertiesForTesting(child_scale.get(),
4755 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204756 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324757 gfx::PointF(2.f, 2.f),
4758 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574759 false,
[email protected]fb661802013-03-25 01:59:324760 true);
[email protected]11ec92972012-11-10 03:06:214761
[email protected]35a99a12013-05-09 23:52:294762 scoped_refptr<ContentLayer> child_empty =
4763 CreateDrawableContentLayer(&delegate);
4764 SetLayerPropertiesForTesting(child_empty.get(),
4765 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204766 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294767 gfx::PointF(2.f, 2.f),
4768 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574769 false,
[email protected]35a99a12013-05-09 23:52:294770 true);
4771
4772 scoped_refptr<NoScaleContentLayer> child_no_scale =
4773 CreateNoScaleDrawableContentLayer(&delegate);
4774 SetLayerPropertiesForTesting(child_no_scale.get(),
4775 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204776 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294777 gfx::PointF(12.f, 12.f),
4778 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574779 false,
[email protected]35a99a12013-05-09 23:52:294780 true);
4781
4782 root->AddChild(parent);
4783
4784 parent->AddChild(child_scale);
4785 parent->AddChild(child_empty);
4786 parent->AddChild(child_no_scale);
4787
enne2097cab2014-09-25 20:16:314788 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284789 host->SetRootLayer(root);
4790
[email protected]989386c2013-07-18 21:37:234791 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:294792
4793 float device_scale_factor = 2.5f;
4794 float page_scale_factor = 1.f;
4795
[email protected]7aad55f2013-07-26 11:25:534796 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224797 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534798 inputs.device_scale_factor = device_scale_factor;
4799 inputs.page_scale_factor = page_scale_factor;
4800 inputs.page_scale_application_layer = root.get(),
4801 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:294802
4803 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4804 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4805 child_scale);
4806 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4807 child_empty);
4808 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4809
4810 // Since the transform scale does not affect contents scale, it should affect
4811 // the draw transform instead.
4812 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264813 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294814 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264815 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294816 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264817 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294818 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264819 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294820 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264821 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294822 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264823 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294824 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264825 initial_parent_scale * initial_child_scale,
4826 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294827 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264828 initial_parent_scale * initial_child_scale,
4829 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294830}
4831
sohan.jyotie3bd6192014-10-13 07:13:594832TEST_F(LayerTreeHostCommonTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294833 MockContentLayerClient delegate;
4834 gfx::Transform identity_matrix;
4835
4836 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264837 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294838 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4839
4840 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264841 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294842 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4843
4844 scoped_refptr<Layer> root = Layer::Create();
4845 root->SetBounds(gfx::Size(100, 100));
4846
sohan.jyotie3bd6192014-10-13 07:13:594847 scoped_refptr<FakePictureLayer> parent =
4848 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294849 SetLayerPropertiesForTesting(parent.get(),
4850 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204851 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294852 gfx::PointF(),
4853 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574854 false,
[email protected]35a99a12013-05-09 23:52:294855 true);
4856
sohan.jyotie3bd6192014-10-13 07:13:594857 scoped_refptr<FakePictureLayer> child_scale =
4858 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294859 SetLayerPropertiesForTesting(child_scale.get(),
4860 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204861 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294862 gfx::PointF(2.f, 2.f),
4863 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574864 false,
[email protected]35a99a12013-05-09 23:52:294865 true);
4866
4867 root->AddChild(parent);
4868
[email protected]fb661802013-03-25 01:59:324869 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:214870
enne2097cab2014-09-25 20:16:314871 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284872 host->SetRootLayer(root);
4873
[email protected]fb661802013-03-25 01:59:324874 float device_scale_factor = 2.5f;
4875 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214876
[email protected]989386c2013-07-18 21:37:234877 {
4878 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534879 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224880 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534881 inputs.device_scale_factor = device_scale_factor;
4882 inputs.page_scale_factor = page_scale_factor;
4883 inputs.page_scale_application_layer = root.get();
4884 inputs.can_adjust_raster_scales = true;
4885 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214886
sohan.jyotie3bd6192014-10-13 07:13:594887 // The ideal scale is able to go below 1.
4888 float expected_ideal_scale =
4889 device_scale_factor * page_scale_factor * initial_parent_scale;
4890 EXPECT_LT(expected_ideal_scale, 1.f);
4891 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214892
sohan.jyotie3bd6192014-10-13 07:13:594893 expected_ideal_scale = device_scale_factor * page_scale_factor *
4894 initial_parent_scale * initial_child_scale;
4895 EXPECT_LT(expected_ideal_scale, 1.f);
4896 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234897 }
[email protected]11ec92972012-11-10 03:06:214898}
4899
[email protected]989386c2013-07-18 21:37:234900TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:324901 MockContentLayerClient delegate;
4902 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444903
[email protected]fb661802013-03-25 01:59:324904 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264905 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:324906 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444907
[email protected]fb661802013-03-25 01:59:324908 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264909 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:324910 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444911
[email protected]35a99a12013-05-09 23:52:294912 scoped_refptr<Layer> root = Layer::Create();
4913 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444914
[email protected]fb661802013-03-25 01:59:324915 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4916 SetLayerPropertiesForTesting(parent.get(),
4917 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204918 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324919 gfx::PointF(),
4920 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574921 false,
[email protected]fb661802013-03-25 01:59:324922 true);
[email protected]518ee582012-10-24 18:29:444923
[email protected]fb661802013-03-25 01:59:324924 scoped_refptr<ContentLayer> surface_scale =
4925 CreateDrawableContentLayer(&delegate);
4926 SetLayerPropertiesForTesting(surface_scale.get(),
4927 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204928 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324929 gfx::PointF(2.f, 2.f),
4930 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574931 false,
[email protected]fb661802013-03-25 01:59:324932 true);
[email protected]518ee582012-10-24 18:29:444933
[email protected]fb661802013-03-25 01:59:324934 scoped_refptr<ContentLayer> surface_scale_child_scale =
4935 CreateDrawableContentLayer(&delegate);
4936 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
4937 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204938 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324939 gfx::PointF(),
4940 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574941 false,
[email protected]fb661802013-03-25 01:59:324942 true);
[email protected]518ee582012-10-24 18:29:444943
[email protected]fb661802013-03-25 01:59:324944 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
4945 CreateNoScaleDrawableContentLayer(&delegate);
4946 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
4947 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204948 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324949 gfx::PointF(),
4950 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574951 false,
[email protected]fb661802013-03-25 01:59:324952 true);
[email protected]518ee582012-10-24 18:29:444953
[email protected]fb661802013-03-25 01:59:324954 scoped_refptr<NoScaleContentLayer> surface_no_scale =
4955 CreateNoScaleDrawableContentLayer(&delegate);
4956 SetLayerPropertiesForTesting(surface_no_scale.get(),
4957 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204958 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324959 gfx::PointF(12.f, 12.f),
4960 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574961 false,
[email protected]fb661802013-03-25 01:59:324962 true);
[email protected]518ee582012-10-24 18:29:444963
[email protected]fb661802013-03-25 01:59:324964 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
4965 CreateDrawableContentLayer(&delegate);
4966 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
4967 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204968 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324969 gfx::PointF(),
4970 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574971 false,
[email protected]fb661802013-03-25 01:59:324972 true);
[email protected]518ee582012-10-24 18:29:444973
[email protected]fb661802013-03-25 01:59:324974 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
4975 CreateNoScaleDrawableContentLayer(&delegate);
4976 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
4977 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204978 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324979 gfx::PointF(),
4980 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574981 false,
[email protected]fb661802013-03-25 01:59:324982 true);
[email protected]518ee582012-10-24 18:29:444983
[email protected]35a99a12013-05-09 23:52:294984 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444985
[email protected]fb661802013-03-25 01:59:324986 parent->AddChild(surface_scale);
4987 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:444988
[email protected]fb661802013-03-25 01:59:324989 surface_scale->SetForceRenderSurface(true);
4990 surface_scale->AddChild(surface_scale_child_scale);
4991 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444992
[email protected]fb661802013-03-25 01:59:324993 surface_no_scale->SetForceRenderSurface(true);
4994 surface_no_scale->AddChild(surface_no_scale_child_scale);
4995 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444996
enne2097cab2014-09-25 20:16:314997 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284998 host->SetRootLayer(root);
4999
[email protected]803f6b52013-09-12 00:51:265000 SkMScalar device_scale_factor = 5;
5001 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:445002
[email protected]7aad55f2013-07-26 11:25:535003 RenderSurfaceLayerList render_surface_layer_list;
5004 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225005 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535006 inputs.device_scale_factor = device_scale_factor;
5007 inputs.page_scale_factor = page_scale_factor;
5008 inputs.page_scale_application_layer = root.get();
5009 inputs.can_adjust_raster_scales = true;
5010 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5011
5012 EXPECT_CONTENTS_SCALE_EQ(
5013 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:195014 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:535015 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:325016 surface_scale);
5017 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
5018 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:325019 device_scale_factor * page_scale_factor * initial_parent_scale *
5020 initial_child_scale * initial_child_scale,
5021 surface_scale_child_scale);
5022 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
5023 EXPECT_CONTENTS_SCALE_EQ(
5024 device_scale_factor * page_scale_factor * initial_parent_scale *
5025 initial_child_scale * initial_child_scale,
5026 surface_no_scale_child_scale);
5027 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445028
[email protected]fb661802013-03-25 01:59:325029 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:265030 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
5031 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445032
[email protected]fb661802013-03-25 01:59:325033 // RenderSurfaces should always be 1:1 with their target.
5034 EXPECT_FLOAT_EQ(
5035 1.0,
[email protected]803f6b52013-09-12 00:51:265036 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325037 EXPECT_FLOAT_EQ(
5038 1.0,
[email protected]803f6b52013-09-12 00:51:265039 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445040
[email protected]fb661802013-03-25 01:59:325041 // The surface_scale can apply contents scale so the layer shouldn't need to
5042 // scale during draw.
[email protected]803f6b52013-09-12 00:51:265043 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
5044 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445045
[email protected]fb661802013-03-25 01:59:325046 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5047 // to scale during draw.
5048 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265049 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325050 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265051 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445052
[email protected]fb661802013-03-25 01:59:325053 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5054 // to be scaled during draw.
5055 EXPECT_FLOAT_EQ(
5056 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265057 initial_child_scale * initial_child_scale,
5058 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325059 EXPECT_FLOAT_EQ(
5060 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265061 initial_child_scale * initial_child_scale,
5062 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445063
[email protected]fb661802013-03-25 01:59:325064 // RenderSurfaces should always be 1:1 with their target.
5065 EXPECT_FLOAT_EQ(
5066 1.0,
[email protected]803f6b52013-09-12 00:51:265067 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325068 EXPECT_FLOAT_EQ(
5069 1.0,
[email protected]803f6b52013-09-12 00:51:265070 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445071
[email protected]fb661802013-03-25 01:59:325072 // The surface_no_scale layer can not apply contents scale, so it needs to be
5073 // scaled during draw.
5074 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265075 initial_parent_scale * initial_child_scale,
5076 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325077 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265078 initial_parent_scale * initial_child_scale,
5079 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445080
[email protected]fb661802013-03-25 01:59:325081 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5082 // to scale during draw.
5083 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265084 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325085 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265086 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445087
[email protected]fb661802013-03-25 01:59:325088 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5089 // to be scaled during draw.
5090 EXPECT_FLOAT_EQ(
5091 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265092 initial_child_scale * initial_child_scale,
5093 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325094 EXPECT_FLOAT_EQ(
5095 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265096 initial_child_scale * initial_child_scale,
5097 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295098}
[email protected]518ee582012-10-24 18:29:445099
sohan.jyotie3bd6192014-10-13 07:13:595100// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:235101TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:595102 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
[email protected]35a99a12013-05-09 23:52:295103 MockContentLayerClient delegate;
5104 gfx::Transform identity_matrix;
5105
5106 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265107 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:295108 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5109
5110 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265111 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:295112 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5113
5114 scoped_refptr<Layer> root = Layer::Create();
5115 root->SetBounds(gfx::Size(100, 100));
5116
5117 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5118 SetLayerPropertiesForTesting(parent.get(),
5119 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205120 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295121 gfx::PointF(),
5122 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575123 false,
[email protected]35a99a12013-05-09 23:52:295124 true);
5125
5126 scoped_refptr<ContentLayer> surface_scale =
5127 CreateDrawableContentLayer(&delegate);
5128 SetLayerPropertiesForTesting(surface_scale.get(),
5129 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205130 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295131 gfx::PointF(2.f, 2.f),
5132 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575133 false,
[email protected]35a99a12013-05-09 23:52:295134 true);
5135
5136 scoped_refptr<ContentLayer> surface_scale_child_scale =
5137 CreateDrawableContentLayer(&delegate);
5138 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5139 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205140 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295141 gfx::PointF(),
5142 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575143 false,
[email protected]35a99a12013-05-09 23:52:295144 true);
5145
5146 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
5147 CreateNoScaleDrawableContentLayer(&delegate);
5148 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5149 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205150 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295151 gfx::PointF(),
5152 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575153 false,
[email protected]35a99a12013-05-09 23:52:295154 true);
5155
5156 scoped_refptr<NoScaleContentLayer> surface_no_scale =
5157 CreateNoScaleDrawableContentLayer(&delegate);
5158 SetLayerPropertiesForTesting(surface_no_scale.get(),
5159 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205160 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295161 gfx::PointF(12.f, 12.f),
5162 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575163 false,
[email protected]35a99a12013-05-09 23:52:295164 true);
5165
5166 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
5167 CreateDrawableContentLayer(&delegate);
5168 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5169 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205170 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295171 gfx::PointF(),
5172 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575173 false,
[email protected]35a99a12013-05-09 23:52:295174 true);
5175
5176 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
5177 CreateNoScaleDrawableContentLayer(&delegate);
5178 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5179 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205180 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295181 gfx::PointF(),
5182 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575183 false,
[email protected]35a99a12013-05-09 23:52:295184 true);
5185
5186 root->AddChild(parent);
5187
5188 parent->AddChild(surface_scale);
5189 parent->AddChild(surface_no_scale);
5190
5191 surface_scale->SetForceRenderSurface(true);
5192 surface_scale->AddChild(surface_scale_child_scale);
5193 surface_scale->AddChild(surface_scale_child_no_scale);
5194
5195 surface_no_scale->SetForceRenderSurface(true);
5196 surface_no_scale->AddChild(surface_no_scale_child_scale);
5197 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
5198
enne2097cab2014-09-25 20:16:315199 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285200 host->SetRootLayer(root);
5201
[email protected]989386c2013-07-18 21:37:235202 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:295203
[email protected]803f6b52013-09-12 00:51:265204 SkMScalar device_scale_factor = 5.0;
5205 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:535206 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225207 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535208 inputs.device_scale_factor = device_scale_factor;
5209 inputs.page_scale_factor = page_scale_factor;
5210 inputs.page_scale_application_layer = root.get();
5211 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:295212
[email protected]35a99a12013-05-09 23:52:295213 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5214 parent);
5215 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5216 surface_scale);
5217 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
5218 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5219 surface_scale_child_scale);
5220 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
5221 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5222 surface_no_scale_child_scale);
5223 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
5224
5225 // The parent is scaled up during draw, since its contents are not scaled by
5226 // the transform hierarchy.
5227 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265228 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295229 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265230 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295231
hendrikwc493d2682015-01-26 23:35:115232 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295233 // by the transform hierarchy.
5234 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115235 1.f,
[email protected]803f6b52013-09-12 00:51:265236 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295237 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115238 1.f,
[email protected]803f6b52013-09-12 00:51:265239 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295240
hendrikwc493d2682015-01-26 23:35:115241 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5242 // needs to be scaled when drawing into its surface.
5243 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5244 surface_scale->draw_transform().matrix().get(0, 0));
5245 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5246 surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445247
hendrikwc493d2682015-01-26 23:35:115248 // The surface_scale_child_scale is not scaled when drawing into its surface,
5249 // since its content bounds are scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:325250 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115251 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265252 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325253 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115254 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265255 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445256
hendrikwc493d2682015-01-26 23:35:115257 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5258 // and transform hierarchy.
[email protected]fb661802013-03-25 01:59:325259 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115260 device_scale_factor * page_scale_factor * initial_parent_scale *
5261 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265262 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295263 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115264 device_scale_factor * page_scale_factor * initial_parent_scale *
5265 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265266 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295267
hendrikwc493d2682015-01-26 23:35:115268 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295269 // by the transform hierarchy.
5270 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115271 1.f,
[email protected]803f6b52013-09-12 00:51:265272 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325273 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115274 1.f,
[email protected]803f6b52013-09-12 00:51:265275 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445276
[email protected]35a99a12013-05-09 23:52:295277 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5278 // be scaled by the device and page scale factors. Its surface is already
5279 // scaled by the transform hierarchy so those don't need to scale the layer's
5280 // drawing.
hendrikwc493d2682015-01-26 23:35:115281 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5282 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265283 surface_no_scale->draw_transform().matrix().get(0, 0));
hendrikwc493d2682015-01-26 23:35:115284 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5285 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265286 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295287
5288 // The surface_no_scale_child_scale has its contents scaled by the page and
5289 // device scale factors, but needs to be scaled by the transform hierarchy
5290 // when drawing.
[email protected]fb661802013-03-25 01:59:325291 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115292 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265293 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325294 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115295 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265296 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295297
hendrikwc493d2682015-01-26 23:35:115298 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5299 // page scale factors and by any transform heirarchy below its target surface.
[email protected]35a99a12013-05-09 23:52:295300 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115301 device_scale_factor * page_scale_factor * initial_parent_scale *
5302 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265303 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295304 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115305 device_scale_factor * page_scale_factor * initial_parent_scale *
5306 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265307 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445308}
5309
sohan.jyotie3bd6192014-10-13 07:13:595310TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:325311 MockContentLayerClient delegate;
5312 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265313
[email protected]fb661802013-03-25 01:59:325314 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265315 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:325316 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:265317
[email protected]fb661802013-03-25 01:59:325318 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265319 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:325320 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:265321
[email protected]35a99a12013-05-09 23:52:295322 scoped_refptr<Layer> root = Layer::Create();
5323 root->SetBounds(gfx::Size(100, 100));
5324
sohan.jyotie3bd6192014-10-13 07:13:595325 scoped_refptr<FakePictureLayer> parent =
5326 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325327 SetLayerPropertiesForTesting(parent.get(),
5328 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205329 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325330 gfx::PointF(),
5331 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575332 false,
[email protected]fb661802013-03-25 01:59:325333 true);
[email protected]6a9cff92012-11-08 11:53:265334
sohan.jyotie3bd6192014-10-13 07:13:595335 scoped_refptr<FakePictureLayer> child_scale =
5336 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325337 SetLayerPropertiesForTesting(child_scale.get(),
5338 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205339 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325340 gfx::PointF(2.f, 2.f),
5341 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575342 false,
[email protected]fb661802013-03-25 01:59:325343 true);
[email protected]6a9cff92012-11-08 11:53:265344
[email protected]35a99a12013-05-09 23:52:295345 root->AddChild(parent);
5346
[email protected]fb661802013-03-25 01:59:325347 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:265348
enne2097cab2014-09-25 20:16:315349 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285350 host->SetRootLayer(root);
5351
[email protected]989386c2013-07-18 21:37:235352 {
5353 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535354 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225355 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535356 inputs.can_adjust_raster_scales = true;
5357 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265358
sohan.jyotie3bd6192014-10-13 07:13:595359 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
5360 // Animating layers compute ideal scale in the same way as when
5361 // they are static.
5362 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
5363 child_scale);
[email protected]989386c2013-07-18 21:37:235364 }
[email protected]6a9cff92012-11-08 11:53:265365}
5366
sohan.jyotie3bd6192014-10-13 07:13:595367// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]7a5a9322014-02-25 12:54:575368TEST_F(LayerTreeHostCommonTest,
5369 ChangeInContentBoundsOrScaleTriggersPushProperties) {
5370 MockContentLayerClient delegate;
5371 scoped_refptr<Layer> root = Layer::Create();
5372 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
5373 root->AddChild(child);
5374
enne2097cab2014-09-25 20:16:315375 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]7a5a9322014-02-25 12:54:575376 host->SetRootLayer(root);
5377
5378 gfx::Transform identity_matrix;
5379 SetLayerPropertiesForTesting(root.get(),
5380 identity_matrix,
[email protected]a2566412014-06-05 03:14:205381 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575382 gfx::PointF(),
5383 gfx::Size(100, 100),
5384 true,
5385 false);
5386 SetLayerPropertiesForTesting(child.get(),
5387 identity_matrix,
[email protected]a2566412014-06-05 03:14:205388 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575389 gfx::PointF(),
5390 gfx::Size(100, 100),
5391 true,
5392 false);
5393
5394 root->reset_needs_push_properties_for_testing();
5395 child->reset_needs_push_properties_for_testing();
5396
5397 // This will change both layers' content bounds.
5398 ExecuteCalculateDrawProperties(root.get());
5399 EXPECT_TRUE(root->needs_push_properties());
5400 EXPECT_TRUE(child->needs_push_properties());
5401
5402 root->reset_needs_push_properties_for_testing();
5403 child->reset_needs_push_properties_for_testing();
5404
5405 // This will change only the child layer's contents scale and content bounds,
5406 // since the root layer is not a ContentsScalingLayer.
5407 ExecuteCalculateDrawProperties(root.get(), 2.f);
5408 EXPECT_FALSE(root->needs_push_properties());
5409 EXPECT_TRUE(child->needs_push_properties());
5410
5411 root->reset_needs_push_properties_for_testing();
5412 child->reset_needs_push_properties_for_testing();
5413
5414 // This will not change either layer's contents scale or content bounds.
5415 ExecuteCalculateDrawProperties(root.get(), 2.f);
5416 EXPECT_FALSE(root->needs_push_properties());
5417 EXPECT_FALSE(child->needs_push_properties());
5418}
5419
[email protected]989386c2013-07-18 21:37:235420TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:325421 MockContentLayerClient delegate;
5422 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265423
sohan.jyotie3bd6192014-10-13 07:13:595424 scoped_refptr<FakePictureLayer> parent =
5425 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325426 SetLayerPropertiesForTesting(parent.get(),
5427 identity_matrix,
[email protected]a2566412014-06-05 03:14:205428 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325429 gfx::PointF(),
5430 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575431 false,
[email protected]fb661802013-03-25 01:59:325432 true);
[email protected]94f206c12012-08-25 00:09:145433
sohan.jyotie3bd6192014-10-13 07:13:595434 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325435 SetLayerPropertiesForTesting(child.get(),
5436 identity_matrix,
[email protected]a2566412014-06-05 03:14:205437 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325438 gfx::PointF(2.f, 2.f),
5439 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575440 false,
[email protected]fb661802013-03-25 01:59:325441 true);
[email protected]94f206c12012-08-25 00:09:145442
[email protected]fb661802013-03-25 01:59:325443 gfx::Transform replica_transform;
5444 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595445 scoped_refptr<FakePictureLayer> replica =
5446 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325447 SetLayerPropertiesForTesting(replica.get(),
5448 replica_transform,
[email protected]a2566412014-06-05 03:14:205449 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325450 gfx::PointF(2.f, 2.f),
5451 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575452 false,
[email protected]fb661802013-03-25 01:59:325453 true);
[email protected]94f206c12012-08-25 00:09:145454
[email protected]fb661802013-03-25 01:59:325455 // This layer should end up in the same surface as child, with the same draw
5456 // and screen space transforms.
sohan.jyotie3bd6192014-10-13 07:13:595457 scoped_refptr<FakePictureLayer> duplicate_child_non_owner =
5458 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325459 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5460 identity_matrix,
[email protected]a2566412014-06-05 03:14:205461 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325462 gfx::PointF(),
5463 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575464 false,
[email protected]fb661802013-03-25 01:59:325465 true);
[email protected]94f206c12012-08-25 00:09:145466
[email protected]fb661802013-03-25 01:59:325467 parent->AddChild(child);
5468 child->AddChild(duplicate_child_non_owner);
5469 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:145470
enne2097cab2014-09-25 20:16:315471 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285472 host->SetRootLayer(parent);
5473
[email protected]989386c2013-07-18 21:37:235474 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145475
[email protected]fb661802013-03-25 01:59:325476 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:535477 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5478 parent.get(), parent->bounds(), &render_surface_layer_list);
5479 inputs.device_scale_factor = device_scale_factor;
5480 inputs.can_adjust_raster_scales = true;
5481 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145482
[email protected]fb661802013-03-25 01:59:325483 // We should have two render surfaces. The root's render surface and child's
5484 // render surface (it needs one because it has a replica layer).
5485 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:145486
[email protected]fb661802013-03-25 01:59:325487 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:595488 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325489 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5490 parent->screen_space_transform());
5491 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5492 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:145493
[email protected]fb661802013-03-25 01:59:325494 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:595495 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325496 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
5497 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:145498
[email protected]fb661802013-03-25 01:59:325499 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:595500 expected_screen_space_transform.Scale(device_scale_factor,
5501 device_scale_factor);
5502 expected_screen_space_transform.Translate(child->position().x(),
5503 child->position().y());
[email protected]fb661802013-03-25 01:59:325504 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
5505 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145506
[email protected]fb661802013-03-25 01:59:325507 gfx::Transform expected_duplicate_child_draw_transform =
5508 child->draw_transform();
5509 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
5510 duplicate_child_non_owner->draw_transform());
5511 EXPECT_TRANSFORMATION_MATRIX_EQ(
5512 child->screen_space_transform(),
5513 duplicate_child_non_owner->screen_space_transform());
hush6b614212014-12-04 22:37:325514 EXPECT_EQ(child->drawable_content_rect(),
5515 duplicate_child_non_owner->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:325516 EXPECT_EQ(child->content_bounds(),
5517 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:145518
[email protected]fb661802013-03-25 01:59:325519 gfx::Transform expected_render_surface_draw_transform;
5520 expected_render_surface_draw_transform.Translate(
5521 device_scale_factor * child->position().x(),
5522 device_scale_factor * child->position().y());
5523 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
5524 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145525
[email protected]fb661802013-03-25 01:59:325526 gfx::Transform expected_surface_draw_transform;
5527 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5528 device_scale_factor * 2.f);
5529 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5530 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145531
[email protected]fb661802013-03-25 01:59:325532 gfx::Transform expected_surface_screen_space_transform;
5533 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5534 device_scale_factor * 2.f);
5535 EXPECT_TRANSFORMATION_MATRIX_EQ(
5536 expected_surface_screen_space_transform,
5537 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145538
[email protected]fb661802013-03-25 01:59:325539 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265540 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5541 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5542 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325543 EXPECT_TRANSFORMATION_MATRIX_EQ(
5544 expected_replica_draw_transform,
5545 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145546
[email protected]fb661802013-03-25 01:59:325547 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265548 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5549 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5550 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325551 EXPECT_TRANSFORMATION_MATRIX_EQ(
5552 expected_replica_screen_space_transform,
5553 child->render_surface()->replica_screen_space_transform());
5554 EXPECT_TRANSFORMATION_MATRIX_EQ(
5555 expected_replica_screen_space_transform,
5556 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475557}
5558
[email protected]989386c2013-07-18 21:37:235559TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325560 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5561 MockContentLayerClient delegate;
5562 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475563
sohan.jyotie3bd6192014-10-13 07:13:595564 scoped_refptr<FakePictureLayer> parent =
5565 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325566 SetLayerPropertiesForTesting(parent.get(),
5567 identity_matrix,
[email protected]a2566412014-06-05 03:14:205568 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325569 gfx::PointF(),
5570 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:575571 false,
[email protected]fb661802013-03-25 01:59:325572 true);
[email protected]904e9132012-11-01 00:12:475573
sohan.jyotie3bd6192014-10-13 07:13:595574 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325575 SetLayerPropertiesForTesting(child.get(),
5576 identity_matrix,
[email protected]a2566412014-06-05 03:14:205577 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325578 gfx::PointF(),
5579 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575580 false,
[email protected]fb661802013-03-25 01:59:325581 true);
[email protected]904e9132012-11-01 00:12:475582
[email protected]fb661802013-03-25 01:59:325583 gfx::Transform replica_transform;
5584 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595585 scoped_refptr<FakePictureLayer> replica =
5586 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325587 SetLayerPropertiesForTesting(replica.get(),
5588 replica_transform,
[email protected]a2566412014-06-05 03:14:205589 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325590 gfx::PointF(),
5591 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575592 false,
[email protected]fb661802013-03-25 01:59:325593 true);
[email protected]904e9132012-11-01 00:12:475594
[email protected]fb661802013-03-25 01:59:325595 parent->AddChild(child);
[email protected]fb661802013-03-25 01:59:325596 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:475597
enne2097cab2014-09-25 20:16:315598 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285599 host->SetRootLayer(parent);
5600
[email protected]873639e2013-07-24 19:56:315601 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:535602
5603 RenderSurfaceLayerList render_surface_layer_list;
5604 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5605 parent.get(), parent->bounds(), &render_surface_layer_list);
5606 inputs.device_scale_factor = device_scale_factor;
5607 inputs.can_adjust_raster_scales = true;
5608 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:475609
[email protected]fb661802013-03-25 01:59:325610 // We should have two render surfaces. The root's render surface and child's
5611 // render surface (it needs one because it has a replica layer).
5612 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:475613
[email protected]fb661802013-03-25 01:59:325614 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325615 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5616 child->render_surface()->draw_transform());
5617 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5618 child->render_surface()->draw_transform());
5619 EXPECT_TRANSFORMATION_MATRIX_EQ(
5620 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475621
[email protected]fb661802013-03-25 01:59:325622 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265623 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325624 EXPECT_TRANSFORMATION_MATRIX_EQ(
5625 expected_replica_draw_transform,
5626 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475627
[email protected]fb661802013-03-25 01:59:325628 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265629 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325630 EXPECT_TRANSFORMATION_MATRIX_EQ(
5631 expected_replica_screen_space_transform,
5632 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145633}
5634
[email protected]989386c2013-07-18 21:37:235635TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:325636 scoped_refptr<Layer> root = Layer::Create();
5637 scoped_refptr<Layer> child = Layer::Create();
5638 scoped_refptr<Layer> grand_child = Layer::Create();
5639 scoped_refptr<Layer> mask_layer = Layer::Create();
5640 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145641
[email protected]fb661802013-03-25 01:59:325642 grand_child->SetReplicaLayer(replica_layer.get());
5643 child->AddChild(grand_child.get());
5644 child->SetMaskLayer(mask_layer.get());
5645 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145646
enne2097cab2014-09-25 20:16:315647 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285648 host->SetRootLayer(root);
5649
[email protected]fb661802013-03-25 01:59:325650 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:105651 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:325652 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:105653 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:325654 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5655 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105656 grand_child.get(),
[email protected]fb661802013-03-25 01:59:325657 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5658 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105659 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:325660 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5661 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105662 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:325663 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5664 EXPECT_EQ(
5665 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145666}
5667
[email protected]989386c2013-07-18 21:37:235668TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:325669 scoped_refptr<Layer> root = Layer::Create();
5670 scoped_refptr<Layer> child = Layer::Create();
5671 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
5672 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:575673
[email protected]fb661802013-03-25 01:59:325674 const gfx::Transform identity_matrix;
5675 SetLayerPropertiesForTesting(root.get(),
5676 identity_matrix,
[email protected]a2566412014-06-05 03:14:205677 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325678 gfx::PointF(),
5679 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575680 true,
[email protected]fb661802013-03-25 01:59:325681 false);
5682 SetLayerPropertiesForTesting(child.get(),
5683 identity_matrix,
[email protected]a2566412014-06-05 03:14:205684 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325685 gfx::PointF(),
5686 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575687 true,
[email protected]fb661802013-03-25 01:59:325688 false);
5689 SetLayerPropertiesForTesting(grand_child.get(),
5690 identity_matrix,
[email protected]a2566412014-06-05 03:14:205691 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325692 gfx::PointF(),
5693 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575694 true,
[email protected]fb661802013-03-25 01:59:325695 false);
[email protected]498ec6e0e2012-11-30 18:24:575696
[email protected]fb661802013-03-25 01:59:325697 root->AddChild(child);
5698 child->AddChild(grand_child);
5699 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575700
enne2097cab2014-09-25 20:16:315701 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285702 host->SetRootLayer(root);
5703
[email protected]fb661802013-03-25 01:59:325704 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575705
[email protected]fb661802013-03-25 01:59:325706 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575707}
5708
[email protected]989386c2013-07-18 21:37:235709TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:165710 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455711 TestSharedBitmapManager shared_bitmap_manager;
5712 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:165713 host_impl.CreatePendingTree();
5714 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5715
5716 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005717 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5718 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165719 false);
5720 root->SetDrawsContent(true);
5721
5722 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005723 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5724 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165725 false);
5726 child->SetDrawsContent(true);
5727 child->SetOpacity(0.0f);
5728
5729 // Add opacity animation.
5730 AddOpacityTransitionToController(
5731 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
5732
5733 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:005734 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:165735
[email protected]c0ae06c12013-06-24 18:32:195736 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535737 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225738 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535739 inputs.can_adjust_raster_scales = true;
5740 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165741
5742 // We should have one render surface and two layers. The child
5743 // layer should be included even though it is transparent.
5744 ASSERT_EQ(1u, render_surface_layer_list.size());
5745 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5746}
5747
danakj3f76ace2014-11-18 16:56:005748using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
[email protected]989386c2013-07-18 21:37:235749class LCDTextTest
5750 : public LayerTreeHostCommonTestBase,
5751 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365752 public:
5753 LCDTextTest()
5754 : host_impl_(&proxy_, &shared_bitmap_manager_),
5755 root_(nullptr),
5756 child_(nullptr),
5757 grand_child_(nullptr) {}
5758
[email protected]fb661802013-03-25 01:59:325759 protected:
dcheng93a52eb2014-12-23 02:14:235760 void SetUp() override {
[email protected]fb661802013-03-25 01:59:325761 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005762 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595763
enneaf5bda32015-02-19 01:27:365764 scoped_ptr<LayerImpl> root_ptr =
5765 LayerImpl::Create(host_impl_.active_tree(), 1);
5766 scoped_ptr<LayerImpl> child_ptr =
5767 LayerImpl::Create(host_impl_.active_tree(), 2);
5768 scoped_ptr<LayerImpl> grand_child_ptr =
5769 LayerImpl::Create(host_impl_.active_tree(), 3);
5770
5771 // Stash raw pointers to look at later.
5772 root_ = root_ptr.get();
5773 child_ = child_ptr.get();
5774 grand_child_ = grand_child_ptr.get();
5775
5776 child_->AddChild(grand_child_ptr.Pass());
5777 root_->AddChild(child_ptr.Pass());
5778 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
[email protected]10aabcc32012-12-13 09:18:595779
fmalita51b5e202014-11-18 20:11:505780 root_->SetContentsOpaque(true);
5781 child_->SetContentsOpaque(true);
5782 grand_child_->SetContentsOpaque(true);
5783
[email protected]fb661802013-03-25 01:59:325784 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365785 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5786 gfx::PointF(), gfx::Size(1, 1), true, false,
5787 true);
5788 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5789 gfx::PointF(), gfx::Size(1, 1), true, false,
5790 std::tr1::get<2>(GetParam()));
5791 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5792 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325793 false);
[email protected]fb661802013-03-25 01:59:325794 }
[email protected]10aabcc32012-12-13 09:18:595795
[email protected]fb661802013-03-25 01:59:325796 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005797 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365798
5799 FakeImplProxy proxy_;
5800 TestSharedBitmapManager shared_bitmap_manager_;
5801 FakeLayerTreeHostImpl host_impl_;
5802
5803 LayerImpl* root_;
5804 LayerImpl* child_;
5805 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595806};
5807
[email protected]fb661802013-03-25 01:59:325808TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005809 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5810 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5811
[email protected]fb661802013-03-25 01:59:325812 // Case 1: Identity transform.
5813 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365814 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005815 layers_always_allowed_lcd_text_);
5816 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5817 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5818 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595819
[email protected]fb661802013-03-25 01:59:325820 // Case 2: Integral translation.
5821 gfx::Transform integral_translation;
5822 integral_translation.Translate(1.0, 2.0);
5823 child_->SetTransform(integral_translation);
enneaf5bda32015-02-19 01:27:365824 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005825 layers_always_allowed_lcd_text_);
5826 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5827 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5828 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595829
[email protected]fb661802013-03-25 01:59:325830 // Case 3: Non-integral translation.
5831 gfx::Transform non_integral_translation;
5832 non_integral_translation.Translate(1.5, 2.5);
5833 child_->SetTransform(non_integral_translation);
enneaf5bda32015-02-19 01:27:365834 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005835 layers_always_allowed_lcd_text_);
5836 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5837 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5838 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595839
[email protected]fb661802013-03-25 01:59:325840 // Case 4: Rotation.
5841 gfx::Transform rotation;
5842 rotation.Rotate(10.0);
5843 child_->SetTransform(rotation);
enneaf5bda32015-02-19 01:27:365844 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005845 layers_always_allowed_lcd_text_);
5846 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5847 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5848 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595849
[email protected]fb661802013-03-25 01:59:325850 // Case 5: Scale.
5851 gfx::Transform scale;
5852 scale.Scale(2.0, 2.0);
5853 child_->SetTransform(scale);
enneaf5bda32015-02-19 01:27:365854 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005855 layers_always_allowed_lcd_text_);
5856 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5857 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5858 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595859
[email protected]fb661802013-03-25 01:59:325860 // Case 6: Skew.
5861 gfx::Transform skew;
5862 skew.SkewX(10.0);
5863 child_->SetTransform(skew);
enneaf5bda32015-02-19 01:27:365864 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005865 layers_always_allowed_lcd_text_);
5866 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5867 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5868 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595869
[email protected]fb661802013-03-25 01:59:325870 // Case 7: Translucent.
5871 child_->SetTransform(identity_matrix);
5872 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365873 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005874 layers_always_allowed_lcd_text_);
5875 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5876 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5877 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595878
[email protected]fb661802013-03-25 01:59:325879 // Case 8: Sanity check: restore transform and opacity.
5880 child_->SetTransform(identity_matrix);
5881 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365882 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005883 layers_always_allowed_lcd_text_);
5884 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5885 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5886 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505887
5888 // Case 9: Non-opaque content.
5889 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365890 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505891 layers_always_allowed_lcd_text_);
5892 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5893 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5894 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5895
5896 // Case 10: Sanity check: restore content opaqueness.
5897 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365898 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505899 layers_always_allowed_lcd_text_);
5900 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5901 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5902 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595903}
5904
[email protected]fd9a3b6d2013-08-03 00:46:175905TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005906 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5907
[email protected]fb661802013-03-25 01:59:325908 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365909 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005910 layers_always_allowed_lcd_text_);
5911 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5912 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5913 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595914
[email protected]fb661802013-03-25 01:59:325915 // Add opacity animation.
5916 child_->SetOpacity(0.9f);
5917 AddOpacityTransitionToController(
5918 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:595919
enneaf5bda32015-02-19 01:27:365920 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005921 layers_always_allowed_lcd_text_);
[email protected]fb661802013-03-25 01:59:325922 // Text AA should not be adjusted while animation is active.
5923 // Make sure LCD text AA setting remains unchanged.
danakj3f76ace2014-11-18 16:56:005924 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5925 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5926 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595927}
5928
5929INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5930 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005931 testing::Combine(testing::Bool(),
5932 testing::Bool(),
5933 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595934
[email protected]989386c2013-07-18 21:37:235935TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:195936 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455937 TestSharedBitmapManager shared_bitmap_manager;
5938 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195939 host_impl.CreatePendingTree();
5940 const gfx::Transform identity_matrix;
5941
5942 scoped_refptr<Layer> root = Layer::Create();
5943 SetLayerPropertiesForTesting(root.get(),
5944 identity_matrix,
[email protected]a2566412014-06-05 03:14:205945 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195946 gfx::PointF(),
5947 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575948 true,
[email protected]c0ae06c12013-06-24 18:32:195949 false);
5950 root->SetIsDrawable(true);
5951
5952 scoped_refptr<Layer> child = Layer::Create();
5953 SetLayerPropertiesForTesting(child.get(),
5954 identity_matrix,
[email protected]a2566412014-06-05 03:14:205955 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195956 gfx::PointF(),
5957 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:575958 true,
[email protected]c0ae06c12013-06-24 18:32:195959 false);
5960 child->SetIsDrawable(true);
5961
5962 scoped_refptr<Layer> grand_child = Layer::Create();
5963 SetLayerPropertiesForTesting(grand_child.get(),
5964 identity_matrix,
[email protected]a2566412014-06-05 03:14:205965 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195966 gfx::PointF(),
5967 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575968 true,
[email protected]c0ae06c12013-06-24 18:32:195969 false);
5970 grand_child->SetIsDrawable(true);
5971 grand_child->SetHideLayerAndSubtree(true);
5972
5973 child->AddChild(grand_child);
5974 root->AddChild(child);
5975
enne2097cab2014-09-25 20:16:315976 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285977 host->SetRootLayer(root);
5978
[email protected]989386c2013-07-18 21:37:235979 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535980 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225981 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535982 inputs.can_adjust_raster_scales = true;
5983 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195984
5985 // We should have one render surface and two layers. The grand child has
5986 // hidden itself.
5987 ASSERT_EQ(1u, render_surface_layer_list.size());
5988 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235989 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5990 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195991}
5992
[email protected]989386c2013-07-18 21:37:235993TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:195994 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455995 TestSharedBitmapManager shared_bitmap_manager;
5996 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195997 host_impl.CreatePendingTree();
5998 const gfx::Transform identity_matrix;
5999
6000 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006001 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6002 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:196003 false);
6004 root->SetDrawsContent(true);
6005
6006 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006007 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6008 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196009 false);
6010 child->SetDrawsContent(true);
6011
6012 scoped_ptr<LayerImpl> grand_child =
6013 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006014 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6015 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6016 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196017 grand_child->SetDrawsContent(true);
6018 grand_child->SetHideLayerAndSubtree(true);
6019
6020 child->AddChild(grand_child.Pass());
6021 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:006022 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:196023
6024 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536025 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226026 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536027 inputs.can_adjust_raster_scales = true;
6028 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196029
6030 // We should have one render surface and two layers. The grand child has
6031 // hidden itself.
6032 ASSERT_EQ(1u, render_surface_layer_list.size());
6033 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236034 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
6035 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196036}
6037
[email protected]989386c2013-07-18 21:37:236038TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:196039 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456040 TestSharedBitmapManager shared_bitmap_manager;
6041 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196042 host_impl.CreatePendingTree();
6043 const gfx::Transform identity_matrix;
6044
6045 scoped_refptr<Layer> root = Layer::Create();
6046 SetLayerPropertiesForTesting(root.get(),
6047 identity_matrix,
[email protected]a2566412014-06-05 03:14:206048 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196049 gfx::PointF(),
6050 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576051 true,
[email protected]c0ae06c12013-06-24 18:32:196052 false);
6053 root->SetIsDrawable(true);
6054
6055 scoped_refptr<Layer> child = Layer::Create();
6056 SetLayerPropertiesForTesting(child.get(),
6057 identity_matrix,
[email protected]a2566412014-06-05 03:14:206058 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196059 gfx::PointF(),
6060 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576061 true,
[email protected]c0ae06c12013-06-24 18:32:196062 false);
6063 child->SetIsDrawable(true);
6064 child->SetHideLayerAndSubtree(true);
6065
6066 scoped_refptr<Layer> grand_child = Layer::Create();
6067 SetLayerPropertiesForTesting(grand_child.get(),
6068 identity_matrix,
[email protected]a2566412014-06-05 03:14:206069 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196070 gfx::PointF(),
6071 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576072 true,
[email protected]c0ae06c12013-06-24 18:32:196073 false);
6074 grand_child->SetIsDrawable(true);
6075
6076 child->AddChild(grand_child);
6077 root->AddChild(child);
6078
enne2097cab2014-09-25 20:16:316079 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286080 host->SetRootLayer(root);
6081
[email protected]989386c2013-07-18 21:37:236082 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536083 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226084 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536085 inputs.can_adjust_raster_scales = true;
6086 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196087
6088 // We should have one render surface and one layers. The child has
6089 // hidden itself and the grand child.
6090 ASSERT_EQ(1u, render_surface_layer_list.size());
6091 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236092 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196093}
6094
[email protected]989386c2013-07-18 21:37:236095TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:196096 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456097 TestSharedBitmapManager shared_bitmap_manager;
6098 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196099 host_impl.CreatePendingTree();
6100 const gfx::Transform identity_matrix;
6101
6102 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006103 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6104 gfx::PointF(), gfx::Size(50, 50), true, false,
6105 true);
[email protected]c0ae06c12013-06-24 18:32:196106 root->SetDrawsContent(true);
6107
6108 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006109 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6110 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196111 false);
6112 child->SetDrawsContent(true);
6113 child->SetHideLayerAndSubtree(true);
6114
6115 scoped_ptr<LayerImpl> grand_child =
6116 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006117 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6118 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6119 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196120 grand_child->SetDrawsContent(true);
6121
6122 child->AddChild(grand_child.Pass());
6123 root->AddChild(child.Pass());
6124
6125 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536126 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226127 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536128 inputs.can_adjust_raster_scales = true;
6129 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196130
6131 // We should have one render surface and one layers. The child has
6132 // hidden itself and the grand child.
6133 ASSERT_EQ(1u, render_surface_layer_list.size());
6134 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236135 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196136}
6137
[email protected]30fe19ff2013-07-04 00:54:456138void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
6139
[email protected]989386c2013-07-18 21:37:236140TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456141 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456142 TestSharedBitmapManager shared_bitmap_manager;
6143 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456144 host_impl.CreatePendingTree();
6145 const gfx::Transform identity_matrix;
6146
6147 scoped_refptr<Layer> root = Layer::Create();
6148 SetLayerPropertiesForTesting(root.get(),
6149 identity_matrix,
[email protected]a2566412014-06-05 03:14:206150 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456151 gfx::PointF(),
6152 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576153 true,
[email protected]30fe19ff2013-07-04 00:54:456154 false);
6155 root->SetIsDrawable(true);
6156
6157 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
6158 SetLayerPropertiesForTesting(copy_grand_parent.get(),
6159 identity_matrix,
[email protected]a2566412014-06-05 03:14:206160 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456161 gfx::PointF(),
6162 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576163 true,
[email protected]30fe19ff2013-07-04 00:54:456164 false);
6165 copy_grand_parent->SetIsDrawable(true);
6166
6167 scoped_refptr<Layer> copy_parent = Layer::Create();
6168 SetLayerPropertiesForTesting(copy_parent.get(),
6169 identity_matrix,
[email protected]a2566412014-06-05 03:14:206170 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456171 gfx::PointF(),
6172 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576173 true,
[email protected]30fe19ff2013-07-04 00:54:456174 false);
6175 copy_parent->SetIsDrawable(true);
6176 copy_parent->SetForceRenderSurface(true);
6177
6178 scoped_refptr<Layer> copy_layer = Layer::Create();
6179 SetLayerPropertiesForTesting(copy_layer.get(),
6180 identity_matrix,
[email protected]a2566412014-06-05 03:14:206181 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456182 gfx::PointF(),
6183 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576184 true,
[email protected]30fe19ff2013-07-04 00:54:456185 false);
6186 copy_layer->SetIsDrawable(true);
6187
6188 scoped_refptr<Layer> copy_child = Layer::Create();
6189 SetLayerPropertiesForTesting(copy_child.get(),
6190 identity_matrix,
[email protected]a2566412014-06-05 03:14:206191 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456192 gfx::PointF(),
6193 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576194 true,
[email protected]30fe19ff2013-07-04 00:54:456195 false);
6196 copy_child->SetIsDrawable(true);
6197
[email protected]ac020122013-07-12 23:45:536198 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
6199 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
6200 identity_matrix,
[email protected]a2566412014-06-05 03:14:206201 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536202 gfx::PointF(),
6203 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576204 true,
[email protected]ac020122013-07-12 23:45:536205 false);
6206 copy_grand_parent_sibling_before->SetIsDrawable(true);
6207
6208 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
6209 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
6210 identity_matrix,
[email protected]a2566412014-06-05 03:14:206211 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536212 gfx::PointF(),
6213 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576214 true,
[email protected]ac020122013-07-12 23:45:536215 false);
6216 copy_grand_parent_sibling_after->SetIsDrawable(true);
6217
[email protected]30fe19ff2013-07-04 00:54:456218 copy_layer->AddChild(copy_child);
6219 copy_parent->AddChild(copy_layer);
6220 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:536221 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:456222 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:536223 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:456224
enne2097cab2014-09-25 20:16:316225 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286226 host->SetRootLayer(root);
6227
[email protected]30fe19ff2013-07-04 00:54:456228 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6229 // hidden subtree on copy_layer.
6230 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:536231 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
6232 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:456233 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6234 base::Bind(&EmptyCopyOutputCallback)));
6235 EXPECT_TRUE(copy_layer->HasCopyRequest());
6236
[email protected]989386c2013-07-18 21:37:236237 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536238 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226239 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536240 inputs.can_adjust_raster_scales = true;
6241 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456242
[email protected]ac020122013-07-12 23:45:536243 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
6244 EXPECT_TRUE(copy_grand_parent->draw_properties().
6245 layer_or_descendant_has_copy_request);
6246 EXPECT_TRUE(copy_parent->draw_properties().
6247 layer_or_descendant_has_copy_request);
6248 EXPECT_TRUE(copy_layer->draw_properties().
6249 layer_or_descendant_has_copy_request);
6250 EXPECT_FALSE(copy_child->draw_properties().
6251 layer_or_descendant_has_copy_request);
6252 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
6253 layer_or_descendant_has_copy_request);
6254 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
6255 layer_or_descendant_has_copy_request);
6256
[email protected]30fe19ff2013-07-04 00:54:456257 // We should have three render surfaces, one for the root, one for the parent
6258 // since it owns a surface, and one for the copy_layer.
6259 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236260 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
6261 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
6262 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:456263
6264 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:536265 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6266 // will appear since something in its subtree needs to be drawn for a copy
6267 // request.
[email protected]30fe19ff2013-07-04 00:54:456268 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236269 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6270 EXPECT_EQ(copy_parent->id(),
6271 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456272
[email protected]7392c7b2014-02-07 08:28:286273 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:456274 // appear in its list, since it needs to be drawn for the copy request.
6275 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
6276 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236277 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456278
6279 // The copy_layer's render surface should have two contributing layers.
6280 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
6281 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236282 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456283 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:236284 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456285}
6286
[email protected]989386c2013-07-18 21:37:236287TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456288 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456289 TestSharedBitmapManager shared_bitmap_manager;
6290 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456291 host_impl.CreatePendingTree();
6292 const gfx::Transform identity_matrix;
6293
6294 scoped_refptr<Layer> root = Layer::Create();
6295 SetLayerPropertiesForTesting(root.get(),
6296 identity_matrix,
[email protected]a2566412014-06-05 03:14:206297 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456298 gfx::PointF(),
6299 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576300 true,
[email protected]30fe19ff2013-07-04 00:54:456301 false);
6302 root->SetIsDrawable(true);
6303
6304 scoped_refptr<Layer> copy_parent = Layer::Create();
6305 SetLayerPropertiesForTesting(copy_parent.get(),
6306 identity_matrix,
[email protected]a2566412014-06-05 03:14:206307 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456308 gfx::PointF(),
6309 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576310 true,
[email protected]30fe19ff2013-07-04 00:54:456311 false);
6312 copy_parent->SetIsDrawable(true);
6313 copy_parent->SetMasksToBounds(true);
6314
6315 scoped_refptr<Layer> copy_layer = Layer::Create();
6316 SetLayerPropertiesForTesting(copy_layer.get(),
6317 identity_matrix,
[email protected]a2566412014-06-05 03:14:206318 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456319 gfx::PointF(),
6320 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576321 true,
[email protected]30fe19ff2013-07-04 00:54:456322 false);
6323 copy_layer->SetIsDrawable(true);
6324
6325 scoped_refptr<Layer> copy_child = Layer::Create();
6326 SetLayerPropertiesForTesting(copy_child.get(),
6327 identity_matrix,
[email protected]a2566412014-06-05 03:14:206328 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456329 gfx::PointF(),
6330 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576331 true,
[email protected]30fe19ff2013-07-04 00:54:456332 false);
6333 copy_child->SetIsDrawable(true);
6334
6335 copy_layer->AddChild(copy_child);
6336 copy_parent->AddChild(copy_layer);
6337 root->AddChild(copy_parent);
6338
enne2097cab2014-09-25 20:16:316339 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286340 host->SetRootLayer(root);
6341
[email protected]30fe19ff2013-07-04 00:54:456342 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6343 base::Bind(&EmptyCopyOutputCallback)));
6344 EXPECT_TRUE(copy_layer->HasCopyRequest());
6345
[email protected]989386c2013-07-18 21:37:236346 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536347 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226348 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536349 inputs.can_adjust_raster_scales = true;
6350 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456351
6352 // We should have one render surface, as the others are clipped out.
6353 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236354 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456355
6356 // The root render surface should only have 1 contributing layer, since the
6357 // other layers are empty/clipped away.
6358 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236359 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456360}
6361
[email protected]11a07b102013-07-24 17:33:196362TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
6363 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456364 TestSharedBitmapManager shared_bitmap_manager;
6365 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:196366 host_impl.CreatePendingTree();
6367 const gfx::Transform identity_matrix;
6368
6369 scoped_refptr<Layer> root = Layer::Create();
6370 SetLayerPropertiesForTesting(root.get(),
6371 identity_matrix,
[email protected]a2566412014-06-05 03:14:206372 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196373 gfx::PointF(),
6374 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576375 true,
[email protected]11a07b102013-07-24 17:33:196376 false);
6377 root->SetIsDrawable(true);
6378
6379 // The surface is moved slightly outside of the viewport.
6380 scoped_refptr<Layer> surface = Layer::Create();
6381 SetLayerPropertiesForTesting(surface.get(),
6382 identity_matrix,
[email protected]a2566412014-06-05 03:14:206383 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196384 gfx::PointF(-10, -20),
6385 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576386 true,
[email protected]11a07b102013-07-24 17:33:196387 false);
6388 surface->SetForceRenderSurface(true);
6389
6390 scoped_refptr<Layer> surface_child = Layer::Create();
6391 SetLayerPropertiesForTesting(surface_child.get(),
6392 identity_matrix,
[email protected]a2566412014-06-05 03:14:206393 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196394 gfx::PointF(),
6395 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576396 true,
[email protected]11a07b102013-07-24 17:33:196397 false);
6398 surface_child->SetIsDrawable(true);
6399
6400 surface->AddChild(surface_child);
6401 root->AddChild(surface);
6402
enne2097cab2014-09-25 20:16:316403 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286404 host->SetRootLayer(root);
6405
[email protected]11a07b102013-07-24 17:33:196406 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536407 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226408 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536409 inputs.can_adjust_raster_scales = true;
6410 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:196411
6412 // The visible_content_rect for the |surface_child| should not be clipped by
6413 // the viewport.
6414 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6415 surface_child->visible_content_rect().ToString());
6416}
6417
[email protected]420fdf6e2013-08-26 20:36:386418TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6419 // Ensure that a transform between the layer and its render surface is not a
6420 // problem. Constructs the following layer tree.
6421 //
6422 // root (a render surface)
6423 // + render_surface
6424 // + clip_parent (scaled)
6425 // + intervening_clipping_layer
6426 // + clip_child
6427 //
6428 // The render surface should be resized correctly and the clip child should
6429 // inherit the right clip rect.
6430 scoped_refptr<Layer> root = Layer::Create();
6431 scoped_refptr<Layer> render_surface = Layer::Create();
6432 scoped_refptr<Layer> clip_parent = Layer::Create();
6433 scoped_refptr<Layer> intervening = Layer::Create();
6434 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6435 make_scoped_refptr(new LayerWithForcedDrawsContent);
6436
6437 root->AddChild(render_surface);
6438 render_surface->AddChild(clip_parent);
6439 clip_parent->AddChild(intervening);
6440 intervening->AddChild(clip_child);
6441
6442 clip_child->SetClipParent(clip_parent.get());
6443
6444 intervening->SetMasksToBounds(true);
6445 clip_parent->SetMasksToBounds(true);
6446
6447 render_surface->SetForceRenderSurface(true);
6448
6449 gfx::Transform scale_transform;
6450 scale_transform.Scale(2, 2);
6451
6452 gfx::Transform identity_transform;
6453
6454 SetLayerPropertiesForTesting(root.get(),
6455 identity_transform,
[email protected]a2566412014-06-05 03:14:206456 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386457 gfx::PointF(),
6458 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576459 true,
[email protected]420fdf6e2013-08-26 20:36:386460 false);
6461 SetLayerPropertiesForTesting(render_surface.get(),
6462 identity_transform,
[email protected]a2566412014-06-05 03:14:206463 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386464 gfx::PointF(),
6465 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576466 true,
[email protected]420fdf6e2013-08-26 20:36:386467 false);
6468 SetLayerPropertiesForTesting(clip_parent.get(),
6469 scale_transform,
[email protected]a2566412014-06-05 03:14:206470 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386471 gfx::PointF(1.f, 1.f),
6472 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576473 true,
[email protected]420fdf6e2013-08-26 20:36:386474 false);
6475 SetLayerPropertiesForTesting(intervening.get(),
6476 identity_transform,
[email protected]a2566412014-06-05 03:14:206477 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386478 gfx::PointF(1.f, 1.f),
6479 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576480 true,
[email protected]420fdf6e2013-08-26 20:36:386481 false);
6482 SetLayerPropertiesForTesting(clip_child.get(),
6483 identity_transform,
[email protected]a2566412014-06-05 03:14:206484 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386485 gfx::PointF(1.f, 1.f),
6486 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576487 true,
[email protected]420fdf6e2013-08-26 20:36:386488 false);
6489
enne2097cab2014-09-25 20:16:316490 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386491 host->SetRootLayer(root);
6492
6493 ExecuteCalculateDrawProperties(root.get());
6494
6495 ASSERT_TRUE(root->render_surface());
6496 ASSERT_TRUE(render_surface->render_surface());
6497
6498 // Ensure that we've inherited our clip parent's clip and weren't affected
6499 // by the intervening clip layer.
6500 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6501 clip_parent->clip_rect().ToString());
6502 ASSERT_EQ(clip_parent->clip_rect().ToString(),
6503 clip_child->clip_rect().ToString());
6504 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6505 intervening->clip_rect().ToString());
6506
6507 // Ensure that the render surface reports a content rect that has been grown
6508 // to accomodate for the clip child.
6509 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6510 render_surface->render_surface()->content_rect().ToString());
6511
6512 // The above check implies the two below, but they nicely demonstrate that
6513 // we've grown, despite the intervening layer's clip.
6514 ASSERT_TRUE(clip_parent->clip_rect().Contains(
6515 render_surface->render_surface()->content_rect()));
6516 ASSERT_FALSE(intervening->clip_rect().Contains(
6517 render_surface->render_surface()->content_rect()));
6518}
6519
6520TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
6521 // Ensure that intervening render surfaces are not a problem in the basic
6522 // case. In the following tree, both render surfaces should be resized to
6523 // accomodate for the clip child, despite an intervening clip.
6524 //
6525 // root (a render surface)
6526 // + clip_parent (masks to bounds)
6527 // + render_surface1 (sets opacity)
6528 // + intervening (masks to bounds)
6529 // + render_surface2 (also sets opacity)
6530 // + clip_child
6531 //
6532 scoped_refptr<Layer> root = Layer::Create();
6533 scoped_refptr<Layer> clip_parent = Layer::Create();
6534 scoped_refptr<Layer> render_surface1 = Layer::Create();
6535 scoped_refptr<Layer> intervening = Layer::Create();
6536 scoped_refptr<Layer> render_surface2 = Layer::Create();
6537 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6538 make_scoped_refptr(new LayerWithForcedDrawsContent);
6539
6540 root->AddChild(clip_parent);
6541 clip_parent->AddChild(render_surface1);
6542 render_surface1->AddChild(intervening);
6543 intervening->AddChild(render_surface2);
6544 render_surface2->AddChild(clip_child);
6545
6546 clip_child->SetClipParent(clip_parent.get());
6547
6548 intervening->SetMasksToBounds(true);
6549 clip_parent->SetMasksToBounds(true);
6550
6551 render_surface1->SetForceRenderSurface(true);
6552 render_surface2->SetForceRenderSurface(true);
6553
6554 gfx::Transform translation_transform;
6555 translation_transform.Translate(2, 2);
6556
6557 gfx::Transform identity_transform;
6558 SetLayerPropertiesForTesting(root.get(),
6559 identity_transform,
[email protected]a2566412014-06-05 03:14:206560 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386561 gfx::PointF(),
6562 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576563 true,
[email protected]420fdf6e2013-08-26 20:36:386564 false);
6565 SetLayerPropertiesForTesting(clip_parent.get(),
6566 translation_transform,
[email protected]a2566412014-06-05 03:14:206567 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386568 gfx::PointF(1.f, 1.f),
6569 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576570 true,
[email protected]420fdf6e2013-08-26 20:36:386571 false);
6572 SetLayerPropertiesForTesting(render_surface1.get(),
6573 identity_transform,
[email protected]a2566412014-06-05 03:14:206574 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386575 gfx::PointF(),
6576 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576577 true,
[email protected]420fdf6e2013-08-26 20:36:386578 false);
6579 SetLayerPropertiesForTesting(intervening.get(),
6580 identity_transform,
[email protected]a2566412014-06-05 03:14:206581 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386582 gfx::PointF(1.f, 1.f),
6583 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576584 true,
[email protected]420fdf6e2013-08-26 20:36:386585 false);
6586 SetLayerPropertiesForTesting(render_surface2.get(),
6587 identity_transform,
[email protected]a2566412014-06-05 03:14:206588 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386589 gfx::PointF(),
6590 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576591 true,
[email protected]420fdf6e2013-08-26 20:36:386592 false);
6593 SetLayerPropertiesForTesting(clip_child.get(),
6594 identity_transform,
[email protected]a2566412014-06-05 03:14:206595 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386596 gfx::PointF(-10.f, -10.f),
6597 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576598 true,
[email protected]420fdf6e2013-08-26 20:36:386599 false);
6600
enne2097cab2014-09-25 20:16:316601 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386602 host->SetRootLayer(root);
6603
6604 ExecuteCalculateDrawProperties(root.get());
6605
6606 EXPECT_TRUE(root->render_surface());
6607 EXPECT_TRUE(render_surface1->render_surface());
6608 EXPECT_TRUE(render_surface2->render_surface());
6609
6610 // Since the render surfaces could have expanded, they should not clip (their
6611 // bounds would no longer be reliable). We should resort to layer clipping
6612 // in this case.
6613 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6614 render_surface1->render_surface()->clip_rect().ToString());
6615 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6616 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6617 render_surface2->render_surface()->clip_rect().ToString());
6618 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6619
6620 // NB: clip rects are in target space.
6621 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6622 render_surface1->clip_rect().ToString());
6623 EXPECT_TRUE(render_surface1->is_clipped());
6624
6625 // This value is inherited from the clipping ancestor layer, 'intervening'.
6626 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6627 render_surface2->clip_rect().ToString());
6628 EXPECT_TRUE(render_surface2->is_clipped());
6629
6630 // The content rects of both render surfaces should both have expanded to
6631 // contain the clip child.
6632 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6633 render_surface1->render_surface()->content_rect().ToString());
6634 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6635 render_surface2->render_surface()->content_rect().ToString());
6636
6637 // The clip child should have inherited the clip parent's clip (projected to
6638 // the right space, of course), and should have the correctly sized visible
6639 // content rect.
6640 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6641 clip_child->clip_rect().ToString());
6642 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6643 clip_child->visible_content_rect().ToString());
6644 EXPECT_TRUE(clip_child->is_clipped());
6645}
6646
6647TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6648 // Ensure that intervening render surfaces are not a problem, even if there
6649 // is a scroll involved. Note, we do _not_ have to consider any other sort
6650 // of transform.
6651 //
6652 // root (a render surface)
6653 // + clip_parent (masks to bounds)
6654 // + render_surface1 (sets opacity)
6655 // + intervening (masks to bounds AND scrolls)
6656 // + render_surface2 (also sets opacity)
6657 // + clip_child
6658 //
6659 scoped_refptr<Layer> root = Layer::Create();
6660 scoped_refptr<Layer> clip_parent = Layer::Create();
6661 scoped_refptr<Layer> render_surface1 = Layer::Create();
6662 scoped_refptr<Layer> intervening = Layer::Create();
6663 scoped_refptr<Layer> render_surface2 = Layer::Create();
6664 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6665 make_scoped_refptr(new LayerWithForcedDrawsContent);
6666
6667 root->AddChild(clip_parent);
6668 clip_parent->AddChild(render_surface1);
6669 render_surface1->AddChild(intervening);
6670 intervening->AddChild(render_surface2);
6671 render_surface2->AddChild(clip_child);
6672
6673 clip_child->SetClipParent(clip_parent.get());
6674
6675 intervening->SetMasksToBounds(true);
6676 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:476677 intervening->SetScrollClipLayerId(clip_parent->id());
miletusf57925d2014-10-01 19:38:136678 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386679
6680 render_surface1->SetForceRenderSurface(true);
6681 render_surface2->SetForceRenderSurface(true);
6682
6683 gfx::Transform translation_transform;
6684 translation_transform.Translate(2, 2);
6685
6686 gfx::Transform identity_transform;
6687 SetLayerPropertiesForTesting(root.get(),
6688 identity_transform,
[email protected]a2566412014-06-05 03:14:206689 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386690 gfx::PointF(),
6691 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576692 true,
[email protected]420fdf6e2013-08-26 20:36:386693 false);
6694 SetLayerPropertiesForTesting(clip_parent.get(),
6695 translation_transform,
[email protected]a2566412014-06-05 03:14:206696 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386697 gfx::PointF(1.f, 1.f),
6698 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576699 true,
[email protected]420fdf6e2013-08-26 20:36:386700 false);
6701 SetLayerPropertiesForTesting(render_surface1.get(),
6702 identity_transform,
[email protected]a2566412014-06-05 03:14:206703 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386704 gfx::PointF(),
6705 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576706 true,
[email protected]420fdf6e2013-08-26 20:36:386707 false);
6708 SetLayerPropertiesForTesting(intervening.get(),
6709 identity_transform,
[email protected]a2566412014-06-05 03:14:206710 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386711 gfx::PointF(1.f, 1.f),
6712 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576713 true,
[email protected]420fdf6e2013-08-26 20:36:386714 false);
6715 SetLayerPropertiesForTesting(render_surface2.get(),
6716 identity_transform,
[email protected]a2566412014-06-05 03:14:206717 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386718 gfx::PointF(),
6719 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576720 true,
[email protected]420fdf6e2013-08-26 20:36:386721 false);
6722 SetLayerPropertiesForTesting(clip_child.get(),
6723 identity_transform,
[email protected]a2566412014-06-05 03:14:206724 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386725 gfx::PointF(-10.f, -10.f),
6726 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576727 true,
[email protected]420fdf6e2013-08-26 20:36:386728 false);
6729
enne2097cab2014-09-25 20:16:316730 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386731 host->SetRootLayer(root);
6732
6733 ExecuteCalculateDrawProperties(root.get());
6734
6735 EXPECT_TRUE(root->render_surface());
6736 EXPECT_TRUE(render_surface1->render_surface());
6737 EXPECT_TRUE(render_surface2->render_surface());
6738
6739 // Since the render surfaces could have expanded, they should not clip (their
6740 // bounds would no longer be reliable). We should resort to layer clipping
6741 // in this case.
6742 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6743 render_surface1->render_surface()->clip_rect().ToString());
6744 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6745 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6746 render_surface2->render_surface()->clip_rect().ToString());
6747 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6748
6749 // NB: clip rects are in target space.
6750 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6751 render_surface1->clip_rect().ToString());
6752 EXPECT_TRUE(render_surface1->is_clipped());
6753
6754 // This value is inherited from the clipping ancestor layer, 'intervening'.
6755 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6756 render_surface2->clip_rect().ToString());
6757 EXPECT_TRUE(render_surface2->is_clipped());
6758
6759 // The content rects of both render surfaces should both have expanded to
6760 // contain the clip child.
6761 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6762 render_surface1->render_surface()->content_rect().ToString());
6763 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6764 render_surface2->render_surface()->content_rect().ToString());
6765
6766 // The clip child should have inherited the clip parent's clip (projected to
6767 // the right space, of course), and should have the correctly sized visible
6768 // content rect.
6769 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6770 clip_child->clip_rect().ToString());
6771 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6772 clip_child->visible_content_rect().ToString());
6773 EXPECT_TRUE(clip_child->is_clipped());
6774}
6775
6776TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6777 // Ensures that descendants of the clip child inherit the correct clip.
6778 //
6779 // root (a render surface)
6780 // + clip_parent (masks to bounds)
6781 // + intervening (masks to bounds)
6782 // + clip_child
6783 // + child
6784 //
6785 scoped_refptr<Layer> root = Layer::Create();
6786 scoped_refptr<Layer> clip_parent = Layer::Create();
6787 scoped_refptr<Layer> intervening = Layer::Create();
6788 scoped_refptr<Layer> clip_child = Layer::Create();
6789 scoped_refptr<LayerWithForcedDrawsContent> child =
6790 make_scoped_refptr(new LayerWithForcedDrawsContent);
6791
6792 root->AddChild(clip_parent);
6793 clip_parent->AddChild(intervening);
6794 intervening->AddChild(clip_child);
6795 clip_child->AddChild(child);
6796
6797 clip_child->SetClipParent(clip_parent.get());
6798
6799 intervening->SetMasksToBounds(true);
6800 clip_parent->SetMasksToBounds(true);
6801
6802 gfx::Transform identity_transform;
6803 SetLayerPropertiesForTesting(root.get(),
6804 identity_transform,
[email protected]a2566412014-06-05 03:14:206805 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386806 gfx::PointF(),
6807 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576808 true,
[email protected]420fdf6e2013-08-26 20:36:386809 false);
6810 SetLayerPropertiesForTesting(clip_parent.get(),
6811 identity_transform,
[email protected]a2566412014-06-05 03:14:206812 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386813 gfx::PointF(),
6814 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576815 true,
[email protected]420fdf6e2013-08-26 20:36:386816 false);
6817 SetLayerPropertiesForTesting(intervening.get(),
6818 identity_transform,
[email protected]a2566412014-06-05 03:14:206819 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386820 gfx::PointF(),
6821 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576822 true,
[email protected]420fdf6e2013-08-26 20:36:386823 false);
6824 SetLayerPropertiesForTesting(clip_child.get(),
6825 identity_transform,
[email protected]a2566412014-06-05 03:14:206826 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386827 gfx::PointF(),
6828 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576829 true,
[email protected]420fdf6e2013-08-26 20:36:386830 false);
6831 SetLayerPropertiesForTesting(child.get(),
6832 identity_transform,
[email protected]a2566412014-06-05 03:14:206833 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386834 gfx::PointF(),
6835 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576836 true,
[email protected]420fdf6e2013-08-26 20:36:386837 false);
6838
enne2097cab2014-09-25 20:16:316839 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386840 host->SetRootLayer(root);
6841
6842 ExecuteCalculateDrawProperties(root.get());
6843
6844 EXPECT_TRUE(root->render_surface());
6845
6846 // Neither the clip child nor its descendant should have inherited the clip
6847 // from |intervening|.
6848 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6849 clip_child->clip_rect().ToString());
6850 EXPECT_TRUE(clip_child->is_clipped());
6851 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6852 child->visible_content_rect().ToString());
6853 EXPECT_TRUE(child->is_clipped());
6854}
6855
6856TEST_F(LayerTreeHostCommonTest,
6857 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6858 // Ensures that non-descendant clip children in the tree do not affect
6859 // render surfaces.
6860 //
6861 // root (a render surface)
6862 // + clip_parent (masks to bounds)
6863 // + render_surface1
6864 // + clip_child
6865 // + render_surface2
6866 // + non_clip_child
6867 //
6868 // In this example render_surface2 should be unaffected by clip_child.
6869 scoped_refptr<Layer> root = Layer::Create();
6870 scoped_refptr<Layer> clip_parent = Layer::Create();
6871 scoped_refptr<Layer> render_surface1 = Layer::Create();
6872 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6873 make_scoped_refptr(new LayerWithForcedDrawsContent);
6874 scoped_refptr<Layer> render_surface2 = Layer::Create();
6875 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
6876 make_scoped_refptr(new LayerWithForcedDrawsContent);
6877
6878 root->AddChild(clip_parent);
6879 clip_parent->AddChild(render_surface1);
6880 render_surface1->AddChild(clip_child);
6881 clip_parent->AddChild(render_surface2);
6882 render_surface2->AddChild(non_clip_child);
6883
6884 clip_child->SetClipParent(clip_parent.get());
6885
6886 clip_parent->SetMasksToBounds(true);
6887 render_surface1->SetMasksToBounds(true);
6888
6889 gfx::Transform identity_transform;
6890 SetLayerPropertiesForTesting(root.get(),
6891 identity_transform,
[email protected]a2566412014-06-05 03:14:206892 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386893 gfx::PointF(),
6894 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:576895 true,
[email protected]420fdf6e2013-08-26 20:36:386896 false);
6897 SetLayerPropertiesForTesting(clip_parent.get(),
6898 identity_transform,
[email protected]a2566412014-06-05 03:14:206899 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386900 gfx::PointF(),
6901 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576902 true,
[email protected]420fdf6e2013-08-26 20:36:386903 false);
6904 SetLayerPropertiesForTesting(render_surface1.get(),
6905 identity_transform,
[email protected]a2566412014-06-05 03:14:206906 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386907 gfx::PointF(5, 5),
6908 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576909 true,
[email protected]420fdf6e2013-08-26 20:36:386910 false);
6911 SetLayerPropertiesForTesting(render_surface2.get(),
6912 identity_transform,
[email protected]a2566412014-06-05 03:14:206913 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386914 gfx::PointF(),
6915 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576916 true,
[email protected]420fdf6e2013-08-26 20:36:386917 false);
6918 SetLayerPropertiesForTesting(clip_child.get(),
6919 identity_transform,
[email protected]a2566412014-06-05 03:14:206920 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386921 gfx::PointF(-1, 1),
6922 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576923 true,
[email protected]420fdf6e2013-08-26 20:36:386924 false);
6925 SetLayerPropertiesForTesting(non_clip_child.get(),
6926 identity_transform,
[email protected]a2566412014-06-05 03:14:206927 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386928 gfx::PointF(),
6929 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576930 true,
[email protected]420fdf6e2013-08-26 20:36:386931 false);
6932
6933 render_surface1->SetForceRenderSurface(true);
6934 render_surface2->SetForceRenderSurface(true);
6935
enne2097cab2014-09-25 20:16:316936 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386937 host->SetRootLayer(root);
6938
6939 ExecuteCalculateDrawProperties(root.get());
6940
6941 EXPECT_TRUE(root->render_surface());
6942 EXPECT_TRUE(render_surface1->render_surface());
6943 EXPECT_TRUE(render_surface2->render_surface());
6944
6945 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6946 render_surface1->clip_rect().ToString());
6947 EXPECT_TRUE(render_surface1->is_clipped());
6948
6949 // The render surface should not clip (it has unclipped descendants), instead
6950 // it should rely on layer clipping.
6951 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6952 render_surface1->render_surface()->clip_rect().ToString());
6953 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6954
6955 // That said, it should have grown to accomodate the unclipped descendant.
6956 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6957 render_surface1->render_surface()->content_rect().ToString());
6958
6959 // This render surface should clip. It has no unclipped descendants.
6960 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6961 render_surface2->clip_rect().ToString());
6962 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
6963
6964 // It also shouldn't have grown to accomodate the clip child.
6965 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6966 render_surface2->render_surface()->content_rect().ToString());
6967
6968 // Sanity check our num_unclipped_descendants values.
6969 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
6970 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
6971}
6972
[email protected]45948712013-09-27 02:46:486973TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
6974 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456975 TestSharedBitmapManager shared_bitmap_manager;
6976 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:486977 scoped_ptr<LayerImpl> root =
6978 LayerImpl::Create(host_impl.active_tree(), 12345);
6979 scoped_ptr<LayerImpl> child1 =
6980 LayerImpl::Create(host_impl.active_tree(), 123456);
6981 scoped_ptr<LayerImpl> child2 =
6982 LayerImpl::Create(host_impl.active_tree(), 1234567);
6983 scoped_ptr<LayerImpl> child3 =
6984 LayerImpl::Create(host_impl.active_tree(), 12345678);
6985
6986 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206987 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486988 gfx::PointF position;
6989 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:006990 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6991 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486992 root->SetDrawsContent(true);
6993
6994 // This layer structure normally forces render surface due to preserves3d
6995 // behavior.
awoloszyne83f28c2014-12-22 15:40:006996 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
6997 position, bounds, false, true, true);
[email protected]45948712013-09-27 02:46:486998 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006999 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
7000 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487001 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007002 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
7003 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487004 child3->SetDrawsContent(true);
7005
[email protected]a9d4d4f2014-06-19 06:49:287006 child2->Set3dSortingContextId(1);
7007 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:577008
[email protected]45948712013-09-27 02:46:487009 child2->AddChild(child3.Pass());
7010 child1->AddChild(child2.Pass());
7011 root->AddChild(child1.Pass());
7012
7013 {
7014 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:547015 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
[email protected]45948712013-09-27 02:46:487016 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227017 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487018 inputs.can_render_to_separate_surface = true;
7019 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7020
7021 EXPECT_EQ(2u, render_surface_layer_list.size());
7022 }
7023
7024 {
7025 LayerImplList render_surface_layer_list;
7026 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227027 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487028 inputs.can_render_to_separate_surface = false;
7029 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7030
7031 EXPECT_EQ(1u, render_surface_layer_list.size());
7032 }
7033}
7034
[email protected]a9aa60a82013-08-29 04:28:267035TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
7036 scoped_refptr<Layer> root = Layer::Create();
7037 scoped_refptr<Layer> render_surface = Layer::Create();
7038 scoped_refptr<LayerWithForcedDrawsContent> child =
7039 make_scoped_refptr(new LayerWithForcedDrawsContent);
7040
7041 root->AddChild(render_surface);
7042 render_surface->AddChild(child);
7043
7044 gfx::Transform identity_transform;
7045 SetLayerPropertiesForTesting(root.get(),
7046 identity_transform,
[email protected]a2566412014-06-05 03:14:207047 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267048 gfx::PointF(),
7049 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577050 true,
[email protected]a9aa60a82013-08-29 04:28:267051 false);
7052 SetLayerPropertiesForTesting(render_surface.get(),
7053 identity_transform,
[email protected]a2566412014-06-05 03:14:207054 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267055 gfx::PointF(),
7056 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577057 false,
7058 true);
[email protected]a9aa60a82013-08-29 04:28:267059 SetLayerPropertiesForTesting(child.get(),
7060 identity_transform,
[email protected]a2566412014-06-05 03:14:207061 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267062 gfx::PointF(),
7063 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577064 true,
[email protected]a9aa60a82013-08-29 04:28:267065 false);
7066
[email protected]56fffdd2014-02-11 19:50:577067 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:287068 root->Set3dSortingContextId(1);
[email protected]a9aa60a82013-08-29 04:28:267069 render_surface->SetDoubleSided(false);
7070 render_surface->SetForceRenderSurface(true);
7071
enne2097cab2014-09-25 20:16:317072 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]a9aa60a82013-08-29 04:28:267073 host->SetRootLayer(root);
7074
7075 ExecuteCalculateDrawProperties(root.get());
7076
7077 EXPECT_EQ(2u, render_surface_layer_list()->size());
7078 EXPECT_EQ(1u,
7079 render_surface_layer_list()->at(0)
7080 ->render_surface()->layer_list().size());
7081 EXPECT_EQ(1u,
7082 render_surface_layer_list()->at(1)
7083 ->render_surface()->layer_list().size());
7084
7085 gfx::Transform rotation_transform = identity_transform;
7086 rotation_transform.RotateAboutXAxis(180.0);
7087
7088 render_surface->SetTransform(rotation_transform);
7089
7090 ExecuteCalculateDrawProperties(root.get());
7091
7092 EXPECT_EQ(1u, render_surface_layer_list()->size());
7093 EXPECT_EQ(0u,
7094 render_surface_layer_list()->at(0)
7095 ->render_surface()->layer_list().size());
7096}
7097
[email protected]995708c52013-10-17 20:52:597098TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
7099 // Checks that the simple case (being clipped by a scroll parent that would
7100 // have been processed before you anyhow) results in the right clips.
7101 //
7102 // + root
7103 // + scroll_parent_border
7104 // | + scroll_parent_clip
7105 // | + scroll_parent
7106 // + scroll_child
7107 //
7108 scoped_refptr<Layer> root = Layer::Create();
7109 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7110 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7111 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7112 make_scoped_refptr(new LayerWithForcedDrawsContent);
7113 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7114 make_scoped_refptr(new LayerWithForcedDrawsContent);
7115
7116 root->AddChild(scroll_child);
7117
7118 root->AddChild(scroll_parent_border);
7119 scroll_parent_border->AddChild(scroll_parent_clip);
7120 scroll_parent_clip->AddChild(scroll_parent);
7121
7122 scroll_parent_clip->SetMasksToBounds(true);
7123
7124 scroll_child->SetScrollParent(scroll_parent.get());
7125
7126 gfx::Transform identity_transform;
7127 SetLayerPropertiesForTesting(root.get(),
7128 identity_transform,
[email protected]a2566412014-06-05 03:14:207129 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597130 gfx::PointF(),
7131 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577132 true,
[email protected]995708c52013-10-17 20:52:597133 false);
7134 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7135 identity_transform,
[email protected]a2566412014-06-05 03:14:207136 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597137 gfx::PointF(),
7138 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577139 true,
[email protected]995708c52013-10-17 20:52:597140 false);
7141 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7142 identity_transform,
[email protected]a2566412014-06-05 03:14:207143 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597144 gfx::PointF(),
7145 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577146 true,
[email protected]995708c52013-10-17 20:52:597147 false);
7148 SetLayerPropertiesForTesting(scroll_parent.get(),
7149 identity_transform,
[email protected]a2566412014-06-05 03:14:207150 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597151 gfx::PointF(),
7152 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577153 true,
[email protected]995708c52013-10-17 20:52:597154 false);
7155 SetLayerPropertiesForTesting(scroll_child.get(),
7156 identity_transform,
[email protected]a2566412014-06-05 03:14:207157 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597158 gfx::PointF(),
7159 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577160 true,
[email protected]995708c52013-10-17 20:52:597161 false);
7162
enne2097cab2014-09-25 20:16:317163 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597164 host->SetRootLayer(root);
7165
7166 ExecuteCalculateDrawProperties(root.get());
7167
7168 EXPECT_TRUE(root->render_surface());
7169
7170 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7171 scroll_child->clip_rect().ToString());
7172 EXPECT_TRUE(scroll_child->is_clipped());
7173}
7174
[email protected]08bdf1b2014-04-16 23:23:297175TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7176 scoped_refptr<LayerWithForcedDrawsContent> root =
7177 make_scoped_refptr(new LayerWithForcedDrawsContent);
7178 scoped_refptr<LayerWithForcedDrawsContent> parent =
7179 make_scoped_refptr(new LayerWithForcedDrawsContent);
7180 scoped_refptr<LayerWithForcedDrawsContent> child =
7181 make_scoped_refptr(new LayerWithForcedDrawsContent);
7182
7183 root->AddChild(parent);
7184 parent->AddChild(child);
7185
7186 gfx::Transform identity_transform;
7187 SetLayerPropertiesForTesting(root.get(),
7188 identity_transform,
[email protected]a2566412014-06-05 03:14:207189 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297190 gfx::PointF(),
7191 gfx::Size(50, 50),
7192 true,
7193 true);
7194 root->SetForceRenderSurface(true);
7195 SetLayerPropertiesForTesting(parent.get(),
7196 identity_transform,
[email protected]a2566412014-06-05 03:14:207197 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297198 gfx::PointF(),
7199 gfx::Size(30, 30),
7200 true,
7201 true);
7202 parent->SetForceRenderSurface(true);
7203 SetLayerPropertiesForTesting(child.get(),
7204 identity_transform,
[email protected]a2566412014-06-05 03:14:207205 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297206 gfx::PointF(),
7207 gfx::Size(20, 20),
7208 true,
7209 true);
7210 child->SetForceRenderSurface(true);
7211
enne2097cab2014-09-25 20:16:317212 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]08bdf1b2014-04-16 23:23:297213 host->SetRootLayer(root);
7214
7215 ExecuteCalculateDrawProperties(root.get());
7216
7217 EXPECT_EQ(3u, render_surface_layer_list()->size());
7218
7219 gfx::Transform singular_transform;
7220 singular_transform.Scale3d(
7221 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7222
7223 child->SetTransform(singular_transform);
7224
7225 ExecuteCalculateDrawProperties(root.get());
7226
7227 EXPECT_EQ(2u, render_surface_layer_list()->size());
7228
7229 // Ensure that the entire subtree under a layer with singular transform does
7230 // not get rendered.
7231 parent->SetTransform(singular_transform);
7232 child->SetTransform(identity_transform);
7233
7234 ExecuteCalculateDrawProperties(root.get());
7235
7236 EXPECT_EQ(1u, render_surface_layer_list()->size());
7237}
7238
[email protected]995708c52013-10-17 20:52:597239TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
7240 // Checks that clipping by a scroll parent that follows you in paint order
7241 // still results in correct clipping.
7242 //
7243 // + root
7244 // + scroll_child
7245 // + scroll_parent_border
7246 // + scroll_parent_clip
7247 // + scroll_parent
7248 //
7249 scoped_refptr<Layer> root = Layer::Create();
7250 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7251 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7252 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7253 make_scoped_refptr(new LayerWithForcedDrawsContent);
7254 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7255 make_scoped_refptr(new LayerWithForcedDrawsContent);
7256
7257 root->AddChild(scroll_parent_border);
7258 scroll_parent_border->AddChild(scroll_parent_clip);
7259 scroll_parent_clip->AddChild(scroll_parent);
7260
7261 root->AddChild(scroll_child);
7262
7263 scroll_parent_clip->SetMasksToBounds(true);
7264
7265 scroll_child->SetScrollParent(scroll_parent.get());
7266
7267 gfx::Transform identity_transform;
7268 SetLayerPropertiesForTesting(root.get(),
7269 identity_transform,
[email protected]a2566412014-06-05 03:14:207270 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597271 gfx::PointF(),
7272 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577273 true,
[email protected]995708c52013-10-17 20:52:597274 false);
7275 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7276 identity_transform,
[email protected]a2566412014-06-05 03:14:207277 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597278 gfx::PointF(),
7279 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577280 true,
[email protected]995708c52013-10-17 20:52:597281 false);
7282 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7283 identity_transform,
[email protected]a2566412014-06-05 03:14:207284 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597285 gfx::PointF(),
7286 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577287 true,
[email protected]995708c52013-10-17 20:52:597288 false);
7289 SetLayerPropertiesForTesting(scroll_parent.get(),
7290 identity_transform,
[email protected]a2566412014-06-05 03:14:207291 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597292 gfx::PointF(),
7293 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577294 true,
[email protected]995708c52013-10-17 20:52:597295 false);
7296 SetLayerPropertiesForTesting(scroll_child.get(),
7297 identity_transform,
[email protected]a2566412014-06-05 03:14:207298 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597299 gfx::PointF(),
7300 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577301 true,
[email protected]995708c52013-10-17 20:52:597302 false);
7303
enne2097cab2014-09-25 20:16:317304 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597305 host->SetRootLayer(root);
7306
7307 ExecuteCalculateDrawProperties(root.get());
7308
7309 EXPECT_TRUE(root->render_surface());
7310
7311 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7312 scroll_child->clip_rect().ToString());
7313 EXPECT_TRUE(scroll_child->is_clipped());
7314}
7315
7316TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
7317 // Checks that clipping by a scroll parent and scroll grandparent that follow
7318 // you in paint order still results in correct clipping.
7319 //
7320 // + root
7321 // + scroll_child
7322 // + scroll_parent_border
7323 // | + scroll_parent_clip
7324 // | + scroll_parent
7325 // + scroll_grandparent_border
7326 // + scroll_grandparent_clip
7327 // + scroll_grandparent
7328 //
7329 scoped_refptr<Layer> root = Layer::Create();
7330 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7331 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7332 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7333 make_scoped_refptr(new LayerWithForcedDrawsContent);
7334
7335 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7336 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7337 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7338 make_scoped_refptr(new LayerWithForcedDrawsContent);
7339
7340 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7341 make_scoped_refptr(new LayerWithForcedDrawsContent);
7342
7343 root->AddChild(scroll_child);
7344
7345 root->AddChild(scroll_parent_border);
7346 scroll_parent_border->AddChild(scroll_parent_clip);
7347 scroll_parent_clip->AddChild(scroll_parent);
7348
7349 root->AddChild(scroll_grandparent_border);
7350 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7351 scroll_grandparent_clip->AddChild(scroll_grandparent);
7352
7353 scroll_parent_clip->SetMasksToBounds(true);
7354 scroll_grandparent_clip->SetMasksToBounds(true);
7355
7356 scroll_child->SetScrollParent(scroll_parent.get());
7357 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7358
7359 gfx::Transform identity_transform;
7360 SetLayerPropertiesForTesting(root.get(),
7361 identity_transform,
[email protected]a2566412014-06-05 03:14:207362 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597363 gfx::PointF(),
7364 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577365 true,
[email protected]995708c52013-10-17 20:52:597366 false);
7367 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7368 identity_transform,
[email protected]a2566412014-06-05 03:14:207369 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597370 gfx::PointF(),
7371 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577372 true,
[email protected]995708c52013-10-17 20:52:597373 false);
7374 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7375 identity_transform,
[email protected]a2566412014-06-05 03:14:207376 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597377 gfx::PointF(),
7378 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577379 true,
[email protected]995708c52013-10-17 20:52:597380 false);
7381 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7382 identity_transform,
[email protected]a2566412014-06-05 03:14:207383 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597384 gfx::PointF(),
7385 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577386 true,
[email protected]995708c52013-10-17 20:52:597387 false);
7388 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7389 identity_transform,
[email protected]a2566412014-06-05 03:14:207390 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597391 gfx::PointF(),
7392 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577393 true,
[email protected]995708c52013-10-17 20:52:597394 false);
7395 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7396 identity_transform,
[email protected]a2566412014-06-05 03:14:207397 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597398 gfx::PointF(),
7399 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577400 true,
[email protected]995708c52013-10-17 20:52:597401 false);
7402 SetLayerPropertiesForTesting(scroll_parent.get(),
7403 identity_transform,
[email protected]a2566412014-06-05 03:14:207404 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597405 gfx::PointF(),
7406 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577407 true,
[email protected]995708c52013-10-17 20:52:597408 false);
7409 SetLayerPropertiesForTesting(scroll_child.get(),
7410 identity_transform,
[email protected]a2566412014-06-05 03:14:207411 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597412 gfx::PointF(),
7413 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577414 true,
[email protected]995708c52013-10-17 20:52:597415 false);
7416
enne2097cab2014-09-25 20:16:317417 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597418 host->SetRootLayer(root);
7419
7420 ExecuteCalculateDrawProperties(root.get());
7421
7422 EXPECT_TRUE(root->render_surface());
7423
7424 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7425 scroll_child->clip_rect().ToString());
7426 EXPECT_TRUE(scroll_child->is_clipped());
7427
7428 // Despite the fact that we visited the above layers out of order to get the
7429 // correct clip, the layer lists should be unaffected.
7430 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
7431 EXPECT_EQ(scroll_child.get(),
Daniel Chengeea98042014-08-26 00:28:107432 root->render_surface()->layer_list().at(0).get());
[email protected]995708c52013-10-17 20:52:597433 EXPECT_EQ(scroll_parent.get(),
Daniel Chengeea98042014-08-26 00:28:107434 root->render_surface()->layer_list().at(1).get());
[email protected]995708c52013-10-17 20:52:597435 EXPECT_EQ(scroll_grandparent.get(),
Daniel Chengeea98042014-08-26 00:28:107436 root->render_surface()->layer_list().at(2).get());
[email protected]995708c52013-10-17 20:52:597437}
7438
7439TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
7440 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:227441 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:597442 // + root
7443 // + scroll_child
7444 // + scroll_parent_border
7445 // + scroll_parent_clip
7446 // + scroll_parent
7447 // + render_surface1
7448 // + scroll_grandparent_border
7449 // + scroll_grandparent_clip
7450 // + scroll_grandparent
7451 // + render_surface2
7452 //
[email protected]44d8e84c2013-10-19 19:13:227453 scoped_refptr<LayerWithForcedDrawsContent> root =
7454 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:597455
7456 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7457 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7458 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7459 make_scoped_refptr(new LayerWithForcedDrawsContent);
7460 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
7461 make_scoped_refptr(new LayerWithForcedDrawsContent);
7462
7463 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7464 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7465 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7466 make_scoped_refptr(new LayerWithForcedDrawsContent);
7467 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
7468 make_scoped_refptr(new LayerWithForcedDrawsContent);
7469
7470 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7471 make_scoped_refptr(new LayerWithForcedDrawsContent);
7472
7473 root->AddChild(scroll_child);
7474
7475 root->AddChild(scroll_parent_border);
7476 scroll_parent_border->AddChild(scroll_parent_clip);
7477 scroll_parent_clip->AddChild(scroll_parent);
7478 scroll_parent->AddChild(render_surface2);
7479
7480 root->AddChild(scroll_grandparent_border);
7481 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7482 scroll_grandparent_clip->AddChild(scroll_grandparent);
7483 scroll_grandparent->AddChild(render_surface1);
7484
7485 scroll_parent_clip->SetMasksToBounds(true);
7486 scroll_grandparent_clip->SetMasksToBounds(true);
7487
7488 scroll_child->SetScrollParent(scroll_parent.get());
7489 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7490
7491 render_surface1->SetForceRenderSurface(true);
7492 render_surface2->SetForceRenderSurface(true);
7493
7494 gfx::Transform identity_transform;
7495 SetLayerPropertiesForTesting(root.get(),
7496 identity_transform,
[email protected]a2566412014-06-05 03:14:207497 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597498 gfx::PointF(),
7499 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577500 true,
[email protected]995708c52013-10-17 20:52:597501 false);
7502 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7503 identity_transform,
[email protected]a2566412014-06-05 03:14:207504 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597505 gfx::PointF(),
7506 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577507 true,
[email protected]995708c52013-10-17 20:52:597508 false);
7509 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7510 identity_transform,
[email protected]a2566412014-06-05 03:14:207511 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597512 gfx::PointF(),
7513 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577514 true,
[email protected]995708c52013-10-17 20:52:597515 false);
7516 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7517 identity_transform,
[email protected]a2566412014-06-05 03:14:207518 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597519 gfx::PointF(),
7520 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577521 true,
[email protected]995708c52013-10-17 20:52:597522 false);
7523 SetLayerPropertiesForTesting(render_surface1.get(),
7524 identity_transform,
[email protected]a2566412014-06-05 03:14:207525 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597526 gfx::PointF(),
7527 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577528 true,
[email protected]995708c52013-10-17 20:52:597529 false);
7530 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7531 identity_transform,
[email protected]a2566412014-06-05 03:14:207532 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597533 gfx::PointF(),
7534 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577535 true,
[email protected]995708c52013-10-17 20:52:597536 false);
7537 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7538 identity_transform,
[email protected]a2566412014-06-05 03:14:207539 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597540 gfx::PointF(),
7541 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577542 true,
[email protected]995708c52013-10-17 20:52:597543 false);
7544 SetLayerPropertiesForTesting(scroll_parent.get(),
7545 identity_transform,
[email protected]a2566412014-06-05 03:14:207546 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597547 gfx::PointF(),
7548 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577549 true,
[email protected]995708c52013-10-17 20:52:597550 false);
7551 SetLayerPropertiesForTesting(render_surface2.get(),
7552 identity_transform,
[email protected]a2566412014-06-05 03:14:207553 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597554 gfx::PointF(),
7555 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577556 true,
[email protected]995708c52013-10-17 20:52:597557 false);
7558 SetLayerPropertiesForTesting(scroll_child.get(),
7559 identity_transform,
[email protected]a2566412014-06-05 03:14:207560 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597561 gfx::PointF(),
7562 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577563 true,
[email protected]995708c52013-10-17 20:52:597564 false);
7565
enne2097cab2014-09-25 20:16:317566 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597567 host->SetRootLayer(root);
7568
7569 RenderSurfaceLayerList render_surface_layer_list;
7570 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7571 root.get(),
bokancccfde72014-10-08 15:15:227572 root->bounds(),
[email protected]995708c52013-10-17 20:52:597573 identity_transform,
7574 &render_surface_layer_list);
7575
7576 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7577
7578 EXPECT_TRUE(root->render_surface());
7579
7580 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7581 scroll_child->clip_rect().ToString());
7582 EXPECT_TRUE(scroll_child->is_clipped());
7583
7584 // Despite the fact that we had to process the layers out of order to get the
7585 // right clip, our render_surface_layer_list's order should be unaffected.
7586 EXPECT_EQ(3u, render_surface_layer_list.size());
7587 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7588 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7589 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:227590 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7591 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7592 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:597593}
7594
eroman822f0dc32015-02-27 22:12:267595TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
7596 // We rearrange layer list contributions if we have to visit children out of
7597 // order, but it should be a 'stable' rearrangement. That is, the layer list
7598 // additions for a single layer should not be reordered, though their position
7599 // wrt to the contributions due to a sibling may vary.
7600 //
7601 // + root
7602 // + scroll_child
7603 // + top_content
7604 // + bottom_content
7605 // + scroll_parent_border
7606 // + scroll_parent_clip
7607 // + scroll_parent
7608 //
7609 FakeImplProxy proxy;
7610 TestSharedBitmapManager shared_bitmap_manager;
7611 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7612 host_impl.CreatePendingTree();
7613 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7614 scoped_ptr<LayerImpl> scroll_parent_border =
7615 LayerImpl::Create(host_impl.active_tree(), 2);
7616 scoped_ptr<LayerImpl> scroll_parent_clip =
7617 LayerImpl::Create(host_impl.active_tree(), 3);
7618 scoped_ptr<LayerImpl> scroll_parent =
7619 LayerImpl::Create(host_impl.active_tree(), 4);
7620 scoped_ptr<LayerImpl> scroll_child =
7621 LayerImpl::Create(host_impl.active_tree(), 5);
7622 scoped_ptr<LayerImpl> bottom_content =
7623 LayerImpl::Create(host_impl.active_tree(), 6);
7624 scoped_ptr<LayerImpl> top_content =
7625 LayerImpl::Create(host_impl.active_tree(), 7);
7626
7627 scroll_parent_clip->SetMasksToBounds(true);
7628
7629 scroll_child->SetScrollParent(scroll_parent.get());
7630 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
7631 scroll_children->insert(scroll_child.get());
7632 scroll_parent->SetScrollChildren(scroll_children.release());
7633
7634 scroll_child->SetDrawsContent(true);
7635 scroll_parent->SetDrawsContent(true);
7636 top_content->SetDrawsContent(true);
7637 bottom_content->SetDrawsContent(true);
7638
7639 gfx::Transform identity_transform;
7640 gfx::Transform top_transform;
7641 top_transform.Translate3d(0.0, 0.0, 5.0);
7642 gfx::Transform bottom_transform;
7643 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7644
7645 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7646 gfx::PointF(), gfx::Size(50, 50), true, false,
7647 true);
7648 SetLayerPropertiesForTesting(scroll_parent_border.get(), identity_transform,
7649 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7650 true, false, false);
7651 SetLayerPropertiesForTesting(scroll_parent_clip.get(), identity_transform,
7652 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7653 true, false, false);
7654 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
7655 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7656 true, false, false);
7657 SetLayerPropertiesForTesting(scroll_child.get(), identity_transform,
7658 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7659 true, false, false);
7660 SetLayerPropertiesForTesting(top_content.get(), top_transform, gfx::Point3F(),
7661 gfx::PointF(), gfx::Size(50, 50), false, true,
7662 true);
7663 SetLayerPropertiesForTesting(bottom_content.get(), bottom_transform,
7664 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7665 false, true, true);
7666
7667 scroll_child->SetShouldFlattenTransform(false);
7668 scroll_child->Set3dSortingContextId(1);
7669
7670 scroll_child->AddChild(top_content.Pass());
7671 scroll_child->AddChild(bottom_content.Pass());
7672 root->AddChild(scroll_child.Pass());
7673
7674 scroll_parent_clip->AddChild(scroll_parent.Pass());
7675 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
7676 root->AddChild(scroll_parent_border.Pass());
7677
7678 LayerImplList render_surface_layer_list;
7679 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7680 root.get(), root->bounds(), &render_surface_layer_list);
7681
7682 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7683
7684 EXPECT_TRUE(root->render_surface());
7685
7686 // If we don't sort by depth and let the layers get added in the order they
7687 // would normally be visited in, then layers 6 and 7 will be out of order. In
7688 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7689 // in the list (because of the scroll parent relationship), this should not
7690 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7691 // due to layer sorting).
7692 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
7693 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
7694 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
7695 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
7696 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
7697}
7698
[email protected]d81752b2013-10-25 08:32:237699TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7700 // This test verifies that a scrolling layer that gets snapped to
7701 // integer coordinates doesn't move a fixed position child.
7702 //
7703 // + root
7704 // + container
7705 // + scroller
7706 // + fixed
7707 //
7708 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457709 TestSharedBitmapManager shared_bitmap_manager;
7710 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:237711 host_impl.CreatePendingTree();
7712 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7713 scoped_ptr<LayerImpl> container =
7714 LayerImpl::Create(host_impl.active_tree(), 2);
7715 LayerImpl* container_layer = container.get();
7716 scoped_ptr<LayerImpl> scroller =
7717 LayerImpl::Create(host_impl.active_tree(), 3);
7718 LayerImpl* scroll_layer = scroller.get();
7719 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7720 LayerImpl* fixed_layer = fixed.get();
7721
7722 container->SetIsContainerForFixedPositionLayers(true);
7723
7724 LayerPositionConstraint constraint;
7725 constraint.set_is_fixed_position(true);
7726 fixed->SetPositionConstraint(constraint);
7727
[email protected]adeda572014-01-31 00:49:477728 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237729
7730 gfx::Transform identity_transform;
7731 gfx::Transform container_transform;
7732 container_transform.Translate3d(10.0, 20.0, 0.0);
7733 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7734
awoloszyne83f28c2014-12-22 15:40:007735 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7736 gfx::PointF(), gfx::Size(50, 50), true, false,
7737 true);
7738 SetLayerPropertiesForTesting(container.get(), container_transform,
7739 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7740 true, false, false);
7741 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7742 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7743 true, false, false);
7744 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7745 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237746 false);
7747
7748 scroller->AddChild(fixed.Pass());
7749 container->AddChild(scroller.Pass());
7750 root->AddChild(container.Pass());
7751
7752 // Rounded to integers already.
7753 {
7754 gfx::Vector2dF scroll_delta(3.0, 5.0);
7755 scroll_layer->SetScrollDelta(scroll_delta);
7756
7757 LayerImplList render_surface_layer_list;
7758 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227759 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237760 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7761
7762 EXPECT_TRANSFORMATION_MATRIX_EQ(
7763 container_layer->draw_properties().screen_space_transform,
7764 fixed_layer->draw_properties().screen_space_transform);
7765 EXPECT_VECTOR_EQ(
7766 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7767 container_offset);
7768 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7769 .screen_space_transform.To2dTranslation(),
7770 container_offset - scroll_delta);
7771 }
7772
7773 // Scroll delta requiring rounding.
7774 {
7775 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7776 scroll_layer->SetScrollDelta(scroll_delta);
7777
7778 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7779
7780 LayerImplList render_surface_layer_list;
7781 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227782 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237783 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7784
7785 EXPECT_TRANSFORMATION_MATRIX_EQ(
7786 container_layer->draw_properties().screen_space_transform,
7787 fixed_layer->draw_properties().screen_space_transform);
7788 EXPECT_VECTOR_EQ(
7789 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7790 container_offset);
7791 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7792 .screen_space_transform.To2dTranslation(),
7793 container_offset - rounded_scroll_delta);
7794 }
[email protected]cf15ad7b2014-04-02 03:59:267795
7796 // Scale is applied earlier in the tree.
7797 {
7798 gfx::Transform scaled_container_transform = container_transform;
7799 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
7800 container_layer->SetTransform(scaled_container_transform);
7801
7802 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7803 scroll_layer->SetScrollDelta(scroll_delta);
7804
7805 LayerImplList render_surface_layer_list;
7806 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227807 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267808 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7809
7810 EXPECT_TRANSFORMATION_MATRIX_EQ(
7811 container_layer->draw_properties().screen_space_transform,
7812 fixed_layer->draw_properties().screen_space_transform);
7813 EXPECT_VECTOR_EQ(
7814 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7815 container_offset);
7816
7817 container_layer->SetTransform(container_transform);
7818 }
7819
7820 // Scale is applied on the scroll layer itself.
7821 {
7822 gfx::Transform scale_transform;
7823 scale_transform.Scale3d(3.0, 3.0, 1.0);
7824 scroll_layer->SetTransform(scale_transform);
7825
7826 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7827 scroll_layer->SetScrollDelta(scroll_delta);
7828
7829 LayerImplList render_surface_layer_list;
7830 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227831 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267832 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7833
7834 EXPECT_VECTOR_EQ(
7835 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7836 container_offset);
7837
7838 scroll_layer->SetTransform(identity_transform);
7839 }
[email protected]d81752b2013-10-25 08:32:237840}
7841
miletus2c78036b2015-01-29 20:52:377842TEST_F(LayerTreeHostCommonTest,
7843 ScrollCompensationMainScrollOffsetFractionalPart) {
7844 // This test verifies that a scrolling layer that has fractional scroll offset
7845 // from main doesn't move a fixed position child.
7846 //
7847 // + root
7848 // + container
7849 // + scroller
7850 // + fixed
7851 //
7852 FakeImplProxy proxy;
7853 TestSharedBitmapManager shared_bitmap_manager;
7854 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7855 host_impl.CreatePendingTree();
7856 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7857 scoped_ptr<LayerImpl> container =
7858 LayerImpl::Create(host_impl.active_tree(), 2);
7859 LayerImpl* container_layer = container.get();
7860 scoped_ptr<LayerImpl> scroller =
7861 LayerImpl::Create(host_impl.active_tree(), 3);
7862 LayerImpl* scroll_layer = scroller.get();
7863 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7864 LayerImpl* fixed_layer = fixed.get();
7865
7866 container->SetIsContainerForFixedPositionLayers(true);
7867
7868 LayerPositionConstraint constraint;
7869 constraint.set_is_fixed_position(true);
7870 fixed->SetPositionConstraint(constraint);
7871
7872 scroller->SetScrollClipLayer(container->id());
7873
7874 gfx::Transform identity_transform;
7875 gfx::Transform container_transform;
7876 container_transform.Translate3d(10.0, 20.0, 0.0);
7877 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7878
7879 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7880 gfx::PointF(), gfx::Size(50, 50), true, false,
7881 true);
7882 SetLayerPropertiesForTesting(container.get(), container_transform,
7883 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7884 true, false, false);
7885 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7886 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7887 gfx::Size(30, 30), true, false, false);
7888
7889 gfx::ScrollOffset scroll_offset(3.3, 4.2);
7890 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
7891 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
7892 // Blink only uses the integer part of the scroll_offset for fixed
7893 // position layer.
7894 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7895 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
7896 false, false);
aeliasf998da82015-02-03 01:40:517897 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:497898 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:447899 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:377900
7901 scroller->AddChild(fixed.Pass());
7902 container->AddChild(scroller.Pass());
7903 root->AddChild(container.Pass());
7904
7905 LayerImplList render_surface_layer_list;
7906 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7907 root.get(), root->bounds(), &render_surface_layer_list);
7908 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7909
7910 EXPECT_TRANSFORMATION_MATRIX_EQ(
7911 container_layer->draw_properties().screen_space_transform,
7912 fixed_layer->draw_properties().screen_space_transform);
7913 EXPECT_VECTOR_EQ(
7914 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7915 container_offset);
7916
7917 gfx::ScrollOffset effective_scroll_offset =
7918 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
7919 gfx::Vector2d rounded_effective_scroll_offset =
7920 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
7921 EXPECT_VECTOR_EQ(
7922 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
7923 container_offset - rounded_effective_scroll_offset);
7924}
7925
[email protected]1c3626e2014-04-09 17:49:227926class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7927 public:
7928 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7929 LayerTreeImpl* tree_impl,
7930 int id) {
7931 return make_scoped_ptr(
7932 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7933 }
7934
dcheng716bedf2014-10-21 09:51:087935 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227936
[email protected]1c3626e2014-04-09 17:49:227937 private:
7938 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7939 int id)
[email protected]a57cb8b12014-06-13 18:15:377940 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227941 SetDrawsContent(true);
7942 }
[email protected]1c3626e2014-04-09 17:49:227943};
7944
7945TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
7946 FakeImplProxy proxy;
7947 TestSharedBitmapManager shared_bitmap_manager;
7948 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7949 gfx::Transform identity_matrix;
7950 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7951 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7952 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7953 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7954 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7955 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7956 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7957 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7958
7959 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7960 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7961 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7962
danakjf446a072014-09-27 21:55:487963 child->AddChild(grand_child.Pass());
7964 parent->AddChild(child.Pass());
7965 grand_parent->AddChild(parent.Pass());
[email protected]1c3626e2014-04-09 17:49:227966
awoloszyne83f28c2014-12-22 15:40:007967 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
7968 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7969 true, false, true);
7970 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7971 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227972 false);
awoloszyne83f28c2014-12-22 15:40:007973 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7974 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227975 false);
awoloszyne83f28c2014-12-22 15:40:007976
7977 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7978 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227979 false);
7980
7981 ExecuteCalculateDrawProperties(grand_parent.get());
7982
7983 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:377984 EXPECT_EQ(0.f,
7985 grand_parent->draw_properties().maximum_animation_contents_scale);
7986 EXPECT_EQ(0.f,
7987 parent_raw->draw_properties().maximum_animation_contents_scale);
7988 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7989 EXPECT_EQ(
7990 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227991
7992 TransformOperations translation;
7993 translation.AppendTranslate(1.f, 2.f, 3.f);
7994
7995 AddAnimatedTransformToLayer(
7996 parent_raw, 1.0, TransformOperations(), translation);
7997
7998 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377999 EXPECT_EQ(0.f,
8000 grand_parent->draw_properties().maximum_animation_contents_scale);
8001 EXPECT_EQ(0.f,
8002 parent_raw->draw_properties().maximum_animation_contents_scale);
8003 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8004 EXPECT_EQ(
8005 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228006
8007 TransformOperations scale;
8008 scale.AppendScale(5.f, 4.f, 3.f);
8009
8010 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
8011 ExecuteCalculateDrawProperties(grand_parent.get());
8012
8013 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:378014 EXPECT_EQ(0.f,
8015 grand_parent->draw_properties().maximum_animation_contents_scale);
8016 EXPECT_EQ(0.f,
8017 parent_raw->draw_properties().maximum_animation_contents_scale);
8018 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
8019 EXPECT_EQ(
8020 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228021
8022 AddAnimatedTransformToLayer(
8023 grand_parent.get(), 1.0, TransformOperations(), scale);
8024 ExecuteCalculateDrawProperties(grand_parent.get());
8025
8026 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378027 EXPECT_EQ(5.f,
8028 grand_parent->draw_properties().maximum_animation_contents_scale);
8029 EXPECT_EQ(5.f,
8030 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228031 // We don't support combining animated scales from two nodes; 0.f means
8032 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:378033 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8034 EXPECT_EQ(
8035 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228036
8037 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8038 ExecuteCalculateDrawProperties(grand_parent.get());
8039
8040 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378041 EXPECT_EQ(5.f,
8042 grand_parent->draw_properties().maximum_animation_contents_scale);
8043 EXPECT_EQ(0.f,
8044 parent_raw->draw_properties().maximum_animation_contents_scale);
8045 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8046 EXPECT_EQ(
8047 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228048
8049 grand_parent->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388050 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228051 parent_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388052 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228053 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388054 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228055
8056 TransformOperations perspective;
8057 perspective.AppendPerspective(10.f);
8058
8059 AddAnimatedTransformToLayer(
8060 child_raw, 1.0, TransformOperations(), perspective);
8061 ExecuteCalculateDrawProperties(grand_parent.get());
8062
8063 // |child| has a scale-affecting animation but computing the maximum of this
8064 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:378065 EXPECT_EQ(0.f,
8066 grand_parent->draw_properties().maximum_animation_contents_scale);
8067 EXPECT_EQ(0.f,
8068 parent_raw->draw_properties().maximum_animation_contents_scale);
8069 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8070 EXPECT_EQ(
8071 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228072
8073 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388074 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228075
8076 gfx::Transform scale_matrix;
8077 scale_matrix.Scale(1.f, 2.f);
8078 grand_parent->SetTransform(scale_matrix);
8079 parent_raw->SetTransform(scale_matrix);
8080 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8081 ExecuteCalculateDrawProperties(grand_parent.get());
8082
8083 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8084 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:378085 EXPECT_EQ(0.f,
8086 grand_parent->draw_properties().maximum_animation_contents_scale);
8087 EXPECT_EQ(10.f,
8088 parent_raw->draw_properties().maximum_animation_contents_scale);
8089 EXPECT_EQ(10.f,
8090 child_raw->draw_properties().maximum_animation_contents_scale);
8091 EXPECT_EQ(
8092 10.f,
8093 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228094
8095 gfx::Transform perspective_matrix;
8096 perspective_matrix.ApplyPerspectiveDepth(2.f);
8097 child_raw->SetTransform(perspective_matrix);
8098 ExecuteCalculateDrawProperties(grand_parent.get());
8099
8100 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378101 EXPECT_EQ(0.f,
8102 grand_parent->draw_properties().maximum_animation_contents_scale);
8103 EXPECT_EQ(10.f,
8104 parent_raw->draw_properties().maximum_animation_contents_scale);
8105 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8106 EXPECT_EQ(
8107 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228108
8109 parent_raw->SetTransform(perspective_matrix);
8110 ExecuteCalculateDrawProperties(grand_parent.get());
8111
8112 // |parent| and |child| have transforms that are neither translations nor
8113 // scales.
[email protected]a57cb8b12014-06-13 18:15:378114 EXPECT_EQ(0.f,
8115 grand_parent->draw_properties().maximum_animation_contents_scale);
8116 EXPECT_EQ(0.f,
8117 parent_raw->draw_properties().maximum_animation_contents_scale);
8118 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8119 EXPECT_EQ(
8120 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228121
8122 parent_raw->SetTransform(identity_matrix);
8123 child_raw->SetTransform(identity_matrix);
8124 grand_parent->SetTransform(perspective_matrix);
8125
8126 ExecuteCalculateDrawProperties(grand_parent.get());
8127
8128 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378129 EXPECT_EQ(0.f,
8130 grand_parent->draw_properties().maximum_animation_contents_scale);
8131 EXPECT_EQ(0.f,
8132 parent_raw->draw_properties().maximum_animation_contents_scale);
8133 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8134 EXPECT_EQ(
8135 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228136}
8137
[email protected]390bb1ff2014-05-09 17:14:408138static int membership_id(LayerImpl* layer) {
8139 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8140}
8141
8142static void GatherDrawnLayers(LayerImplList* rsll,
8143 std::set<LayerImpl*>* drawn_layers) {
8144 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8145 end = LayerIterator<LayerImpl>::End(rsll);
8146 it != end;
8147 ++it) {
8148 LayerImpl* layer = *it;
8149 if (it.represents_itself())
8150 drawn_layers->insert(layer);
8151
8152 if (!it.represents_contributing_render_surface())
8153 continue;
8154
8155 if (layer->mask_layer())
8156 drawn_layers->insert(layer->mask_layer());
8157 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
8158 drawn_layers->insert(layer->replica_layer()->mask_layer());
8159 }
8160}
8161
8162TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
8163 FakeImplProxy proxy;
8164 TestSharedBitmapManager shared_bitmap_manager;
8165 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8166 gfx::Transform identity_matrix;
8167
8168 scoped_ptr<LayerImpl> grand_parent =
8169 LayerImpl::Create(host_impl.active_tree(), 1);
8170 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
8171 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
8172 scoped_ptr<LayerImpl> grand_child1 =
8173 LayerImpl::Create(host_impl.active_tree(), 7);
8174 scoped_ptr<LayerImpl> grand_child2 =
8175 LayerImpl::Create(host_impl.active_tree(), 9);
8176
8177 LayerImpl* grand_parent_raw = grand_parent.get();
8178 LayerImpl* parent_raw = parent.get();
8179 LayerImpl* child_raw = child.get();
8180 LayerImpl* grand_child1_raw = grand_child1.get();
8181 LayerImpl* grand_child2_raw = grand_child2.get();
8182
8183 child->AddChild(grand_child1.Pass());
8184 child->AddChild(grand_child2.Pass());
8185 parent->AddChild(child.Pass());
8186 grand_parent->AddChild(parent.Pass());
8187
awoloszyne83f28c2014-12-22 15:40:008188 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
8189 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8190 true, false, true);
8191 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8192 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408193 false);
awoloszyne83f28c2014-12-22 15:40:008194
8195 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8196 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408197 false);
awoloszyne83f28c2014-12-22 15:40:008198
8199 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
8200 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8201 true, false, false);
8202
8203 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
8204 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8205 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:408206
8207 // Start with nothing being drawn.
8208 ExecuteCalculateDrawProperties(grand_parent_raw);
8209 int member_id = render_surface_layer_list_count();
8210
8211 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8212 EXPECT_NE(member_id, membership_id(parent_raw));
8213 EXPECT_NE(member_id, membership_id(child_raw));
8214 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8215 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8216
8217 std::set<LayerImpl*> expected;
8218 std::set<LayerImpl*> actual;
8219 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8220 EXPECT_EQ(expected, actual);
8221
8222 // If we force render surface, but none of the layers are in the layer list,
8223 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:008224 grand_child1_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408225
8226 ExecuteCalculateDrawProperties(grand_parent_raw);
8227 member_id = render_surface_layer_list_count();
8228
8229 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8230 EXPECT_NE(member_id, membership_id(parent_raw));
8231 EXPECT_NE(member_id, membership_id(child_raw));
8232 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8233 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8234
8235 expected.clear();
8236 actual.clear();
8237 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8238 EXPECT_EQ(expected, actual);
8239
8240 // However, if we say that this layer also draws content, it will appear in
8241 // RSLL.
8242 grand_child1_raw->SetDrawsContent(true);
8243
8244 ExecuteCalculateDrawProperties(grand_parent_raw);
8245 member_id = render_surface_layer_list_count();
8246
8247 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8248 EXPECT_NE(member_id, membership_id(parent_raw));
8249 EXPECT_NE(member_id, membership_id(child_raw));
8250 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8251 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8252
8253 expected.clear();
8254 expected.insert(grand_child1_raw);
8255
8256 actual.clear();
8257 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8258 EXPECT_EQ(expected, actual);
8259
8260 // Now child is forced to have a render surface, and one if its children draws
8261 // content.
8262 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:008263 grand_child1_raw->SetHasRenderSurface(false);
8264 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408265 grand_child2_raw->SetDrawsContent(true);
8266
8267 ExecuteCalculateDrawProperties(grand_parent_raw);
8268 member_id = render_surface_layer_list_count();
8269
8270 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8271 EXPECT_NE(member_id, membership_id(parent_raw));
8272 EXPECT_NE(member_id, membership_id(child_raw));
8273 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8274 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8275
8276 expected.clear();
8277 expected.insert(grand_child2_raw);
8278
8279 actual.clear();
8280 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8281 EXPECT_EQ(expected, actual);
8282
8283 // Add a mask layer to child.
8284 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
8285
8286 ExecuteCalculateDrawProperties(grand_parent_raw);
8287 member_id = render_surface_layer_list_count();
8288
8289 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8290 EXPECT_NE(member_id, membership_id(parent_raw));
8291 EXPECT_NE(member_id, membership_id(child_raw));
8292 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8293 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8294 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8295
8296 expected.clear();
8297 expected.insert(grand_child2_raw);
8298 expected.insert(child_raw->mask_layer());
8299
8300 expected.clear();
8301 expected.insert(grand_child2_raw);
8302 expected.insert(child_raw->mask_layer());
8303
8304 actual.clear();
8305 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8306 EXPECT_EQ(expected, actual);
8307
8308 // Add replica mask layer.
8309 scoped_ptr<LayerImpl> replica_layer =
8310 LayerImpl::Create(host_impl.active_tree(), 20);
8311 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
8312 child_raw->SetReplicaLayer(replica_layer.Pass());
8313
8314 ExecuteCalculateDrawProperties(grand_parent_raw);
8315 member_id = render_surface_layer_list_count();
8316
8317 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8318 EXPECT_NE(member_id, membership_id(parent_raw));
8319 EXPECT_NE(member_id, membership_id(child_raw));
8320 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8321 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
8322 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8323 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8324
8325 expected.clear();
8326 expected.insert(grand_child2_raw);
8327 expected.insert(child_raw->mask_layer());
8328 expected.insert(child_raw->replica_layer()->mask_layer());
8329
8330 actual.clear();
8331 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8332 EXPECT_EQ(expected, actual);
8333
8334 child_raw->TakeReplicaLayer();
8335
8336 // With nothing drawing, we should have no layers.
8337 grand_child2_raw->SetDrawsContent(false);
8338
8339 ExecuteCalculateDrawProperties(grand_parent_raw);
8340 member_id = render_surface_layer_list_count();
8341
8342 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8343 EXPECT_NE(member_id, membership_id(parent_raw));
8344 EXPECT_NE(member_id, membership_id(child_raw));
8345 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
8346 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8347 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8348
8349 expected.clear();
8350 actual.clear();
8351 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8352 EXPECT_EQ(expected, actual);
8353
8354 // Child itself draws means that we should have the child and the mask in the
8355 // list.
8356 child_raw->SetDrawsContent(true);
8357
8358 ExecuteCalculateDrawProperties(grand_parent_raw);
8359 member_id = render_surface_layer_list_count();
8360
8361 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8362 EXPECT_NE(member_id, membership_id(parent_raw));
8363 EXPECT_EQ(member_id, membership_id(child_raw));
8364 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8365 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8366 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8367
8368 expected.clear();
8369 expected.insert(child_raw);
8370 expected.insert(child_raw->mask_layer());
8371 actual.clear();
8372 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8373 EXPECT_EQ(expected, actual);
8374
8375 child_raw->TakeMaskLayer();
8376
8377 // Now everyone's a member!
8378 grand_parent_raw->SetDrawsContent(true);
8379 parent_raw->SetDrawsContent(true);
8380 child_raw->SetDrawsContent(true);
8381 grand_child1_raw->SetDrawsContent(true);
8382 grand_child2_raw->SetDrawsContent(true);
8383
8384 ExecuteCalculateDrawProperties(grand_parent_raw);
8385 member_id = render_surface_layer_list_count();
8386
8387 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
8388 EXPECT_EQ(member_id, membership_id(parent_raw));
8389 EXPECT_EQ(member_id, membership_id(child_raw));
8390 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8391 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8392
8393 expected.clear();
8394 expected.insert(grand_parent_raw);
8395 expected.insert(parent_raw);
8396 expected.insert(child_raw);
8397 expected.insert(grand_child1_raw);
8398 expected.insert(grand_child2_raw);
8399
8400 actual.clear();
8401 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8402 EXPECT_EQ(expected, actual);
8403}
[email protected]18e69652014-06-13 12:50:588404
8405TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
8406 FakeImplProxy proxy;
8407 TestSharedBitmapManager shared_bitmap_manager;
8408 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8409
8410 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8411 LayerImpl* root_layer = root.get();
8412 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
8413 LayerImpl* child1_layer = child1.get();
8414 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
8415 LayerImpl* child2_layer = child2.get();
8416
8417 root->AddChild(child1.Pass());
8418 root->AddChild(child2.Pass());
awoloszyne83f28c2014-12-22 15:40:008419 root->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588420
8421 gfx::Transform identity_matrix, scale_transform_child1,
8422 scale_transform_child2;
8423 scale_transform_child1.Scale(2, 3);
8424 scale_transform_child2.Scale(4, 5);
8425
awoloszyne83f28c2014-12-22 15:40:008426 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
8427 gfx::PointF(), gfx::Size(1, 1), true, false,
8428 true);
8429 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
8430 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8431 false, false);
[email protected]18e69652014-06-13 12:50:588432
8433 child1_layer->SetMaskLayer(
8434 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
8435
8436 scoped_ptr<LayerImpl> replica_layer =
8437 LayerImpl::Create(host_impl.active_tree(), 5);
awoloszyne83f28c2014-12-22 15:40:008438 replica_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588439 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
8440 child1_layer->SetReplicaLayer(replica_layer.Pass());
awoloszyne83f28c2014-12-22 15:40:008441 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588442
8443 ExecuteCalculateDrawProperties(root_layer);
8444
8445 TransformOperations scale;
8446 scale.AppendScale(5.f, 8.f, 3.f);
8447
8448 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
awoloszyne83f28c2014-12-22 15:40:008449 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
8450 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8451 false, false);
[email protected]18e69652014-06-13 12:50:588452
8453 ExecuteCalculateDrawProperties(root_layer);
8454
8455 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8456 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale);
8457 EXPECT_FLOAT_EQ(
8458 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8459 EXPECT_FLOAT_EQ(3.f,
8460 child1_layer->replica_layer()
8461 ->mask_layer()
8462 ->draw_properties()
8463 .ideal_contents_scale);
8464 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale);
8465
8466 EXPECT_FLOAT_EQ(
8467 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8468 EXPECT_FLOAT_EQ(
8469 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8470 EXPECT_FLOAT_EQ(0.f,
8471 child1_layer->mask_layer()
8472 ->draw_properties()
8473 .maximum_animation_contents_scale);
8474 EXPECT_FLOAT_EQ(0.f,
8475 child1_layer->replica_layer()
8476 ->mask_layer()
8477 ->draw_properties()
8478 .maximum_animation_contents_scale);
8479 EXPECT_FLOAT_EQ(
8480 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8481
8482 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8483 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor);
8484 EXPECT_FLOAT_EQ(
8485 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8486 EXPECT_FLOAT_EQ(1.f,
8487 child1_layer->replica_layer()
8488 ->mask_layer()
8489 ->draw_properties()
8490 .page_scale_factor);
8491 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor);
8492
8493 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8494 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8495 EXPECT_FLOAT_EQ(
8496 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8497 EXPECT_FLOAT_EQ(1.f,
8498 child1_layer->replica_layer()
8499 ->mask_layer()
8500 ->draw_properties()
8501 .device_scale_factor);
8502 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8503
8504 // Changing page-scale would affect ideal_contents_scale and
8505 // maximum_animation_contents_scale.
8506
8507 float page_scale_factor = 3.f;
8508 float device_scale_factor = 1.0f;
8509 std::vector<LayerImpl*> render_surface_layer_list;
8510 gfx::Size device_viewport_size =
8511 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8512 root_layer->bounds().height() * device_scale_factor);
8513 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8514 root_layer, device_viewport_size, &render_surface_layer_list);
8515
8516 inputs.page_scale_factor = page_scale_factor;
8517 inputs.can_adjust_raster_scales = true;
8518 inputs.page_scale_application_layer = root_layer;
8519 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8520
8521 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8522 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale);
8523 EXPECT_FLOAT_EQ(
8524 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8525 EXPECT_FLOAT_EQ(9.f,
8526 child1_layer->replica_layer()
8527 ->mask_layer()
8528 ->draw_properties()
8529 .ideal_contents_scale);
8530 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale);
8531
8532 EXPECT_FLOAT_EQ(
8533 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8534 EXPECT_FLOAT_EQ(
8535 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8536 EXPECT_FLOAT_EQ(0.f,
8537 child1_layer->mask_layer()
8538 ->draw_properties()
8539 .maximum_animation_contents_scale);
8540 EXPECT_FLOAT_EQ(0.f,
8541 child1_layer->replica_layer()
8542 ->mask_layer()
8543 ->draw_properties()
8544 .maximum_animation_contents_scale);
8545 EXPECT_FLOAT_EQ(
8546 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8547
8548 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8549 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8550 EXPECT_FLOAT_EQ(
8551 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8552 EXPECT_FLOAT_EQ(3.f,
8553 child1_layer->replica_layer()
8554 ->mask_layer()
8555 ->draw_properties()
8556 .page_scale_factor);
8557 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8558
8559 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8560 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8561 EXPECT_FLOAT_EQ(
8562 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8563 EXPECT_FLOAT_EQ(1.f,
8564 child1_layer->replica_layer()
8565 ->mask_layer()
8566 ->draw_properties()
8567 .device_scale_factor);
8568 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8569
8570 // Changing device-scale would affect ideal_contents_scale and
8571 // maximum_animation_contents_scale.
8572
8573 device_scale_factor = 4.0f;
8574 inputs.device_scale_factor = device_scale_factor;
8575 inputs.can_adjust_raster_scales = true;
8576 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8577
8578 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale);
8579 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale);
8580 EXPECT_FLOAT_EQ(
8581 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8582 EXPECT_FLOAT_EQ(36.f,
8583 child1_layer->replica_layer()
8584 ->mask_layer()
8585 ->draw_properties()
8586 .ideal_contents_scale);
8587 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale);
8588
8589 EXPECT_FLOAT_EQ(
8590 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8591 EXPECT_FLOAT_EQ(
8592 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8593 EXPECT_FLOAT_EQ(0.f,
8594 child1_layer->mask_layer()
8595 ->draw_properties()
8596 .maximum_animation_contents_scale);
8597 EXPECT_FLOAT_EQ(0.f,
8598 child1_layer->replica_layer()
8599 ->mask_layer()
8600 ->draw_properties()
8601 .maximum_animation_contents_scale);
8602 EXPECT_FLOAT_EQ(
8603 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8604
8605 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8606 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8607 EXPECT_FLOAT_EQ(
8608 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8609 EXPECT_FLOAT_EQ(3.f,
8610 child1_layer->replica_layer()
8611 ->mask_layer()
8612 ->draw_properties()
8613 .page_scale_factor);
8614 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8615
8616 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor);
8617 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor);
8618 EXPECT_FLOAT_EQ(
8619 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8620 EXPECT_FLOAT_EQ(4.f,
8621 child1_layer->replica_layer()
8622 ->mask_layer()
8623 ->draw_properties()
8624 .device_scale_factor);
8625 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8626}
8627
danakjf6069db2014-09-13 00:46:478628TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
8629 scoped_refptr<Layer> root = Layer::Create();
8630 SetLayerPropertiesForTesting(root.get(),
8631 gfx::Transform(),
8632 gfx::Point3F(),
8633 gfx::PointF(),
8634 gfx::Size(768 / 2, 3000),
8635 true,
8636 false);
8637 root->SetIsDrawable(true);
8638
8639 scoped_refptr<Layer> clip = Layer::Create();
8640 SetLayerPropertiesForTesting(clip.get(),
8641 gfx::Transform(),
8642 gfx::Point3F(),
8643 gfx::PointF(),
8644 gfx::Size(768 / 2, 10000),
8645 true,
8646 false);
8647 clip->SetMasksToBounds(true);
8648
8649 scoped_refptr<Layer> content = Layer::Create();
8650 SetLayerPropertiesForTesting(content.get(),
8651 gfx::Transform(),
8652 gfx::Point3F(),
8653 gfx::PointF(),
8654 gfx::Size(768 / 2, 10000),
8655 true,
8656 false);
8657 content->SetIsDrawable(true);
8658 content->SetForceRenderSurface(true);
8659
8660 root->AddChild(clip);
8661 clip->AddChild(content);
8662
enne2097cab2014-09-25 20:16:318663 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
8664 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
danakjf6069db2014-09-13 00:46:478665 host->SetRootLayer(root);
8666
8667 gfx::Size device_viewport_size(768, 582);
8668 RenderSurfaceLayerList render_surface_layer_list;
8669 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8670 host->root_layer(), device_viewport_size, &render_surface_layer_list);
8671 inputs.device_scale_factor = 2.f;
8672 inputs.page_scale_factor = 1.f;
8673 inputs.page_scale_application_layer = NULL;
8674 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8675
8676 // Layers in the root render surface have their visible content rect clipped
8677 // by the viewport.
8678 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8679
8680 // Layers drawing to a child render surface should still have their visible
8681 // content rect clipped by the viewport.
8682 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8683}
8684
timav599f4359d2014-12-05 00:12:228685TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
8686 FakeImplProxy proxy;
8687 TestSharedBitmapManager shared_bitmap_manager;
8688 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8689
8690 // Set two layers: the root layer clips it's child,
8691 // the child draws its content.
8692
8693 gfx::Size root_size = gfx::Size(300, 500);
8694
8695 // Sublayer should be bigger than the root enlarged by bounds_delta.
8696 gfx::Size sublayer_size = gfx::Size(300, 1000);
8697
8698 // Device viewport accomidated the root and the top controls.
8699 gfx::Size device_viewport_size = gfx::Size(300, 600);
8700 gfx::Transform identity_matrix;
8701
8702 host_impl.active_tree()->SetRootLayer(
8703 LayerImpl::Create(host_impl.active_tree(), 1));
8704
8705 LayerImpl* root = host_impl.active_tree()->root_layer();
8706 SetLayerPropertiesForTesting(root,
8707 identity_matrix,
8708 gfx::Point3F(),
8709 gfx::PointF(),
8710 root_size,
8711 false,
awoloszyne83f28c2014-12-22 15:40:008712 false,
8713 true);
timav599f4359d2014-12-05 00:12:228714
8715 root->SetContentBounds(root_size);
8716 root->SetMasksToBounds(true);
8717
8718 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8719
8720 LayerImpl* sublayer = root->child_at(0);
8721 SetLayerPropertiesForTesting(sublayer,
8722 identity_matrix,
8723 gfx::Point3F(),
8724 gfx::PointF(),
8725 sublayer_size,
8726 false,
awoloszyne83f28c2014-12-22 15:40:008727 false,
timav599f4359d2014-12-05 00:12:228728 false);
8729
8730 sublayer->SetContentBounds(sublayer_size);
8731 sublayer->SetDrawsContent(true);
8732
8733 LayerImplList layer_impl_list;
8734 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8735 root, device_viewport_size, &layer_impl_list);
8736
8737 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8738
8739 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect());
8740
8741 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8742
8743 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8744
8745 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8746 root_size.height() + 50);
8747 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect());
8748}
8749
vollick7d83b452015-02-24 20:18:068750TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8751 const gfx::Transform identity_matrix;
8752 scoped_refptr<Layer> root = Layer::Create();
8753 scoped_refptr<LayerWithForcedDrawsContent> animated =
8754 make_scoped_refptr(new LayerWithForcedDrawsContent());
8755
8756 root->AddChild(animated);
8757
8758 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8759 host->SetRootLayer(root);
8760
8761 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8762 gfx::PointF(), gfx::Size(100, 100), true, false);
8763 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8764 gfx::PointF(), gfx::Size(20, 20), true, false);
8765
8766 root->SetMasksToBounds(true);
8767 root->SetForceRenderSurface(true);
8768 animated->SetOpacity(0.f);
8769
8770 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
8771 0.f, 1.f, false);
8772
8773 ExecuteCalculateDrawProperties(root.get());
8774
8775 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
8776}
8777
enne92f2f6d92015-02-25 23:13:318778// Verify that having an animated filter (but no current filter, as these
8779// are mutually exclusive) correctly creates a render surface.
8780TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
8781 scoped_refptr<Layer> root = Layer::Create();
8782 scoped_refptr<Layer> child = Layer::Create();
8783 scoped_refptr<Layer> grandchild = Layer::Create();
8784 root->AddChild(child);
8785 child->AddChild(grandchild);
8786
8787 gfx::Transform identity_transform;
8788 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8789 gfx::PointF(), gfx::Size(50, 50), true, false);
8790 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8791 gfx::PointF(), gfx::Size(50, 50), true, false);
8792 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8793 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8794 true, false);
8795 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8796 host->SetRootLayer(root);
8797
8798 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
8799
8800 ExecuteCalculateDrawProperties(root.get());
8801
8802 EXPECT_TRUE(root->render_surface());
8803 EXPECT_TRUE(child->render_surface());
8804 EXPECT_FALSE(grandchild->render_surface());
8805
8806 EXPECT_TRUE(root->filters().IsEmpty());
8807 EXPECT_TRUE(child->filters().IsEmpty());
8808 EXPECT_TRUE(grandchild->filters().IsEmpty());
8809
8810 EXPECT_FALSE(root->FilterIsAnimating());
8811 EXPECT_TRUE(child->FilterIsAnimating());
8812 EXPECT_FALSE(grandchild->FilterIsAnimating());
8813}
8814
vollick0120eb22015-03-02 03:07:348815// Ensures that the property tree code accounts for offsets between fixed
8816// position layers and their respective containers.
8817TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
8818 scoped_refptr<Layer> root = Layer::Create();
8819 scoped_refptr<Layer> child = Layer::Create();
8820 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8821 make_scoped_refptr(new LayerWithForcedDrawsContent());
8822
8823 root->AddChild(child);
8824 child->AddChild(grandchild);
8825
8826 gfx::Transform identity_transform;
8827 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8828 gfx::PointF(), gfx::Size(50, 50), true, false);
8829 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8830 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8831 false);
8832 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8833 gfx::Point3F(), gfx::PointF(-1000, -1000),
8834 gfx::Size(50, 50), true, false);
8835
8836 root->SetMasksToBounds(true);
8837 root->SetIsContainerForFixedPositionLayers(true);
8838 LayerPositionConstraint constraint;
8839 constraint.set_is_fixed_position(true);
8840 grandchild->SetPositionConstraint(constraint);
8841
8842 root->SetIsContainerForFixedPositionLayers(true);
8843
8844 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8845 host->SetRootLayer(root);
8846
8847 ExecuteCalculateDrawProperties(root.get());
8848
8849 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8850 grandchild->visible_rect_from_property_trees());
8851}
8852
[email protected]ba565742012-11-10 09:29:488853} // namespace
8854} // namespace cc