blob: e3a48bfedae98b13e02d3cfd710591fca0694f59 [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());
ajumad0d64422015-03-14 04:20:081009 scoped_refptr<LayerWithForcedDrawsContent> great_grand_child =
1010 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:321011
1012 gfx::Transform rotation_about_y_axis;
1013 rotation_about_y_axis.RotateAboutYAxis(30.0);
1014
1015 const gfx::Transform identity_matrix;
1016 SetLayerPropertiesForTesting(root.get(),
1017 identity_matrix,
[email protected]a2566412014-06-05 03:14:201018 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321019 gfx::PointF(),
1020 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571021 true,
[email protected]fb661802013-03-25 01:59:321022 false);
1023 SetLayerPropertiesForTesting(child.get(),
1024 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201025 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321026 gfx::PointF(),
1027 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571028 true,
[email protected]fb661802013-03-25 01:59:321029 false);
1030 SetLayerPropertiesForTesting(grand_child.get(),
1031 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201032 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321033 gfx::PointF(),
1034 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571035 true,
[email protected]fb661802013-03-25 01:59:321036 false);
ajumad0d64422015-03-14 04:20:081037 SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix,
1038 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1039 true, false);
[email protected]fb661802013-03-25 01:59:321040
1041 root->AddChild(child);
1042 child->AddChild(grand_child);
ajumad0d64422015-03-14 04:20:081043 grand_child->AddChild(great_grand_child);
[email protected]fb661802013-03-25 01:59:321044 child->SetForceRenderSurface(true);
1045
enne2097cab2014-09-25 20:16:311046 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281047 host->SetRootLayer(root);
1048
[email protected]fb661802013-03-25 01:59:321049 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571050 ASSERT_TRUE(root->should_flatten_transform());
1051 ASSERT_TRUE(child->should_flatten_transform());
1052 ASSERT_TRUE(grand_child->should_flatten_transform());
ajumad0d64422015-03-14 04:20:081053 ASSERT_TRUE(great_grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321054
1055 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1056 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1057 gfx::Transform expected_grand_child_draw_transform =
1058 rotation_about_y_axis; // draws onto child's render surface
1059 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1060 flattened_rotation_about_y.FlattenTo2d();
1061 gfx::Transform expected_grand_child_screen_space_transform =
1062 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081063 gfx::Transform expected_great_grand_child_draw_transform =
1064 flattened_rotation_about_y;
1065 gfx::Transform expected_great_grand_child_screen_space_transform =
1066 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321067
1068 ExecuteCalculateDrawProperties(root.get());
1069
1070 // The child's draw transform should have been taken by its surface.
1071 ASSERT_TRUE(child->render_surface());
1072 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1073 child->render_surface()->draw_transform());
1074 EXPECT_TRANSFORMATION_MATRIX_EQ(
1075 expected_child_screen_space_transform,
1076 child->render_surface()->screen_space_transform());
1077 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1078 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1079 child->screen_space_transform());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1081 grand_child->draw_transform());
1082 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1083 grand_child->screen_space_transform());
ajumad0d64422015-03-14 04:20:081084 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
1085 great_grand_child->draw_transform());
1086 EXPECT_TRANSFORMATION_MATRIX_EQ(
1087 expected_great_grand_child_screen_space_transform,
1088 great_grand_child->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321089}
1090
[email protected]989386c2013-07-18 21:37:231091TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321092 // A layer that is empty in one axis, but not the other, was accidentally
1093 // skipping a necessary translation. Without that translation, the coordinate
1094 // space of the layer's draw transform is incorrect.
1095 //
1096 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1097 // but if that layer becomes a render surface, then its draw transform is
1098 // implicitly inherited by the rest of the subtree, which then is positioned
1099 // incorrectly as a result.
1100
1101 scoped_refptr<Layer> root = Layer::Create();
1102 scoped_refptr<Layer> child = Layer::Create();
1103 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1104 make_scoped_refptr(new LayerWithForcedDrawsContent());
1105
1106 // The child height is zero, but has non-zero width that should be accounted
1107 // for while computing draw transforms.
1108 const gfx::Transform identity_matrix;
1109 SetLayerPropertiesForTesting(root.get(),
1110 identity_matrix,
[email protected]a2566412014-06-05 03:14:201111 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321112 gfx::PointF(),
1113 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571114 true,
[email protected]fb661802013-03-25 01:59:321115 false);
1116 SetLayerPropertiesForTesting(child.get(),
1117 identity_matrix,
[email protected]a2566412014-06-05 03:14:201118 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321119 gfx::PointF(),
1120 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571121 true,
[email protected]fb661802013-03-25 01:59:321122 false);
1123 SetLayerPropertiesForTesting(grand_child.get(),
1124 identity_matrix,
[email protected]a2566412014-06-05 03:14:201125 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321126 gfx::PointF(),
1127 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571128 true,
[email protected]fb661802013-03-25 01:59:321129 false);
1130
1131 root->AddChild(child);
1132 child->AddChild(grand_child);
1133 child->SetForceRenderSurface(true);
1134
enne2097cab2014-09-25 20:16:311135 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281136 host->SetRootLayer(root);
1137
[email protected]fb661802013-03-25 01:59:321138 ExecuteCalculateDrawProperties(root.get());
1139
1140 ASSERT_TRUE(child->render_surface());
1141 // This is the real test, the rest are sanity checks.
1142 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1143 child->render_surface()->draw_transform());
1144 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1146 grand_child->draw_transform());
1147}
1148
[email protected]989386c2013-07-18 21:37:231149TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321150 // Transformations applied at the root of the tree should be forwarded
1151 // to child layers instead of applied to the root RenderSurface.
1152 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291153 scoped_refptr<LayerWithForcedDrawsContent> root =
1154 new LayerWithForcedDrawsContent;
1155 scoped_refptr<LayerWithForcedDrawsContent> child =
1156 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471157 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321158 root->AddChild(child);
1159
enne2097cab2014-09-25 20:16:311160 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281161 host->SetRootLayer(root);
1162
[email protected]f224cc92013-06-06 23:23:321163 SetLayerPropertiesForTesting(root.get(),
1164 identity_matrix,
[email protected]a2566412014-06-05 03:14:201165 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321166 gfx::PointF(),
1167 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571168 true,
[email protected]f224cc92013-06-06 23:23:321169 false);
1170 SetLayerPropertiesForTesting(child.get(),
1171 identity_matrix,
[email protected]a2566412014-06-05 03:14:201172 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321173 gfx::PointF(),
1174 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571175 true,
[email protected]f224cc92013-06-06 23:23:321176 false);
1177
[email protected]f224cc92013-06-06 23:23:321178 gfx::Transform translate;
1179 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231180 {
1181 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531182 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221183 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531184 inputs.can_adjust_raster_scales = true;
1185 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231186 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1187 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1188 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201189 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1190 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231191 }
[email protected]f224cc92013-06-06 23:23:321192
1193 gfx::Transform scale;
1194 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231195 {
1196 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531197 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221198 root.get(), root->bounds(), scale, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531199 inputs.can_adjust_raster_scales = true;
1200 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231201 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1202 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1203 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201204 EXPECT_EQ(2.f, root->draw_properties().device_scale_factor);
1205 EXPECT_EQ(2.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231206 }
[email protected]f224cc92013-06-06 23:23:321207
1208 gfx::Transform rotate;
1209 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231210 {
1211 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531212 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221213 root.get(), root->bounds(), rotate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531214 inputs.can_adjust_raster_scales = true;
1215 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231216 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1217 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1218 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201219 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1220 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231221 }
[email protected]f224cc92013-06-06 23:23:321222
1223 gfx::Transform composite;
1224 composite.ConcatTransform(translate);
1225 composite.ConcatTransform(scale);
1226 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231227 {
1228 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531229 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221230 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531231 inputs.can_adjust_raster_scales = true;
1232 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231233 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1234 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1235 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1236 }
[email protected]f224cc92013-06-06 23:23:321237
[email protected]9781afa2013-07-17 23:15:321238 // Verify it composes correctly with device scale.
1239 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231240
1241 {
1242 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531243 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221244 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531245 inputs.device_scale_factor = device_scale_factor;
1246 inputs.can_adjust_raster_scales = true;
1247 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231248 gfx::Transform device_scaled_translate = translate;
1249 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1250 EXPECT_EQ(device_scaled_translate,
1251 root->draw_properties().target_space_transform);
1252 EXPECT_EQ(device_scaled_translate,
1253 child->draw_properties().target_space_transform);
1254 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201255 EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor);
1256 EXPECT_EQ(device_scale_factor,
1257 child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231258 }
[email protected]9781afa2013-07-17 23:15:321259
1260 // Verify it composes correctly with page scale.
1261 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231262
1263 {
1264 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531265 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221266 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531267 inputs.page_scale_factor = page_scale_factor;
1268 inputs.page_scale_application_layer = root.get();
1269 inputs.can_adjust_raster_scales = true;
1270 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231271 gfx::Transform page_scaled_translate = translate;
1272 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1273 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1274 EXPECT_EQ(page_scaled_translate,
1275 child->draw_properties().target_space_transform);
1276 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201277 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1278 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231279 }
[email protected]9781afa2013-07-17 23:15:321280
[email protected]f224cc92013-06-06 23:23:321281 // Verify that it composes correctly with transforms directly on root layer.
1282 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231283
1284 {
1285 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531286 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221287 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531288 inputs.can_adjust_raster_scales = true;
1289 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231290 gfx::Transform compositeSquared = composite;
1291 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261292 EXPECT_TRANSFORMATION_MATRIX_EQ(
1293 compositeSquared, root->draw_properties().target_space_transform);
1294 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391295 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231296 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1297 }
[email protected]f224cc92013-06-06 23:23:321298}
1299
[email protected]989386c2013-07-18 21:37:231300TEST_F(LayerTreeHostCommonTest,
1301 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321302 scoped_refptr<Layer> parent = Layer::Create();
1303 scoped_refptr<Layer> render_surface1 = Layer::Create();
1304 scoped_refptr<LayerWithForcedDrawsContent> child =
1305 make_scoped_refptr(new LayerWithForcedDrawsContent());
1306
enne2097cab2014-09-25 20:16:311307 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281308 host->SetRootLayer(parent);
1309
[email protected]fb661802013-03-25 01:59:321310 const gfx::Transform identity_matrix;
1311 SetLayerPropertiesForTesting(parent.get(),
1312 identity_matrix,
[email protected]a2566412014-06-05 03:14:201313 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321314 gfx::PointF(),
1315 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571316 true,
[email protected]fb661802013-03-25 01:59:321317 false);
1318 SetLayerPropertiesForTesting(render_surface1.get(),
1319 identity_matrix,
[email protected]a2566412014-06-05 03:14:201320 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321321 gfx::PointF(),
1322 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571323 true,
[email protected]fb661802013-03-25 01:59:321324 false);
1325 SetLayerPropertiesForTesting(child.get(),
1326 identity_matrix,
[email protected]a2566412014-06-05 03:14:201327 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321328 gfx::PointF(30.f, 30.f),
1329 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571330 true,
[email protected]fb661802013-03-25 01:59:321331 false);
1332
1333 parent->AddChild(render_surface1);
1334 parent->SetMasksToBounds(true);
1335 render_surface1->AddChild(child);
1336 render_surface1->SetForceRenderSurface(true);
1337
[email protected]989386c2013-07-18 21:37:231338 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531339 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1340 parent.get(),
1341 parent->bounds(),
1342 gfx::Transform(),
1343 &render_surface_layer_list);
1344 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321345
1346 // The child layer's content is entirely outside the parent's clip rect, so
1347 // the intermediate render surface should not be listed here, even if it was
1348 // forced to be created. Render surfaces without children or visible content
1349 // are unexpected at draw time (e.g. we might try to create a content texture
1350 // of size 0).
1351 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321352 EXPECT_EQ(1U, render_surface_layer_list.size());
1353}
1354
[email protected]989386c2013-07-18 21:37:231355TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321356 scoped_refptr<Layer> parent = Layer::Create();
1357 scoped_refptr<Layer> render_surface1 = Layer::Create();
1358 scoped_refptr<LayerWithForcedDrawsContent> child =
1359 make_scoped_refptr(new LayerWithForcedDrawsContent());
1360
enne2097cab2014-09-25 20:16:311361 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281362 host->SetRootLayer(parent);
1363
[email protected]fb661802013-03-25 01:59:321364 const gfx::Transform identity_matrix;
1365 SetLayerPropertiesForTesting(render_surface1.get(),
1366 identity_matrix,
[email protected]a2566412014-06-05 03:14:201367 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321368 gfx::PointF(),
1369 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571370 true,
[email protected]fb661802013-03-25 01:59:321371 false);
1372 SetLayerPropertiesForTesting(child.get(),
1373 identity_matrix,
[email protected]a2566412014-06-05 03:14:201374 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321375 gfx::PointF(),
1376 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571377 true,
[email protected]fb661802013-03-25 01:59:321378 false);
1379
1380 parent->AddChild(render_surface1);
1381 render_surface1->AddChild(child);
1382 render_surface1->SetForceRenderSurface(true);
1383 render_surface1->SetOpacity(0.f);
1384
[email protected]989386c2013-07-18 21:37:231385 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531386 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1387 parent.get(), parent->bounds(), &render_surface_layer_list);
1388 inputs.can_adjust_raster_scales = true;
1389 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321390
1391 // Since the layer is transparent, render_surface1->render_surface() should
1392 // not have gotten added anywhere. Also, the drawable content rect should not
1393 // have been extended by the children.
1394 ASSERT_TRUE(parent->render_surface());
1395 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1396 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231397 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321398 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1399}
1400
rosca948d29d2014-11-09 10:25:131401TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1402 scoped_refptr<Layer> parent = Layer::Create();
1403 scoped_refptr<LayerWithForcedDrawsContent> child =
1404 make_scoped_refptr(new LayerWithForcedDrawsContent());
1405
1406 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1407 host->SetRootLayer(parent);
1408
1409 const gfx::Transform identity_matrix;
1410 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1411 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1412 gfx::PointF(), gfx::Size(10, 10), true, false);
1413
1414 parent->AddChild(child);
1415 child->SetBlendMode(blend_mode);
1416
1417 RenderSurfaceLayerList render_surface_layer_list;
1418 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1419 parent.get(), parent->bounds(), &render_surface_layer_list);
1420 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1421
1422 // Since the child layer has a blend mode other than normal, it should get
1423 // its own render surface. Also, layer's draw_properties should contain the
1424 // default blend mode, since the render surface becomes responsible for
1425 // applying the blend mode.
1426 ASSERT_TRUE(child->render_surface());
1427 EXPECT_EQ(1U, child->render_surface()->layer_list().size());
1428 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode);
1429}
1430
[email protected]989386c2013-07-18 21:37:231431TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321432 scoped_refptr<Layer> parent = Layer::Create();
1433 scoped_refptr<Layer> render_surface1 = Layer::Create();
1434 scoped_refptr<LayerWithForcedDrawsContent> child =
1435 make_scoped_refptr(new LayerWithForcedDrawsContent());
1436 render_surface1->SetForceRenderSurface(true);
1437
enne2097cab2014-09-25 20:16:311438 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281439 host->SetRootLayer(parent);
1440
[email protected]fb661802013-03-25 01:59:321441 const gfx::Transform identity_matrix;
1442 SetLayerPropertiesForTesting(parent.get(),
1443 identity_matrix,
[email protected]a2566412014-06-05 03:14:201444 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321445 gfx::PointF(),
1446 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571447 true,
[email protected]fb661802013-03-25 01:59:321448 false);
1449 SetLayerPropertiesForTesting(render_surface1.get(),
1450 identity_matrix,
[email protected]a2566412014-06-05 03:14:201451 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321452 gfx::PointF(),
1453 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571454 true,
[email protected]fb661802013-03-25 01:59:321455 false);
1456 SetLayerPropertiesForTesting(child.get(),
1457 identity_matrix,
[email protected]a2566412014-06-05 03:14:201458 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321459 gfx::PointF(),
1460 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571461 true,
[email protected]fb661802013-03-25 01:59:321462 false);
1463
1464 parent->AddChild(render_surface1);
1465 render_surface1->AddChild(child);
1466
1467 // Sanity check before the actual test
1468 EXPECT_FALSE(parent->render_surface());
1469 EXPECT_FALSE(render_surface1->render_surface());
1470
[email protected]989386c2013-07-18 21:37:231471 {
1472 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531473 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1474 parent.get(), parent->bounds(), &render_surface_layer_list);
1475 inputs.can_adjust_raster_scales = true;
1476 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321477
[email protected]989386c2013-07-18 21:37:231478 // The root layer always creates a render surface
1479 EXPECT_TRUE(parent->render_surface());
1480 EXPECT_TRUE(render_surface1->render_surface());
1481 EXPECT_EQ(2U, render_surface_layer_list.size());
1482 }
[email protected]fb661802013-03-25 01:59:321483
[email protected]989386c2013-07-18 21:37:231484 {
1485 RenderSurfaceLayerList render_surface_layer_list;
1486 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531487 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1488 parent.get(), parent->bounds(), &render_surface_layer_list);
1489 inputs.can_adjust_raster_scales = true;
1490 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231491 EXPECT_TRUE(parent->render_surface());
1492 EXPECT_FALSE(render_surface1->render_surface());
1493 EXPECT_EQ(1U, render_surface_layer_list.size());
1494 }
[email protected]fb661802013-03-25 01:59:321495}
1496
ajuma246190a2015-03-11 20:56:031497TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1498 // Render surfaces act as a flattening point for their subtree, so should
1499 // always flatten the target-to-screen space transform seen by descendants.
1500
1501 scoped_refptr<Layer> root = Layer::Create();
1502 scoped_refptr<Layer> parent = Layer::Create();
1503 scoped_refptr<LayerWithForcedDrawsContent> child =
1504 make_scoped_refptr(new LayerWithForcedDrawsContent());
1505 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1506 make_scoped_refptr(new LayerWithForcedDrawsContent());
1507
1508 gfx::Transform rotation_about_y_axis;
1509 rotation_about_y_axis.RotateAboutYAxis(30.0);
1510 // Make |parent| have a render surface.
1511 parent->SetOpacity(0.9f);
1512
1513 const gfx::Transform identity_matrix;
1514 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
1515 gfx::PointF(), gfx::Size(100, 100), true, false);
1516 SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis,
1517 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1518 true, false);
1519 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1520 gfx::PointF(), gfx::Size(10, 10), true, false);
1521 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
1522 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1523 true, false);
1524
1525 root->AddChild(parent);
1526 parent->AddChild(child);
1527 child->AddChild(grand_child);
1528
1529 grand_child->SetShouldFlattenTransform(false);
1530
1531 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1532 host->SetRootLayer(root);
1533
1534 // Only grand_child should preserve 3d.
1535 EXPECT_TRUE(root->should_flatten_transform());
1536 EXPECT_TRUE(parent->should_flatten_transform());
1537 EXPECT_TRUE(child->should_flatten_transform());
1538 EXPECT_FALSE(grand_child->should_flatten_transform());
1539
1540 gfx::Transform expected_child_draw_transform = identity_matrix;
1541 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1542
1543 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1544 flattened_rotation_about_y.FlattenTo2d();
1545
1546 ExecuteCalculateDrawProperties(root.get());
1547
1548 EXPECT_TRUE(parent->render_surface());
1549 EXPECT_FALSE(child->render_surface());
1550 EXPECT_FALSE(grand_child->render_surface());
1551
1552 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1553 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1554 grand_child->draw_transform());
1555
1556 // The screen-space transform inherited by |child| and |grand_child| should
1557 // have been flattened at their render target. In particular, the fact that
1558 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1559 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1560 child->screen_space_transform());
1561 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1562 grand_child->screen_space_transform());
1563}
1564
[email protected]989386c2013-07-18 21:37:231565TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321566 // The entire subtree of layers that are outside the clip rect should be
1567 // culled away, and should not affect the render_surface_layer_list.
1568 //
1569 // The test tree is set up as follows:
1570 // - all layers except the leaf_nodes are forced to be a new render surface
1571 // that have something to draw.
1572 // - parent is a large container layer.
1573 // - child has masksToBounds=true to cause clipping.
1574 // - grand_child is positioned outside of the child's bounds
1575 // - great_grand_child is also kept outside child's bounds.
1576 //
1577 // In this configuration, grand_child and great_grand_child are completely
1578 // outside the clip rect, and they should never get scheduled on the list of
1579 // render surfaces.
1580 //
1581
1582 const gfx::Transform identity_matrix;
1583 scoped_refptr<Layer> parent = Layer::Create();
1584 scoped_refptr<Layer> child = Layer::Create();
1585 scoped_refptr<Layer> grand_child = Layer::Create();
1586 scoped_refptr<Layer> great_grand_child = Layer::Create();
1587 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1588 make_scoped_refptr(new LayerWithForcedDrawsContent());
1589 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1590 make_scoped_refptr(new LayerWithForcedDrawsContent());
1591 parent->AddChild(child);
1592 child->AddChild(grand_child);
1593 grand_child->AddChild(great_grand_child);
1594
enne2097cab2014-09-25 20:16:311595 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281596 host->SetRootLayer(parent);
1597
[email protected]fb661802013-03-25 01:59:321598 // leaf_node1 ensures that parent and child are kept on the
1599 // render_surface_layer_list, even though grand_child and great_grand_child
1600 // should be clipped.
1601 child->AddChild(leaf_node1);
1602 great_grand_child->AddChild(leaf_node2);
1603
1604 SetLayerPropertiesForTesting(parent.get(),
1605 identity_matrix,
[email protected]a2566412014-06-05 03:14:201606 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321607 gfx::PointF(),
1608 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571609 true,
[email protected]fb661802013-03-25 01:59:321610 false);
1611 SetLayerPropertiesForTesting(child.get(),
1612 identity_matrix,
[email protected]a2566412014-06-05 03:14:201613 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321614 gfx::PointF(),
1615 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571616 true,
[email protected]fb661802013-03-25 01:59:321617 false);
1618 SetLayerPropertiesForTesting(grand_child.get(),
1619 identity_matrix,
[email protected]a2566412014-06-05 03:14:201620 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321621 gfx::PointF(45.f, 45.f),
1622 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571623 true,
[email protected]fb661802013-03-25 01:59:321624 false);
1625 SetLayerPropertiesForTesting(great_grand_child.get(),
1626 identity_matrix,
[email protected]a2566412014-06-05 03:14:201627 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321628 gfx::PointF(),
1629 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571630 true,
[email protected]fb661802013-03-25 01:59:321631 false);
1632 SetLayerPropertiesForTesting(leaf_node1.get(),
1633 identity_matrix,
[email protected]a2566412014-06-05 03:14:201634 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321635 gfx::PointF(),
1636 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571637 true,
[email protected]fb661802013-03-25 01:59:321638 false);
1639 SetLayerPropertiesForTesting(leaf_node2.get(),
1640 identity_matrix,
[email protected]a2566412014-06-05 03:14:201641 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321642 gfx::PointF(),
1643 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571644 true,
[email protected]fb661802013-03-25 01:59:321645 false);
1646
1647 child->SetMasksToBounds(true);
1648 child->SetOpacity(0.4f);
1649 child->SetForceRenderSurface(true);
1650 grand_child->SetOpacity(0.5f);
1651 great_grand_child->SetOpacity(0.4f);
1652
[email protected]989386c2013-07-18 21:37:231653 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531654 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1655 parent.get(), parent->bounds(), &render_surface_layer_list);
1656 inputs.can_adjust_raster_scales = true;
1657 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321658
1659 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231660 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1661 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321662}
1663
[email protected]989386c2013-07-18 21:37:231664TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321665 // When a render surface has a clip rect, it is used to clip the content rect
1666 // of the surface. When the render surface is animating its transforms, then
1667 // the content rect's position in the clip rect is not defined on the main
1668 // thread, and its content rect should not be clipped.
1669
1670 // The test tree is set up as follows:
1671 // - parent is a container layer that masksToBounds=true to cause clipping.
1672 // - child is a render surface, which has a clip rect set to the bounds of
1673 // the parent.
1674 // - grand_child is a render surface, and the only visible content in child.
1675 // It is positioned outside of the clip rect from parent.
1676
1677 // In this configuration, grand_child should be outside the clipped
1678 // content rect of the child, making grand_child not appear in the
1679 // render_surface_layer_list. However, when we place an animation on the
1680 // child, this clipping should be avoided and we should keep the grand_child
1681 // in the render_surface_layer_list.
1682
1683 const gfx::Transform identity_matrix;
1684 scoped_refptr<Layer> parent = Layer::Create();
1685 scoped_refptr<Layer> child = Layer::Create();
1686 scoped_refptr<Layer> grand_child = Layer::Create();
1687 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1688 make_scoped_refptr(new LayerWithForcedDrawsContent());
1689 parent->AddChild(child);
1690 child->AddChild(grand_child);
1691 grand_child->AddChild(leaf_node);
1692
enne2097cab2014-09-25 20:16:311693 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281694 host->SetRootLayer(parent);
1695
[email protected]fb661802013-03-25 01:59:321696 SetLayerPropertiesForTesting(parent.get(),
1697 identity_matrix,
[email protected]a2566412014-06-05 03:14:201698 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321699 gfx::PointF(),
1700 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571701 true,
[email protected]fb661802013-03-25 01:59:321702 false);
1703 SetLayerPropertiesForTesting(child.get(),
1704 identity_matrix,
[email protected]a2566412014-06-05 03:14:201705 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321706 gfx::PointF(),
1707 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571708 true,
[email protected]fb661802013-03-25 01:59:321709 false);
1710 SetLayerPropertiesForTesting(grand_child.get(),
1711 identity_matrix,
[email protected]a2566412014-06-05 03:14:201712 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321713 gfx::PointF(200.f, 200.f),
1714 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571715 true,
[email protected]fb661802013-03-25 01:59:321716 false);
1717 SetLayerPropertiesForTesting(leaf_node.get(),
1718 identity_matrix,
[email protected]a2566412014-06-05 03:14:201719 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321720 gfx::PointF(),
1721 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571722 true,
[email protected]fb661802013-03-25 01:59:321723 false);
1724
1725 parent->SetMasksToBounds(true);
1726 child->SetOpacity(0.4f);
1727 child->SetForceRenderSurface(true);
1728 grand_child->SetOpacity(0.4f);
1729 grand_child->SetForceRenderSurface(true);
1730
[email protected]989386c2013-07-18 21:37:231731 {
1732 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531733 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1734 parent.get(), parent->bounds(), &render_surface_layer_list);
1735 inputs.can_adjust_raster_scales = true;
1736 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321737
[email protected]989386c2013-07-18 21:37:231738 // Without an animation, we should cull child and grand_child from the
1739 // render_surface_layer_list.
1740 ASSERT_EQ(1U, render_surface_layer_list.size());
1741 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1742 }
[email protected]fb661802013-03-25 01:59:321743
1744 // Now put an animating transform on child.
1745 AddAnimatedTransformToController(
1746 child->layer_animation_controller(), 10.0, 30, 0);
1747
[email protected]989386c2013-07-18 21:37:231748 {
1749 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531750 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1751 parent.get(), parent->bounds(), &render_surface_layer_list);
1752 inputs.can_adjust_raster_scales = true;
1753 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321754
[email protected]989386c2013-07-18 21:37:231755 // With an animating transform, we should keep child and grand_child in the
1756 // render_surface_layer_list.
1757 ASSERT_EQ(3U, render_surface_layer_list.size());
1758 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1759 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1760 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1761 }
[email protected]fb661802013-03-25 01:59:321762}
1763
[email protected]989386c2013-07-18 21:37:231764TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321765 // Layer's IsClipped() property is set to true when:
1766 // - the layer clips its subtree, e.g. masks to bounds,
1767 // - the layer is clipped by an ancestor that contributes to the same
1768 // render target,
1769 // - a surface is clipped by an ancestor that contributes to the same
1770 // render target.
1771 //
1772 // In particular, for a layer that owns a render surface:
1773 // - the render surface inherits any clip from ancestors, and does NOT
1774 // pass that clipped status to the layer itself.
1775 // - but if the layer itself masks to bounds, it is considered clipped
1776 // and propagates the clip to the subtree.
1777
1778 const gfx::Transform identity_matrix;
1779 scoped_refptr<Layer> root = Layer::Create();
1780 scoped_refptr<Layer> parent = Layer::Create();
1781 scoped_refptr<Layer> child1 = Layer::Create();
1782 scoped_refptr<Layer> child2 = Layer::Create();
1783 scoped_refptr<Layer> grand_child = Layer::Create();
1784 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1785 make_scoped_refptr(new LayerWithForcedDrawsContent());
1786 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1787 make_scoped_refptr(new LayerWithForcedDrawsContent());
1788 root->AddChild(parent);
1789 parent->AddChild(child1);
1790 parent->AddChild(child2);
1791 child1->AddChild(grand_child);
1792 child2->AddChild(leaf_node2);
1793 grand_child->AddChild(leaf_node1);
1794
enne2097cab2014-09-25 20:16:311795 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281796 host->SetRootLayer(root);
1797
[email protected]fb661802013-03-25 01:59:321798 child2->SetForceRenderSurface(true);
1799
1800 SetLayerPropertiesForTesting(root.get(),
1801 identity_matrix,
[email protected]a2566412014-06-05 03:14:201802 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321803 gfx::PointF(),
1804 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571805 true,
[email protected]fb661802013-03-25 01:59:321806 false);
1807 SetLayerPropertiesForTesting(parent.get(),
1808 identity_matrix,
[email protected]a2566412014-06-05 03:14:201809 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321810 gfx::PointF(),
1811 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571812 true,
[email protected]fb661802013-03-25 01:59:321813 false);
1814 SetLayerPropertiesForTesting(child1.get(),
1815 identity_matrix,
[email protected]a2566412014-06-05 03:14:201816 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321817 gfx::PointF(),
1818 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571819 true,
[email protected]fb661802013-03-25 01:59:321820 false);
1821 SetLayerPropertiesForTesting(child2.get(),
1822 identity_matrix,
[email protected]a2566412014-06-05 03:14:201823 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321824 gfx::PointF(),
1825 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571826 true,
[email protected]fb661802013-03-25 01:59:321827 false);
1828 SetLayerPropertiesForTesting(grand_child.get(),
1829 identity_matrix,
[email protected]a2566412014-06-05 03:14:201830 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321831 gfx::PointF(),
1832 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571833 true,
[email protected]fb661802013-03-25 01:59:321834 false);
1835 SetLayerPropertiesForTesting(leaf_node1.get(),
1836 identity_matrix,
[email protected]a2566412014-06-05 03:14:201837 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321838 gfx::PointF(),
1839 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571840 true,
[email protected]fb661802013-03-25 01:59:321841 false);
1842 SetLayerPropertiesForTesting(leaf_node2.get(),
1843 identity_matrix,
[email protected]a2566412014-06-05 03:14:201844 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321845 gfx::PointF(),
1846 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571847 true,
[email protected]fb661802013-03-25 01:59:321848 false);
1849
[email protected]989386c2013-07-18 21:37:231850 // Case 1: nothing is clipped except the root render surface.
1851 {
1852 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531853 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1854 root.get(), parent->bounds(), &render_surface_layer_list);
1855 inputs.can_adjust_raster_scales = true;
1856 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321857
[email protected]989386c2013-07-18 21:37:231858 ASSERT_TRUE(root->render_surface());
1859 ASSERT_TRUE(child2->render_surface());
1860
1861 EXPECT_FALSE(root->is_clipped());
1862 EXPECT_TRUE(root->render_surface()->is_clipped());
1863 EXPECT_FALSE(parent->is_clipped());
1864 EXPECT_FALSE(child1->is_clipped());
1865 EXPECT_FALSE(child2->is_clipped());
1866 EXPECT_FALSE(child2->render_surface()->is_clipped());
1867 EXPECT_FALSE(grand_child->is_clipped());
1868 EXPECT_FALSE(leaf_node1->is_clipped());
1869 EXPECT_FALSE(leaf_node2->is_clipped());
1870 }
[email protected]fb661802013-03-25 01:59:321871
1872 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1873 // surface are clipped. But layers that contribute to child2's surface are
1874 // not clipped explicitly because child2's surface already accounts for
1875 // that clip.
[email protected]989386c2013-07-18 21:37:231876 {
1877 RenderSurfaceLayerList render_surface_layer_list;
1878 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531879 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1880 root.get(), parent->bounds(), &render_surface_layer_list);
1881 inputs.can_adjust_raster_scales = true;
1882 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321883
[email protected]989386c2013-07-18 21:37:231884 ASSERT_TRUE(root->render_surface());
1885 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321886
[email protected]989386c2013-07-18 21:37:231887 EXPECT_FALSE(root->is_clipped());
1888 EXPECT_TRUE(root->render_surface()->is_clipped());
1889 EXPECT_TRUE(parent->is_clipped());
1890 EXPECT_TRUE(child1->is_clipped());
1891 EXPECT_FALSE(child2->is_clipped());
1892 EXPECT_TRUE(child2->render_surface()->is_clipped());
1893 EXPECT_TRUE(grand_child->is_clipped());
1894 EXPECT_TRUE(leaf_node1->is_clipped());
1895 EXPECT_FALSE(leaf_node2->is_clipped());
1896 }
[email protected]fb661802013-03-25 01:59:321897
1898 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1899 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231900 {
1901 RenderSurfaceLayerList render_surface_layer_list;
1902 parent->SetMasksToBounds(false);
1903 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531904 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1905 root.get(), parent->bounds(), &render_surface_layer_list);
1906 inputs.can_adjust_raster_scales = true;
1907 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321908
[email protected]989386c2013-07-18 21:37:231909 ASSERT_TRUE(root->render_surface());
1910 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321911
[email protected]989386c2013-07-18 21:37:231912 EXPECT_FALSE(root->is_clipped());
1913 EXPECT_TRUE(root->render_surface()->is_clipped());
1914 EXPECT_FALSE(parent->is_clipped());
1915 EXPECT_FALSE(child1->is_clipped());
1916 EXPECT_TRUE(child2->is_clipped());
1917 EXPECT_FALSE(child2->render_surface()->is_clipped());
1918 EXPECT_FALSE(grand_child->is_clipped());
1919 EXPECT_FALSE(leaf_node1->is_clipped());
1920 EXPECT_TRUE(leaf_node2->is_clipped());
1921 }
[email protected]fb661802013-03-25 01:59:321922}
1923
[email protected]fd9a3b6d2013-08-03 00:46:171924TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321925 // Verify that layers get the appropriate DrawableContentRect when their
1926 // parent masksToBounds is true.
1927 //
1928 // grand_child1 - completely inside the region; DrawableContentRect should
1929 // be the layer rect expressed in target space.
1930 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1931 // will be the intersection of layer bounds and the mask region.
1932 // grand_child3 - partially clipped and masksToBounds; the
1933 // DrawableContentRect will still be the intersection of layer bounds and
1934 // the mask region.
1935 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1936 // be empty.
1937 //
1938
1939 const gfx::Transform identity_matrix;
1940 scoped_refptr<Layer> parent = Layer::Create();
1941 scoped_refptr<Layer> child = Layer::Create();
1942 scoped_refptr<Layer> grand_child1 = Layer::Create();
1943 scoped_refptr<Layer> grand_child2 = Layer::Create();
1944 scoped_refptr<Layer> grand_child3 = Layer::Create();
1945 scoped_refptr<Layer> grand_child4 = Layer::Create();
1946
1947 parent->AddChild(child);
1948 child->AddChild(grand_child1);
1949 child->AddChild(grand_child2);
1950 child->AddChild(grand_child3);
1951 child->AddChild(grand_child4);
1952
enne2097cab2014-09-25 20:16:311953 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281954 host->SetRootLayer(parent);
1955
[email protected]fb661802013-03-25 01:59:321956 SetLayerPropertiesForTesting(parent.get(),
1957 identity_matrix,
[email protected]a2566412014-06-05 03:14:201958 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321959 gfx::PointF(),
1960 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571961 true,
[email protected]fb661802013-03-25 01:59:321962 false);
1963 SetLayerPropertiesForTesting(child.get(),
1964 identity_matrix,
[email protected]a2566412014-06-05 03:14:201965 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321966 gfx::PointF(),
1967 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571968 true,
[email protected]fb661802013-03-25 01:59:321969 false);
1970 SetLayerPropertiesForTesting(grand_child1.get(),
1971 identity_matrix,
[email protected]a2566412014-06-05 03:14:201972 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321973 gfx::PointF(5.f, 5.f),
1974 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571975 true,
[email protected]fb661802013-03-25 01:59:321976 false);
1977 SetLayerPropertiesForTesting(grand_child2.get(),
1978 identity_matrix,
[email protected]a2566412014-06-05 03:14:201979 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321980 gfx::PointF(15.f, 15.f),
1981 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571982 true,
[email protected]fb661802013-03-25 01:59:321983 false);
1984 SetLayerPropertiesForTesting(grand_child3.get(),
1985 identity_matrix,
[email protected]a2566412014-06-05 03:14:201986 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321987 gfx::PointF(15.f, 15.f),
1988 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571989 true,
[email protected]fb661802013-03-25 01:59:321990 false);
1991 SetLayerPropertiesForTesting(grand_child4.get(),
1992 identity_matrix,
[email protected]a2566412014-06-05 03:14:201993 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321994 gfx::PointF(45.f, 45.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
1999 child->SetMasksToBounds(true);
2000 grand_child3->SetMasksToBounds(true);
2001
2002 // Force everyone to be a render surface.
2003 child->SetOpacity(0.4f);
2004 grand_child1->SetOpacity(0.5f);
2005 grand_child2->SetOpacity(0.5f);
2006 grand_child3->SetOpacity(0.5f);
2007 grand_child4->SetOpacity(0.5f);
2008
[email protected]989386c2013-07-18 21:37:232009 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532010 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2011 parent.get(), parent->bounds(), &render_surface_layer_list);
2012 inputs.can_adjust_raster_scales = true;
2013 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322014
hush6b614212014-12-04 22:37:322015 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2016 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2017 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322018 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2019}
2020
[email protected]989386c2013-07-18 21:37:232021TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322022 // Verify that render surfaces (and their layers) get the appropriate
2023 // clip rects when their parent masksToBounds is true.
2024 //
2025 // Layers that own render surfaces (at least for now) do not inherit any
2026 // clipping; instead the surface will enforce the clip for the entire subtree.
2027 // They may still have a clip rect of their own layer bounds, however, if
2028 // masksToBounds was true.
2029 const gfx::Transform identity_matrix;
2030 scoped_refptr<Layer> parent = Layer::Create();
2031 scoped_refptr<Layer> child = Layer::Create();
2032 scoped_refptr<Layer> grand_child1 = Layer::Create();
2033 scoped_refptr<Layer> grand_child2 = Layer::Create();
2034 scoped_refptr<Layer> grand_child3 = Layer::Create();
2035 scoped_refptr<Layer> grand_child4 = Layer::Create();
2036 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2037 make_scoped_refptr(new LayerWithForcedDrawsContent());
2038 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2039 make_scoped_refptr(new LayerWithForcedDrawsContent());
2040 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2041 make_scoped_refptr(new LayerWithForcedDrawsContent());
2042 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2043 make_scoped_refptr(new LayerWithForcedDrawsContent());
2044
2045 parent->AddChild(child);
2046 child->AddChild(grand_child1);
2047 child->AddChild(grand_child2);
2048 child->AddChild(grand_child3);
2049 child->AddChild(grand_child4);
2050
enne2097cab2014-09-25 20:16:312051 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282052 host->SetRootLayer(parent);
2053
[email protected]fb661802013-03-25 01:59:322054 // the leaf nodes ensure that these grand_children become render surfaces for
2055 // this test.
2056 grand_child1->AddChild(leaf_node1);
2057 grand_child2->AddChild(leaf_node2);
2058 grand_child3->AddChild(leaf_node3);
2059 grand_child4->AddChild(leaf_node4);
2060
2061 SetLayerPropertiesForTesting(parent.get(),
2062 identity_matrix,
[email protected]a2566412014-06-05 03:14:202063 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322064 gfx::PointF(),
2065 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572066 true,
[email protected]fb661802013-03-25 01:59:322067 false);
2068 SetLayerPropertiesForTesting(child.get(),
2069 identity_matrix,
[email protected]a2566412014-06-05 03:14:202070 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322071 gfx::PointF(),
2072 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572073 true,
[email protected]fb661802013-03-25 01:59:322074 false);
2075 SetLayerPropertiesForTesting(grand_child1.get(),
2076 identity_matrix,
[email protected]a2566412014-06-05 03:14:202077 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322078 gfx::PointF(5.f, 5.f),
2079 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572080 true,
[email protected]fb661802013-03-25 01:59:322081 false);
2082 SetLayerPropertiesForTesting(grand_child2.get(),
2083 identity_matrix,
[email protected]a2566412014-06-05 03:14:202084 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322085 gfx::PointF(15.f, 15.f),
2086 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572087 true,
[email protected]fb661802013-03-25 01:59:322088 false);
2089 SetLayerPropertiesForTesting(grand_child3.get(),
2090 identity_matrix,
[email protected]a2566412014-06-05 03:14:202091 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322092 gfx::PointF(15.f, 15.f),
2093 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572094 true,
[email protected]fb661802013-03-25 01:59:322095 false);
2096 SetLayerPropertiesForTesting(grand_child4.get(),
2097 identity_matrix,
[email protected]a2566412014-06-05 03:14:202098 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322099 gfx::PointF(45.f, 45.f),
2100 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572101 true,
[email protected]fb661802013-03-25 01:59:322102 false);
2103 SetLayerPropertiesForTesting(leaf_node1.get(),
2104 identity_matrix,
[email protected]a2566412014-06-05 03:14:202105 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322106 gfx::PointF(),
2107 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572108 true,
[email protected]fb661802013-03-25 01:59:322109 false);
2110 SetLayerPropertiesForTesting(leaf_node2.get(),
2111 identity_matrix,
[email protected]a2566412014-06-05 03:14:202112 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322113 gfx::PointF(),
2114 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572115 true,
[email protected]fb661802013-03-25 01:59:322116 false);
2117 SetLayerPropertiesForTesting(leaf_node3.get(),
2118 identity_matrix,
[email protected]a2566412014-06-05 03:14:202119 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322120 gfx::PointF(),
2121 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572122 true,
[email protected]fb661802013-03-25 01:59:322123 false);
2124 SetLayerPropertiesForTesting(leaf_node4.get(),
2125 identity_matrix,
[email protected]a2566412014-06-05 03:14:202126 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322127 gfx::PointF(),
2128 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572129 true,
[email protected]fb661802013-03-25 01:59:322130 false);
2131
2132 child->SetMasksToBounds(true);
2133 grand_child3->SetMasksToBounds(true);
2134 grand_child4->SetMasksToBounds(true);
2135
2136 // Force everyone to be a render surface.
2137 child->SetOpacity(0.4f);
2138 child->SetForceRenderSurface(true);
2139 grand_child1->SetOpacity(0.5f);
2140 grand_child1->SetForceRenderSurface(true);
2141 grand_child2->SetOpacity(0.5f);
2142 grand_child2->SetForceRenderSurface(true);
2143 grand_child3->SetOpacity(0.5f);
2144 grand_child3->SetForceRenderSurface(true);
2145 grand_child4->SetOpacity(0.5f);
2146 grand_child4->SetForceRenderSurface(true);
2147
[email protected]989386c2013-07-18 21:37:232148 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532149 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2150 parent.get(), parent->bounds(), &render_surface_layer_list);
2151 inputs.can_adjust_raster_scales = true;
2152 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322153 ASSERT_TRUE(grand_child1->render_surface());
2154 ASSERT_TRUE(grand_child2->render_surface());
2155 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322156
2157 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2158 // masksToBounds.
hush6b614212014-12-04 22:37:322159 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2160 grand_child1->render_surface()->clip_rect());
2161 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2162 grand_child2->render_surface()->clip_rect());
2163 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2164 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322165}
2166
[email protected]989386c2013-07-18 21:37:232167TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322168 scoped_refptr<Layer> parent = Layer::Create();
2169 scoped_refptr<Layer> render_surface1 = Layer::Create();
2170 scoped_refptr<Layer> render_surface2 = Layer::Create();
2171 scoped_refptr<Layer> child_of_root = Layer::Create();
2172 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2173 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2174 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2175 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2176 make_scoped_refptr(new LayerWithForcedDrawsContent());
2177 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2178 make_scoped_refptr(new LayerWithForcedDrawsContent());
2179 parent->AddChild(render_surface1);
2180 parent->AddChild(child_of_root);
2181 render_surface1->AddChild(child_of_rs1);
2182 render_surface1->AddChild(render_surface2);
2183 render_surface2->AddChild(child_of_rs2);
2184 child_of_root->AddChild(grand_child_of_root);
2185 child_of_rs1->AddChild(grand_child_of_rs1);
2186 child_of_rs2->AddChild(grand_child_of_rs2);
2187
enne2097cab2014-09-25 20:16:312188 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282189 host->SetRootLayer(parent);
2190
[email protected]fb661802013-03-25 01:59:322191 // Make our render surfaces.
2192 render_surface1->SetForceRenderSurface(true);
2193 render_surface2->SetForceRenderSurface(true);
2194
2195 gfx::Transform layer_transform;
2196 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322197
2198 SetLayerPropertiesForTesting(parent.get(),
2199 layer_transform,
[email protected]a2566412014-06-05 03:14:202200 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322201 gfx::PointF(2.5f, 0.f),
2202 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572203 true,
[email protected]fb661802013-03-25 01:59:322204 false);
2205 SetLayerPropertiesForTesting(render_surface1.get(),
2206 layer_transform,
[email protected]a2566412014-06-05 03:14:202207 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322208 gfx::PointF(2.5f, 0.f),
2209 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572210 true,
[email protected]fb661802013-03-25 01:59:322211 false);
2212 SetLayerPropertiesForTesting(render_surface2.get(),
2213 layer_transform,
[email protected]a2566412014-06-05 03:14:202214 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322215 gfx::PointF(2.5f, 0.f),
2216 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572217 true,
[email protected]fb661802013-03-25 01:59:322218 false);
2219 SetLayerPropertiesForTesting(child_of_root.get(),
2220 layer_transform,
[email protected]a2566412014-06-05 03:14:202221 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322222 gfx::PointF(2.5f, 0.f),
2223 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572224 true,
[email protected]fb661802013-03-25 01:59:322225 false);
2226 SetLayerPropertiesForTesting(child_of_rs1.get(),
2227 layer_transform,
[email protected]a2566412014-06-05 03:14:202228 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322229 gfx::PointF(2.5f, 0.f),
2230 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572231 true,
[email protected]fb661802013-03-25 01:59:322232 false);
2233 SetLayerPropertiesForTesting(child_of_rs2.get(),
2234 layer_transform,
[email protected]a2566412014-06-05 03:14:202235 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322236 gfx::PointF(2.5f, 0.f),
2237 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572238 true,
[email protected]fb661802013-03-25 01:59:322239 false);
2240 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2241 layer_transform,
[email protected]a2566412014-06-05 03:14:202242 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322243 gfx::PointF(2.5f, 0.f),
2244 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572245 true,
[email protected]fb661802013-03-25 01:59:322246 false);
2247 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2248 layer_transform,
[email protected]a2566412014-06-05 03:14:202249 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322250 gfx::PointF(2.5f, 0.f),
2251 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572252 true,
[email protected]fb661802013-03-25 01:59:322253 false);
2254 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2255 layer_transform,
[email protected]a2566412014-06-05 03:14:202256 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322257 gfx::PointF(2.5f, 0.f),
2258 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572259 true,
[email protected]fb661802013-03-25 01:59:322260 false);
2261
2262 // Put an animated opacity on the render surface.
2263 AddOpacityTransitionToController(
2264 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2265
2266 // Also put an animated opacity on a layer without descendants.
2267 AddOpacityTransitionToController(
2268 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2269
2270 // Put a transform animation on the render surface.
2271 AddAnimatedTransformToController(
2272 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2273
2274 // Also put transform animations on grand_child_of_root, and
2275 // grand_child_of_rs2
2276 AddAnimatedTransformToController(
2277 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2278 AddAnimatedTransformToController(
2279 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2280
2281 ExecuteCalculateDrawProperties(parent.get());
2282
2283 // Only layers that are associated with render surfaces should have an actual
2284 // RenderSurface() value.
2285 ASSERT_TRUE(parent->render_surface());
2286 ASSERT_FALSE(child_of_root->render_surface());
2287 ASSERT_FALSE(grand_child_of_root->render_surface());
2288
2289 ASSERT_TRUE(render_surface1->render_surface());
2290 ASSERT_FALSE(child_of_rs1->render_surface());
2291 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2292
2293 ASSERT_TRUE(render_surface2->render_surface());
2294 ASSERT_FALSE(child_of_rs2->render_surface());
2295 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2296
2297 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:102298 EXPECT_EQ(parent.get(), parent->render_target());
2299 EXPECT_EQ(parent.get(), child_of_root->render_target());
2300 EXPECT_EQ(parent.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322301
Daniel Chengeea98042014-08-26 00:28:102302 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
2303 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
2304 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322305
Daniel Chengeea98042014-08-26 00:28:102306 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
2307 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
2308 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322309
2310 // Verify draw_opacity_is_animating values
2311 EXPECT_FALSE(parent->draw_opacity_is_animating());
2312 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2313 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2314 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2315 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2316 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2317 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2318 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2319 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2320 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2321 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2322
2323 // Verify draw_transform_is_animating values
2324 EXPECT_FALSE(parent->draw_transform_is_animating());
2325 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2326 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2327 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2328 EXPECT_FALSE(render_surface1->render_surface()
2329 ->target_surface_transforms_are_animating());
2330 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2331 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2332 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2333 EXPECT_TRUE(render_surface2->render_surface()
2334 ->target_surface_transforms_are_animating());
2335 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2336 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2337
2338 // Verify screen_space_transform_is_animating values
2339 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2340 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2341 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2342 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2343 EXPECT_FALSE(render_surface1->render_surface()
2344 ->screen_space_transforms_are_animating());
2345 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2346 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2347 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2348 EXPECT_TRUE(render_surface2->render_surface()
2349 ->screen_space_transforms_are_animating());
2350 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2351 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2352
2353 // Sanity check. If these fail there is probably a bug in the test itself.
2354 // It is expected that we correctly set up transforms so that the y-component
2355 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262356 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2357 EXPECT_FLOAT_EQ(2.0,
2358 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322359 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262360 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322361
[email protected]803f6b52013-09-12 00:51:262362 EXPECT_FLOAT_EQ(2.0,
2363 render_surface1->screen_space_transform().matrix().get(1, 3));
2364 EXPECT_FLOAT_EQ(3.0,
2365 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322366 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262367 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322368
[email protected]803f6b52013-09-12 00:51:262369 EXPECT_FLOAT_EQ(3.0,
2370 render_surface2->screen_space_transform().matrix().get(1, 3));
2371 EXPECT_FLOAT_EQ(4.0,
2372 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322373 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262374 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322375}
2376
[email protected]989386c2013-07-18 21:37:232377TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322378 // Test the calculateVisibleRect() function works correctly for identity
2379 // transforms.
2380
[email protected]2c7c6702013-03-26 03:14:052381 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322382 gfx::Transform layer_to_surface_transform;
2383
2384 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232385 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052386 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322387 gfx::Rect 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 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052392 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322393 actual = LayerTreeHostCommon::CalculateVisibleRect(
2394 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2395 EXPECT_TRUE(actual.IsEmpty());
2396
2397 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052398 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2399 expected = gfx::Rect(80, 80, 20, 20);
[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, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322406 // Test the calculateVisibleRect() function works correctly for scaling
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, 30, 30);
[email protected]fb661802013-03-25 01:59:322411 gfx::Transform layer_to_surface_transform;
2412
2413 // Case 1: Layer is contained within the surface.
2414 layer_to_surface_transform.MakeIdentity();
2415 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052416 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322417 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2418 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322419 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322420
2421 // Case 2: Layer is outside the surface rect.
2422 layer_to_surface_transform.MakeIdentity();
2423 layer_to_surface_transform.Translate(120.0, 120.0);
2424 actual = LayerTreeHostCommon::CalculateVisibleRect(
2425 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2426 EXPECT_TRUE(actual.IsEmpty());
2427
2428 // Case 3: Layer is partially overlapping the surface rect.
2429 layer_to_surface_transform.MakeIdentity();
2430 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052431 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322432 actual = LayerTreeHostCommon::CalculateVisibleRect(
2433 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322434 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322435}
2436
[email protected]989386c2013-07-18 21:37:232437TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322438 // Test the calculateVisibleRect() function works correctly for rotations
2439 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2440 // should return the g in the layer's space.
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(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322444 gfx::Transform layer_to_surface_transform;
2445
2446 // Case 1: Layer is contained within the surface.
2447 layer_to_surface_transform.MakeIdentity();
2448 layer_to_surface_transform.Translate(50.0, 50.0);
2449 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052450 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322451 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2452 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322453 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322454
2455 // Case 2: Layer is outside the surface rect.
2456 layer_to_surface_transform.MakeIdentity();
2457 layer_to_surface_transform.Translate(-50.0, 0.0);
2458 layer_to_surface_transform.Rotate(45.0);
2459 actual = LayerTreeHostCommon::CalculateVisibleRect(
2460 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2461 EXPECT_TRUE(actual.IsEmpty());
2462
2463 // Case 3: The layer is rotated about its top-left corner. In surface space,
2464 // the layer is oriented diagonally, with the left half outside of the render
2465 // surface. In this case, the g should still be the entire layer
2466 // (remember the g is computed in layer space); both the top-left
2467 // and bottom-right corners of the layer are still visible.
2468 layer_to_surface_transform.MakeIdentity();
2469 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052470 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322471 actual = LayerTreeHostCommon::CalculateVisibleRect(
2472 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322473 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322474
2475 // Case 4: The layer is rotated about its top-left corner, and translated
2476 // upwards. In surface space, the layer is oriented diagonally, with only the
2477 // top corner of the surface overlapping the layer. In layer space, the render
2478 // surface overlaps the right side of the layer. The g should be
2479 // the layer's right half.
2480 layer_to_surface_transform.MakeIdentity();
2481 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2482 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052483 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322484 actual = LayerTreeHostCommon::CalculateVisibleRect(
2485 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322486 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322487}
2488
[email protected]989386c2013-07-18 21:37:232489TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322490 // Test that the calculateVisibleRect() function works correctly for 3d
2491 // transforms.
2492
[email protected]2c7c6702013-03-26 03:14:052493 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2494 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322495 gfx::Transform layer_to_surface_transform;
2496
2497 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2498 // degrees, should be fully contained in the render surface.
2499 layer_to_surface_transform.MakeIdentity();
2500 layer_to_surface_transform.RotateAboutYAxis(45.0);
[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 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2507 // degrees, but shifted to the side so only the right-half the layer would be
2508 // visible on the surface.
2509 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262510 SkMScalar half_width_of_rotated_layer =
2511 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322512 layer_to_surface_transform.MakeIdentity();
2513 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232514 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2515 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052516 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322517 actual = LayerTreeHostCommon::CalculateVisibleRect(
2518 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322519 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322520}
2521
[email protected]989386c2013-07-18 21:37:232522TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322523 // Test the calculateVisibleRect() function works correctly when the layer has
2524 // a perspective projection onto the target surface.
2525
[email protected]2c7c6702013-03-26 03:14:052526 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2527 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322528 gfx::Transform layer_to_surface_transform;
2529
2530 // Case 1: Even though the layer is twice as large as the surface, due to
2531 // perspective foreshortening, the layer will fit fully in the surface when
2532 // its translated more than the perspective amount.
2533 layer_to_surface_transform.MakeIdentity();
2534
2535 // The following sequence of transforms applies the perspective about the
2536 // center of the surface.
2537 layer_to_surface_transform.Translate(50.0, 50.0);
2538 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2539 layer_to_surface_transform.Translate(-50.0, -50.0);
2540
2541 // This translate places the layer in front of the surface's projection plane.
2542 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2543
[email protected]2c7c6702013-03-26 03:14:052544 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322545 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2546 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322547 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322548
2549 // Case 2: same projection as before, except that the layer is also translated
2550 // to the side, so that only the right half of the layer should be visible.
2551 //
2552 // Explanation of expected result: The perspective ratio is (z distance
2553 // between layer and camera origin) / (z distance between projection plane and
2554 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2555 // move a layer by translating -50 units in projected surface units (so that
2556 // only half of it is visible), then we would need to translate by (-36 / 9) *
2557 // -50 == -200 in the layer's units.
2558 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232559 expected = gfx::Rect(gfx::Point(50, -50),
2560 gfx::Size(100, 200)); // The right half of the layer's
2561 // bounding rect.
[email protected]fb661802013-03-25 01:59:322562 actual = LayerTreeHostCommon::CalculateVisibleRect(
2563 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322564 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322565}
2566
[email protected]989386c2013-07-18 21:37:232567TEST_F(LayerTreeHostCommonTest,
2568 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322569 // There is currently no explicit concept of an orthographic projection plane
2570 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2571 // are technically behind the surface in an orthographic world should not be
2572 // clipped when they are flattened to the surface.
2573
[email protected]2c7c6702013-03-26 03:14:052574 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2575 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322576 gfx::Transform layer_to_surface_transform;
2577
2578 // This sequence of transforms effectively rotates the layer about the y-axis
2579 // at the center of the layer.
2580 layer_to_surface_transform.MakeIdentity();
2581 layer_to_surface_transform.Translate(50.0, 0.0);
2582 layer_to_surface_transform.RotateAboutYAxis(45.0);
2583 layer_to_surface_transform.Translate(-50.0, 0.0);
2584
[email protected]2c7c6702013-03-26 03:14:052585 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322586 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2587 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322588 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322589}
2590
[email protected]989386c2013-07-18 21:37:232591TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322592 // Test the calculateVisibleRect() function works correctly when projecting a
2593 // surface onto a layer, but the layer is partially behind the camera (not
2594 // just behind the projection plane). In this case, the cartesian coordinates
2595 // may seem to be valid, but actually they are not. The visible rect needs to
2596 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2597 // converting to cartesian coordinates.
2598
[email protected]2c7c6702013-03-26 03:14:052599 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232600 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322601 gfx::Transform layer_to_surface_transform;
2602
2603 // The layer is positioned so that the right half of the layer should be in
2604 // front of the camera, while the other half is behind the surface's
2605 // projection plane. The following sequence of transforms applies the
2606 // perspective and rotation about the center of the layer.
2607 layer_to_surface_transform.MakeIdentity();
2608 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2609 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2610 layer_to_surface_transform.RotateAboutYAxis(45.0);
2611
2612 // Sanity check that this transform does indeed cause w < 0 when applying the
2613 // transform, otherwise this code is not testing the intended scenario.
2614 bool clipped;
2615 MathUtil::MapQuad(layer_to_surface_transform,
2616 gfx::QuadF(gfx::RectF(layer_content_rect)),
2617 &clipped);
2618 ASSERT_TRUE(clipped);
2619
2620 int expected_x_position = 0;
2621 int expected_width = 10;
2622 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2623 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2624 EXPECT_EQ(expected_x_position, actual.x());
2625 EXPECT_EQ(expected_width, actual.width());
2626}
2627
[email protected]989386c2013-07-18 21:37:232628TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322629 // To determine visible rect in layer space, there needs to be an
2630 // un-projection from surface space to layer space. When the original
2631 // transform was a perspective projection that was clipped, it returns a rect
2632 // that encloses the clipped bounds. Un-projecting this new rect may require
2633 // clipping again.
2634
2635 // This sequence of transforms causes one corner of the layer to protrude
2636 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232637 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2638 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322639 gfx::Transform layer_to_surface_transform;
2640 layer_to_surface_transform.MakeIdentity();
2641 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2642 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2643 layer_to_surface_transform.RotateAboutYAxis(45.0);
2644 layer_to_surface_transform.RotateAboutXAxis(80.0);
2645
2646 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2647 // code is not testing the intended scenario.
2648 bool clipped;
2649 gfx::RectF clipped_rect =
2650 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2651 MathUtil::ProjectQuad(
2652 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2653 ASSERT_TRUE(clipped);
2654
2655 // Only the corner of the layer is not visible on the surface because of being
2656 // clipped. But, the net result of rounding visible region to an axis-aligned
2657 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052658 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322659 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2660 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322661 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322662}
2663
[email protected]989386c2013-07-18 21:37:232664TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322665 scoped_refptr<Layer> root = Layer::Create();
2666 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2667 make_scoped_refptr(new LayerWithForcedDrawsContent());
2668 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2669 make_scoped_refptr(new LayerWithForcedDrawsContent());
2670 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2671 make_scoped_refptr(new LayerWithForcedDrawsContent());
2672 root->AddChild(child1);
2673 root->AddChild(child2);
2674 root->AddChild(child3);
2675
enne2097cab2014-09-25 20:16:312676 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282677 host->SetRootLayer(root);
2678
[email protected]fb661802013-03-25 01:59:322679 gfx::Transform identity_matrix;
2680 SetLayerPropertiesForTesting(root.get(),
2681 identity_matrix,
[email protected]a2566412014-06-05 03:14:202682 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322683 gfx::PointF(),
2684 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572685 true,
[email protected]fb661802013-03-25 01:59:322686 false);
2687 SetLayerPropertiesForTesting(child1.get(),
2688 identity_matrix,
[email protected]a2566412014-06-05 03:14:202689 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322690 gfx::PointF(),
2691 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572692 true,
[email protected]fb661802013-03-25 01:59:322693 false);
2694 SetLayerPropertiesForTesting(child2.get(),
2695 identity_matrix,
[email protected]a2566412014-06-05 03:14:202696 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322697 gfx::PointF(75.f, 75.f),
2698 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572699 true,
[email protected]fb661802013-03-25 01:59:322700 false);
2701 SetLayerPropertiesForTesting(child3.get(),
2702 identity_matrix,
[email protected]a2566412014-06-05 03:14:202703 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322704 gfx::PointF(125.f, 125.f),
2705 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572706 true,
[email protected]fb661802013-03-25 01:59:322707 false);
2708
2709 ExecuteCalculateDrawProperties(root.get());
2710
hush6b614212014-12-04 22:37:322711 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2712 root->render_surface()->DrawableContentRect());
2713 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322714
2715 // Layers that do not draw content should have empty visible_content_rects.
hush6b614212014-12-04 22:37:322716 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322717
2718 // layer visible_content_rects are clipped by their target surface.
hush6b614212014-12-04 22:37:322719 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2720 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322721 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2722
2723 // layer drawable_content_rects are not clipped.
hush6b614212014-12-04 22:37:322724 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2725 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2726 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322727}
2728
[email protected]989386c2013-07-18 21:37:232729TEST_F(LayerTreeHostCommonTest,
2730 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322731 scoped_refptr<Layer> root = Layer::Create();
2732 scoped_refptr<Layer> child = Layer::Create();
2733 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2734 make_scoped_refptr(new LayerWithForcedDrawsContent());
2735 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2736 make_scoped_refptr(new LayerWithForcedDrawsContent());
2737 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2738 make_scoped_refptr(new LayerWithForcedDrawsContent());
2739 root->AddChild(child);
2740 child->AddChild(grand_child1);
2741 child->AddChild(grand_child2);
2742 child->AddChild(grand_child3);
2743
enne2097cab2014-09-25 20:16:312744 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282745 host->SetRootLayer(root);
2746
[email protected]fb661802013-03-25 01:59:322747 gfx::Transform identity_matrix;
2748 SetLayerPropertiesForTesting(root.get(),
2749 identity_matrix,
[email protected]a2566412014-06-05 03:14:202750 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322751 gfx::PointF(),
2752 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572753 true,
[email protected]fb661802013-03-25 01:59:322754 false);
2755 SetLayerPropertiesForTesting(child.get(),
2756 identity_matrix,
[email protected]a2566412014-06-05 03:14:202757 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322758 gfx::PointF(),
2759 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572760 true,
[email protected]fb661802013-03-25 01:59:322761 false);
2762 SetLayerPropertiesForTesting(grand_child1.get(),
2763 identity_matrix,
[email protected]a2566412014-06-05 03:14:202764 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322765 gfx::PointF(5.f, 5.f),
2766 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572767 true,
[email protected]fb661802013-03-25 01:59:322768 false);
2769 SetLayerPropertiesForTesting(grand_child2.get(),
2770 identity_matrix,
[email protected]a2566412014-06-05 03:14:202771 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322772 gfx::PointF(75.f, 75.f),
2773 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572774 true,
[email protected]fb661802013-03-25 01:59:322775 false);
2776 SetLayerPropertiesForTesting(grand_child3.get(),
2777 identity_matrix,
[email protected]a2566412014-06-05 03:14:202778 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322779 gfx::PointF(125.f, 125.f),
2780 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572781 true,
[email protected]fb661802013-03-25 01:59:322782 false);
2783
2784 child->SetMasksToBounds(true);
2785 ExecuteCalculateDrawProperties(root.get());
2786
2787 ASSERT_FALSE(child->render_surface());
2788
hush6b614212014-12-04 22:37:322789 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2790 root->render_surface()->DrawableContentRect());
2791 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322792
2793 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322794 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2795 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322796
2797 // All grandchild visible content rects should be clipped by child.
hush6b614212014-12-04 22:37:322798 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2799 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322800 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2801
2802 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322803 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2804 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322805 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2806}
2807
[email protected]989386c2013-07-18 21:37:232808TEST_F(LayerTreeHostCommonTest,
2809 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322810 scoped_refptr<Layer> root = Layer::Create();
2811 scoped_refptr<Layer> render_surface1 = Layer::Create();
2812 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2813 make_scoped_refptr(new LayerWithForcedDrawsContent());
2814 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2815 make_scoped_refptr(new LayerWithForcedDrawsContent());
2816 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2817 make_scoped_refptr(new LayerWithForcedDrawsContent());
2818 root->AddChild(render_surface1);
2819 render_surface1->AddChild(child1);
2820 render_surface1->AddChild(child2);
2821 render_surface1->AddChild(child3);
2822
enne2097cab2014-09-25 20:16:312823 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282824 host->SetRootLayer(root);
2825
[email protected]fb661802013-03-25 01:59:322826 gfx::Transform identity_matrix;
2827 SetLayerPropertiesForTesting(root.get(),
2828 identity_matrix,
[email protected]a2566412014-06-05 03:14:202829 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322830 gfx::PointF(),
2831 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572832 true,
[email protected]fb661802013-03-25 01:59:322833 false);
2834 SetLayerPropertiesForTesting(render_surface1.get(),
2835 identity_matrix,
[email protected]a2566412014-06-05 03:14:202836 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322837 gfx::PointF(),
2838 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572839 true,
[email protected]fb661802013-03-25 01:59:322840 false);
2841 SetLayerPropertiesForTesting(child1.get(),
2842 identity_matrix,
[email protected]a2566412014-06-05 03:14:202843 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322844 gfx::PointF(5.f, 5.f),
2845 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572846 true,
[email protected]fb661802013-03-25 01:59:322847 false);
2848 SetLayerPropertiesForTesting(child2.get(),
2849 identity_matrix,
[email protected]a2566412014-06-05 03:14:202850 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322851 gfx::PointF(75.f, 75.f),
2852 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572853 true,
[email protected]fb661802013-03-25 01:59:322854 false);
2855 SetLayerPropertiesForTesting(child3.get(),
2856 identity_matrix,
[email protected]a2566412014-06-05 03:14:202857 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322858 gfx::PointF(125.f, 125.f),
2859 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572860 true,
[email protected]fb661802013-03-25 01:59:322861 false);
2862
2863 render_surface1->SetForceRenderSurface(true);
2864 ExecuteCalculateDrawProperties(root.get());
2865
2866 ASSERT_TRUE(render_surface1->render_surface());
2867
hush6b614212014-12-04 22:37:322868 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2869 root->render_surface()->DrawableContentRect());
2870 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322871
2872 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322873 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2874 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322875
2876 // An unclipped surface grows its DrawableContentRect to include all drawable
2877 // regions of the subtree.
hush6b614212014-12-04 22:37:322878 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2879 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322880
2881 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:322882 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2883 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2884 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322885
hush6b614212014-12-04 22:37:322886 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2887 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2888 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322889}
2890
[email protected]989386c2013-07-18 21:37:232891TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:022892 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2893 scoped_refptr<Layer> root = Layer::Create();
2894 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2895 make_scoped_refptr(new LayerWithForcedDrawsContent());
2896 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2897 make_scoped_refptr(new LayerWithForcedDrawsContent());
2898 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2899 make_scoped_refptr(new LayerWithForcedDrawsContent());
2900 root->AddChild(child1);
2901 root->AddChild(child2);
2902 root->AddChild(child3);
2903
2904 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2905 host->SetRootLayer(root);
2906
2907 gfx::Transform identity_matrix;
2908 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2909 gfx::PointF(), gfx::Size(100, 100), true, false);
2910 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(),
2911 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2912 false);
2913 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(),
2914 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2915 false);
2916 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(),
2917 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2918 true, false);
2919
2920 RenderSurfaceLayerList render_surface_layer_list;
2921 // Now set the root render surface an empty clip.
2922 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2923 root.get(), gfx::Size(), &render_surface_layer_list);
2924
2925 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2926 ASSERT_TRUE(root->render_surface());
2927 EXPECT_FALSE(root->is_clipped());
2928
2929 gfx::Rect empty;
2930 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2931 EXPECT_TRUE(root->render_surface()->is_clipped());
2932
2933 // Visible content rect calculation will check if the target surface is
2934 // clipped or not. An empty clip rect does not indicate the render surface
2935 // is unclipped.
2936 EXPECT_EQ(empty, child1->visible_content_rect());
2937 EXPECT_EQ(empty, child2->visible_content_rect());
2938 EXPECT_EQ(empty, child3->visible_content_rect());
2939}
2940
2941TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:232942 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472943 scoped_refptr<Layer> root = Layer::Create();
2944 scoped_refptr<LayerWithForcedDrawsContent> child =
2945 make_scoped_refptr(new LayerWithForcedDrawsContent());
2946 root->AddChild(child);
2947
enne2097cab2014-09-25 20:16:312948 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282949 host->SetRootLayer(root);
2950
[email protected]630ddad2013-08-16 03:01:322951 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472952 gfx::Transform identity_matrix;
2953 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322954 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472955
2956 SetLayerPropertiesForTesting(root.get(),
2957 identity_matrix,
[email protected]a2566412014-06-05 03:14:202958 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472959 gfx::PointF(),
2960 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572961 true,
[email protected]451107a32013-04-10 05:12:472962 false);
2963 SetLayerPropertiesForTesting(child.get(),
2964 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202965 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472966 gfx::PointF(5.f, 5.f),
2967 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572968 true,
[email protected]451107a32013-04-10 05:12:472969 false);
2970
2971 ExecuteCalculateDrawProperties(root.get());
2972
2973 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2974 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322975
[email protected]08bdf1b2014-04-16 23:23:292976 // Case 2: a matrix with flattened z, uninvertible and not visible according
2977 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322978 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262979 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322980 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2981
2982 SetLayerPropertiesForTesting(child.get(),
2983 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202984 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322985 gfx::PointF(5.f, 5.f),
2986 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572987 true,
[email protected]630ddad2013-08-16 03:01:322988 false);
2989
2990 ExecuteCalculateDrawProperties(root.get());
2991
[email protected]08bdf1b2014-04-16 23:23:292992 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2993 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322994
[email protected]08bdf1b2014-04-16 23:23:292995 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322996 uninvertible_matrix.MakeIdentity();
2997 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262998 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322999 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3000
3001 SetLayerPropertiesForTesting(child.get(),
3002 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203003 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:323004 gfx::PointF(5.f, 5.f),
3005 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573006 true,
[email protected]630ddad2013-08-16 03:01:323007 false);
3008
3009 ExecuteCalculateDrawProperties(root.get());
3010
3011 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293012 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473013}
3014
[email protected]989386c2013-07-18 21:37:233015TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:363016 SingularTransformDoesNotPreventClearingDrawProperties) {
3017 scoped_refptr<Layer> root = Layer::Create();
3018 scoped_refptr<LayerWithForcedDrawsContent> child =
3019 make_scoped_refptr(new LayerWithForcedDrawsContent());
3020 root->AddChild(child);
3021
enne2097cab2014-09-25 20:16:313022 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]e43c68b2014-05-01 05:10:363023 host->SetRootLayer(root);
3024
3025 gfx::Transform identity_matrix;
3026 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3027 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3028
3029 SetLayerPropertiesForTesting(root.get(),
3030 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203031 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363032 gfx::PointF(),
3033 gfx::Size(100, 100),
3034 true,
3035 false);
3036 SetLayerPropertiesForTesting(child.get(),
3037 identity_matrix,
[email protected]a2566412014-06-05 03:14:203038 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363039 gfx::PointF(5.f, 5.f),
3040 gfx::Size(50, 50),
3041 true,
3042 false);
3043
vollickeb194942014-09-12 17:45:273044 child->draw_properties().sorted_for_recursion = true;
[email protected]e43c68b2014-05-01 05:10:363045
3046 TransformOperations start_transform_operations;
3047 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3048
3049 TransformOperations end_transform_operations;
3050 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3051
3052 AddAnimatedTransformToLayer(
3053 root.get(), 10.0, start_transform_operations, end_transform_operations);
3054
3055 EXPECT_TRUE(root->TransformIsAnimating());
3056
3057 ExecuteCalculateDrawProperties(root.get());
3058
vollickeb194942014-09-12 17:45:273059 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
[email protected]e43c68b2014-05-01 05:10:363060}
3061
[email protected]e43c68b2014-05-01 05:10:363062TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:063063 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
3064 scoped_refptr<Layer> root = Layer::Create();
3065
enne2097cab2014-09-25 20:16:313066 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]8dbc85c2014-05-03 03:21:063067 host->SetRootLayer(root);
3068
3069 gfx::Transform identity_matrix;
3070 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3071 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3072
3073 SetLayerPropertiesForTesting(root.get(),
3074 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203075 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:063076 gfx::PointF(),
3077 gfx::Size(100, 100),
3078 true,
3079 false);
3080
vollickeb194942014-09-12 17:45:273081 root->draw_properties().sorted_for_recursion = true;
[email protected]8dbc85c2014-05-03 03:21:063082
3083 EXPECT_FALSE(root->TransformIsAnimating());
3084
3085 ExecuteCalculateDrawProperties(root.get());
3086
vollickeb194942014-09-12 17:45:273087 EXPECT_FALSE(root->draw_properties().sorted_for_recursion);
[email protected]8dbc85c2014-05-03 03:21:063088}
3089
3090TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233091 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323092 scoped_refptr<Layer> root = Layer::Create();
3093 scoped_refptr<Layer> render_surface1 = Layer::Create();
3094 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3095 make_scoped_refptr(new LayerWithForcedDrawsContent());
3096 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3097 make_scoped_refptr(new LayerWithForcedDrawsContent());
3098 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3099 make_scoped_refptr(new LayerWithForcedDrawsContent());
3100 root->AddChild(render_surface1);
3101 render_surface1->AddChild(child1);
3102 render_surface1->AddChild(child2);
3103 render_surface1->AddChild(child3);
3104
enne2097cab2014-09-25 20:16:313105 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283106 host->SetRootLayer(root);
3107
[email protected]fb661802013-03-25 01:59:323108 gfx::Transform identity_matrix;
3109 SetLayerPropertiesForTesting(root.get(),
3110 identity_matrix,
[email protected]a2566412014-06-05 03:14:203111 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323112 gfx::PointF(),
3113 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573114 true,
[email protected]fb661802013-03-25 01:59:323115 false);
3116 SetLayerPropertiesForTesting(render_surface1.get(),
3117 identity_matrix,
[email protected]a2566412014-06-05 03:14:203118 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323119 gfx::PointF(),
3120 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573121 true,
[email protected]fb661802013-03-25 01:59:323122 false);
3123 SetLayerPropertiesForTesting(child1.get(),
3124 identity_matrix,
[email protected]a2566412014-06-05 03:14:203125 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323126 gfx::PointF(5.f, 5.f),
3127 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573128 true,
[email protected]fb661802013-03-25 01:59:323129 false);
3130 SetLayerPropertiesForTesting(child2.get(),
3131 identity_matrix,
[email protected]a2566412014-06-05 03:14:203132 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323133 gfx::PointF(75.f, 75.f),
3134 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573135 true,
[email protected]fb661802013-03-25 01:59:323136 false);
3137 SetLayerPropertiesForTesting(child3.get(),
3138 identity_matrix,
[email protected]a2566412014-06-05 03:14:203139 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323140 gfx::PointF(125.f, 125.f),
3141 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573142 true,
[email protected]fb661802013-03-25 01:59:323143 false);
3144
3145 root->SetMasksToBounds(true);
3146 render_surface1->SetForceRenderSurface(true);
3147 ExecuteCalculateDrawProperties(root.get());
3148
3149 ASSERT_TRUE(render_surface1->render_surface());
3150
hush6b614212014-12-04 22:37:323151 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3152 root->render_surface()->DrawableContentRect());
3153 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323154
3155 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323156 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3157 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323158
3159 // A clipped surface grows its DrawableContentRect to include all drawable
3160 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323161 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3162 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323163
3164 // All layers that draw content into the surface have their visible content
3165 // rect clipped by the surface clip rect.
hush6b614212014-12-04 22:37:323166 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3167 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323168 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3169
3170 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323171 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3172 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3173 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323174}
3175
[email protected]989386c2013-07-18 21:37:233176TEST_F(LayerTreeHostCommonTest,
3177 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323178 // Check that clipping does not propagate down surfaces.
3179 scoped_refptr<Layer> root = Layer::Create();
3180 scoped_refptr<Layer> render_surface1 = Layer::Create();
3181 scoped_refptr<Layer> render_surface2 = Layer::Create();
3182 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3183 make_scoped_refptr(new LayerWithForcedDrawsContent());
3184 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3185 make_scoped_refptr(new LayerWithForcedDrawsContent());
3186 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3187 make_scoped_refptr(new LayerWithForcedDrawsContent());
3188 root->AddChild(render_surface1);
3189 render_surface1->AddChild(render_surface2);
3190 render_surface2->AddChild(child1);
3191 render_surface2->AddChild(child2);
3192 render_surface2->AddChild(child3);
3193
enne2097cab2014-09-25 20:16:313194 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283195 host->SetRootLayer(root);
3196
[email protected]fb661802013-03-25 01:59:323197 gfx::Transform identity_matrix;
3198 SetLayerPropertiesForTesting(root.get(),
3199 identity_matrix,
[email protected]a2566412014-06-05 03:14:203200 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323201 gfx::PointF(),
3202 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573203 true,
[email protected]fb661802013-03-25 01:59:323204 false);
3205 SetLayerPropertiesForTesting(render_surface1.get(),
3206 identity_matrix,
[email protected]a2566412014-06-05 03:14:203207 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323208 gfx::PointF(),
3209 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573210 true,
[email protected]fb661802013-03-25 01:59:323211 false);
3212 SetLayerPropertiesForTesting(render_surface2.get(),
3213 identity_matrix,
[email protected]a2566412014-06-05 03:14:203214 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323215 gfx::PointF(),
3216 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573217 true,
[email protected]fb661802013-03-25 01:59:323218 false);
3219 SetLayerPropertiesForTesting(child1.get(),
3220 identity_matrix,
[email protected]a2566412014-06-05 03:14:203221 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323222 gfx::PointF(5.f, 5.f),
3223 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573224 true,
[email protected]fb661802013-03-25 01:59:323225 false);
3226 SetLayerPropertiesForTesting(child2.get(),
3227 identity_matrix,
[email protected]a2566412014-06-05 03:14:203228 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323229 gfx::PointF(75.f, 75.f),
3230 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573231 true,
[email protected]fb661802013-03-25 01:59:323232 false);
3233 SetLayerPropertiesForTesting(child3.get(),
3234 identity_matrix,
[email protected]a2566412014-06-05 03:14:203235 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323236 gfx::PointF(125.f, 125.f),
3237 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573238 true,
[email protected]fb661802013-03-25 01:59:323239 false);
3240
3241 root->SetMasksToBounds(true);
3242 render_surface1->SetForceRenderSurface(true);
3243 render_surface2->SetForceRenderSurface(true);
3244 ExecuteCalculateDrawProperties(root.get());
3245
3246 ASSERT_TRUE(render_surface1->render_surface());
3247 ASSERT_TRUE(render_surface2->render_surface());
3248
hush6b614212014-12-04 22:37:323249 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3250 root->render_surface()->DrawableContentRect());
3251 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323252
3253 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323254 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3255 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
3256 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323257
3258 // A clipped surface grows its DrawableContentRect to include all drawable
3259 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323260 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3261 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323262
3263 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3264 // is only implicitly clipped by render_surface1's content rect. So,
3265 // render_surface2 grows to enclose all drawable content of its subtree.
hush6b614212014-12-04 22:37:323266 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3267 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323268
3269 // All layers that draw content into render_surface2 think they are unclipped.
hush6b614212014-12-04 22:37:323270 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3271 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3272 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323273
3274 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323275 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3276 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3277 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323278}
3279
[email protected]989386c2013-07-18 21:37:233280TEST_F(LayerTreeHostCommonTest,
3281 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323282 // Layers that have non-axis aligned bounds (due to transforms) have an
3283 // expanded, axis-aligned DrawableContentRect and visible content rect.
3284
3285 scoped_refptr<Layer> root = Layer::Create();
3286 scoped_refptr<Layer> render_surface1 = Layer::Create();
3287 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3288 make_scoped_refptr(new LayerWithForcedDrawsContent());
3289 root->AddChild(render_surface1);
3290 render_surface1->AddChild(child1);
3291
enne2097cab2014-09-25 20:16:313292 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283293 host->SetRootLayer(root);
3294
[email protected]fb661802013-03-25 01:59:323295 gfx::Transform identity_matrix;
3296 gfx::Transform child_rotation;
3297 child_rotation.Rotate(45.0);
3298 SetLayerPropertiesForTesting(root.get(),
3299 identity_matrix,
[email protected]a2566412014-06-05 03:14:203300 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323301 gfx::PointF(),
3302 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573303 true,
[email protected]fb661802013-03-25 01:59:323304 false);
3305 SetLayerPropertiesForTesting(render_surface1.get(),
3306 identity_matrix,
[email protected]a2566412014-06-05 03:14:203307 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323308 gfx::PointF(),
3309 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573310 true,
[email protected]fb661802013-03-25 01:59:323311 false);
3312 SetLayerPropertiesForTesting(child1.get(),
3313 child_rotation,
[email protected]a2566412014-06-05 03:14:203314 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323315 gfx::PointF(25.f, 25.f),
3316 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573317 true,
[email protected]fb661802013-03-25 01:59:323318 false);
3319
3320 render_surface1->SetForceRenderSurface(true);
3321 ExecuteCalculateDrawProperties(root.get());
3322
3323 ASSERT_TRUE(render_surface1->render_surface());
3324
hush6b614212014-12-04 22:37:323325 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3326 root->render_surface()->DrawableContentRect());
3327 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323328
3329 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323330 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3331 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323332
3333 // The unclipped surface grows its DrawableContentRect to include all drawable
3334 // regions of the subtree.
3335 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3336 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263337 gfx::Rect(50 - diagonal_radius,
3338 50 - diagonal_radius,
3339 diagonal_radius * 2,
3340 diagonal_radius * 2);
hush6b614212014-12-04 22:37:323341 EXPECT_EQ(expected_surface_drawable_content,
3342 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323343
3344 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:323345 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3346 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323347}
3348
[email protected]989386c2013-07-18 21:37:233349TEST_F(LayerTreeHostCommonTest,
3350 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323351 // Layers that have non-axis aligned bounds (due to transforms) have an
3352 // expanded, axis-aligned DrawableContentRect and visible content rect.
3353
3354 scoped_refptr<Layer> root = Layer::Create();
3355 scoped_refptr<Layer> render_surface1 = Layer::Create();
3356 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3357 make_scoped_refptr(new LayerWithForcedDrawsContent());
3358 root->AddChild(render_surface1);
3359 render_surface1->AddChild(child1);
3360
enne2097cab2014-09-25 20:16:313361 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283362 host->SetRootLayer(root);
3363
[email protected]fb661802013-03-25 01:59:323364 gfx::Transform identity_matrix;
3365 gfx::Transform child_rotation;
3366 child_rotation.Rotate(45.0);
3367 SetLayerPropertiesForTesting(root.get(),
3368 identity_matrix,
[email protected]a2566412014-06-05 03:14:203369 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323370 gfx::PointF(),
3371 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573372 true,
[email protected]fb661802013-03-25 01:59:323373 false);
3374 SetLayerPropertiesForTesting(render_surface1.get(),
3375 identity_matrix,
[email protected]a2566412014-06-05 03:14:203376 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323377 gfx::PointF(),
3378 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573379 true,
[email protected]fb661802013-03-25 01:59:323380 false);
[email protected]a2566412014-06-05 03:14:203381
[email protected]fb661802013-03-25 01:59:323382 SetLayerPropertiesForTesting(child1.get(),
3383 child_rotation,
[email protected]a2566412014-06-05 03:14:203384 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323385 gfx::PointF(25.f, 25.f),
3386 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573387 true,
[email protected]fb661802013-03-25 01:59:323388 false);
3389
3390 root->SetMasksToBounds(true);
3391 render_surface1->SetForceRenderSurface(true);
3392 ExecuteCalculateDrawProperties(root.get());
3393
3394 ASSERT_TRUE(render_surface1->render_surface());
3395
3396 // The clipped surface clamps the DrawableContentRect that encloses the
3397 // rotated layer.
3398 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263399 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3400 50 - diagonal_radius,
3401 diagonal_radius * 2,
3402 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323403 gfx::Rect expected_surface_drawable_content =
3404 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
hush6b614212014-12-04 22:37:323405 EXPECT_EQ(expected_surface_drawable_content,
3406 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323407
3408 // On the clipped surface, only a quarter of the child1 is visible, but when
3409 // rotating it back to child1's content space, the actual enclosing rect ends
3410 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263411 //
3412 // Given the floating point math, this number is a little bit fuzzy.
hush6b614212014-12-04 22:37:323413 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323414
3415 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323416 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323417}
3418
[email protected]989386c2013-07-18 21:37:233419TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323420 MockContentLayerClient client;
3421
3422 scoped_refptr<Layer> root = Layer::Create();
sohan.jyotie3bd6192014-10-13 07:13:593423 scoped_refptr<FakePictureLayer> render_surface1 =
3424 CreateDrawablePictureLayer(&client);
3425 scoped_refptr<FakePictureLayer> render_surface2 =
3426 CreateDrawablePictureLayer(&client);
3427 scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client);
3428 scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client);
3429 scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client);
[email protected]fb661802013-03-25 01:59:323430 root->AddChild(render_surface1);
3431 render_surface1->AddChild(render_surface2);
3432 render_surface2->AddChild(child1);
3433 render_surface2->AddChild(child2);
3434 render_surface2->AddChild(child3);
3435
enne2097cab2014-09-25 20:16:313436 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283437 host->SetRootLayer(root);
3438
[email protected]fb661802013-03-25 01:59:323439 gfx::Transform identity_matrix;
3440 SetLayerPropertiesForTesting(root.get(),
3441 identity_matrix,
[email protected]a2566412014-06-05 03:14:203442 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323443 gfx::PointF(),
3444 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573445 true,
[email protected]fb661802013-03-25 01:59:323446 false);
3447 SetLayerPropertiesForTesting(render_surface1.get(),
3448 identity_matrix,
[email protected]a2566412014-06-05 03:14:203449 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323450 gfx::PointF(5.f, 5.f),
3451 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573452 true,
[email protected]fb661802013-03-25 01:59:323453 false);
3454 SetLayerPropertiesForTesting(render_surface2.get(),
3455 identity_matrix,
[email protected]a2566412014-06-05 03:14:203456 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323457 gfx::PointF(5.f, 5.f),
3458 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573459 true,
[email protected]fb661802013-03-25 01:59:323460 false);
3461 SetLayerPropertiesForTesting(child1.get(),
3462 identity_matrix,
[email protected]a2566412014-06-05 03:14:203463 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323464 gfx::PointF(5.f, 5.f),
3465 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573466 true,
[email protected]fb661802013-03-25 01:59:323467 false);
3468 SetLayerPropertiesForTesting(child2.get(),
3469 identity_matrix,
[email protected]a2566412014-06-05 03:14:203470 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323471 gfx::PointF(75.f, 75.f),
3472 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573473 true,
[email protected]fb661802013-03-25 01:59:323474 false);
3475 SetLayerPropertiesForTesting(child3.get(),
3476 identity_matrix,
[email protected]a2566412014-06-05 03:14:203477 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323478 gfx::PointF(125.f, 125.f),
3479 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573480 true,
[email protected]fb661802013-03-25 01:59:323481 false);
3482
3483 float device_scale_factor = 2.f;
3484
3485 root->SetMasksToBounds(true);
3486 render_surface1->SetForceRenderSurface(true);
3487 render_surface2->SetForceRenderSurface(true);
3488 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3489
3490 ASSERT_TRUE(render_surface1->render_surface());
3491 ASSERT_TRUE(render_surface2->render_surface());
3492
3493 // drawable_content_rects for all layers and surfaces are scaled by
3494 // device_scale_factor.
hush6b614212014-12-04 22:37:323495 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3496 root->render_surface()->DrawableContentRect());
3497 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3498 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3499 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323500
3501 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3502 // is only implicitly clipped by render_surface1.
hush6b614212014-12-04 22:37:323503 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3504 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323505
hush6b614212014-12-04 22:37:323506 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3507 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3508 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323509
3510 // The root layer does not actually draw content of its own.
hush6b614212014-12-04 22:37:323511 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323512
sohan.jyotie3bd6192014-10-13 07:13:593513 // All layer visible content rects are not expressed in content space of each
3514 // layer, so they are not scaled by the device_scale_factor.
hush6b614212014-12-04 22:37:323515 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect());
3516 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect());
3517 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3518 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3519 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323520}
3521
[email protected]989386c2013-07-18 21:37:233522TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323523 // Verify the behavior of back-face culling when there are no preserve-3d
3524 // layers. Note that 3d transforms still apply in this case, but they are
3525 // "flattened" to each parent layer according to current W3C spec.
3526
3527 const gfx::Transform identity_matrix;
3528 scoped_refptr<Layer> parent = Layer::Create();
3529 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3530 make_scoped_refptr(new LayerWithForcedDrawsContent());
3531 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3532 make_scoped_refptr(new LayerWithForcedDrawsContent());
3533 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3534 make_scoped_refptr(new LayerWithForcedDrawsContent());
3535 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3536 make_scoped_refptr(new LayerWithForcedDrawsContent());
3537 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233538 front_facing_child_of_front_facing_surface =
3539 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323540 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233541 back_facing_child_of_front_facing_surface =
3542 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323543 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233544 front_facing_child_of_back_facing_surface =
3545 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323546 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233547 back_facing_child_of_back_facing_surface =
3548 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323549
3550 parent->AddChild(front_facing_child);
3551 parent->AddChild(back_facing_child);
3552 parent->AddChild(front_facing_surface);
3553 parent->AddChild(back_facing_surface);
3554 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3555 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3556 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3557 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3558
enne2097cab2014-09-25 20:16:313559 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283560 host->SetRootLayer(parent);
3561
[email protected]fb661802013-03-25 01:59:323562 // Nothing is double-sided
3563 front_facing_child->SetDoubleSided(false);
3564 back_facing_child->SetDoubleSided(false);
3565 front_facing_surface->SetDoubleSided(false);
3566 back_facing_surface->SetDoubleSided(false);
3567 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3568 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3569 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3570 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3571
3572 gfx::Transform backface_matrix;
3573 backface_matrix.Translate(50.0, 50.0);
3574 backface_matrix.RotateAboutYAxis(180.0);
3575 backface_matrix.Translate(-50.0, -50.0);
3576
3577 // Having a descendant and opacity will force these to have render surfaces.
3578 front_facing_surface->SetOpacity(0.5f);
3579 back_facing_surface->SetOpacity(0.5f);
3580
3581 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3582 // these layers should blindly use their own local transforms to determine
3583 // back-face culling.
3584 SetLayerPropertiesForTesting(parent.get(),
3585 identity_matrix,
[email protected]a2566412014-06-05 03:14:203586 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323587 gfx::PointF(),
3588 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573589 true,
[email protected]fb661802013-03-25 01:59:323590 false);
3591 SetLayerPropertiesForTesting(front_facing_child.get(),
3592 identity_matrix,
[email protected]a2566412014-06-05 03:14:203593 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323594 gfx::PointF(),
3595 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573596 true,
[email protected]fb661802013-03-25 01:59:323597 false);
3598 SetLayerPropertiesForTesting(back_facing_child.get(),
3599 backface_matrix,
[email protected]a2566412014-06-05 03:14:203600 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323601 gfx::PointF(),
3602 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573603 true,
[email protected]fb661802013-03-25 01:59:323604 false);
3605 SetLayerPropertiesForTesting(front_facing_surface.get(),
3606 identity_matrix,
[email protected]a2566412014-06-05 03:14:203607 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323608 gfx::PointF(),
3609 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573610 true,
[email protected]fb661802013-03-25 01:59:323611 false);
3612 SetLayerPropertiesForTesting(back_facing_surface.get(),
3613 backface_matrix,
[email protected]a2566412014-06-05 03:14:203614 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323615 gfx::PointF(),
3616 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573617 true,
[email protected]fb661802013-03-25 01:59:323618 false);
3619 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3620 identity_matrix,
[email protected]a2566412014-06-05 03:14:203621 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323622 gfx::PointF(),
3623 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573624 true,
[email protected]fb661802013-03-25 01:59:323625 false);
3626 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3627 backface_matrix,
[email protected]a2566412014-06-05 03:14:203628 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323629 gfx::PointF(),
3630 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573631 true,
[email protected]fb661802013-03-25 01:59:323632 false);
3633 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3634 identity_matrix,
[email protected]a2566412014-06-05 03:14:203635 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323636 gfx::PointF(),
3637 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573638 true,
[email protected]fb661802013-03-25 01:59:323639 false);
3640 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3641 backface_matrix,
[email protected]a2566412014-06-05 03:14:203642 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323643 gfx::PointF(),
3644 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573645 true,
[email protected]fb661802013-03-25 01:59:323646 false);
3647
[email protected]989386c2013-07-18 21:37:233648 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533649 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3650 parent.get(), parent->bounds(), &render_surface_layer_list);
3651 inputs.can_adjust_raster_scales = true;
3652 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323653
3654 // Verify which render surfaces were created.
3655 EXPECT_FALSE(front_facing_child->render_surface());
3656 EXPECT_FALSE(back_facing_child->render_surface());
3657 EXPECT_TRUE(front_facing_surface->render_surface());
3658 EXPECT_TRUE(back_facing_surface->render_surface());
3659 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3660 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3661 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3662 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3663
3664 // Verify the render_surface_layer_list.
3665 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233666 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3667 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323668 // Even though the back facing surface LAYER gets culled, the other
3669 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233670 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323671
3672 // Verify root surface's layer list.
3673 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233674 3u,
3675 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3676 EXPECT_EQ(front_facing_child->id(),
3677 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573678 ->render_surface()
3679 ->layer_list()
3680 .at(0)
3681 ->id());
[email protected]989386c2013-07-18 21:37:233682 EXPECT_EQ(front_facing_surface->id(),
3683 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573684 ->render_surface()
3685 ->layer_list()
3686 .at(1)
3687 ->id());
[email protected]989386c2013-07-18 21:37:233688 EXPECT_EQ(back_facing_surface->id(),
3689 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573690 ->render_surface()
3691 ->layer_list()
3692 .at(2)
3693 ->id());
[email protected]fb661802013-03-25 01:59:323694
3695 // Verify front_facing_surface's layer list.
3696 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233697 2u,
3698 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3699 EXPECT_EQ(front_facing_surface->id(),
3700 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573701 ->render_surface()
3702 ->layer_list()
3703 .at(0)
3704 ->id());
[email protected]989386c2013-07-18 21:37:233705 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3706 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573707 ->render_surface()
3708 ->layer_list()
3709 .at(1)
3710 ->id());
[email protected]fb661802013-03-25 01:59:323711
3712 // Verify back_facing_surface's layer list; its own layer should be culled
3713 // from the surface list.
3714 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233715 1u,
3716 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3717 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3718 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573719 ->render_surface()
3720 ->layer_list()
3721 .at(0)
3722 ->id());
[email protected]fb661802013-03-25 01:59:323723}
3724
[email protected]989386c2013-07-18 21:37:233725TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323726 // Verify the behavior of back-face culling when preserves-3d transform style
3727 // is used.
3728
3729 const gfx::Transform identity_matrix;
3730 scoped_refptr<Layer> parent = Layer::Create();
3731 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3732 make_scoped_refptr(new LayerWithForcedDrawsContent());
3733 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3734 make_scoped_refptr(new LayerWithForcedDrawsContent());
3735 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3736 make_scoped_refptr(new LayerWithForcedDrawsContent());
3737 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3738 make_scoped_refptr(new LayerWithForcedDrawsContent());
3739 scoped_refptr<LayerWithForcedDrawsContent>
3740 front_facing_child_of_front_facing_surface =
3741 make_scoped_refptr(new LayerWithForcedDrawsContent());
3742 scoped_refptr<LayerWithForcedDrawsContent>
3743 back_facing_child_of_front_facing_surface =
3744 make_scoped_refptr(new LayerWithForcedDrawsContent());
3745 scoped_refptr<LayerWithForcedDrawsContent>
3746 front_facing_child_of_back_facing_surface =
3747 make_scoped_refptr(new LayerWithForcedDrawsContent());
3748 scoped_refptr<LayerWithForcedDrawsContent>
3749 back_facing_child_of_back_facing_surface =
3750 make_scoped_refptr(new LayerWithForcedDrawsContent());
3751 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3752 make_scoped_refptr(new LayerWithForcedDrawsContent());
3753 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3754 make_scoped_refptr(new LayerWithForcedDrawsContent());
3755
3756 parent->AddChild(front_facing_child);
3757 parent->AddChild(back_facing_child);
3758 parent->AddChild(front_facing_surface);
3759 parent->AddChild(back_facing_surface);
3760 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3761 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3762 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3763 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3764
enne2097cab2014-09-25 20:16:313765 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283766 host->SetRootLayer(parent);
3767
[email protected]fb661802013-03-25 01:59:323768 // Nothing is double-sided
3769 front_facing_child->SetDoubleSided(false);
3770 back_facing_child->SetDoubleSided(false);
3771 front_facing_surface->SetDoubleSided(false);
3772 back_facing_surface->SetDoubleSided(false);
3773 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3774 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3775 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3776 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3777
3778 gfx::Transform backface_matrix;
3779 backface_matrix.Translate(50.0, 50.0);
3780 backface_matrix.RotateAboutYAxis(180.0);
3781 backface_matrix.Translate(-50.0, -50.0);
3782
3783 // Opacity will not force creation of render surfaces in this case because of
3784 // the preserve-3d transform style. Instead, an example of when a surface
3785 // would be created with preserve-3d is when there is a replica layer.
3786 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3787 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3788
3789 // Each surface creates its own new 3d rendering context (as defined by W3C
3790 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3791 // rendering context should use the transform with respect to that context.
3792 // This 3d rendering context occurs when (a) parent's transform style is flat
3793 // and (b) the layer's transform style is preserve-3d.
3794 SetLayerPropertiesForTesting(parent.get(),
3795 identity_matrix,
[email protected]a2566412014-06-05 03:14:203796 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323797 gfx::PointF(),
3798 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573799 true,
[email protected]fb661802013-03-25 01:59:323800 false); // parent transform style is flat.
3801 SetLayerPropertiesForTesting(front_facing_child.get(),
3802 identity_matrix,
[email protected]a2566412014-06-05 03:14:203803 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323804 gfx::PointF(),
3805 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573806 true,
[email protected]fb661802013-03-25 01:59:323807 false);
3808 SetLayerPropertiesForTesting(back_facing_child.get(),
3809 backface_matrix,
[email protected]a2566412014-06-05 03:14:203810 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323811 gfx::PointF(),
3812 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573813 true,
[email protected]fb661802013-03-25 01:59:323814 false);
[email protected]56fffdd2014-02-11 19:50:573815 // surface transform style is preserve-3d.
3816 SetLayerPropertiesForTesting(front_facing_surface.get(),
3817 identity_matrix,
[email protected]a2566412014-06-05 03:14:203818 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573819 gfx::PointF(),
3820 gfx::Size(100, 100),
3821 false,
3822 true);
3823 // surface transform style is preserve-3d.
3824 SetLayerPropertiesForTesting(back_facing_surface.get(),
3825 backface_matrix,
[email protected]a2566412014-06-05 03:14:203826 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573827 gfx::PointF(),
3828 gfx::Size(100, 100),
3829 false,
3830 true);
[email protected]fb661802013-03-25 01:59:323831 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3832 identity_matrix,
[email protected]a2566412014-06-05 03:14:203833 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323834 gfx::PointF(),
3835 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573836 true,
3837 true);
[email protected]fb661802013-03-25 01:59:323838 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3839 backface_matrix,
[email protected]a2566412014-06-05 03:14:203840 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323841 gfx::PointF(),
3842 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573843 true,
3844 true);
[email protected]fb661802013-03-25 01:59:323845 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3846 identity_matrix,
[email protected]a2566412014-06-05 03:14:203847 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323848 gfx::PointF(),
3849 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573850 true,
3851 true);
[email protected]fb661802013-03-25 01:59:323852 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3853 backface_matrix,
[email protected]a2566412014-06-05 03:14:203854 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323855 gfx::PointF(),
3856 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573857 true,
3858 true);
[email protected]fb661802013-03-25 01:59:323859
[email protected]989386c2013-07-18 21:37:233860 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533861 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3862 parent.get(), parent->bounds(), &render_surface_layer_list);
3863 inputs.can_adjust_raster_scales = true;
3864 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323865
awoloszyne83f28c2014-12-22 15:40:003866 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:323867 EXPECT_FALSE(front_facing_child->render_surface());
3868 EXPECT_FALSE(back_facing_child->render_surface());
3869 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:003870 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3871 // We expect that a render_surface was created but not used.
3872 EXPECT_TRUE(back_facing_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323873 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3874 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3875 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3876 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3877
3878 // Verify the render_surface_layer_list. The back-facing surface should be
3879 // culled.
3880 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233881 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3882 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323883
3884 // Verify root surface's layer list.
3885 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233886 2u,
3887 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3888 EXPECT_EQ(front_facing_child->id(),
3889 render_surface_layer_list.at(0)
3890 ->render_surface()->layer_list().at(0)->id());
3891 EXPECT_EQ(front_facing_surface->id(),
3892 render_surface_layer_list.at(0)
3893 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323894
3895 // Verify front_facing_surface's layer list.
3896 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233897 2u,
3898 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3899 EXPECT_EQ(front_facing_surface->id(),
3900 render_surface_layer_list.at(1)
3901 ->render_surface()->layer_list().at(0)->id());
3902 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3903 render_surface_layer_list.at(1)
3904 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323905}
3906
[email protected]989386c2013-07-18 21:37:233907TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323908 // Verify that layers are appropriately culled when their back face is showing
3909 // and they are not double sided, while animations are going on.
3910 //
3911 // Layers that are animating do not get culled on the main thread, as their
3912 // transforms should be treated as "unknown" so we can not be sure that their
3913 // back face is really showing.
3914 const gfx::Transform identity_matrix;
3915 scoped_refptr<Layer> parent = Layer::Create();
3916 scoped_refptr<LayerWithForcedDrawsContent> child =
3917 make_scoped_refptr(new LayerWithForcedDrawsContent());
3918 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3919 make_scoped_refptr(new LayerWithForcedDrawsContent());
3920 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3921 make_scoped_refptr(new LayerWithForcedDrawsContent());
3922 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3923 make_scoped_refptr(new LayerWithForcedDrawsContent());
3924 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3925 make_scoped_refptr(new LayerWithForcedDrawsContent());
3926
3927 parent->AddChild(child);
3928 parent->AddChild(animating_surface);
3929 animating_surface->AddChild(child_of_animating_surface);
3930 parent->AddChild(animating_child);
3931 parent->AddChild(child2);
3932
enne2097cab2014-09-25 20:16:313933 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283934 host->SetRootLayer(parent);
3935
[email protected]fb661802013-03-25 01:59:323936 // Nothing is double-sided
3937 child->SetDoubleSided(false);
3938 child2->SetDoubleSided(false);
3939 animating_surface->SetDoubleSided(false);
3940 child_of_animating_surface->SetDoubleSided(false);
3941 animating_child->SetDoubleSided(false);
3942
3943 gfx::Transform backface_matrix;
3944 backface_matrix.Translate(50.0, 50.0);
3945 backface_matrix.RotateAboutYAxis(180.0);
3946 backface_matrix.Translate(-50.0, -50.0);
3947
3948 // Make our render surface.
3949 animating_surface->SetForceRenderSurface(true);
3950
3951 // Animate the transform on the render surface.
3952 AddAnimatedTransformToController(
3953 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3954 // This is just an animating layer, not a surface.
3955 AddAnimatedTransformToController(
3956 animating_child->layer_animation_controller(), 10.0, 30, 0);
3957
3958 SetLayerPropertiesForTesting(parent.get(),
3959 identity_matrix,
[email protected]a2566412014-06-05 03:14:203960 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323961 gfx::PointF(),
3962 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573963 true,
[email protected]fb661802013-03-25 01:59:323964 false);
3965 SetLayerPropertiesForTesting(child.get(),
3966 backface_matrix,
[email protected]a2566412014-06-05 03:14:203967 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323968 gfx::PointF(),
3969 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573970 true,
[email protected]fb661802013-03-25 01:59:323971 false);
3972 SetLayerPropertiesForTesting(animating_surface.get(),
3973 backface_matrix,
[email protected]a2566412014-06-05 03:14:203974 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323975 gfx::PointF(),
3976 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573977 true,
[email protected]fb661802013-03-25 01:59:323978 false);
3979 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3980 backface_matrix,
[email protected]a2566412014-06-05 03:14:203981 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323982 gfx::PointF(),
3983 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573984 true,
[email protected]fb661802013-03-25 01:59:323985 false);
3986 SetLayerPropertiesForTesting(animating_child.get(),
3987 backface_matrix,
[email protected]a2566412014-06-05 03:14:203988 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323989 gfx::PointF(),
3990 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573991 true,
[email protected]fb661802013-03-25 01:59:323992 false);
3993 SetLayerPropertiesForTesting(child2.get(),
3994 identity_matrix,
[email protected]a2566412014-06-05 03:14:203995 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323996 gfx::PointF(),
3997 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573998 true,
[email protected]fb661802013-03-25 01:59:323999 false);
4000
[email protected]989386c2013-07-18 21:37:234001 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534002 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4003 parent.get(), parent->bounds(), &render_surface_layer_list);
4004 inputs.can_adjust_raster_scales = true;
4005 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324006
4007 EXPECT_FALSE(child->render_surface());
4008 EXPECT_TRUE(animating_surface->render_surface());
4009 EXPECT_FALSE(child_of_animating_surface->render_surface());
4010 EXPECT_FALSE(animating_child->render_surface());
4011 EXPECT_FALSE(child2->render_surface());
4012
4013 // Verify that the animating_child and child_of_animating_surface were not
4014 // culled, but that child was.
4015 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234016 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4017 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324018
4019 // The non-animating child be culled from the layer list for the parent render
4020 // surface.
4021 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234022 3u,
4023 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4024 EXPECT_EQ(animating_surface->id(),
4025 render_surface_layer_list.at(0)
4026 ->render_surface()->layer_list().at(0)->id());
4027 EXPECT_EQ(animating_child->id(),
4028 render_surface_layer_list.at(0)
4029 ->render_surface()->layer_list().at(1)->id());
4030 EXPECT_EQ(child2->id(),
4031 render_surface_layer_list.at(0)
4032 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324033
4034 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234035 2u,
4036 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4037 EXPECT_EQ(animating_surface->id(),
4038 render_surface_layer_list.at(1)
4039 ->render_surface()->layer_list().at(0)->id());
4040 EXPECT_EQ(child_of_animating_surface->id(),
4041 render_surface_layer_list.at(1)
4042 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324043
4044 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4045
4046 // The animating layers should have a visible content rect that represents the
4047 // area of the front face that is within the viewport.
4048 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054049 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324050 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054051 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324052 // And layers in the subtree of the animating layer should have valid visible
4053 // content rects also.
[email protected]989386c2013-07-18 21:37:234054 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4055 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324056}
4057
[email protected]989386c2013-07-18 21:37:234058TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324059 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4060 // Verify the behavior of back-face culling for a render surface that is
4061 // created when it flattens its subtree, and its parent has preserves-3d.
4062
4063 const gfx::Transform identity_matrix;
4064 scoped_refptr<Layer> parent = Layer::Create();
4065 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4066 make_scoped_refptr(new LayerWithForcedDrawsContent());
4067 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4068 make_scoped_refptr(new LayerWithForcedDrawsContent());
4069 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4070 make_scoped_refptr(new LayerWithForcedDrawsContent());
4071 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4072 make_scoped_refptr(new LayerWithForcedDrawsContent());
4073
4074 parent->AddChild(front_facing_surface);
4075 parent->AddChild(back_facing_surface);
4076 front_facing_surface->AddChild(child1);
4077 back_facing_surface->AddChild(child2);
4078
enne2097cab2014-09-25 20:16:314079 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284080 host->SetRootLayer(parent);
4081
[email protected]fb661802013-03-25 01:59:324082 // RenderSurfaces are not double-sided
4083 front_facing_surface->SetDoubleSided(false);
4084 back_facing_surface->SetDoubleSided(false);
4085
4086 gfx::Transform backface_matrix;
4087 backface_matrix.Translate(50.0, 50.0);
4088 backface_matrix.RotateAboutYAxis(180.0);
4089 backface_matrix.Translate(-50.0, -50.0);
4090
4091 SetLayerPropertiesForTesting(parent.get(),
4092 identity_matrix,
[email protected]a2566412014-06-05 03:14:204093 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324094 gfx::PointF(),
4095 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574096 false,
4097 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324098 SetLayerPropertiesForTesting(front_facing_surface.get(),
4099 identity_matrix,
[email protected]a2566412014-06-05 03:14:204100 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324101 gfx::PointF(),
4102 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574103 true,
4104 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324105 SetLayerPropertiesForTesting(back_facing_surface.get(),
4106 backface_matrix,
[email protected]a2566412014-06-05 03:14:204107 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324108 gfx::PointF(),
4109 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574110 true,
4111 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324112 SetLayerPropertiesForTesting(child1.get(),
4113 identity_matrix,
[email protected]a2566412014-06-05 03:14:204114 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324115 gfx::PointF(),
4116 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574117 true,
[email protected]fb661802013-03-25 01:59:324118 false);
4119 SetLayerPropertiesForTesting(child2.get(),
4120 identity_matrix,
[email protected]a2566412014-06-05 03:14:204121 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324122 gfx::PointF(),
4123 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574124 true,
[email protected]fb661802013-03-25 01:59:324125 false);
4126
[email protected]a9d4d4f2014-06-19 06:49:284127 front_facing_surface->Set3dSortingContextId(1);
4128 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574129
[email protected]989386c2013-07-18 21:37:234130 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534131 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4132 parent.get(), parent->bounds(), &render_surface_layer_list);
4133 inputs.can_adjust_raster_scales = true;
4134 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324135
awoloszyne83f28c2014-12-22 15:40:004136 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:324137 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:004138
4139 // We expect the render surface to have been created, but remain unused.
4140 EXPECT_TRUE(back_facing_surface->render_surface());
4141 EXPECT_NE(back_facing_surface->render_target(),
4142 back_facing_surface); // because it should be culled
[email protected]fb661802013-03-25 01:59:324143 EXPECT_FALSE(child1->render_surface());
4144 EXPECT_FALSE(child2->render_surface());
4145
4146 // Verify the render_surface_layer_list. The back-facing surface should be
4147 // culled.
4148 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234149 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4150 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324151
4152 // Verify root surface's layer list.
4153 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234154 1u,
4155 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4156 EXPECT_EQ(front_facing_surface->id(),
4157 render_surface_layer_list.at(0)
4158 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324159
4160 // Verify front_facing_surface's layer list.
4161 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234162 2u,
4163 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4164 EXPECT_EQ(front_facing_surface->id(),
4165 render_surface_layer_list.at(1)
4166 ->render_surface()->layer_list().at(0)->id());
4167 EXPECT_EQ(child1->id(),
4168 render_surface_layer_list.at(1)
4169 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324170}
4171
[email protected]fb661802013-03-25 01:59:324172class NoScaleContentLayer : public ContentLayer {
4173 public:
4174 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
4175 return make_scoped_refptr(new NoScaleContentLayer(client));
4176 }
[email protected]94f206c12012-08-25 00:09:144177
dcheng716bedf2014-10-21 09:51:084178 void CalculateContentsScale(float ideal_contents_scale,
4179 float* contents_scale_x,
4180 float* contents_scale_y,
4181 gfx::Size* content_bounds) override {
[email protected]fb661802013-03-25 01:59:324182 // Skip over the ContentLayer to the base Layer class.
4183 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]fb661802013-03-25 01:59:324184 contents_scale_x,
4185 contents_scale_y,
4186 content_bounds);
4187 }
[email protected]94f206c12012-08-25 00:09:144188
[email protected]fb661802013-03-25 01:59:324189 protected:
4190 explicit NoScaleContentLayer(ContentLayerClient* client)
4191 : ContentLayer(client) {}
dcheng716bedf2014-10-21 09:51:084192 ~NoScaleContentLayer() override {}
[email protected]518ee582012-10-24 18:29:444193};
4194
[email protected]fb661802013-03-25 01:59:324195scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
4196 ContentLayerClient* delegate) {
4197 scoped_refptr<NoScaleContentLayer> to_return =
4198 NoScaleContentLayer::Create(delegate);
4199 to_return->SetIsDrawable(true);
4200 return to_return;
[email protected]518ee582012-10-24 18:29:444201}
4202
[email protected]989386c2013-07-18 21:37:234203TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324204 // Verify draw and screen space transforms of layers not in a surface.
4205 MockContentLayerClient delegate;
4206 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144207
sohan.jyotie3bd6192014-10-13 07:13:594208 scoped_refptr<FakePictureLayer> parent =
4209 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324210 SetLayerPropertiesForTesting(parent.get(),
4211 identity_matrix,
[email protected]a2566412014-06-05 03:14:204212 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324213 gfx::PointF(),
4214 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574215 false,
[email protected]fb661802013-03-25 01:59:324216 true);
[email protected]94f206c12012-08-25 00:09:144217
sohan.jyotie3bd6192014-10-13 07:13:594218 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324219 SetLayerPropertiesForTesting(child.get(),
4220 identity_matrix,
[email protected]a2566412014-06-05 03:14:204221 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324222 gfx::PointF(2.f, 2.f),
4223 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574224 false,
[email protected]fb661802013-03-25 01:59:324225 true);
[email protected]94f206c12012-08-25 00:09:144226
sohan.jyotie3bd6192014-10-13 07:13:594227 scoped_refptr<FakePictureLayer> child_empty =
4228 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324229 SetLayerPropertiesForTesting(child_empty.get(),
4230 identity_matrix,
[email protected]a2566412014-06-05 03:14:204231 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324232 gfx::PointF(2.f, 2.f),
4233 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574234 false,
[email protected]fb661802013-03-25 01:59:324235 true);
[email protected]f89f5632012-11-14 23:34:454236
[email protected]fb661802013-03-25 01:59:324237 parent->AddChild(child);
4238 parent->AddChild(child_empty);
[email protected]94f206c12012-08-25 00:09:144239
enne2097cab2014-09-25 20:16:314240 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284241 host->SetRootLayer(parent);
4242
[email protected]fb661802013-03-25 01:59:324243 float device_scale_factor = 2.5f;
4244 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:144245
[email protected]7aad55f2013-07-26 11:25:534246 RenderSurfaceLayerList render_surface_layer_list;
4247 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4248 parent.get(), parent->bounds(), &render_surface_layer_list);
4249 inputs.device_scale_factor = device_scale_factor;
4250 inputs.page_scale_factor = page_scale_factor;
4251 inputs.can_adjust_raster_scales = true;
4252 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444253
sohan.jyotie3bd6192014-10-13 07:13:594254 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4255 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4256 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty);
[email protected]94f206c12012-08-25 00:09:144257
[email protected]fb661802013-03-25 01:59:324258 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:144259
[email protected]fb661802013-03-25 01:59:324260 // Verify parent transforms
4261 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594262 expected_parent_transform.Scale(device_scale_factor * page_scale_factor,
4263 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324264 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4265 parent->screen_space_transform());
4266 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4267 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:144268
[email protected]fb661802013-03-25 01:59:324269 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054270 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:144271
[email protected]fb661802013-03-25 01:59:324272 gfx::RectF parent_draw_rect =
4273 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4274 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4275 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:144276
[email protected]2c7c6702013-03-26 03:14:054277 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324278 expected_parent_draw_rect.Scale(device_scale_factor);
4279 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4280 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144281
[email protected]fb661802013-03-25 01:59:324282 // Verify child and child_empty transforms. They should match.
4283 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594284 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4285 expected_child_transform.Translate(child->position().x(),
4286 child->position().y());
[email protected]fb661802013-03-25 01:59:324287 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4288 child->draw_transform());
4289 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4290 child->screen_space_transform());
4291 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4292 child_empty->draw_transform());
4293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4294 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144295
[email protected]fb661802013-03-25 01:59:324296 // Verify results of transformed child and child_empty rects. They should
4297 // match.
[email protected]2c7c6702013-03-26 03:14:054298 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:144299
[email protected]fb661802013-03-25 01:59:324300 gfx::RectF child_draw_rect =
4301 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4302 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4303 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:144304
[email protected]fb661802013-03-25 01:59:324305 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
4306 child_empty->draw_transform(), child_content_bounds);
4307 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4308 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:454309
[email protected]fb661802013-03-25 01:59:324310 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4311 expected_child_draw_rect.Scale(device_scale_factor);
4312 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4313 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4314 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4315 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144316}
4317
[email protected]989386c2013-07-18 21:37:234318TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324319 // Verify draw and screen space transforms of layers in a surface.
4320 MockContentLayerClient delegate;
4321 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:094322
[email protected]fb661802013-03-25 01:59:324323 gfx::Transform perspective_matrix;
4324 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094325
[email protected]fb661802013-03-25 01:59:324326 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054327 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094328
[email protected]9781afa2013-07-17 23:15:324329 scoped_refptr<Layer> root = Layer::Create();
4330
sohan.jyotie3bd6192014-10-13 07:13:594331 scoped_refptr<FakePictureLayer> parent =
4332 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324333 SetLayerPropertiesForTesting(parent.get(),
4334 identity_matrix,
[email protected]a2566412014-06-05 03:14:204335 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324336 gfx::PointF(),
4337 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574338 false,
[email protected]fb661802013-03-25 01:59:324339 true);
[email protected]1b30e8e2012-12-21 02:59:094340
sohan.jyotie3bd6192014-10-13 07:13:594341 scoped_refptr<FakePictureLayer> perspective_surface =
4342 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324343 SetLayerPropertiesForTesting(perspective_surface.get(),
4344 perspective_matrix * scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204345 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324346 gfx::PointF(2.f, 2.f),
4347 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574348 false,
[email protected]fb661802013-03-25 01:59:324349 true);
[email protected]1b30e8e2012-12-21 02:59:094350
sohan.jyotie3bd6192014-10-13 07:13:594351 scoped_refptr<FakePictureLayer> scale_surface =
4352 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324353 SetLayerPropertiesForTesting(scale_surface.get(),
4354 scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204355 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324356 gfx::PointF(2.f, 2.f),
4357 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574358 false,
[email protected]fb661802013-03-25 01:59:324359 true);
[email protected]1b30e8e2012-12-21 02:59:094360
[email protected]fb661802013-03-25 01:59:324361 perspective_surface->SetForceRenderSurface(true);
4362 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:094363
[email protected]fb661802013-03-25 01:59:324364 parent->AddChild(perspective_surface);
4365 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:324366 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:094367
enne2097cab2014-09-25 20:16:314368 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284369 host->SetRootLayer(root);
4370
[email protected]fb661802013-03-25 01:59:324371 float device_scale_factor = 2.5f;
4372 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:094373
[email protected]7aad55f2013-07-26 11:25:534374 RenderSurfaceLayerList render_surface_layer_list;
4375 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4376 root.get(), parent->bounds(), &render_surface_layer_list);
4377 inputs.device_scale_factor = device_scale_factor;
4378 inputs.page_scale_factor = page_scale_factor;
Daniel Chengeea98042014-08-26 00:28:104379 inputs.page_scale_application_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534380 inputs.can_adjust_raster_scales = true;
4381 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:094382
sohan.jyotie3bd6192014-10-13 07:13:594383 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4384 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4385 perspective_surface);
4386 // Ideal scale is the max 2d scale component of the combined transform up to
4387 // the nearest render target. Here this includes the layer transform as well
4388 // as the device and page scale factors.
4389 gfx::Transform transform = scale_small_matrix;
4390 transform.Scale(device_scale_factor * page_scale_factor,
4391 device_scale_factor * page_scale_factor);
4392 gfx::Vector2dF scales =
4393 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4394 float max_2d_scale = std::max(scales.x(), scales.y());
4395 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4396
4397 // The ideal scale will draw 1:1 with its render target space along
4398 // the larger-scale axis.
4399 gfx::Vector2dF target_space_transform_scales =
4400 MathUtil::ComputeTransform2dScaleComponents(
4401 scale_surface->draw_properties().target_space_transform, 0.f);
4402 EXPECT_FLOAT_EQ(max_2d_scale,
4403 std::max(target_space_transform_scales.x(),
4404 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094405
[email protected]fb661802013-03-25 01:59:324406 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:094407
[email protected]fb661802013-03-25 01:59:324408 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594409 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4410 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324411 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4412 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094413
[email protected]fb661802013-03-25 01:59:324414 // The scale for the perspective surface is not known, so it is rendered 1:1
4415 // with the screen, and then scaled during drawing.
4416 gfx::Transform expected_perspective_surface_draw_transform;
4417 expected_perspective_surface_draw_transform.Translate(
4418 device_scale_factor * page_scale_factor *
4419 perspective_surface->position().x(),
4420 device_scale_factor * page_scale_factor *
4421 perspective_surface->position().y());
4422 expected_perspective_surface_draw_transform.PreconcatTransform(
4423 perspective_matrix);
4424 expected_perspective_surface_draw_transform.PreconcatTransform(
4425 scale_small_matrix);
4426 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594427 expected_perspective_surface_layer_draw_transform.Scale(
4428 device_scale_factor * page_scale_factor,
4429 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324430 EXPECT_TRANSFORMATION_MATRIX_EQ(
4431 expected_perspective_surface_draw_transform,
4432 perspective_surface->render_surface()->draw_transform());
4433 EXPECT_TRANSFORMATION_MATRIX_EQ(
4434 expected_perspective_surface_layer_draw_transform,
4435 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094436}
4437
sohan.jyotie3bd6192014-10-13 07:13:594438// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234439TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324440 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
4441 // Verify draw and screen space transforms of layers not in a surface.
4442 MockContentLayerClient delegate;
4443 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474444
[email protected]fb661802013-03-25 01:59:324445 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4446 SetLayerPropertiesForTesting(parent.get(),
4447 identity_matrix,
[email protected]a2566412014-06-05 03:14:204448 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324449 gfx::PointF(),
4450 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:574451 false,
[email protected]fb661802013-03-25 01:59:324452 true);
[email protected]904e9132012-11-01 00:12:474453
[email protected]fb661802013-03-25 01:59:324454 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
4455 SetLayerPropertiesForTesting(child.get(),
4456 identity_matrix,
[email protected]a2566412014-06-05 03:14:204457 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324458 gfx::PointF(),
4459 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574460 false,
[email protected]fb661802013-03-25 01:59:324461 true);
[email protected]904e9132012-11-01 00:12:474462
[email protected]fb661802013-03-25 01:59:324463 scoped_refptr<NoScaleContentLayer> child_no_scale =
4464 CreateNoScaleDrawableContentLayer(&delegate);
4465 SetLayerPropertiesForTesting(child_no_scale.get(),
4466 identity_matrix,
[email protected]a2566412014-06-05 03:14:204467 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324468 gfx::PointF(),
4469 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574470 false,
[email protected]fb661802013-03-25 01:59:324471 true);
[email protected]904e9132012-11-01 00:12:474472
[email protected]fb661802013-03-25 01:59:324473 parent->AddChild(child);
4474 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:474475
enne2097cab2014-09-25 20:16:314476 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284477 host->SetRootLayer(parent);
4478
[email protected]fb661802013-03-25 01:59:324479 float device_scale_factor = 1.7f;
4480 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:474481
[email protected]7aad55f2013-07-26 11:25:534482 RenderSurfaceLayerList render_surface_layer_list;
4483 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4484 parent.get(), parent->bounds(), &render_surface_layer_list);
4485 inputs.device_scale_factor = device_scale_factor;
4486 inputs.page_scale_factor = page_scale_factor;
4487 inputs.page_scale_application_layer = parent.get();
4488 inputs.can_adjust_raster_scales = true;
4489 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:474490
[email protected]fb661802013-03-25 01:59:324491 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4492 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4493 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:474494
[email protected]fb661802013-03-25 01:59:324495 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:474496
[email protected]fb661802013-03-25 01:59:324497 // Verify parent transforms
4498 gfx::Transform expected_parent_transform;
4499 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4500 parent->screen_space_transform());
4501 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4502 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:474503
[email protected]fb661802013-03-25 01:59:324504 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054505 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:474506
[email protected]fb661802013-03-25 01:59:324507 gfx::RectF parent_draw_rect =
4508 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4509 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4510 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:474511
[email protected]2c7c6702013-03-26 03:14:054512 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324513 expected_parent_draw_rect.Scale(device_scale_factor);
4514 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
4515 expected_parent_draw_rect.set_height(
4516 ceil(expected_parent_draw_rect.height()));
4517 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4518 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474519
[email protected]fb661802013-03-25 01:59:324520 // Verify child transforms
4521 gfx::Transform expected_child_transform;
4522 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4523 child->draw_transform());
4524 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4525 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474526
[email protected]fb661802013-03-25 01:59:324527 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:054528 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:474529
[email protected]fb661802013-03-25 01:59:324530 gfx::RectF child_draw_rect =
4531 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4532 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4533 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:474534
[email protected]2c7c6702013-03-26 03:14:054535 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:324536 expected_child_draw_rect.Scale(device_scale_factor);
4537 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
4538 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
4539 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4540 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474541
[email protected]fb661802013-03-25 01:59:324542 // Verify child_no_scale transforms
4543 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4544 // All transforms operate on content rects. The child's content rect
4545 // incorporates device scale, but the child_no_scale does not; add it here.
4546 expected_child_no_scale_transform.Scale(device_scale_factor,
4547 device_scale_factor);
4548 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4549 child_no_scale->draw_transform());
4550 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4551 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474552}
4553
sohan.jyotie3bd6192014-10-13 07:13:594554// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234555TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:324556 MockContentLayerClient delegate;
4557 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444558
[email protected]fb661802013-03-25 01:59:324559 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264560 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324561 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444562
[email protected]fb661802013-03-25 01:59:324563 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264564 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324565 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444566
[email protected]35a99a12013-05-09 23:52:294567 scoped_refptr<Layer> root = Layer::Create();
4568 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444569
[email protected]fb661802013-03-25 01:59:324570 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4571 SetLayerPropertiesForTesting(parent.get(),
4572 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204573 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324574 gfx::PointF(),
4575 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574576 false,
[email protected]fb661802013-03-25 01:59:324577 true);
[email protected]518ee582012-10-24 18:29:444578
[email protected]fb661802013-03-25 01:59:324579 scoped_refptr<ContentLayer> child_scale =
4580 CreateDrawableContentLayer(&delegate);
4581 SetLayerPropertiesForTesting(child_scale.get(),
4582 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204583 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324584 gfx::PointF(2.f, 2.f),
4585 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574586 false,
[email protected]fb661802013-03-25 01:59:324587 true);
[email protected]518ee582012-10-24 18:29:444588
[email protected]fb661802013-03-25 01:59:324589 scoped_refptr<ContentLayer> child_empty =
4590 CreateDrawableContentLayer(&delegate);
4591 SetLayerPropertiesForTesting(child_empty.get(),
4592 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204593 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324594 gfx::PointF(2.f, 2.f),
4595 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574596 false,
[email protected]fb661802013-03-25 01:59:324597 true);
[email protected]f89f5632012-11-14 23:34:454598
[email protected]fb661802013-03-25 01:59:324599 scoped_refptr<NoScaleContentLayer> child_no_scale =
4600 CreateNoScaleDrawableContentLayer(&delegate);
4601 SetLayerPropertiesForTesting(child_no_scale.get(),
4602 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204603 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324604 gfx::PointF(12.f, 12.f),
4605 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574606 false,
[email protected]fb661802013-03-25 01:59:324607 true);
[email protected]518ee582012-10-24 18:29:444608
[email protected]35a99a12013-05-09 23:52:294609 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444610
[email protected]fb661802013-03-25 01:59:324611 parent->AddChild(child_scale);
4612 parent->AddChild(child_empty);
4613 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:444614
enne2097cab2014-09-25 20:16:314615 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284616 host->SetRootLayer(root);
4617
[email protected]fb661802013-03-25 01:59:324618 float device_scale_factor = 2.5f;
4619 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:444620
[email protected]989386c2013-07-18 21:37:234621 {
4622 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534623 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224624 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534625 inputs.device_scale_factor = device_scale_factor;
4626 inputs.page_scale_factor = page_scale_factor;
4627 inputs.page_scale_application_layer = root.get();
4628 inputs.can_adjust_raster_scales = true;
4629 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444630
[email protected]989386c2013-07-18 21:37:234631 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4632 initial_parent_scale, parent);
4633 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4634 initial_parent_scale * initial_child_scale,
4635 child_scale);
4636 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4637 initial_parent_scale * initial_child_scale,
4638 child_empty);
4639 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:444640
[email protected]989386c2013-07-18 21:37:234641 // The parent is scaled up and shouldn't need to scale during draw. The
4642 // child that can scale its contents should also not need to scale during
4643 // draw. This shouldn't change if the child has empty bounds. The other
4644 // children should.
[email protected]803f6b52013-09-12 00:51:264645 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4646 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
4647 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
4648 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
4649 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
4650 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234651 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
4652 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264653 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:234654 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264655 initial_parent_scale * initial_child_scale,
4656 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234657 }
[email protected]518ee582012-10-24 18:29:444658
[email protected]fb661802013-03-25 01:59:324659 // If the device_scale_factor or page_scale_factor changes, then it should be
4660 // updated using the initial transform as the raster scale.
4661 device_scale_factor = 2.25f;
4662 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:444663
[email protected]989386c2013-07-18 21:37:234664 {
4665 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534666 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224667 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534668 inputs.device_scale_factor = device_scale_factor;
4669 inputs.page_scale_factor = page_scale_factor;
4670 inputs.page_scale_application_layer = root.get();
4671 inputs.can_adjust_raster_scales = true;
4672 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4673
4674 EXPECT_CONTENTS_SCALE_EQ(
4675 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:234676 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534677 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:234678 child_scale);
4679 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4680 initial_parent_scale * initial_child_scale,
4681 child_empty);
4682 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4683 }
[email protected]d0518202013-02-08 02:06:494684
[email protected]fb661802013-03-25 01:59:324685 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:264686 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324687 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
4688 second_child_scale / initial_child_scale);
4689 child_scale->SetTransform(child_scale_matrix);
4690 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:494691
[email protected]989386c2013-07-18 21:37:234692 {
4693 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534694 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224695 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534696 inputs.device_scale_factor = device_scale_factor;
4697 inputs.page_scale_factor = page_scale_factor;
4698 inputs.page_scale_application_layer = root.get();
4699 inputs.can_adjust_raster_scales = true;
4700 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494701
[email protected]989386c2013-07-18 21:37:234702 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4703 initial_parent_scale,
4704 parent);
4705 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4706 child_scale);
4707 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4708 child_empty);
4709 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4710 }
[email protected]d0518202013-02-08 02:06:494711
[email protected]fb661802013-03-25 01:59:324712 // If the device_scale_factor or page_scale_factor changes, then it should be
4713 // updated, but still using 1.0 as the raster scale.
4714 device_scale_factor = 2.75f;
4715 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:494716
[email protected]989386c2013-07-18 21:37:234717 {
4718 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534719 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224720 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534721 inputs.device_scale_factor = device_scale_factor;
4722 inputs.page_scale_factor = page_scale_factor;
4723 inputs.page_scale_application_layer = root.get();
4724 inputs.can_adjust_raster_scales = true;
4725 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494726
[email protected]989386c2013-07-18 21:37:234727 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4728 initial_parent_scale,
4729 parent);
4730 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4731 child_scale);
4732 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4733 child_empty);
4734 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4735 }
[email protected]518ee582012-10-24 18:29:444736}
4737
sohan.jyotie3bd6192014-10-13 07:13:594738// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234739TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:594740 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:324741 MockContentLayerClient delegate;
4742 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:214743
[email protected]fb661802013-03-25 01:59:324744 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264745 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324746 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:214747
[email protected]fb661802013-03-25 01:59:324748 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264749 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324750 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:214751
[email protected]35a99a12013-05-09 23:52:294752 scoped_refptr<Layer> root = Layer::Create();
4753 root->SetBounds(gfx::Size(100, 100));
4754
[email protected]fb661802013-03-25 01:59:324755 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4756 SetLayerPropertiesForTesting(parent.get(),
4757 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204758 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324759 gfx::PointF(),
4760 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574761 false,
[email protected]fb661802013-03-25 01:59:324762 true);
[email protected]11ec92972012-11-10 03:06:214763
[email protected]fb661802013-03-25 01:59:324764 scoped_refptr<ContentLayer> child_scale =
4765 CreateDrawableContentLayer(&delegate);
4766 SetLayerPropertiesForTesting(child_scale.get(),
4767 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204768 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324769 gfx::PointF(2.f, 2.f),
4770 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574771 false,
[email protected]fb661802013-03-25 01:59:324772 true);
[email protected]11ec92972012-11-10 03:06:214773
[email protected]35a99a12013-05-09 23:52:294774 scoped_refptr<ContentLayer> child_empty =
4775 CreateDrawableContentLayer(&delegate);
4776 SetLayerPropertiesForTesting(child_empty.get(),
4777 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204778 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294779 gfx::PointF(2.f, 2.f),
4780 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574781 false,
[email protected]35a99a12013-05-09 23:52:294782 true);
4783
4784 scoped_refptr<NoScaleContentLayer> child_no_scale =
4785 CreateNoScaleDrawableContentLayer(&delegate);
4786 SetLayerPropertiesForTesting(child_no_scale.get(),
4787 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204788 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294789 gfx::PointF(12.f, 12.f),
4790 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574791 false,
[email protected]35a99a12013-05-09 23:52:294792 true);
4793
4794 root->AddChild(parent);
4795
4796 parent->AddChild(child_scale);
4797 parent->AddChild(child_empty);
4798 parent->AddChild(child_no_scale);
4799
enne2097cab2014-09-25 20:16:314800 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284801 host->SetRootLayer(root);
4802
[email protected]989386c2013-07-18 21:37:234803 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:294804
4805 float device_scale_factor = 2.5f;
4806 float page_scale_factor = 1.f;
4807
[email protected]7aad55f2013-07-26 11:25:534808 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224809 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534810 inputs.device_scale_factor = device_scale_factor;
4811 inputs.page_scale_factor = page_scale_factor;
4812 inputs.page_scale_application_layer = root.get(),
4813 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:294814
4815 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4816 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4817 child_scale);
4818 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4819 child_empty);
4820 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4821
4822 // Since the transform scale does not affect contents scale, it should affect
4823 // the draw transform instead.
4824 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264825 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294826 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264827 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294828 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264829 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294830 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264831 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294832 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264833 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294834 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264835 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294836 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264837 initial_parent_scale * initial_child_scale,
4838 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294839 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264840 initial_parent_scale * initial_child_scale,
4841 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294842}
4843
sohan.jyotie3bd6192014-10-13 07:13:594844TEST_F(LayerTreeHostCommonTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294845 MockContentLayerClient delegate;
4846 gfx::Transform identity_matrix;
4847
4848 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264849 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294850 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4851
4852 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264853 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294854 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4855
4856 scoped_refptr<Layer> root = Layer::Create();
4857 root->SetBounds(gfx::Size(100, 100));
4858
sohan.jyotie3bd6192014-10-13 07:13:594859 scoped_refptr<FakePictureLayer> parent =
4860 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294861 SetLayerPropertiesForTesting(parent.get(),
4862 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204863 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294864 gfx::PointF(),
4865 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574866 false,
[email protected]35a99a12013-05-09 23:52:294867 true);
4868
sohan.jyotie3bd6192014-10-13 07:13:594869 scoped_refptr<FakePictureLayer> child_scale =
4870 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294871 SetLayerPropertiesForTesting(child_scale.get(),
4872 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204873 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294874 gfx::PointF(2.f, 2.f),
4875 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574876 false,
[email protected]35a99a12013-05-09 23:52:294877 true);
4878
4879 root->AddChild(parent);
4880
[email protected]fb661802013-03-25 01:59:324881 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:214882
enne2097cab2014-09-25 20:16:314883 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284884 host->SetRootLayer(root);
4885
[email protected]fb661802013-03-25 01:59:324886 float device_scale_factor = 2.5f;
4887 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214888
[email protected]989386c2013-07-18 21:37:234889 {
4890 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534891 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224892 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534893 inputs.device_scale_factor = device_scale_factor;
4894 inputs.page_scale_factor = page_scale_factor;
4895 inputs.page_scale_application_layer = root.get();
4896 inputs.can_adjust_raster_scales = true;
4897 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214898
sohan.jyotie3bd6192014-10-13 07:13:594899 // The ideal scale is able to go below 1.
4900 float expected_ideal_scale =
4901 device_scale_factor * page_scale_factor * initial_parent_scale;
4902 EXPECT_LT(expected_ideal_scale, 1.f);
4903 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214904
sohan.jyotie3bd6192014-10-13 07:13:594905 expected_ideal_scale = device_scale_factor * page_scale_factor *
4906 initial_parent_scale * initial_child_scale;
4907 EXPECT_LT(expected_ideal_scale, 1.f);
4908 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234909 }
[email protected]11ec92972012-11-10 03:06:214910}
4911
[email protected]989386c2013-07-18 21:37:234912TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:324913 MockContentLayerClient delegate;
4914 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444915
[email protected]fb661802013-03-25 01:59:324916 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264917 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:324918 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444919
[email protected]fb661802013-03-25 01:59:324920 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264921 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:324922 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444923
[email protected]35a99a12013-05-09 23:52:294924 scoped_refptr<Layer> root = Layer::Create();
4925 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444926
[email protected]fb661802013-03-25 01:59:324927 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4928 SetLayerPropertiesForTesting(parent.get(),
4929 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204930 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324931 gfx::PointF(),
4932 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574933 false,
[email protected]fb661802013-03-25 01:59:324934 true);
[email protected]518ee582012-10-24 18:29:444935
[email protected]fb661802013-03-25 01:59:324936 scoped_refptr<ContentLayer> surface_scale =
4937 CreateDrawableContentLayer(&delegate);
4938 SetLayerPropertiesForTesting(surface_scale.get(),
4939 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204940 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324941 gfx::PointF(2.f, 2.f),
4942 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574943 false,
[email protected]fb661802013-03-25 01:59:324944 true);
[email protected]518ee582012-10-24 18:29:444945
[email protected]fb661802013-03-25 01:59:324946 scoped_refptr<ContentLayer> surface_scale_child_scale =
4947 CreateDrawableContentLayer(&delegate);
4948 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
4949 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204950 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324951 gfx::PointF(),
4952 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574953 false,
[email protected]fb661802013-03-25 01:59:324954 true);
[email protected]518ee582012-10-24 18:29:444955
[email protected]fb661802013-03-25 01:59:324956 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
4957 CreateNoScaleDrawableContentLayer(&delegate);
4958 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
4959 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204960 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324961 gfx::PointF(),
4962 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574963 false,
[email protected]fb661802013-03-25 01:59:324964 true);
[email protected]518ee582012-10-24 18:29:444965
[email protected]fb661802013-03-25 01:59:324966 scoped_refptr<NoScaleContentLayer> surface_no_scale =
4967 CreateNoScaleDrawableContentLayer(&delegate);
4968 SetLayerPropertiesForTesting(surface_no_scale.get(),
4969 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204970 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324971 gfx::PointF(12.f, 12.f),
4972 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574973 false,
[email protected]fb661802013-03-25 01:59:324974 true);
[email protected]518ee582012-10-24 18:29:444975
[email protected]fb661802013-03-25 01:59:324976 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
4977 CreateDrawableContentLayer(&delegate);
4978 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
4979 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204980 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324981 gfx::PointF(),
4982 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574983 false,
[email protected]fb661802013-03-25 01:59:324984 true);
[email protected]518ee582012-10-24 18:29:444985
[email protected]fb661802013-03-25 01:59:324986 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
4987 CreateNoScaleDrawableContentLayer(&delegate);
4988 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
4989 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204990 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324991 gfx::PointF(),
4992 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574993 false,
[email protected]fb661802013-03-25 01:59:324994 true);
[email protected]518ee582012-10-24 18:29:444995
[email protected]35a99a12013-05-09 23:52:294996 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444997
[email protected]fb661802013-03-25 01:59:324998 parent->AddChild(surface_scale);
4999 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:445000
[email protected]fb661802013-03-25 01:59:325001 surface_scale->SetForceRenderSurface(true);
5002 surface_scale->AddChild(surface_scale_child_scale);
5003 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445004
[email protected]fb661802013-03-25 01:59:325005 surface_no_scale->SetForceRenderSurface(true);
5006 surface_no_scale->AddChild(surface_no_scale_child_scale);
5007 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445008
enne2097cab2014-09-25 20:16:315009 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285010 host->SetRootLayer(root);
5011
[email protected]803f6b52013-09-12 00:51:265012 SkMScalar device_scale_factor = 5;
5013 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:445014
[email protected]7aad55f2013-07-26 11:25:535015 RenderSurfaceLayerList render_surface_layer_list;
5016 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225017 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535018 inputs.device_scale_factor = device_scale_factor;
5019 inputs.page_scale_factor = page_scale_factor;
5020 inputs.page_scale_application_layer = root.get();
5021 inputs.can_adjust_raster_scales = true;
5022 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5023
5024 EXPECT_CONTENTS_SCALE_EQ(
5025 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:195026 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:535027 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:325028 surface_scale);
5029 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
5030 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:325031 device_scale_factor * page_scale_factor * initial_parent_scale *
5032 initial_child_scale * initial_child_scale,
5033 surface_scale_child_scale);
5034 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
5035 EXPECT_CONTENTS_SCALE_EQ(
5036 device_scale_factor * page_scale_factor * initial_parent_scale *
5037 initial_child_scale * initial_child_scale,
5038 surface_no_scale_child_scale);
5039 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445040
[email protected]fb661802013-03-25 01:59:325041 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:265042 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
5043 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445044
[email protected]fb661802013-03-25 01:59:325045 // RenderSurfaces should always be 1:1 with their target.
5046 EXPECT_FLOAT_EQ(
5047 1.0,
[email protected]803f6b52013-09-12 00:51:265048 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325049 EXPECT_FLOAT_EQ(
5050 1.0,
[email protected]803f6b52013-09-12 00:51:265051 surface_scale->render_surface()->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 can apply contents scale so the layer shouldn't need to
5054 // scale during draw.
[email protected]803f6b52013-09-12 00:51:265055 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
5056 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445057
[email protected]fb661802013-03-25 01:59:325058 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5059 // to scale during draw.
5060 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265061 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325062 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265063 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445064
[email protected]fb661802013-03-25 01:59:325065 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5066 // to be scaled during draw.
5067 EXPECT_FLOAT_EQ(
5068 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265069 initial_child_scale * initial_child_scale,
5070 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325071 EXPECT_FLOAT_EQ(
5072 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265073 initial_child_scale * initial_child_scale,
5074 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445075
[email protected]fb661802013-03-25 01:59:325076 // RenderSurfaces should always be 1:1 with their target.
5077 EXPECT_FLOAT_EQ(
5078 1.0,
[email protected]803f6b52013-09-12 00:51:265079 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325080 EXPECT_FLOAT_EQ(
5081 1.0,
[email protected]803f6b52013-09-12 00:51:265082 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445083
[email protected]fb661802013-03-25 01:59:325084 // The surface_no_scale layer can not apply contents scale, so it needs to be
5085 // scaled during draw.
5086 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265087 initial_parent_scale * initial_child_scale,
5088 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325089 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265090 initial_parent_scale * initial_child_scale,
5091 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445092
[email protected]fb661802013-03-25 01:59:325093 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5094 // to scale during draw.
5095 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265096 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325097 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265098 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445099
[email protected]fb661802013-03-25 01:59:325100 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5101 // to be scaled during draw.
5102 EXPECT_FLOAT_EQ(
5103 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265104 initial_child_scale * initial_child_scale,
5105 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325106 EXPECT_FLOAT_EQ(
5107 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265108 initial_child_scale * initial_child_scale,
5109 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295110}
[email protected]518ee582012-10-24 18:29:445111
sohan.jyotie3bd6192014-10-13 07:13:595112// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:235113TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:595114 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
[email protected]35a99a12013-05-09 23:52:295115 MockContentLayerClient delegate;
5116 gfx::Transform identity_matrix;
5117
5118 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265119 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:295120 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5121
5122 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265123 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:295124 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5125
5126 scoped_refptr<Layer> root = Layer::Create();
5127 root->SetBounds(gfx::Size(100, 100));
5128
5129 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5130 SetLayerPropertiesForTesting(parent.get(),
5131 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205132 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295133 gfx::PointF(),
5134 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575135 false,
[email protected]35a99a12013-05-09 23:52:295136 true);
5137
5138 scoped_refptr<ContentLayer> surface_scale =
5139 CreateDrawableContentLayer(&delegate);
5140 SetLayerPropertiesForTesting(surface_scale.get(),
5141 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205142 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295143 gfx::PointF(2.f, 2.f),
5144 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575145 false,
[email protected]35a99a12013-05-09 23:52:295146 true);
5147
5148 scoped_refptr<ContentLayer> surface_scale_child_scale =
5149 CreateDrawableContentLayer(&delegate);
5150 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5151 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205152 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295153 gfx::PointF(),
5154 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575155 false,
[email protected]35a99a12013-05-09 23:52:295156 true);
5157
5158 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
5159 CreateNoScaleDrawableContentLayer(&delegate);
5160 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5161 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205162 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295163 gfx::PointF(),
5164 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575165 false,
[email protected]35a99a12013-05-09 23:52:295166 true);
5167
5168 scoped_refptr<NoScaleContentLayer> surface_no_scale =
5169 CreateNoScaleDrawableContentLayer(&delegate);
5170 SetLayerPropertiesForTesting(surface_no_scale.get(),
5171 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205172 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295173 gfx::PointF(12.f, 12.f),
5174 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575175 false,
[email protected]35a99a12013-05-09 23:52:295176 true);
5177
5178 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
5179 CreateDrawableContentLayer(&delegate);
5180 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5181 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205182 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295183 gfx::PointF(),
5184 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575185 false,
[email protected]35a99a12013-05-09 23:52:295186 true);
5187
5188 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
5189 CreateNoScaleDrawableContentLayer(&delegate);
5190 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5191 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205192 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295193 gfx::PointF(),
5194 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575195 false,
[email protected]35a99a12013-05-09 23:52:295196 true);
5197
5198 root->AddChild(parent);
5199
5200 parent->AddChild(surface_scale);
5201 parent->AddChild(surface_no_scale);
5202
5203 surface_scale->SetForceRenderSurface(true);
5204 surface_scale->AddChild(surface_scale_child_scale);
5205 surface_scale->AddChild(surface_scale_child_no_scale);
5206
5207 surface_no_scale->SetForceRenderSurface(true);
5208 surface_no_scale->AddChild(surface_no_scale_child_scale);
5209 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
5210
enne2097cab2014-09-25 20:16:315211 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285212 host->SetRootLayer(root);
5213
[email protected]989386c2013-07-18 21:37:235214 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:295215
[email protected]803f6b52013-09-12 00:51:265216 SkMScalar device_scale_factor = 5.0;
5217 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:535218 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225219 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535220 inputs.device_scale_factor = device_scale_factor;
5221 inputs.page_scale_factor = page_scale_factor;
5222 inputs.page_scale_application_layer = root.get();
5223 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:295224
[email protected]35a99a12013-05-09 23:52:295225 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5226 parent);
5227 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5228 surface_scale);
5229 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
5230 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5231 surface_scale_child_scale);
5232 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
5233 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5234 surface_no_scale_child_scale);
5235 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
5236
5237 // The parent is scaled up during draw, since its contents are not scaled by
5238 // the transform hierarchy.
5239 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265240 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295241 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265242 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295243
hendrikwc493d2682015-01-26 23:35:115244 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295245 // by the transform hierarchy.
5246 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115247 1.f,
[email protected]803f6b52013-09-12 00:51:265248 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295249 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115250 1.f,
[email protected]803f6b52013-09-12 00:51:265251 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295252
hendrikwc493d2682015-01-26 23:35:115253 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5254 // needs to be scaled when drawing into its surface.
5255 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5256 surface_scale->draw_transform().matrix().get(0, 0));
5257 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5258 surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445259
hendrikwc493d2682015-01-26 23:35:115260 // The surface_scale_child_scale is not scaled when drawing into its surface,
5261 // since its content bounds are scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:325262 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115263 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265264 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325265 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115266 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265267 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445268
hendrikwc493d2682015-01-26 23:35:115269 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5270 // and transform hierarchy.
[email protected]fb661802013-03-25 01:59:325271 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115272 device_scale_factor * page_scale_factor * initial_parent_scale *
5273 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265274 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295275 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115276 device_scale_factor * page_scale_factor * initial_parent_scale *
5277 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265278 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295279
hendrikwc493d2682015-01-26 23:35:115280 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295281 // by the transform hierarchy.
5282 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115283 1.f,
[email protected]803f6b52013-09-12 00:51:265284 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325285 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115286 1.f,
[email protected]803f6b52013-09-12 00:51:265287 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445288
[email protected]35a99a12013-05-09 23:52:295289 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5290 // be scaled by the device and page scale factors. Its surface is already
5291 // scaled by the transform hierarchy so those don't need to scale the layer's
5292 // drawing.
hendrikwc493d2682015-01-26 23:35:115293 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5294 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265295 surface_no_scale->draw_transform().matrix().get(0, 0));
hendrikwc493d2682015-01-26 23:35:115296 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5297 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265298 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295299
5300 // The surface_no_scale_child_scale has its contents scaled by the page and
5301 // device scale factors, but needs to be scaled by the transform hierarchy
5302 // when drawing.
[email protected]fb661802013-03-25 01:59:325303 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115304 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265305 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325306 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115307 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265308 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295309
hendrikwc493d2682015-01-26 23:35:115310 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5311 // page scale factors and by any transform heirarchy below its target surface.
[email protected]35a99a12013-05-09 23:52:295312 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115313 device_scale_factor * page_scale_factor * initial_parent_scale *
5314 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265315 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295316 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115317 device_scale_factor * page_scale_factor * initial_parent_scale *
5318 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265319 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445320}
5321
sohan.jyotie3bd6192014-10-13 07:13:595322TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:325323 MockContentLayerClient delegate;
5324 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265325
[email protected]fb661802013-03-25 01:59:325326 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265327 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:325328 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:265329
[email protected]fb661802013-03-25 01:59:325330 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265331 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:325332 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:265333
[email protected]35a99a12013-05-09 23:52:295334 scoped_refptr<Layer> root = Layer::Create();
5335 root->SetBounds(gfx::Size(100, 100));
5336
sohan.jyotie3bd6192014-10-13 07:13:595337 scoped_refptr<FakePictureLayer> parent =
5338 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325339 SetLayerPropertiesForTesting(parent.get(),
5340 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205341 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325342 gfx::PointF(),
5343 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575344 false,
[email protected]fb661802013-03-25 01:59:325345 true);
[email protected]6a9cff92012-11-08 11:53:265346
sohan.jyotie3bd6192014-10-13 07:13:595347 scoped_refptr<FakePictureLayer> child_scale =
5348 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325349 SetLayerPropertiesForTesting(child_scale.get(),
5350 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205351 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325352 gfx::PointF(2.f, 2.f),
5353 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575354 false,
[email protected]fb661802013-03-25 01:59:325355 true);
[email protected]6a9cff92012-11-08 11:53:265356
[email protected]35a99a12013-05-09 23:52:295357 root->AddChild(parent);
5358
[email protected]fb661802013-03-25 01:59:325359 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:265360
enne2097cab2014-09-25 20:16:315361 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285362 host->SetRootLayer(root);
5363
[email protected]989386c2013-07-18 21:37:235364 {
5365 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535366 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225367 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535368 inputs.can_adjust_raster_scales = true;
5369 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265370
sohan.jyotie3bd6192014-10-13 07:13:595371 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
5372 // Animating layers compute ideal scale in the same way as when
5373 // they are static.
5374 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
5375 child_scale);
[email protected]989386c2013-07-18 21:37:235376 }
[email protected]6a9cff92012-11-08 11:53:265377}
5378
sohan.jyotie3bd6192014-10-13 07:13:595379// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]7a5a9322014-02-25 12:54:575380TEST_F(LayerTreeHostCommonTest,
5381 ChangeInContentBoundsOrScaleTriggersPushProperties) {
5382 MockContentLayerClient delegate;
5383 scoped_refptr<Layer> root = Layer::Create();
5384 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
5385 root->AddChild(child);
5386
enne2097cab2014-09-25 20:16:315387 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]7a5a9322014-02-25 12:54:575388 host->SetRootLayer(root);
5389
5390 gfx::Transform identity_matrix;
5391 SetLayerPropertiesForTesting(root.get(),
5392 identity_matrix,
[email protected]a2566412014-06-05 03:14:205393 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575394 gfx::PointF(),
5395 gfx::Size(100, 100),
5396 true,
5397 false);
5398 SetLayerPropertiesForTesting(child.get(),
5399 identity_matrix,
[email protected]a2566412014-06-05 03:14:205400 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575401 gfx::PointF(),
5402 gfx::Size(100, 100),
5403 true,
5404 false);
5405
5406 root->reset_needs_push_properties_for_testing();
5407 child->reset_needs_push_properties_for_testing();
5408
5409 // This will change both layers' content bounds.
5410 ExecuteCalculateDrawProperties(root.get());
5411 EXPECT_TRUE(root->needs_push_properties());
5412 EXPECT_TRUE(child->needs_push_properties());
5413
5414 root->reset_needs_push_properties_for_testing();
5415 child->reset_needs_push_properties_for_testing();
5416
5417 // This will change only the child layer's contents scale and content bounds,
5418 // since the root layer is not a ContentsScalingLayer.
5419 ExecuteCalculateDrawProperties(root.get(), 2.f);
5420 EXPECT_FALSE(root->needs_push_properties());
5421 EXPECT_TRUE(child->needs_push_properties());
5422
5423 root->reset_needs_push_properties_for_testing();
5424 child->reset_needs_push_properties_for_testing();
5425
5426 // This will not change either layer's contents scale or content bounds.
5427 ExecuteCalculateDrawProperties(root.get(), 2.f);
5428 EXPECT_FALSE(root->needs_push_properties());
5429 EXPECT_FALSE(child->needs_push_properties());
5430}
5431
[email protected]989386c2013-07-18 21:37:235432TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:325433 MockContentLayerClient delegate;
5434 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265435
sohan.jyotie3bd6192014-10-13 07:13:595436 scoped_refptr<FakePictureLayer> parent =
5437 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325438 SetLayerPropertiesForTesting(parent.get(),
5439 identity_matrix,
[email protected]a2566412014-06-05 03:14:205440 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325441 gfx::PointF(),
5442 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575443 false,
[email protected]fb661802013-03-25 01:59:325444 true);
[email protected]94f206c12012-08-25 00:09:145445
sohan.jyotie3bd6192014-10-13 07:13:595446 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325447 SetLayerPropertiesForTesting(child.get(),
5448 identity_matrix,
[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 gfx::Transform replica_transform;
5456 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595457 scoped_refptr<FakePictureLayer> replica =
5458 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325459 SetLayerPropertiesForTesting(replica.get(),
5460 replica_transform,
[email protected]a2566412014-06-05 03:14:205461 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325462 gfx::PointF(2.f, 2.f),
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 // This layer should end up in the same surface as child, with the same draw
5468 // and screen space transforms.
sohan.jyotie3bd6192014-10-13 07:13:595469 scoped_refptr<FakePictureLayer> duplicate_child_non_owner =
5470 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325471 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5472 identity_matrix,
[email protected]a2566412014-06-05 03:14:205473 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325474 gfx::PointF(),
5475 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575476 false,
[email protected]fb661802013-03-25 01:59:325477 true);
[email protected]94f206c12012-08-25 00:09:145478
[email protected]fb661802013-03-25 01:59:325479 parent->AddChild(child);
5480 child->AddChild(duplicate_child_non_owner);
5481 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:145482
enne2097cab2014-09-25 20:16:315483 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285484 host->SetRootLayer(parent);
5485
[email protected]989386c2013-07-18 21:37:235486 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145487
[email protected]fb661802013-03-25 01:59:325488 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:535489 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5490 parent.get(), parent->bounds(), &render_surface_layer_list);
5491 inputs.device_scale_factor = device_scale_factor;
5492 inputs.can_adjust_raster_scales = true;
5493 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145494
[email protected]fb661802013-03-25 01:59:325495 // We should have two render surfaces. The root's render surface and child's
5496 // render surface (it needs one because it has a replica layer).
5497 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:145498
[email protected]fb661802013-03-25 01:59:325499 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:595500 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325501 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5502 parent->screen_space_transform());
5503 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5504 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:145505
[email protected]fb661802013-03-25 01:59:325506 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:595507 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325508 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
5509 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:145510
[email protected]fb661802013-03-25 01:59:325511 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:595512 expected_screen_space_transform.Scale(device_scale_factor,
5513 device_scale_factor);
5514 expected_screen_space_transform.Translate(child->position().x(),
5515 child->position().y());
[email protected]fb661802013-03-25 01:59:325516 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
5517 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145518
[email protected]fb661802013-03-25 01:59:325519 gfx::Transform expected_duplicate_child_draw_transform =
5520 child->draw_transform();
5521 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
5522 duplicate_child_non_owner->draw_transform());
5523 EXPECT_TRANSFORMATION_MATRIX_EQ(
5524 child->screen_space_transform(),
5525 duplicate_child_non_owner->screen_space_transform());
hush6b614212014-12-04 22:37:325526 EXPECT_EQ(child->drawable_content_rect(),
5527 duplicate_child_non_owner->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:325528 EXPECT_EQ(child->content_bounds(),
5529 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:145530
[email protected]fb661802013-03-25 01:59:325531 gfx::Transform expected_render_surface_draw_transform;
5532 expected_render_surface_draw_transform.Translate(
5533 device_scale_factor * child->position().x(),
5534 device_scale_factor * child->position().y());
5535 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
5536 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145537
[email protected]fb661802013-03-25 01:59:325538 gfx::Transform expected_surface_draw_transform;
5539 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5540 device_scale_factor * 2.f);
5541 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5542 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145543
[email protected]fb661802013-03-25 01:59:325544 gfx::Transform expected_surface_screen_space_transform;
5545 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5546 device_scale_factor * 2.f);
5547 EXPECT_TRANSFORMATION_MATRIX_EQ(
5548 expected_surface_screen_space_transform,
5549 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145550
[email protected]fb661802013-03-25 01:59:325551 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265552 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5553 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5554 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325555 EXPECT_TRANSFORMATION_MATRIX_EQ(
5556 expected_replica_draw_transform,
5557 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145558
[email protected]fb661802013-03-25 01:59:325559 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265560 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5561 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5562 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325563 EXPECT_TRANSFORMATION_MATRIX_EQ(
5564 expected_replica_screen_space_transform,
5565 child->render_surface()->replica_screen_space_transform());
5566 EXPECT_TRANSFORMATION_MATRIX_EQ(
5567 expected_replica_screen_space_transform,
5568 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475569}
5570
[email protected]989386c2013-07-18 21:37:235571TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325572 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5573 MockContentLayerClient delegate;
5574 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475575
sohan.jyotie3bd6192014-10-13 07:13:595576 scoped_refptr<FakePictureLayer> parent =
5577 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325578 SetLayerPropertiesForTesting(parent.get(),
5579 identity_matrix,
[email protected]a2566412014-06-05 03:14:205580 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325581 gfx::PointF(),
5582 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:575583 false,
[email protected]fb661802013-03-25 01:59:325584 true);
[email protected]904e9132012-11-01 00:12:475585
sohan.jyotie3bd6192014-10-13 07:13:595586 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325587 SetLayerPropertiesForTesting(child.get(),
5588 identity_matrix,
[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 gfx::Transform replica_transform;
5596 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595597 scoped_refptr<FakePictureLayer> replica =
5598 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325599 SetLayerPropertiesForTesting(replica.get(),
5600 replica_transform,
[email protected]a2566412014-06-05 03:14:205601 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325602 gfx::PointF(),
5603 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575604 false,
[email protected]fb661802013-03-25 01:59:325605 true);
[email protected]904e9132012-11-01 00:12:475606
[email protected]fb661802013-03-25 01:59:325607 parent->AddChild(child);
[email protected]fb661802013-03-25 01:59:325608 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:475609
enne2097cab2014-09-25 20:16:315610 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285611 host->SetRootLayer(parent);
5612
[email protected]873639e2013-07-24 19:56:315613 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:535614
5615 RenderSurfaceLayerList render_surface_layer_list;
5616 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5617 parent.get(), parent->bounds(), &render_surface_layer_list);
5618 inputs.device_scale_factor = device_scale_factor;
5619 inputs.can_adjust_raster_scales = true;
5620 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:475621
[email protected]fb661802013-03-25 01:59:325622 // We should have two render surfaces. The root's render surface and child's
5623 // render surface (it needs one because it has a replica layer).
5624 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:475625
[email protected]fb661802013-03-25 01:59:325626 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325627 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5628 child->render_surface()->draw_transform());
5629 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5630 child->render_surface()->draw_transform());
5631 EXPECT_TRANSFORMATION_MATRIX_EQ(
5632 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475633
[email protected]fb661802013-03-25 01:59:325634 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265635 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325636 EXPECT_TRANSFORMATION_MATRIX_EQ(
5637 expected_replica_draw_transform,
5638 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475639
[email protected]fb661802013-03-25 01:59:325640 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265641 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325642 EXPECT_TRANSFORMATION_MATRIX_EQ(
5643 expected_replica_screen_space_transform,
5644 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145645}
5646
[email protected]989386c2013-07-18 21:37:235647TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:325648 scoped_refptr<Layer> root = Layer::Create();
5649 scoped_refptr<Layer> child = Layer::Create();
5650 scoped_refptr<Layer> grand_child = Layer::Create();
5651 scoped_refptr<Layer> mask_layer = Layer::Create();
5652 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145653
[email protected]fb661802013-03-25 01:59:325654 grand_child->SetReplicaLayer(replica_layer.get());
5655 child->AddChild(grand_child.get());
5656 child->SetMaskLayer(mask_layer.get());
5657 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145658
enne2097cab2014-09-25 20:16:315659 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285660 host->SetRootLayer(root);
5661
[email protected]fb661802013-03-25 01:59:325662 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:105663 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:325664 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:105665 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:325666 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5667 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105668 grand_child.get(),
[email protected]fb661802013-03-25 01:59:325669 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5670 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105671 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:325672 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5673 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105674 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:325675 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5676 EXPECT_EQ(
5677 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145678}
5679
[email protected]989386c2013-07-18 21:37:235680TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:325681 scoped_refptr<Layer> root = Layer::Create();
5682 scoped_refptr<Layer> child = Layer::Create();
5683 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
5684 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:575685
[email protected]fb661802013-03-25 01:59:325686 const gfx::Transform identity_matrix;
5687 SetLayerPropertiesForTesting(root.get(),
5688 identity_matrix,
[email protected]a2566412014-06-05 03:14:205689 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325690 gfx::PointF(),
5691 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575692 true,
[email protected]fb661802013-03-25 01:59:325693 false);
5694 SetLayerPropertiesForTesting(child.get(),
5695 identity_matrix,
[email protected]a2566412014-06-05 03:14:205696 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325697 gfx::PointF(),
5698 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575699 true,
[email protected]fb661802013-03-25 01:59:325700 false);
5701 SetLayerPropertiesForTesting(grand_child.get(),
5702 identity_matrix,
[email protected]a2566412014-06-05 03:14:205703 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325704 gfx::PointF(),
5705 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575706 true,
[email protected]fb661802013-03-25 01:59:325707 false);
[email protected]498ec6e0e2012-11-30 18:24:575708
[email protected]fb661802013-03-25 01:59:325709 root->AddChild(child);
5710 child->AddChild(grand_child);
5711 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575712
enne2097cab2014-09-25 20:16:315713 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285714 host->SetRootLayer(root);
5715
[email protected]fb661802013-03-25 01:59:325716 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575717
[email protected]fb661802013-03-25 01:59:325718 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575719}
5720
[email protected]989386c2013-07-18 21:37:235721TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:165722 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455723 TestSharedBitmapManager shared_bitmap_manager;
5724 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:165725 host_impl.CreatePendingTree();
5726 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5727
5728 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005729 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5730 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165731 false);
5732 root->SetDrawsContent(true);
5733
5734 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005735 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5736 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165737 false);
5738 child->SetDrawsContent(true);
5739 child->SetOpacity(0.0f);
5740
5741 // Add opacity animation.
5742 AddOpacityTransitionToController(
5743 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
5744
5745 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:005746 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:165747
[email protected]c0ae06c12013-06-24 18:32:195748 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535749 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225750 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535751 inputs.can_adjust_raster_scales = true;
5752 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165753
5754 // We should have one render surface and two layers. The child
5755 // layer should be included even though it is transparent.
5756 ASSERT_EQ(1u, render_surface_layer_list.size());
5757 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5758}
5759
danakj3f76ace2014-11-18 16:56:005760using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
[email protected]989386c2013-07-18 21:37:235761class LCDTextTest
5762 : public LayerTreeHostCommonTestBase,
5763 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365764 public:
5765 LCDTextTest()
5766 : host_impl_(&proxy_, &shared_bitmap_manager_),
5767 root_(nullptr),
5768 child_(nullptr),
5769 grand_child_(nullptr) {}
5770
[email protected]fb661802013-03-25 01:59:325771 protected:
dcheng93a52eb2014-12-23 02:14:235772 void SetUp() override {
[email protected]fb661802013-03-25 01:59:325773 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005774 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595775
enneaf5bda32015-02-19 01:27:365776 scoped_ptr<LayerImpl> root_ptr =
5777 LayerImpl::Create(host_impl_.active_tree(), 1);
5778 scoped_ptr<LayerImpl> child_ptr =
5779 LayerImpl::Create(host_impl_.active_tree(), 2);
5780 scoped_ptr<LayerImpl> grand_child_ptr =
5781 LayerImpl::Create(host_impl_.active_tree(), 3);
5782
5783 // Stash raw pointers to look at later.
5784 root_ = root_ptr.get();
5785 child_ = child_ptr.get();
5786 grand_child_ = grand_child_ptr.get();
5787
5788 child_->AddChild(grand_child_ptr.Pass());
5789 root_->AddChild(child_ptr.Pass());
5790 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
[email protected]10aabcc32012-12-13 09:18:595791
fmalita51b5e202014-11-18 20:11:505792 root_->SetContentsOpaque(true);
5793 child_->SetContentsOpaque(true);
5794 grand_child_->SetContentsOpaque(true);
5795
[email protected]fb661802013-03-25 01:59:325796 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365797 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5798 gfx::PointF(), gfx::Size(1, 1), true, false,
5799 true);
5800 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5801 gfx::PointF(), gfx::Size(1, 1), true, false,
5802 std::tr1::get<2>(GetParam()));
5803 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5804 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325805 false);
[email protected]fb661802013-03-25 01:59:325806 }
[email protected]10aabcc32012-12-13 09:18:595807
[email protected]fb661802013-03-25 01:59:325808 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005809 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365810
5811 FakeImplProxy proxy_;
5812 TestSharedBitmapManager shared_bitmap_manager_;
5813 FakeLayerTreeHostImpl host_impl_;
5814
5815 LayerImpl* root_;
5816 LayerImpl* child_;
5817 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595818};
5819
[email protected]fb661802013-03-25 01:59:325820TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005821 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5822 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5823
[email protected]fb661802013-03-25 01:59:325824 // Case 1: Identity transform.
5825 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365826 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005827 layers_always_allowed_lcd_text_);
5828 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5829 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5830 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595831
[email protected]fb661802013-03-25 01:59:325832 // Case 2: Integral translation.
5833 gfx::Transform integral_translation;
5834 integral_translation.Translate(1.0, 2.0);
5835 child_->SetTransform(integral_translation);
enneaf5bda32015-02-19 01:27:365836 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005837 layers_always_allowed_lcd_text_);
5838 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5839 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5840 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595841
[email protected]fb661802013-03-25 01:59:325842 // Case 3: Non-integral translation.
5843 gfx::Transform non_integral_translation;
5844 non_integral_translation.Translate(1.5, 2.5);
5845 child_->SetTransform(non_integral_translation);
enneaf5bda32015-02-19 01:27:365846 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005847 layers_always_allowed_lcd_text_);
5848 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5849 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5850 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595851
[email protected]fb661802013-03-25 01:59:325852 // Case 4: Rotation.
5853 gfx::Transform rotation;
5854 rotation.Rotate(10.0);
5855 child_->SetTransform(rotation);
enneaf5bda32015-02-19 01:27:365856 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005857 layers_always_allowed_lcd_text_);
5858 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5859 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5860 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595861
[email protected]fb661802013-03-25 01:59:325862 // Case 5: Scale.
5863 gfx::Transform scale;
5864 scale.Scale(2.0, 2.0);
5865 child_->SetTransform(scale);
enneaf5bda32015-02-19 01:27:365866 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005867 layers_always_allowed_lcd_text_);
5868 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5869 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5870 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595871
[email protected]fb661802013-03-25 01:59:325872 // Case 6: Skew.
5873 gfx::Transform skew;
5874 skew.SkewX(10.0);
5875 child_->SetTransform(skew);
enneaf5bda32015-02-19 01:27:365876 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005877 layers_always_allowed_lcd_text_);
5878 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5879 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5880 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595881
[email protected]fb661802013-03-25 01:59:325882 // Case 7: Translucent.
5883 child_->SetTransform(identity_matrix);
5884 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365885 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005886 layers_always_allowed_lcd_text_);
5887 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5888 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5889 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595890
[email protected]fb661802013-03-25 01:59:325891 // Case 8: Sanity check: restore transform and opacity.
5892 child_->SetTransform(identity_matrix);
5893 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365894 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005895 layers_always_allowed_lcd_text_);
5896 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5897 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5898 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505899
5900 // Case 9: Non-opaque content.
5901 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365902 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505903 layers_always_allowed_lcd_text_);
5904 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5905 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5906 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5907
5908 // Case 10: Sanity check: restore content opaqueness.
5909 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365910 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505911 layers_always_allowed_lcd_text_);
5912 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5913 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5914 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595915}
5916
[email protected]fd9a3b6d2013-08-03 00:46:175917TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005918 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5919
[email protected]fb661802013-03-25 01:59:325920 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365921 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005922 layers_always_allowed_lcd_text_);
5923 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5924 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5925 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595926
[email protected]fb661802013-03-25 01:59:325927 // Add opacity animation.
5928 child_->SetOpacity(0.9f);
5929 AddOpacityTransitionToController(
5930 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:595931
enneaf5bda32015-02-19 01:27:365932 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005933 layers_always_allowed_lcd_text_);
[email protected]fb661802013-03-25 01:59:325934 // Text AA should not be adjusted while animation is active.
5935 // Make sure LCD text AA setting remains unchanged.
danakj3f76ace2014-11-18 16:56:005936 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5937 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5938 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595939}
5940
5941INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5942 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005943 testing::Combine(testing::Bool(),
5944 testing::Bool(),
5945 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595946
[email protected]989386c2013-07-18 21:37:235947TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:195948 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455949 TestSharedBitmapManager shared_bitmap_manager;
5950 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195951 host_impl.CreatePendingTree();
5952 const gfx::Transform identity_matrix;
5953
5954 scoped_refptr<Layer> root = Layer::Create();
5955 SetLayerPropertiesForTesting(root.get(),
5956 identity_matrix,
[email protected]a2566412014-06-05 03:14:205957 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195958 gfx::PointF(),
5959 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575960 true,
[email protected]c0ae06c12013-06-24 18:32:195961 false);
5962 root->SetIsDrawable(true);
5963
5964 scoped_refptr<Layer> child = Layer::Create();
5965 SetLayerPropertiesForTesting(child.get(),
5966 identity_matrix,
[email protected]a2566412014-06-05 03:14:205967 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195968 gfx::PointF(),
5969 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:575970 true,
[email protected]c0ae06c12013-06-24 18:32:195971 false);
5972 child->SetIsDrawable(true);
5973
5974 scoped_refptr<Layer> grand_child = Layer::Create();
5975 SetLayerPropertiesForTesting(grand_child.get(),
5976 identity_matrix,
[email protected]a2566412014-06-05 03:14:205977 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195978 gfx::PointF(),
5979 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575980 true,
[email protected]c0ae06c12013-06-24 18:32:195981 false);
5982 grand_child->SetIsDrawable(true);
5983 grand_child->SetHideLayerAndSubtree(true);
5984
5985 child->AddChild(grand_child);
5986 root->AddChild(child);
5987
enne2097cab2014-09-25 20:16:315988 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285989 host->SetRootLayer(root);
5990
[email protected]989386c2013-07-18 21:37:235991 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535992 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225993 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535994 inputs.can_adjust_raster_scales = true;
5995 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195996
5997 // We should have one render surface and two layers. The grand child has
5998 // hidden itself.
5999 ASSERT_EQ(1u, render_surface_layer_list.size());
6000 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236001 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6002 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196003}
6004
[email protected]989386c2013-07-18 21:37:236005TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:196006 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456007 TestSharedBitmapManager shared_bitmap_manager;
6008 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196009 host_impl.CreatePendingTree();
6010 const gfx::Transform identity_matrix;
6011
6012 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006013 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6014 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:196015 false);
6016 root->SetDrawsContent(true);
6017
6018 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006019 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6020 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196021 false);
6022 child->SetDrawsContent(true);
6023
6024 scoped_ptr<LayerImpl> grand_child =
6025 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006026 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6027 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6028 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196029 grand_child->SetDrawsContent(true);
6030 grand_child->SetHideLayerAndSubtree(true);
6031
6032 child->AddChild(grand_child.Pass());
6033 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:006034 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:196035
6036 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536037 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226038 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536039 inputs.can_adjust_raster_scales = true;
6040 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196041
6042 // We should have one render surface and two layers. The grand child has
6043 // hidden itself.
6044 ASSERT_EQ(1u, render_surface_layer_list.size());
6045 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236046 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
6047 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196048}
6049
[email protected]989386c2013-07-18 21:37:236050TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:196051 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456052 TestSharedBitmapManager shared_bitmap_manager;
6053 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196054 host_impl.CreatePendingTree();
6055 const gfx::Transform identity_matrix;
6056
6057 scoped_refptr<Layer> root = Layer::Create();
6058 SetLayerPropertiesForTesting(root.get(),
6059 identity_matrix,
[email protected]a2566412014-06-05 03:14:206060 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196061 gfx::PointF(),
6062 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576063 true,
[email protected]c0ae06c12013-06-24 18:32:196064 false);
6065 root->SetIsDrawable(true);
6066
6067 scoped_refptr<Layer> child = Layer::Create();
6068 SetLayerPropertiesForTesting(child.get(),
6069 identity_matrix,
[email protected]a2566412014-06-05 03:14:206070 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196071 gfx::PointF(),
6072 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576073 true,
[email protected]c0ae06c12013-06-24 18:32:196074 false);
6075 child->SetIsDrawable(true);
6076 child->SetHideLayerAndSubtree(true);
6077
6078 scoped_refptr<Layer> grand_child = Layer::Create();
6079 SetLayerPropertiesForTesting(grand_child.get(),
6080 identity_matrix,
[email protected]a2566412014-06-05 03:14:206081 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196082 gfx::PointF(),
6083 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576084 true,
[email protected]c0ae06c12013-06-24 18:32:196085 false);
6086 grand_child->SetIsDrawable(true);
6087
6088 child->AddChild(grand_child);
6089 root->AddChild(child);
6090
enne2097cab2014-09-25 20:16:316091 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286092 host->SetRootLayer(root);
6093
[email protected]989386c2013-07-18 21:37:236094 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536095 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226096 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536097 inputs.can_adjust_raster_scales = true;
6098 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196099
6100 // We should have one render surface and one layers. The child has
6101 // hidden itself and the grand child.
6102 ASSERT_EQ(1u, render_surface_layer_list.size());
6103 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236104 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196105}
6106
[email protected]989386c2013-07-18 21:37:236107TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:196108 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456109 TestSharedBitmapManager shared_bitmap_manager;
6110 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196111 host_impl.CreatePendingTree();
6112 const gfx::Transform identity_matrix;
6113
6114 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006115 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6116 gfx::PointF(), gfx::Size(50, 50), true, false,
6117 true);
[email protected]c0ae06c12013-06-24 18:32:196118 root->SetDrawsContent(true);
6119
6120 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006121 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6122 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196123 false);
6124 child->SetDrawsContent(true);
6125 child->SetHideLayerAndSubtree(true);
6126
6127 scoped_ptr<LayerImpl> grand_child =
6128 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006129 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6130 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6131 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196132 grand_child->SetDrawsContent(true);
6133
6134 child->AddChild(grand_child.Pass());
6135 root->AddChild(child.Pass());
6136
6137 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536138 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226139 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536140 inputs.can_adjust_raster_scales = true;
6141 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196142
6143 // We should have one render surface and one layers. The child has
6144 // hidden itself and the grand child.
6145 ASSERT_EQ(1u, render_surface_layer_list.size());
6146 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236147 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196148}
6149
[email protected]30fe19ff2013-07-04 00:54:456150void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
6151
[email protected]989386c2013-07-18 21:37:236152TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456153 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456154 TestSharedBitmapManager shared_bitmap_manager;
6155 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456156 host_impl.CreatePendingTree();
6157 const gfx::Transform identity_matrix;
6158
6159 scoped_refptr<Layer> root = Layer::Create();
6160 SetLayerPropertiesForTesting(root.get(),
6161 identity_matrix,
[email protected]a2566412014-06-05 03:14:206162 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456163 gfx::PointF(),
6164 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576165 true,
[email protected]30fe19ff2013-07-04 00:54:456166 false);
6167 root->SetIsDrawable(true);
6168
6169 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
6170 SetLayerPropertiesForTesting(copy_grand_parent.get(),
6171 identity_matrix,
[email protected]a2566412014-06-05 03:14:206172 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456173 gfx::PointF(),
6174 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576175 true,
[email protected]30fe19ff2013-07-04 00:54:456176 false);
6177 copy_grand_parent->SetIsDrawable(true);
6178
6179 scoped_refptr<Layer> copy_parent = Layer::Create();
6180 SetLayerPropertiesForTesting(copy_parent.get(),
6181 identity_matrix,
[email protected]a2566412014-06-05 03:14:206182 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456183 gfx::PointF(),
6184 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576185 true,
[email protected]30fe19ff2013-07-04 00:54:456186 false);
6187 copy_parent->SetIsDrawable(true);
6188 copy_parent->SetForceRenderSurface(true);
6189
6190 scoped_refptr<Layer> copy_layer = Layer::Create();
6191 SetLayerPropertiesForTesting(copy_layer.get(),
6192 identity_matrix,
[email protected]a2566412014-06-05 03:14:206193 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456194 gfx::PointF(),
6195 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576196 true,
[email protected]30fe19ff2013-07-04 00:54:456197 false);
6198 copy_layer->SetIsDrawable(true);
6199
6200 scoped_refptr<Layer> copy_child = Layer::Create();
6201 SetLayerPropertiesForTesting(copy_child.get(),
6202 identity_matrix,
[email protected]a2566412014-06-05 03:14:206203 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456204 gfx::PointF(),
6205 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576206 true,
[email protected]30fe19ff2013-07-04 00:54:456207 false);
6208 copy_child->SetIsDrawable(true);
6209
[email protected]ac020122013-07-12 23:45:536210 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
6211 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
6212 identity_matrix,
[email protected]a2566412014-06-05 03:14:206213 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536214 gfx::PointF(),
6215 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576216 true,
[email protected]ac020122013-07-12 23:45:536217 false);
6218 copy_grand_parent_sibling_before->SetIsDrawable(true);
6219
6220 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
6221 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
6222 identity_matrix,
[email protected]a2566412014-06-05 03:14:206223 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536224 gfx::PointF(),
6225 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576226 true,
[email protected]ac020122013-07-12 23:45:536227 false);
6228 copy_grand_parent_sibling_after->SetIsDrawable(true);
6229
[email protected]30fe19ff2013-07-04 00:54:456230 copy_layer->AddChild(copy_child);
6231 copy_parent->AddChild(copy_layer);
6232 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:536233 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:456234 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:536235 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:456236
enne2097cab2014-09-25 20:16:316237 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286238 host->SetRootLayer(root);
6239
[email protected]30fe19ff2013-07-04 00:54:456240 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6241 // hidden subtree on copy_layer.
6242 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:536243 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
6244 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:456245 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6246 base::Bind(&EmptyCopyOutputCallback)));
6247 EXPECT_TRUE(copy_layer->HasCopyRequest());
6248
[email protected]989386c2013-07-18 21:37:236249 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536250 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226251 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536252 inputs.can_adjust_raster_scales = true;
6253 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456254
[email protected]ac020122013-07-12 23:45:536255 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
6256 EXPECT_TRUE(copy_grand_parent->draw_properties().
6257 layer_or_descendant_has_copy_request);
6258 EXPECT_TRUE(copy_parent->draw_properties().
6259 layer_or_descendant_has_copy_request);
6260 EXPECT_TRUE(copy_layer->draw_properties().
6261 layer_or_descendant_has_copy_request);
6262 EXPECT_FALSE(copy_child->draw_properties().
6263 layer_or_descendant_has_copy_request);
6264 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
6265 layer_or_descendant_has_copy_request);
6266 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
6267 layer_or_descendant_has_copy_request);
6268
[email protected]30fe19ff2013-07-04 00:54:456269 // We should have three render surfaces, one for the root, one for the parent
6270 // since it owns a surface, and one for the copy_layer.
6271 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236272 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
6273 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
6274 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:456275
6276 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:536277 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6278 // will appear since something in its subtree needs to be drawn for a copy
6279 // request.
[email protected]30fe19ff2013-07-04 00:54:456280 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236281 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6282 EXPECT_EQ(copy_parent->id(),
6283 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456284
[email protected]7392c7b2014-02-07 08:28:286285 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:456286 // appear in its list, since it needs to be drawn for the copy request.
6287 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
6288 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236289 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456290
6291 // The copy_layer's render surface should have two contributing layers.
6292 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
6293 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236294 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456295 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:236296 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456297}
6298
[email protected]989386c2013-07-18 21:37:236299TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456300 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456301 TestSharedBitmapManager shared_bitmap_manager;
6302 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456303 host_impl.CreatePendingTree();
6304 const gfx::Transform identity_matrix;
6305
6306 scoped_refptr<Layer> root = Layer::Create();
6307 SetLayerPropertiesForTesting(root.get(),
6308 identity_matrix,
[email protected]a2566412014-06-05 03:14:206309 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456310 gfx::PointF(),
6311 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576312 true,
[email protected]30fe19ff2013-07-04 00:54:456313 false);
6314 root->SetIsDrawable(true);
6315
6316 scoped_refptr<Layer> copy_parent = Layer::Create();
6317 SetLayerPropertiesForTesting(copy_parent.get(),
6318 identity_matrix,
[email protected]a2566412014-06-05 03:14:206319 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456320 gfx::PointF(),
6321 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576322 true,
[email protected]30fe19ff2013-07-04 00:54:456323 false);
6324 copy_parent->SetIsDrawable(true);
6325 copy_parent->SetMasksToBounds(true);
6326
6327 scoped_refptr<Layer> copy_layer = Layer::Create();
6328 SetLayerPropertiesForTesting(copy_layer.get(),
6329 identity_matrix,
[email protected]a2566412014-06-05 03:14:206330 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456331 gfx::PointF(),
6332 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576333 true,
[email protected]30fe19ff2013-07-04 00:54:456334 false);
6335 copy_layer->SetIsDrawable(true);
6336
6337 scoped_refptr<Layer> copy_child = Layer::Create();
6338 SetLayerPropertiesForTesting(copy_child.get(),
6339 identity_matrix,
[email protected]a2566412014-06-05 03:14:206340 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456341 gfx::PointF(),
6342 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576343 true,
[email protected]30fe19ff2013-07-04 00:54:456344 false);
6345 copy_child->SetIsDrawable(true);
6346
6347 copy_layer->AddChild(copy_child);
6348 copy_parent->AddChild(copy_layer);
6349 root->AddChild(copy_parent);
6350
enne2097cab2014-09-25 20:16:316351 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286352 host->SetRootLayer(root);
6353
[email protected]30fe19ff2013-07-04 00:54:456354 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6355 base::Bind(&EmptyCopyOutputCallback)));
6356 EXPECT_TRUE(copy_layer->HasCopyRequest());
6357
[email protected]989386c2013-07-18 21:37:236358 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536359 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226360 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536361 inputs.can_adjust_raster_scales = true;
6362 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456363
6364 // We should have one render surface, as the others are clipped out.
6365 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236366 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456367
6368 // The root render surface should only have 1 contributing layer, since the
6369 // other layers are empty/clipped away.
6370 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236371 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456372}
6373
[email protected]11a07b102013-07-24 17:33:196374TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
6375 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456376 TestSharedBitmapManager shared_bitmap_manager;
6377 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:196378 host_impl.CreatePendingTree();
6379 const gfx::Transform identity_matrix;
6380
6381 scoped_refptr<Layer> root = Layer::Create();
6382 SetLayerPropertiesForTesting(root.get(),
6383 identity_matrix,
[email protected]a2566412014-06-05 03:14:206384 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196385 gfx::PointF(),
6386 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576387 true,
[email protected]11a07b102013-07-24 17:33:196388 false);
6389 root->SetIsDrawable(true);
6390
6391 // The surface is moved slightly outside of the viewport.
6392 scoped_refptr<Layer> surface = Layer::Create();
6393 SetLayerPropertiesForTesting(surface.get(),
6394 identity_matrix,
[email protected]a2566412014-06-05 03:14:206395 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196396 gfx::PointF(-10, -20),
6397 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576398 true,
[email protected]11a07b102013-07-24 17:33:196399 false);
6400 surface->SetForceRenderSurface(true);
6401
6402 scoped_refptr<Layer> surface_child = Layer::Create();
6403 SetLayerPropertiesForTesting(surface_child.get(),
6404 identity_matrix,
[email protected]a2566412014-06-05 03:14:206405 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196406 gfx::PointF(),
6407 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576408 true,
[email protected]11a07b102013-07-24 17:33:196409 false);
6410 surface_child->SetIsDrawable(true);
6411
6412 surface->AddChild(surface_child);
6413 root->AddChild(surface);
6414
enne2097cab2014-09-25 20:16:316415 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286416 host->SetRootLayer(root);
6417
[email protected]11a07b102013-07-24 17:33:196418 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536419 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226420 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536421 inputs.can_adjust_raster_scales = true;
6422 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:196423
6424 // The visible_content_rect for the |surface_child| should not be clipped by
6425 // the viewport.
6426 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6427 surface_child->visible_content_rect().ToString());
6428}
6429
[email protected]420fdf6e2013-08-26 20:36:386430TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6431 // Ensure that a transform between the layer and its render surface is not a
6432 // problem. Constructs the following layer tree.
6433 //
6434 // root (a render surface)
6435 // + render_surface
6436 // + clip_parent (scaled)
6437 // + intervening_clipping_layer
6438 // + clip_child
6439 //
6440 // The render surface should be resized correctly and the clip child should
6441 // inherit the right clip rect.
6442 scoped_refptr<Layer> root = Layer::Create();
6443 scoped_refptr<Layer> render_surface = Layer::Create();
6444 scoped_refptr<Layer> clip_parent = Layer::Create();
6445 scoped_refptr<Layer> intervening = Layer::Create();
6446 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6447 make_scoped_refptr(new LayerWithForcedDrawsContent);
6448
6449 root->AddChild(render_surface);
6450 render_surface->AddChild(clip_parent);
6451 clip_parent->AddChild(intervening);
6452 intervening->AddChild(clip_child);
6453
6454 clip_child->SetClipParent(clip_parent.get());
6455
6456 intervening->SetMasksToBounds(true);
6457 clip_parent->SetMasksToBounds(true);
6458
6459 render_surface->SetForceRenderSurface(true);
6460
6461 gfx::Transform scale_transform;
6462 scale_transform.Scale(2, 2);
6463
6464 gfx::Transform identity_transform;
6465
6466 SetLayerPropertiesForTesting(root.get(),
6467 identity_transform,
[email protected]a2566412014-06-05 03:14:206468 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386469 gfx::PointF(),
6470 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576471 true,
[email protected]420fdf6e2013-08-26 20:36:386472 false);
6473 SetLayerPropertiesForTesting(render_surface.get(),
6474 identity_transform,
[email protected]a2566412014-06-05 03:14:206475 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386476 gfx::PointF(),
6477 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576478 true,
[email protected]420fdf6e2013-08-26 20:36:386479 false);
6480 SetLayerPropertiesForTesting(clip_parent.get(),
6481 scale_transform,
[email protected]a2566412014-06-05 03:14:206482 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386483 gfx::PointF(1.f, 1.f),
6484 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576485 true,
[email protected]420fdf6e2013-08-26 20:36:386486 false);
6487 SetLayerPropertiesForTesting(intervening.get(),
6488 identity_transform,
[email protected]a2566412014-06-05 03:14:206489 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386490 gfx::PointF(1.f, 1.f),
6491 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576492 true,
[email protected]420fdf6e2013-08-26 20:36:386493 false);
6494 SetLayerPropertiesForTesting(clip_child.get(),
6495 identity_transform,
[email protected]a2566412014-06-05 03:14:206496 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386497 gfx::PointF(1.f, 1.f),
6498 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576499 true,
[email protected]420fdf6e2013-08-26 20:36:386500 false);
6501
enne2097cab2014-09-25 20:16:316502 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386503 host->SetRootLayer(root);
6504
6505 ExecuteCalculateDrawProperties(root.get());
6506
6507 ASSERT_TRUE(root->render_surface());
6508 ASSERT_TRUE(render_surface->render_surface());
6509
6510 // Ensure that we've inherited our clip parent's clip and weren't affected
6511 // by the intervening clip layer.
6512 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6513 clip_parent->clip_rect().ToString());
6514 ASSERT_EQ(clip_parent->clip_rect().ToString(),
6515 clip_child->clip_rect().ToString());
6516 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6517 intervening->clip_rect().ToString());
6518
6519 // Ensure that the render surface reports a content rect that has been grown
6520 // to accomodate for the clip child.
6521 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6522 render_surface->render_surface()->content_rect().ToString());
6523
6524 // The above check implies the two below, but they nicely demonstrate that
6525 // we've grown, despite the intervening layer's clip.
6526 ASSERT_TRUE(clip_parent->clip_rect().Contains(
6527 render_surface->render_surface()->content_rect()));
6528 ASSERT_FALSE(intervening->clip_rect().Contains(
6529 render_surface->render_surface()->content_rect()));
6530}
6531
6532TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
6533 // Ensure that intervening render surfaces are not a problem in the basic
6534 // case. In the following tree, both render surfaces should be resized to
6535 // accomodate for the clip child, despite an intervening clip.
6536 //
6537 // root (a render surface)
6538 // + clip_parent (masks to bounds)
6539 // + render_surface1 (sets opacity)
6540 // + intervening (masks to bounds)
6541 // + render_surface2 (also sets opacity)
6542 // + clip_child
6543 //
6544 scoped_refptr<Layer> root = Layer::Create();
6545 scoped_refptr<Layer> clip_parent = Layer::Create();
6546 scoped_refptr<Layer> render_surface1 = Layer::Create();
6547 scoped_refptr<Layer> intervening = Layer::Create();
6548 scoped_refptr<Layer> render_surface2 = Layer::Create();
6549 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6550 make_scoped_refptr(new LayerWithForcedDrawsContent);
6551
6552 root->AddChild(clip_parent);
6553 clip_parent->AddChild(render_surface1);
6554 render_surface1->AddChild(intervening);
6555 intervening->AddChild(render_surface2);
6556 render_surface2->AddChild(clip_child);
6557
6558 clip_child->SetClipParent(clip_parent.get());
6559
6560 intervening->SetMasksToBounds(true);
6561 clip_parent->SetMasksToBounds(true);
6562
6563 render_surface1->SetForceRenderSurface(true);
6564 render_surface2->SetForceRenderSurface(true);
6565
6566 gfx::Transform translation_transform;
6567 translation_transform.Translate(2, 2);
6568
6569 gfx::Transform identity_transform;
6570 SetLayerPropertiesForTesting(root.get(),
6571 identity_transform,
[email protected]a2566412014-06-05 03:14:206572 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386573 gfx::PointF(),
6574 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576575 true,
[email protected]420fdf6e2013-08-26 20:36:386576 false);
6577 SetLayerPropertiesForTesting(clip_parent.get(),
6578 translation_transform,
[email protected]a2566412014-06-05 03:14:206579 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386580 gfx::PointF(1.f, 1.f),
6581 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576582 true,
[email protected]420fdf6e2013-08-26 20:36:386583 false);
6584 SetLayerPropertiesForTesting(render_surface1.get(),
6585 identity_transform,
[email protected]a2566412014-06-05 03:14:206586 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386587 gfx::PointF(),
6588 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576589 true,
[email protected]420fdf6e2013-08-26 20:36:386590 false);
6591 SetLayerPropertiesForTesting(intervening.get(),
6592 identity_transform,
[email protected]a2566412014-06-05 03:14:206593 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386594 gfx::PointF(1.f, 1.f),
6595 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576596 true,
[email protected]420fdf6e2013-08-26 20:36:386597 false);
6598 SetLayerPropertiesForTesting(render_surface2.get(),
6599 identity_transform,
[email protected]a2566412014-06-05 03:14:206600 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386601 gfx::PointF(),
6602 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576603 true,
[email protected]420fdf6e2013-08-26 20:36:386604 false);
6605 SetLayerPropertiesForTesting(clip_child.get(),
6606 identity_transform,
[email protected]a2566412014-06-05 03:14:206607 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386608 gfx::PointF(-10.f, -10.f),
6609 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576610 true,
[email protected]420fdf6e2013-08-26 20:36:386611 false);
6612
enne2097cab2014-09-25 20:16:316613 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386614 host->SetRootLayer(root);
6615
6616 ExecuteCalculateDrawProperties(root.get());
6617
6618 EXPECT_TRUE(root->render_surface());
6619 EXPECT_TRUE(render_surface1->render_surface());
6620 EXPECT_TRUE(render_surface2->render_surface());
6621
6622 // Since the render surfaces could have expanded, they should not clip (their
6623 // bounds would no longer be reliable). We should resort to layer clipping
6624 // in this case.
6625 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6626 render_surface1->render_surface()->clip_rect().ToString());
6627 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6628 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6629 render_surface2->render_surface()->clip_rect().ToString());
6630 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6631
6632 // NB: clip rects are in target space.
6633 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6634 render_surface1->clip_rect().ToString());
6635 EXPECT_TRUE(render_surface1->is_clipped());
6636
6637 // This value is inherited from the clipping ancestor layer, 'intervening'.
6638 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6639 render_surface2->clip_rect().ToString());
6640 EXPECT_TRUE(render_surface2->is_clipped());
6641
6642 // The content rects of both render surfaces should both have expanded to
6643 // contain the clip child.
6644 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6645 render_surface1->render_surface()->content_rect().ToString());
6646 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6647 render_surface2->render_surface()->content_rect().ToString());
6648
6649 // The clip child should have inherited the clip parent's clip (projected to
6650 // the right space, of course), and should have the correctly sized visible
6651 // content rect.
6652 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6653 clip_child->clip_rect().ToString());
6654 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6655 clip_child->visible_content_rect().ToString());
6656 EXPECT_TRUE(clip_child->is_clipped());
6657}
6658
6659TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6660 // Ensure that intervening render surfaces are not a problem, even if there
6661 // is a scroll involved. Note, we do _not_ have to consider any other sort
6662 // of transform.
6663 //
6664 // root (a render surface)
6665 // + clip_parent (masks to bounds)
6666 // + render_surface1 (sets opacity)
6667 // + intervening (masks to bounds AND scrolls)
6668 // + render_surface2 (also sets opacity)
6669 // + clip_child
6670 //
6671 scoped_refptr<Layer> root = Layer::Create();
6672 scoped_refptr<Layer> clip_parent = Layer::Create();
6673 scoped_refptr<Layer> render_surface1 = Layer::Create();
6674 scoped_refptr<Layer> intervening = Layer::Create();
6675 scoped_refptr<Layer> render_surface2 = Layer::Create();
6676 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6677 make_scoped_refptr(new LayerWithForcedDrawsContent);
6678
6679 root->AddChild(clip_parent);
6680 clip_parent->AddChild(render_surface1);
6681 render_surface1->AddChild(intervening);
6682 intervening->AddChild(render_surface2);
6683 render_surface2->AddChild(clip_child);
6684
6685 clip_child->SetClipParent(clip_parent.get());
6686
6687 intervening->SetMasksToBounds(true);
6688 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:476689 intervening->SetScrollClipLayerId(clip_parent->id());
miletusf57925d2014-10-01 19:38:136690 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386691
6692 render_surface1->SetForceRenderSurface(true);
6693 render_surface2->SetForceRenderSurface(true);
6694
6695 gfx::Transform translation_transform;
6696 translation_transform.Translate(2, 2);
6697
6698 gfx::Transform identity_transform;
6699 SetLayerPropertiesForTesting(root.get(),
6700 identity_transform,
[email protected]a2566412014-06-05 03:14:206701 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386702 gfx::PointF(),
6703 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576704 true,
[email protected]420fdf6e2013-08-26 20:36:386705 false);
6706 SetLayerPropertiesForTesting(clip_parent.get(),
6707 translation_transform,
[email protected]a2566412014-06-05 03:14:206708 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386709 gfx::PointF(1.f, 1.f),
6710 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576711 true,
[email protected]420fdf6e2013-08-26 20:36:386712 false);
6713 SetLayerPropertiesForTesting(render_surface1.get(),
6714 identity_transform,
[email protected]a2566412014-06-05 03:14:206715 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386716 gfx::PointF(),
6717 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576718 true,
[email protected]420fdf6e2013-08-26 20:36:386719 false);
6720 SetLayerPropertiesForTesting(intervening.get(),
6721 identity_transform,
[email protected]a2566412014-06-05 03:14:206722 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386723 gfx::PointF(1.f, 1.f),
6724 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576725 true,
[email protected]420fdf6e2013-08-26 20:36:386726 false);
6727 SetLayerPropertiesForTesting(render_surface2.get(),
6728 identity_transform,
[email protected]a2566412014-06-05 03:14:206729 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386730 gfx::PointF(),
6731 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576732 true,
[email protected]420fdf6e2013-08-26 20:36:386733 false);
6734 SetLayerPropertiesForTesting(clip_child.get(),
6735 identity_transform,
[email protected]a2566412014-06-05 03:14:206736 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386737 gfx::PointF(-10.f, -10.f),
6738 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576739 true,
[email protected]420fdf6e2013-08-26 20:36:386740 false);
6741
enne2097cab2014-09-25 20:16:316742 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386743 host->SetRootLayer(root);
6744
6745 ExecuteCalculateDrawProperties(root.get());
6746
6747 EXPECT_TRUE(root->render_surface());
6748 EXPECT_TRUE(render_surface1->render_surface());
6749 EXPECT_TRUE(render_surface2->render_surface());
6750
6751 // Since the render surfaces could have expanded, they should not clip (their
6752 // bounds would no longer be reliable). We should resort to layer clipping
6753 // in this case.
6754 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6755 render_surface1->render_surface()->clip_rect().ToString());
6756 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6757 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6758 render_surface2->render_surface()->clip_rect().ToString());
6759 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6760
6761 // NB: clip rects are in target space.
6762 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6763 render_surface1->clip_rect().ToString());
6764 EXPECT_TRUE(render_surface1->is_clipped());
6765
6766 // This value is inherited from the clipping ancestor layer, 'intervening'.
6767 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6768 render_surface2->clip_rect().ToString());
6769 EXPECT_TRUE(render_surface2->is_clipped());
6770
6771 // The content rects of both render surfaces should both have expanded to
6772 // contain the clip child.
6773 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6774 render_surface1->render_surface()->content_rect().ToString());
6775 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6776 render_surface2->render_surface()->content_rect().ToString());
6777
6778 // The clip child should have inherited the clip parent's clip (projected to
6779 // the right space, of course), and should have the correctly sized visible
6780 // content rect.
6781 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6782 clip_child->clip_rect().ToString());
6783 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6784 clip_child->visible_content_rect().ToString());
6785 EXPECT_TRUE(clip_child->is_clipped());
6786}
6787
6788TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6789 // Ensures that descendants of the clip child inherit the correct clip.
6790 //
6791 // root (a render surface)
6792 // + clip_parent (masks to bounds)
6793 // + intervening (masks to bounds)
6794 // + clip_child
6795 // + child
6796 //
6797 scoped_refptr<Layer> root = Layer::Create();
6798 scoped_refptr<Layer> clip_parent = Layer::Create();
6799 scoped_refptr<Layer> intervening = Layer::Create();
6800 scoped_refptr<Layer> clip_child = Layer::Create();
6801 scoped_refptr<LayerWithForcedDrawsContent> child =
6802 make_scoped_refptr(new LayerWithForcedDrawsContent);
6803
6804 root->AddChild(clip_parent);
6805 clip_parent->AddChild(intervening);
6806 intervening->AddChild(clip_child);
6807 clip_child->AddChild(child);
6808
6809 clip_child->SetClipParent(clip_parent.get());
6810
6811 intervening->SetMasksToBounds(true);
6812 clip_parent->SetMasksToBounds(true);
6813
6814 gfx::Transform identity_transform;
6815 SetLayerPropertiesForTesting(root.get(),
6816 identity_transform,
[email protected]a2566412014-06-05 03:14:206817 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386818 gfx::PointF(),
6819 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576820 true,
[email protected]420fdf6e2013-08-26 20:36:386821 false);
6822 SetLayerPropertiesForTesting(clip_parent.get(),
6823 identity_transform,
[email protected]a2566412014-06-05 03:14:206824 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386825 gfx::PointF(),
6826 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576827 true,
[email protected]420fdf6e2013-08-26 20:36:386828 false);
6829 SetLayerPropertiesForTesting(intervening.get(),
6830 identity_transform,
[email protected]a2566412014-06-05 03:14:206831 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386832 gfx::PointF(),
6833 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576834 true,
[email protected]420fdf6e2013-08-26 20:36:386835 false);
6836 SetLayerPropertiesForTesting(clip_child.get(),
6837 identity_transform,
[email protected]a2566412014-06-05 03:14:206838 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386839 gfx::PointF(),
6840 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576841 true,
[email protected]420fdf6e2013-08-26 20:36:386842 false);
6843 SetLayerPropertiesForTesting(child.get(),
6844 identity_transform,
[email protected]a2566412014-06-05 03:14:206845 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386846 gfx::PointF(),
6847 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576848 true,
[email protected]420fdf6e2013-08-26 20:36:386849 false);
6850
enne2097cab2014-09-25 20:16:316851 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386852 host->SetRootLayer(root);
6853
6854 ExecuteCalculateDrawProperties(root.get());
6855
6856 EXPECT_TRUE(root->render_surface());
6857
6858 // Neither the clip child nor its descendant should have inherited the clip
6859 // from |intervening|.
6860 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6861 clip_child->clip_rect().ToString());
6862 EXPECT_TRUE(clip_child->is_clipped());
6863 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6864 child->visible_content_rect().ToString());
6865 EXPECT_TRUE(child->is_clipped());
6866}
6867
6868TEST_F(LayerTreeHostCommonTest,
6869 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6870 // Ensures that non-descendant clip children in the tree do not affect
6871 // render surfaces.
6872 //
6873 // root (a render surface)
6874 // + clip_parent (masks to bounds)
6875 // + render_surface1
6876 // + clip_child
6877 // + render_surface2
6878 // + non_clip_child
6879 //
6880 // In this example render_surface2 should be unaffected by clip_child.
6881 scoped_refptr<Layer> root = Layer::Create();
6882 scoped_refptr<Layer> clip_parent = Layer::Create();
6883 scoped_refptr<Layer> render_surface1 = Layer::Create();
6884 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6885 make_scoped_refptr(new LayerWithForcedDrawsContent);
6886 scoped_refptr<Layer> render_surface2 = Layer::Create();
6887 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
6888 make_scoped_refptr(new LayerWithForcedDrawsContent);
6889
6890 root->AddChild(clip_parent);
6891 clip_parent->AddChild(render_surface1);
6892 render_surface1->AddChild(clip_child);
6893 clip_parent->AddChild(render_surface2);
6894 render_surface2->AddChild(non_clip_child);
6895
6896 clip_child->SetClipParent(clip_parent.get());
6897
6898 clip_parent->SetMasksToBounds(true);
6899 render_surface1->SetMasksToBounds(true);
6900
6901 gfx::Transform identity_transform;
6902 SetLayerPropertiesForTesting(root.get(),
6903 identity_transform,
[email protected]a2566412014-06-05 03:14:206904 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386905 gfx::PointF(),
6906 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:576907 true,
[email protected]420fdf6e2013-08-26 20:36:386908 false);
6909 SetLayerPropertiesForTesting(clip_parent.get(),
6910 identity_transform,
[email protected]a2566412014-06-05 03:14:206911 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386912 gfx::PointF(),
6913 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576914 true,
[email protected]420fdf6e2013-08-26 20:36:386915 false);
6916 SetLayerPropertiesForTesting(render_surface1.get(),
6917 identity_transform,
[email protected]a2566412014-06-05 03:14:206918 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386919 gfx::PointF(5, 5),
6920 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576921 true,
[email protected]420fdf6e2013-08-26 20:36:386922 false);
6923 SetLayerPropertiesForTesting(render_surface2.get(),
6924 identity_transform,
[email protected]a2566412014-06-05 03:14:206925 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386926 gfx::PointF(),
6927 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576928 true,
[email protected]420fdf6e2013-08-26 20:36:386929 false);
6930 SetLayerPropertiesForTesting(clip_child.get(),
6931 identity_transform,
[email protected]a2566412014-06-05 03:14:206932 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386933 gfx::PointF(-1, 1),
6934 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576935 true,
[email protected]420fdf6e2013-08-26 20:36:386936 false);
6937 SetLayerPropertiesForTesting(non_clip_child.get(),
6938 identity_transform,
[email protected]a2566412014-06-05 03:14:206939 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386940 gfx::PointF(),
6941 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576942 true,
[email protected]420fdf6e2013-08-26 20:36:386943 false);
6944
6945 render_surface1->SetForceRenderSurface(true);
6946 render_surface2->SetForceRenderSurface(true);
6947
enne2097cab2014-09-25 20:16:316948 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386949 host->SetRootLayer(root);
6950
6951 ExecuteCalculateDrawProperties(root.get());
6952
6953 EXPECT_TRUE(root->render_surface());
6954 EXPECT_TRUE(render_surface1->render_surface());
6955 EXPECT_TRUE(render_surface2->render_surface());
6956
6957 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6958 render_surface1->clip_rect().ToString());
6959 EXPECT_TRUE(render_surface1->is_clipped());
6960
6961 // The render surface should not clip (it has unclipped descendants), instead
6962 // it should rely on layer clipping.
6963 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6964 render_surface1->render_surface()->clip_rect().ToString());
6965 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6966
6967 // That said, it should have grown to accomodate the unclipped descendant.
6968 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6969 render_surface1->render_surface()->content_rect().ToString());
6970
6971 // This render surface should clip. It has no unclipped descendants.
6972 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6973 render_surface2->clip_rect().ToString());
6974 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
6975
6976 // It also shouldn't have grown to accomodate the clip child.
6977 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6978 render_surface2->render_surface()->content_rect().ToString());
6979
6980 // Sanity check our num_unclipped_descendants values.
6981 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
6982 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
6983}
6984
[email protected]45948712013-09-27 02:46:486985TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
6986 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456987 TestSharedBitmapManager shared_bitmap_manager;
6988 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:486989 scoped_ptr<LayerImpl> root =
6990 LayerImpl::Create(host_impl.active_tree(), 12345);
6991 scoped_ptr<LayerImpl> child1 =
6992 LayerImpl::Create(host_impl.active_tree(), 123456);
6993 scoped_ptr<LayerImpl> child2 =
6994 LayerImpl::Create(host_impl.active_tree(), 1234567);
6995 scoped_ptr<LayerImpl> child3 =
6996 LayerImpl::Create(host_impl.active_tree(), 12345678);
6997
6998 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206999 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:487000 gfx::PointF position;
7001 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:007002 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
7003 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:487004 root->SetDrawsContent(true);
7005
7006 // This layer structure normally forces render surface due to preserves3d
7007 // behavior.
awoloszyne83f28c2014-12-22 15:40:007008 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
7009 position, bounds, false, true, true);
[email protected]45948712013-09-27 02:46:487010 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007011 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
7012 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487013 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007014 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
7015 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487016 child3->SetDrawsContent(true);
7017
[email protected]a9d4d4f2014-06-19 06:49:287018 child2->Set3dSortingContextId(1);
7019 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:577020
[email protected]45948712013-09-27 02:46:487021 child2->AddChild(child3.Pass());
7022 child1->AddChild(child2.Pass());
7023 root->AddChild(child1.Pass());
7024
7025 {
7026 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:547027 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
[email protected]45948712013-09-27 02:46:487028 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227029 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487030 inputs.can_render_to_separate_surface = true;
7031 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7032
7033 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:027034
7035 int count_represents_target_render_surface = 0;
7036 int count_represents_contributing_render_surface = 0;
7037 int count_represents_itself = 0;
7038 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list);
7039 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list);
7040 it != end; ++it) {
7041 if (it.represents_target_render_surface())
7042 count_represents_target_render_surface++;
7043 if (it.represents_contributing_render_surface())
7044 count_represents_contributing_render_surface++;
7045 if (it.represents_itself())
7046 count_represents_itself++;
7047 }
7048
7049 // Two render surfaces.
7050 EXPECT_EQ(2, count_represents_target_render_surface);
7051 // Second render surface contributes to root render surface.
7052 EXPECT_EQ(1, count_represents_contributing_render_surface);
7053 // All 4 layers represent itself.
7054 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:487055 }
7056
7057 {
7058 LayerImplList render_surface_layer_list;
7059 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227060 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487061 inputs.can_render_to_separate_surface = false;
7062 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7063
7064 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:027065
7066 int count_represents_target_render_surface = 0;
7067 int count_represents_contributing_render_surface = 0;
7068 int count_represents_itself = 0;
7069 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list);
7070 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list);
7071 it != end; ++it) {
7072 if (it.represents_target_render_surface())
7073 count_represents_target_render_surface++;
7074 if (it.represents_contributing_render_surface())
7075 count_represents_contributing_render_surface++;
7076 if (it.represents_itself())
7077 count_represents_itself++;
7078 }
7079
7080 // Only root layer has a render surface.
7081 EXPECT_EQ(1, count_represents_target_render_surface);
7082 // No layer contributes a render surface to root render surface.
7083 EXPECT_EQ(0, count_represents_contributing_render_surface);
7084 // All 4 layers represent itself.
7085 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:487086 }
7087}
7088
[email protected]a9aa60a82013-08-29 04:28:267089TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
7090 scoped_refptr<Layer> root = Layer::Create();
7091 scoped_refptr<Layer> render_surface = Layer::Create();
7092 scoped_refptr<LayerWithForcedDrawsContent> child =
7093 make_scoped_refptr(new LayerWithForcedDrawsContent);
7094
7095 root->AddChild(render_surface);
7096 render_surface->AddChild(child);
7097
7098 gfx::Transform identity_transform;
7099 SetLayerPropertiesForTesting(root.get(),
7100 identity_transform,
[email protected]a2566412014-06-05 03:14:207101 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267102 gfx::PointF(),
7103 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577104 true,
[email protected]a9aa60a82013-08-29 04:28:267105 false);
7106 SetLayerPropertiesForTesting(render_surface.get(),
7107 identity_transform,
[email protected]a2566412014-06-05 03:14:207108 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267109 gfx::PointF(),
7110 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577111 false,
7112 true);
[email protected]a9aa60a82013-08-29 04:28:267113 SetLayerPropertiesForTesting(child.get(),
7114 identity_transform,
[email protected]a2566412014-06-05 03:14:207115 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267116 gfx::PointF(),
7117 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577118 true,
[email protected]a9aa60a82013-08-29 04:28:267119 false);
7120
[email protected]56fffdd2014-02-11 19:50:577121 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:287122 root->Set3dSortingContextId(1);
[email protected]a9aa60a82013-08-29 04:28:267123 render_surface->SetDoubleSided(false);
7124 render_surface->SetForceRenderSurface(true);
7125
enne2097cab2014-09-25 20:16:317126 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]a9aa60a82013-08-29 04:28:267127 host->SetRootLayer(root);
7128
7129 ExecuteCalculateDrawProperties(root.get());
7130
7131 EXPECT_EQ(2u, render_surface_layer_list()->size());
7132 EXPECT_EQ(1u,
7133 render_surface_layer_list()->at(0)
7134 ->render_surface()->layer_list().size());
7135 EXPECT_EQ(1u,
7136 render_surface_layer_list()->at(1)
7137 ->render_surface()->layer_list().size());
7138
7139 gfx::Transform rotation_transform = identity_transform;
7140 rotation_transform.RotateAboutXAxis(180.0);
7141
7142 render_surface->SetTransform(rotation_transform);
7143
7144 ExecuteCalculateDrawProperties(root.get());
7145
7146 EXPECT_EQ(1u, render_surface_layer_list()->size());
7147 EXPECT_EQ(0u,
7148 render_surface_layer_list()->at(0)
7149 ->render_surface()->layer_list().size());
7150}
7151
[email protected]995708c52013-10-17 20:52:597152TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
7153 // Checks that the simple case (being clipped by a scroll parent that would
7154 // have been processed before you anyhow) results in the right clips.
7155 //
7156 // + root
7157 // + scroll_parent_border
7158 // | + scroll_parent_clip
7159 // | + scroll_parent
7160 // + scroll_child
7161 //
7162 scoped_refptr<Layer> root = Layer::Create();
7163 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7164 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7165 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7166 make_scoped_refptr(new LayerWithForcedDrawsContent);
7167 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7168 make_scoped_refptr(new LayerWithForcedDrawsContent);
7169
7170 root->AddChild(scroll_child);
7171
7172 root->AddChild(scroll_parent_border);
7173 scroll_parent_border->AddChild(scroll_parent_clip);
7174 scroll_parent_clip->AddChild(scroll_parent);
7175
7176 scroll_parent_clip->SetMasksToBounds(true);
7177
7178 scroll_child->SetScrollParent(scroll_parent.get());
7179
7180 gfx::Transform identity_transform;
7181 SetLayerPropertiesForTesting(root.get(),
7182 identity_transform,
[email protected]a2566412014-06-05 03:14:207183 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597184 gfx::PointF(),
7185 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577186 true,
[email protected]995708c52013-10-17 20:52:597187 false);
7188 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7189 identity_transform,
[email protected]a2566412014-06-05 03:14:207190 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597191 gfx::PointF(),
7192 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577193 true,
[email protected]995708c52013-10-17 20:52:597194 false);
7195 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7196 identity_transform,
[email protected]a2566412014-06-05 03:14:207197 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597198 gfx::PointF(),
7199 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577200 true,
[email protected]995708c52013-10-17 20:52:597201 false);
7202 SetLayerPropertiesForTesting(scroll_parent.get(),
7203 identity_transform,
[email protected]a2566412014-06-05 03:14:207204 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597205 gfx::PointF(),
7206 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577207 true,
[email protected]995708c52013-10-17 20:52:597208 false);
7209 SetLayerPropertiesForTesting(scroll_child.get(),
7210 identity_transform,
[email protected]a2566412014-06-05 03:14:207211 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597212 gfx::PointF(),
7213 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577214 true,
[email protected]995708c52013-10-17 20:52:597215 false);
7216
enne2097cab2014-09-25 20:16:317217 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597218 host->SetRootLayer(root);
7219
7220 ExecuteCalculateDrawProperties(root.get());
7221
7222 EXPECT_TRUE(root->render_surface());
7223
7224 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7225 scroll_child->clip_rect().ToString());
7226 EXPECT_TRUE(scroll_child->is_clipped());
7227}
7228
[email protected]08bdf1b2014-04-16 23:23:297229TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7230 scoped_refptr<LayerWithForcedDrawsContent> root =
7231 make_scoped_refptr(new LayerWithForcedDrawsContent);
7232 scoped_refptr<LayerWithForcedDrawsContent> parent =
7233 make_scoped_refptr(new LayerWithForcedDrawsContent);
7234 scoped_refptr<LayerWithForcedDrawsContent> child =
7235 make_scoped_refptr(new LayerWithForcedDrawsContent);
7236
7237 root->AddChild(parent);
7238 parent->AddChild(child);
7239
7240 gfx::Transform identity_transform;
7241 SetLayerPropertiesForTesting(root.get(),
7242 identity_transform,
[email protected]a2566412014-06-05 03:14:207243 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297244 gfx::PointF(),
7245 gfx::Size(50, 50),
7246 true,
7247 true);
7248 root->SetForceRenderSurface(true);
7249 SetLayerPropertiesForTesting(parent.get(),
7250 identity_transform,
[email protected]a2566412014-06-05 03:14:207251 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297252 gfx::PointF(),
7253 gfx::Size(30, 30),
7254 true,
7255 true);
7256 parent->SetForceRenderSurface(true);
7257 SetLayerPropertiesForTesting(child.get(),
7258 identity_transform,
[email protected]a2566412014-06-05 03:14:207259 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297260 gfx::PointF(),
7261 gfx::Size(20, 20),
7262 true,
7263 true);
7264 child->SetForceRenderSurface(true);
7265
enne2097cab2014-09-25 20:16:317266 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]08bdf1b2014-04-16 23:23:297267 host->SetRootLayer(root);
7268
7269 ExecuteCalculateDrawProperties(root.get());
7270
7271 EXPECT_EQ(3u, render_surface_layer_list()->size());
7272
7273 gfx::Transform singular_transform;
7274 singular_transform.Scale3d(
7275 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7276
7277 child->SetTransform(singular_transform);
7278
7279 ExecuteCalculateDrawProperties(root.get());
7280
7281 EXPECT_EQ(2u, render_surface_layer_list()->size());
7282
7283 // Ensure that the entire subtree under a layer with singular transform does
7284 // not get rendered.
7285 parent->SetTransform(singular_transform);
7286 child->SetTransform(identity_transform);
7287
7288 ExecuteCalculateDrawProperties(root.get());
7289
7290 EXPECT_EQ(1u, render_surface_layer_list()->size());
7291}
7292
[email protected]995708c52013-10-17 20:52:597293TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
7294 // Checks that clipping by a scroll parent that follows you in paint order
7295 // still results in correct clipping.
7296 //
7297 // + root
7298 // + scroll_child
7299 // + scroll_parent_border
7300 // + scroll_parent_clip
7301 // + scroll_parent
7302 //
7303 scoped_refptr<Layer> root = Layer::Create();
7304 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7305 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7306 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7307 make_scoped_refptr(new LayerWithForcedDrawsContent);
7308 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7309 make_scoped_refptr(new LayerWithForcedDrawsContent);
7310
7311 root->AddChild(scroll_parent_border);
7312 scroll_parent_border->AddChild(scroll_parent_clip);
7313 scroll_parent_clip->AddChild(scroll_parent);
7314
7315 root->AddChild(scroll_child);
7316
7317 scroll_parent_clip->SetMasksToBounds(true);
7318
7319 scroll_child->SetScrollParent(scroll_parent.get());
7320
7321 gfx::Transform identity_transform;
7322 SetLayerPropertiesForTesting(root.get(),
7323 identity_transform,
[email protected]a2566412014-06-05 03:14:207324 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597325 gfx::PointF(),
7326 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577327 true,
[email protected]995708c52013-10-17 20:52:597328 false);
7329 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7330 identity_transform,
[email protected]a2566412014-06-05 03:14:207331 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597332 gfx::PointF(),
7333 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577334 true,
[email protected]995708c52013-10-17 20:52:597335 false);
7336 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7337 identity_transform,
[email protected]a2566412014-06-05 03:14:207338 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597339 gfx::PointF(),
7340 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577341 true,
[email protected]995708c52013-10-17 20:52:597342 false);
7343 SetLayerPropertiesForTesting(scroll_parent.get(),
7344 identity_transform,
[email protected]a2566412014-06-05 03:14:207345 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597346 gfx::PointF(),
7347 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577348 true,
[email protected]995708c52013-10-17 20:52:597349 false);
7350 SetLayerPropertiesForTesting(scroll_child.get(),
7351 identity_transform,
[email protected]a2566412014-06-05 03:14:207352 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597353 gfx::PointF(),
7354 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577355 true,
[email protected]995708c52013-10-17 20:52:597356 false);
7357
enne2097cab2014-09-25 20:16:317358 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597359 host->SetRootLayer(root);
7360
7361 ExecuteCalculateDrawProperties(root.get());
7362
7363 EXPECT_TRUE(root->render_surface());
7364
7365 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7366 scroll_child->clip_rect().ToString());
7367 EXPECT_TRUE(scroll_child->is_clipped());
7368}
7369
7370TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
7371 // Checks that clipping by a scroll parent and scroll grandparent that follow
7372 // you in paint order still results in correct clipping.
7373 //
7374 // + root
7375 // + scroll_child
7376 // + scroll_parent_border
7377 // | + scroll_parent_clip
7378 // | + scroll_parent
7379 // + scroll_grandparent_border
7380 // + scroll_grandparent_clip
7381 // + scroll_grandparent
7382 //
7383 scoped_refptr<Layer> root = Layer::Create();
7384 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7385 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7386 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7387 make_scoped_refptr(new LayerWithForcedDrawsContent);
7388
7389 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7390 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7391 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7392 make_scoped_refptr(new LayerWithForcedDrawsContent);
7393
7394 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7395 make_scoped_refptr(new LayerWithForcedDrawsContent);
7396
7397 root->AddChild(scroll_child);
7398
7399 root->AddChild(scroll_parent_border);
7400 scroll_parent_border->AddChild(scroll_parent_clip);
7401 scroll_parent_clip->AddChild(scroll_parent);
7402
7403 root->AddChild(scroll_grandparent_border);
7404 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7405 scroll_grandparent_clip->AddChild(scroll_grandparent);
7406
7407 scroll_parent_clip->SetMasksToBounds(true);
7408 scroll_grandparent_clip->SetMasksToBounds(true);
7409
7410 scroll_child->SetScrollParent(scroll_parent.get());
7411 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7412
7413 gfx::Transform identity_transform;
7414 SetLayerPropertiesForTesting(root.get(),
7415 identity_transform,
[email protected]a2566412014-06-05 03:14:207416 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597417 gfx::PointF(),
7418 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577419 true,
[email protected]995708c52013-10-17 20:52:597420 false);
7421 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7422 identity_transform,
[email protected]a2566412014-06-05 03:14:207423 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597424 gfx::PointF(),
7425 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577426 true,
[email protected]995708c52013-10-17 20:52:597427 false);
7428 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7429 identity_transform,
[email protected]a2566412014-06-05 03:14:207430 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597431 gfx::PointF(),
7432 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577433 true,
[email protected]995708c52013-10-17 20:52:597434 false);
7435 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7436 identity_transform,
[email protected]a2566412014-06-05 03:14:207437 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597438 gfx::PointF(),
7439 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577440 true,
[email protected]995708c52013-10-17 20:52:597441 false);
7442 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7443 identity_transform,
[email protected]a2566412014-06-05 03:14:207444 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597445 gfx::PointF(),
7446 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577447 true,
[email protected]995708c52013-10-17 20:52:597448 false);
7449 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7450 identity_transform,
[email protected]a2566412014-06-05 03:14:207451 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597452 gfx::PointF(),
7453 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577454 true,
[email protected]995708c52013-10-17 20:52:597455 false);
7456 SetLayerPropertiesForTesting(scroll_parent.get(),
7457 identity_transform,
[email protected]a2566412014-06-05 03:14:207458 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597459 gfx::PointF(),
7460 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577461 true,
[email protected]995708c52013-10-17 20:52:597462 false);
7463 SetLayerPropertiesForTesting(scroll_child.get(),
7464 identity_transform,
[email protected]a2566412014-06-05 03:14:207465 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597466 gfx::PointF(),
7467 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577468 true,
[email protected]995708c52013-10-17 20:52:597469 false);
7470
enne2097cab2014-09-25 20:16:317471 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597472 host->SetRootLayer(root);
7473
7474 ExecuteCalculateDrawProperties(root.get());
7475
7476 EXPECT_TRUE(root->render_surface());
7477
7478 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7479 scroll_child->clip_rect().ToString());
7480 EXPECT_TRUE(scroll_child->is_clipped());
7481
7482 // Despite the fact that we visited the above layers out of order to get the
7483 // correct clip, the layer lists should be unaffected.
7484 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
7485 EXPECT_EQ(scroll_child.get(),
Daniel Chengeea98042014-08-26 00:28:107486 root->render_surface()->layer_list().at(0).get());
[email protected]995708c52013-10-17 20:52:597487 EXPECT_EQ(scroll_parent.get(),
Daniel Chengeea98042014-08-26 00:28:107488 root->render_surface()->layer_list().at(1).get());
[email protected]995708c52013-10-17 20:52:597489 EXPECT_EQ(scroll_grandparent.get(),
Daniel Chengeea98042014-08-26 00:28:107490 root->render_surface()->layer_list().at(2).get());
[email protected]995708c52013-10-17 20:52:597491}
7492
7493TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
7494 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:227495 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:597496 // + root
7497 // + scroll_child
7498 // + scroll_parent_border
7499 // + scroll_parent_clip
7500 // + scroll_parent
7501 // + render_surface1
7502 // + scroll_grandparent_border
7503 // + scroll_grandparent_clip
7504 // + scroll_grandparent
7505 // + render_surface2
7506 //
[email protected]44d8e84c2013-10-19 19:13:227507 scoped_refptr<LayerWithForcedDrawsContent> root =
7508 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:597509
7510 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7511 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7512 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7513 make_scoped_refptr(new LayerWithForcedDrawsContent);
7514 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
7515 make_scoped_refptr(new LayerWithForcedDrawsContent);
7516
7517 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7518 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7519 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7520 make_scoped_refptr(new LayerWithForcedDrawsContent);
7521 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
7522 make_scoped_refptr(new LayerWithForcedDrawsContent);
7523
7524 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7525 make_scoped_refptr(new LayerWithForcedDrawsContent);
7526
7527 root->AddChild(scroll_child);
7528
7529 root->AddChild(scroll_parent_border);
7530 scroll_parent_border->AddChild(scroll_parent_clip);
7531 scroll_parent_clip->AddChild(scroll_parent);
7532 scroll_parent->AddChild(render_surface2);
7533
7534 root->AddChild(scroll_grandparent_border);
7535 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7536 scroll_grandparent_clip->AddChild(scroll_grandparent);
7537 scroll_grandparent->AddChild(render_surface1);
7538
7539 scroll_parent_clip->SetMasksToBounds(true);
7540 scroll_grandparent_clip->SetMasksToBounds(true);
7541
7542 scroll_child->SetScrollParent(scroll_parent.get());
7543 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7544
7545 render_surface1->SetForceRenderSurface(true);
7546 render_surface2->SetForceRenderSurface(true);
7547
7548 gfx::Transform identity_transform;
7549 SetLayerPropertiesForTesting(root.get(),
7550 identity_transform,
[email protected]a2566412014-06-05 03:14:207551 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597552 gfx::PointF(),
7553 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577554 true,
[email protected]995708c52013-10-17 20:52:597555 false);
7556 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7557 identity_transform,
[email protected]a2566412014-06-05 03:14:207558 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597559 gfx::PointF(),
7560 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577561 true,
[email protected]995708c52013-10-17 20:52:597562 false);
7563 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7564 identity_transform,
[email protected]a2566412014-06-05 03:14:207565 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597566 gfx::PointF(),
7567 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577568 true,
[email protected]995708c52013-10-17 20:52:597569 false);
7570 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7571 identity_transform,
[email protected]a2566412014-06-05 03:14:207572 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597573 gfx::PointF(),
7574 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577575 true,
[email protected]995708c52013-10-17 20:52:597576 false);
7577 SetLayerPropertiesForTesting(render_surface1.get(),
7578 identity_transform,
[email protected]a2566412014-06-05 03:14:207579 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597580 gfx::PointF(),
7581 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577582 true,
[email protected]995708c52013-10-17 20:52:597583 false);
7584 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7585 identity_transform,
[email protected]a2566412014-06-05 03:14:207586 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597587 gfx::PointF(),
7588 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577589 true,
[email protected]995708c52013-10-17 20:52:597590 false);
7591 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7592 identity_transform,
[email protected]a2566412014-06-05 03:14:207593 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597594 gfx::PointF(),
7595 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577596 true,
[email protected]995708c52013-10-17 20:52:597597 false);
7598 SetLayerPropertiesForTesting(scroll_parent.get(),
7599 identity_transform,
[email protected]a2566412014-06-05 03:14:207600 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597601 gfx::PointF(),
7602 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577603 true,
[email protected]995708c52013-10-17 20:52:597604 false);
7605 SetLayerPropertiesForTesting(render_surface2.get(),
7606 identity_transform,
[email protected]a2566412014-06-05 03:14:207607 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597608 gfx::PointF(),
7609 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577610 true,
[email protected]995708c52013-10-17 20:52:597611 false);
7612 SetLayerPropertiesForTesting(scroll_child.get(),
7613 identity_transform,
[email protected]a2566412014-06-05 03:14:207614 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597615 gfx::PointF(),
7616 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577617 true,
[email protected]995708c52013-10-17 20:52:597618 false);
7619
enne2097cab2014-09-25 20:16:317620 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597621 host->SetRootLayer(root);
7622
7623 RenderSurfaceLayerList render_surface_layer_list;
7624 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7625 root.get(),
bokancccfde72014-10-08 15:15:227626 root->bounds(),
[email protected]995708c52013-10-17 20:52:597627 identity_transform,
7628 &render_surface_layer_list);
7629
7630 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7631
7632 EXPECT_TRUE(root->render_surface());
7633
7634 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7635 scroll_child->clip_rect().ToString());
7636 EXPECT_TRUE(scroll_child->is_clipped());
7637
7638 // Despite the fact that we had to process the layers out of order to get the
7639 // right clip, our render_surface_layer_list's order should be unaffected.
7640 EXPECT_EQ(3u, render_surface_layer_list.size());
7641 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7642 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7643 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:227644 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7645 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7646 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:597647}
7648
[email protected]d81752b2013-10-25 08:32:237649TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7650 // This test verifies that a scrolling layer that gets snapped to
7651 // integer coordinates doesn't move a fixed position child.
7652 //
7653 // + root
7654 // + container
7655 // + scroller
7656 // + fixed
7657 //
7658 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457659 TestSharedBitmapManager shared_bitmap_manager;
7660 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:237661 host_impl.CreatePendingTree();
7662 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7663 scoped_ptr<LayerImpl> container =
7664 LayerImpl::Create(host_impl.active_tree(), 2);
7665 LayerImpl* container_layer = container.get();
7666 scoped_ptr<LayerImpl> scroller =
7667 LayerImpl::Create(host_impl.active_tree(), 3);
7668 LayerImpl* scroll_layer = scroller.get();
7669 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7670 LayerImpl* fixed_layer = fixed.get();
7671
7672 container->SetIsContainerForFixedPositionLayers(true);
7673
7674 LayerPositionConstraint constraint;
7675 constraint.set_is_fixed_position(true);
7676 fixed->SetPositionConstraint(constraint);
7677
[email protected]adeda572014-01-31 00:49:477678 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237679
7680 gfx::Transform identity_transform;
7681 gfx::Transform container_transform;
7682 container_transform.Translate3d(10.0, 20.0, 0.0);
7683 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7684
awoloszyne83f28c2014-12-22 15:40:007685 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7686 gfx::PointF(), gfx::Size(50, 50), true, false,
7687 true);
7688 SetLayerPropertiesForTesting(container.get(), container_transform,
7689 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7690 true, false, false);
7691 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7692 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7693 true, false, false);
7694 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7695 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237696 false);
7697
7698 scroller->AddChild(fixed.Pass());
7699 container->AddChild(scroller.Pass());
7700 root->AddChild(container.Pass());
7701
7702 // Rounded to integers already.
7703 {
7704 gfx::Vector2dF scroll_delta(3.0, 5.0);
7705 scroll_layer->SetScrollDelta(scroll_delta);
7706
7707 LayerImplList render_surface_layer_list;
7708 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227709 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237710 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7711
7712 EXPECT_TRANSFORMATION_MATRIX_EQ(
7713 container_layer->draw_properties().screen_space_transform,
7714 fixed_layer->draw_properties().screen_space_transform);
7715 EXPECT_VECTOR_EQ(
7716 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7717 container_offset);
7718 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7719 .screen_space_transform.To2dTranslation(),
7720 container_offset - scroll_delta);
7721 }
7722
7723 // Scroll delta requiring rounding.
7724 {
7725 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7726 scroll_layer->SetScrollDelta(scroll_delta);
7727
7728 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7729
7730 LayerImplList render_surface_layer_list;
7731 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227732 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237733 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7734
7735 EXPECT_TRANSFORMATION_MATRIX_EQ(
7736 container_layer->draw_properties().screen_space_transform,
7737 fixed_layer->draw_properties().screen_space_transform);
7738 EXPECT_VECTOR_EQ(
7739 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7740 container_offset);
7741 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7742 .screen_space_transform.To2dTranslation(),
7743 container_offset - rounded_scroll_delta);
7744 }
[email protected]cf15ad7b2014-04-02 03:59:267745
7746 // Scale is applied earlier in the tree.
7747 {
7748 gfx::Transform scaled_container_transform = container_transform;
7749 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
7750 container_layer->SetTransform(scaled_container_transform);
7751
7752 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7753 scroll_layer->SetScrollDelta(scroll_delta);
7754
7755 LayerImplList render_surface_layer_list;
7756 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227757 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267758 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7759
7760 EXPECT_TRANSFORMATION_MATRIX_EQ(
7761 container_layer->draw_properties().screen_space_transform,
7762 fixed_layer->draw_properties().screen_space_transform);
7763 EXPECT_VECTOR_EQ(
7764 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7765 container_offset);
7766
7767 container_layer->SetTransform(container_transform);
7768 }
7769
7770 // Scale is applied on the scroll layer itself.
7771 {
7772 gfx::Transform scale_transform;
7773 scale_transform.Scale3d(3.0, 3.0, 1.0);
7774 scroll_layer->SetTransform(scale_transform);
7775
7776 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7777 scroll_layer->SetScrollDelta(scroll_delta);
7778
7779 LayerImplList render_surface_layer_list;
7780 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227781 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267782 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7783
7784 EXPECT_VECTOR_EQ(
7785 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7786 container_offset);
7787
7788 scroll_layer->SetTransform(identity_transform);
7789 }
[email protected]d81752b2013-10-25 08:32:237790}
7791
miletus2c78036b2015-01-29 20:52:377792TEST_F(LayerTreeHostCommonTest,
7793 ScrollCompensationMainScrollOffsetFractionalPart) {
7794 // This test verifies that a scrolling layer that has fractional scroll offset
7795 // from main doesn't move a fixed position child.
7796 //
7797 // + root
7798 // + container
7799 // + scroller
7800 // + fixed
7801 //
7802 FakeImplProxy proxy;
7803 TestSharedBitmapManager shared_bitmap_manager;
7804 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7805 host_impl.CreatePendingTree();
7806 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7807 scoped_ptr<LayerImpl> container =
7808 LayerImpl::Create(host_impl.active_tree(), 2);
7809 LayerImpl* container_layer = container.get();
7810 scoped_ptr<LayerImpl> scroller =
7811 LayerImpl::Create(host_impl.active_tree(), 3);
7812 LayerImpl* scroll_layer = scroller.get();
7813 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7814 LayerImpl* fixed_layer = fixed.get();
7815
7816 container->SetIsContainerForFixedPositionLayers(true);
7817
7818 LayerPositionConstraint constraint;
7819 constraint.set_is_fixed_position(true);
7820 fixed->SetPositionConstraint(constraint);
7821
7822 scroller->SetScrollClipLayer(container->id());
7823
7824 gfx::Transform identity_transform;
7825 gfx::Transform container_transform;
7826 container_transform.Translate3d(10.0, 20.0, 0.0);
7827 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7828
7829 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7830 gfx::PointF(), gfx::Size(50, 50), true, false,
7831 true);
7832 SetLayerPropertiesForTesting(container.get(), container_transform,
7833 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7834 true, false, false);
7835 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7836 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7837 gfx::Size(30, 30), true, false, false);
7838
7839 gfx::ScrollOffset scroll_offset(3.3, 4.2);
7840 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
7841 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
7842 // Blink only uses the integer part of the scroll_offset for fixed
7843 // position layer.
7844 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7845 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
7846 false, false);
aeliasf998da82015-02-03 01:40:517847 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:497848 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:447849 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:377850
7851 scroller->AddChild(fixed.Pass());
7852 container->AddChild(scroller.Pass());
7853 root->AddChild(container.Pass());
7854
7855 LayerImplList render_surface_layer_list;
7856 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7857 root.get(), root->bounds(), &render_surface_layer_list);
7858 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7859
7860 EXPECT_TRANSFORMATION_MATRIX_EQ(
7861 container_layer->draw_properties().screen_space_transform,
7862 fixed_layer->draw_properties().screen_space_transform);
7863 EXPECT_VECTOR_EQ(
7864 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7865 container_offset);
7866
7867 gfx::ScrollOffset effective_scroll_offset =
7868 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
7869 gfx::Vector2d rounded_effective_scroll_offset =
7870 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
7871 EXPECT_VECTOR_EQ(
7872 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
7873 container_offset - rounded_effective_scroll_offset);
7874}
7875
[email protected]1c3626e2014-04-09 17:49:227876class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7877 public:
7878 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7879 LayerTreeImpl* tree_impl,
7880 int id) {
7881 return make_scoped_ptr(
7882 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7883 }
7884
dcheng716bedf2014-10-21 09:51:087885 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227886
[email protected]1c3626e2014-04-09 17:49:227887 private:
7888 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7889 int id)
[email protected]a57cb8b12014-06-13 18:15:377890 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227891 SetDrawsContent(true);
7892 }
[email protected]1c3626e2014-04-09 17:49:227893};
7894
7895TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
7896 FakeImplProxy proxy;
7897 TestSharedBitmapManager shared_bitmap_manager;
7898 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7899 gfx::Transform identity_matrix;
7900 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7901 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7902 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7903 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7904 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7905 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7906 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7907 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7908
7909 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7910 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7911 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7912
danakjf446a072014-09-27 21:55:487913 child->AddChild(grand_child.Pass());
7914 parent->AddChild(child.Pass());
7915 grand_parent->AddChild(parent.Pass());
[email protected]1c3626e2014-04-09 17:49:227916
awoloszyne83f28c2014-12-22 15:40:007917 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
7918 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7919 true, false, true);
7920 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7921 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227922 false);
awoloszyne83f28c2014-12-22 15:40:007923 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7924 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227925 false);
awoloszyne83f28c2014-12-22 15:40:007926
7927 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7928 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227929 false);
7930
7931 ExecuteCalculateDrawProperties(grand_parent.get());
7932
7933 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:377934 EXPECT_EQ(0.f,
7935 grand_parent->draw_properties().maximum_animation_contents_scale);
7936 EXPECT_EQ(0.f,
7937 parent_raw->draw_properties().maximum_animation_contents_scale);
7938 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7939 EXPECT_EQ(
7940 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227941
7942 TransformOperations translation;
7943 translation.AppendTranslate(1.f, 2.f, 3.f);
7944
7945 AddAnimatedTransformToLayer(
7946 parent_raw, 1.0, TransformOperations(), translation);
7947
7948 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377949 EXPECT_EQ(0.f,
7950 grand_parent->draw_properties().maximum_animation_contents_scale);
7951 EXPECT_EQ(0.f,
7952 parent_raw->draw_properties().maximum_animation_contents_scale);
7953 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7954 EXPECT_EQ(
7955 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227956
7957 TransformOperations scale;
7958 scale.AppendScale(5.f, 4.f, 3.f);
7959
7960 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
7961 ExecuteCalculateDrawProperties(grand_parent.get());
7962
7963 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:377964 EXPECT_EQ(0.f,
7965 grand_parent->draw_properties().maximum_animation_contents_scale);
7966 EXPECT_EQ(0.f,
7967 parent_raw->draw_properties().maximum_animation_contents_scale);
7968 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7969 EXPECT_EQ(
7970 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227971
7972 AddAnimatedTransformToLayer(
7973 grand_parent.get(), 1.0, TransformOperations(), scale);
7974 ExecuteCalculateDrawProperties(grand_parent.get());
7975
7976 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377977 EXPECT_EQ(5.f,
7978 grand_parent->draw_properties().maximum_animation_contents_scale);
7979 EXPECT_EQ(5.f,
7980 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227981 // We don't support combining animated scales from two nodes; 0.f means
7982 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377983 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7984 EXPECT_EQ(
7985 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227986
7987 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7988 ExecuteCalculateDrawProperties(grand_parent.get());
7989
7990 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377991 EXPECT_EQ(5.f,
7992 grand_parent->draw_properties().maximum_animation_contents_scale);
7993 EXPECT_EQ(0.f,
7994 parent_raw->draw_properties().maximum_animation_contents_scale);
7995 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7996 EXPECT_EQ(
7997 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227998
7999 grand_parent->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388000 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228001 parent_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388002 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228003 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388004 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228005
8006 TransformOperations perspective;
8007 perspective.AppendPerspective(10.f);
8008
8009 AddAnimatedTransformToLayer(
8010 child_raw, 1.0, TransformOperations(), perspective);
8011 ExecuteCalculateDrawProperties(grand_parent.get());
8012
8013 // |child| has a scale-affecting animation but computing the maximum of this
8014 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:378015 EXPECT_EQ(0.f,
8016 grand_parent->draw_properties().maximum_animation_contents_scale);
8017 EXPECT_EQ(0.f,
8018 parent_raw->draw_properties().maximum_animation_contents_scale);
8019 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8020 EXPECT_EQ(
8021 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228022
8023 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388024 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228025
8026 gfx::Transform scale_matrix;
8027 scale_matrix.Scale(1.f, 2.f);
8028 grand_parent->SetTransform(scale_matrix);
8029 parent_raw->SetTransform(scale_matrix);
8030 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8031 ExecuteCalculateDrawProperties(grand_parent.get());
8032
8033 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8034 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:378035 EXPECT_EQ(0.f,
8036 grand_parent->draw_properties().maximum_animation_contents_scale);
8037 EXPECT_EQ(10.f,
8038 parent_raw->draw_properties().maximum_animation_contents_scale);
8039 EXPECT_EQ(10.f,
8040 child_raw->draw_properties().maximum_animation_contents_scale);
8041 EXPECT_EQ(
8042 10.f,
8043 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228044
8045 gfx::Transform perspective_matrix;
8046 perspective_matrix.ApplyPerspectiveDepth(2.f);
8047 child_raw->SetTransform(perspective_matrix);
8048 ExecuteCalculateDrawProperties(grand_parent.get());
8049
8050 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378051 EXPECT_EQ(0.f,
8052 grand_parent->draw_properties().maximum_animation_contents_scale);
8053 EXPECT_EQ(10.f,
8054 parent_raw->draw_properties().maximum_animation_contents_scale);
8055 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8056 EXPECT_EQ(
8057 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228058
8059 parent_raw->SetTransform(perspective_matrix);
8060 ExecuteCalculateDrawProperties(grand_parent.get());
8061
8062 // |parent| and |child| have transforms that are neither translations nor
8063 // scales.
[email protected]a57cb8b12014-06-13 18:15:378064 EXPECT_EQ(0.f,
8065 grand_parent->draw_properties().maximum_animation_contents_scale);
8066 EXPECT_EQ(0.f,
8067 parent_raw->draw_properties().maximum_animation_contents_scale);
8068 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8069 EXPECT_EQ(
8070 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228071
8072 parent_raw->SetTransform(identity_matrix);
8073 child_raw->SetTransform(identity_matrix);
8074 grand_parent->SetTransform(perspective_matrix);
8075
8076 ExecuteCalculateDrawProperties(grand_parent.get());
8077
8078 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378079 EXPECT_EQ(0.f,
8080 grand_parent->draw_properties().maximum_animation_contents_scale);
8081 EXPECT_EQ(0.f,
8082 parent_raw->draw_properties().maximum_animation_contents_scale);
8083 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8084 EXPECT_EQ(
8085 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228086}
8087
[email protected]390bb1ff2014-05-09 17:14:408088static int membership_id(LayerImpl* layer) {
8089 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8090}
8091
8092static void GatherDrawnLayers(LayerImplList* rsll,
8093 std::set<LayerImpl*>* drawn_layers) {
8094 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8095 end = LayerIterator<LayerImpl>::End(rsll);
8096 it != end;
8097 ++it) {
8098 LayerImpl* layer = *it;
8099 if (it.represents_itself())
8100 drawn_layers->insert(layer);
8101
8102 if (!it.represents_contributing_render_surface())
8103 continue;
8104
8105 if (layer->mask_layer())
8106 drawn_layers->insert(layer->mask_layer());
8107 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
8108 drawn_layers->insert(layer->replica_layer()->mask_layer());
8109 }
8110}
8111
8112TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
8113 FakeImplProxy proxy;
8114 TestSharedBitmapManager shared_bitmap_manager;
8115 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8116 gfx::Transform identity_matrix;
8117
8118 scoped_ptr<LayerImpl> grand_parent =
8119 LayerImpl::Create(host_impl.active_tree(), 1);
8120 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
8121 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
8122 scoped_ptr<LayerImpl> grand_child1 =
8123 LayerImpl::Create(host_impl.active_tree(), 7);
8124 scoped_ptr<LayerImpl> grand_child2 =
8125 LayerImpl::Create(host_impl.active_tree(), 9);
8126
8127 LayerImpl* grand_parent_raw = grand_parent.get();
8128 LayerImpl* parent_raw = parent.get();
8129 LayerImpl* child_raw = child.get();
8130 LayerImpl* grand_child1_raw = grand_child1.get();
8131 LayerImpl* grand_child2_raw = grand_child2.get();
8132
8133 child->AddChild(grand_child1.Pass());
8134 child->AddChild(grand_child2.Pass());
8135 parent->AddChild(child.Pass());
8136 grand_parent->AddChild(parent.Pass());
8137
awoloszyne83f28c2014-12-22 15:40:008138 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
8139 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8140 true, false, true);
8141 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8142 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408143 false);
awoloszyne83f28c2014-12-22 15:40:008144
8145 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8146 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408147 false);
awoloszyne83f28c2014-12-22 15:40:008148
8149 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
8150 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8151 true, false, false);
8152
8153 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
8154 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8155 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:408156
8157 // Start with nothing being drawn.
8158 ExecuteCalculateDrawProperties(grand_parent_raw);
8159 int member_id = render_surface_layer_list_count();
8160
8161 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8162 EXPECT_NE(member_id, membership_id(parent_raw));
8163 EXPECT_NE(member_id, membership_id(child_raw));
8164 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8165 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8166
8167 std::set<LayerImpl*> expected;
8168 std::set<LayerImpl*> actual;
8169 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8170 EXPECT_EQ(expected, actual);
8171
8172 // If we force render surface, but none of the layers are in the layer list,
8173 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:008174 grand_child1_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408175
8176 ExecuteCalculateDrawProperties(grand_parent_raw);
8177 member_id = render_surface_layer_list_count();
8178
8179 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8180 EXPECT_NE(member_id, membership_id(parent_raw));
8181 EXPECT_NE(member_id, membership_id(child_raw));
8182 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8183 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8184
8185 expected.clear();
8186 actual.clear();
8187 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8188 EXPECT_EQ(expected, actual);
8189
8190 // However, if we say that this layer also draws content, it will appear in
8191 // RSLL.
8192 grand_child1_raw->SetDrawsContent(true);
8193
8194 ExecuteCalculateDrawProperties(grand_parent_raw);
8195 member_id = render_surface_layer_list_count();
8196
8197 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8198 EXPECT_NE(member_id, membership_id(parent_raw));
8199 EXPECT_NE(member_id, membership_id(child_raw));
8200 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8201 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8202
8203 expected.clear();
8204 expected.insert(grand_child1_raw);
8205
8206 actual.clear();
8207 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8208 EXPECT_EQ(expected, actual);
8209
8210 // Now child is forced to have a render surface, and one if its children draws
8211 // content.
8212 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:008213 grand_child1_raw->SetHasRenderSurface(false);
8214 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408215 grand_child2_raw->SetDrawsContent(true);
8216
8217 ExecuteCalculateDrawProperties(grand_parent_raw);
8218 member_id = render_surface_layer_list_count();
8219
8220 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8221 EXPECT_NE(member_id, membership_id(parent_raw));
8222 EXPECT_NE(member_id, membership_id(child_raw));
8223 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8224 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8225
8226 expected.clear();
8227 expected.insert(grand_child2_raw);
8228
8229 actual.clear();
8230 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8231 EXPECT_EQ(expected, actual);
8232
8233 // Add a mask layer to child.
8234 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
8235
8236 ExecuteCalculateDrawProperties(grand_parent_raw);
8237 member_id = render_surface_layer_list_count();
8238
8239 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8240 EXPECT_NE(member_id, membership_id(parent_raw));
8241 EXPECT_NE(member_id, membership_id(child_raw));
8242 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8243 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8244 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8245
8246 expected.clear();
8247 expected.insert(grand_child2_raw);
8248 expected.insert(child_raw->mask_layer());
8249
8250 expected.clear();
8251 expected.insert(grand_child2_raw);
8252 expected.insert(child_raw->mask_layer());
8253
8254 actual.clear();
8255 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8256 EXPECT_EQ(expected, actual);
8257
8258 // Add replica mask layer.
8259 scoped_ptr<LayerImpl> replica_layer =
8260 LayerImpl::Create(host_impl.active_tree(), 20);
8261 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
8262 child_raw->SetReplicaLayer(replica_layer.Pass());
8263
8264 ExecuteCalculateDrawProperties(grand_parent_raw);
8265 member_id = render_surface_layer_list_count();
8266
8267 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8268 EXPECT_NE(member_id, membership_id(parent_raw));
8269 EXPECT_NE(member_id, membership_id(child_raw));
8270 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8271 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
8272 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8273 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8274
8275 expected.clear();
8276 expected.insert(grand_child2_raw);
8277 expected.insert(child_raw->mask_layer());
8278 expected.insert(child_raw->replica_layer()->mask_layer());
8279
8280 actual.clear();
8281 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8282 EXPECT_EQ(expected, actual);
8283
8284 child_raw->TakeReplicaLayer();
8285
8286 // With nothing drawing, we should have no layers.
8287 grand_child2_raw->SetDrawsContent(false);
8288
8289 ExecuteCalculateDrawProperties(grand_parent_raw);
8290 member_id = render_surface_layer_list_count();
8291
8292 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8293 EXPECT_NE(member_id, membership_id(parent_raw));
8294 EXPECT_NE(member_id, membership_id(child_raw));
8295 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
8296 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8297 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8298
8299 expected.clear();
8300 actual.clear();
8301 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8302 EXPECT_EQ(expected, actual);
8303
8304 // Child itself draws means that we should have the child and the mask in the
8305 // list.
8306 child_raw->SetDrawsContent(true);
8307
8308 ExecuteCalculateDrawProperties(grand_parent_raw);
8309 member_id = render_surface_layer_list_count();
8310
8311 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8312 EXPECT_NE(member_id, membership_id(parent_raw));
8313 EXPECT_EQ(member_id, membership_id(child_raw));
8314 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8315 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8316 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8317
8318 expected.clear();
8319 expected.insert(child_raw);
8320 expected.insert(child_raw->mask_layer());
8321 actual.clear();
8322 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8323 EXPECT_EQ(expected, actual);
8324
8325 child_raw->TakeMaskLayer();
8326
8327 // Now everyone's a member!
8328 grand_parent_raw->SetDrawsContent(true);
8329 parent_raw->SetDrawsContent(true);
8330 child_raw->SetDrawsContent(true);
8331 grand_child1_raw->SetDrawsContent(true);
8332 grand_child2_raw->SetDrawsContent(true);
8333
8334 ExecuteCalculateDrawProperties(grand_parent_raw);
8335 member_id = render_surface_layer_list_count();
8336
8337 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
8338 EXPECT_EQ(member_id, membership_id(parent_raw));
8339 EXPECT_EQ(member_id, membership_id(child_raw));
8340 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8341 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8342
8343 expected.clear();
8344 expected.insert(grand_parent_raw);
8345 expected.insert(parent_raw);
8346 expected.insert(child_raw);
8347 expected.insert(grand_child1_raw);
8348 expected.insert(grand_child2_raw);
8349
8350 actual.clear();
8351 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8352 EXPECT_EQ(expected, actual);
8353}
[email protected]18e69652014-06-13 12:50:588354
8355TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
8356 FakeImplProxy proxy;
8357 TestSharedBitmapManager shared_bitmap_manager;
8358 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8359
8360 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8361 LayerImpl* root_layer = root.get();
8362 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
8363 LayerImpl* child1_layer = child1.get();
8364 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
8365 LayerImpl* child2_layer = child2.get();
8366
8367 root->AddChild(child1.Pass());
8368 root->AddChild(child2.Pass());
awoloszyne83f28c2014-12-22 15:40:008369 root->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588370
8371 gfx::Transform identity_matrix, scale_transform_child1,
8372 scale_transform_child2;
8373 scale_transform_child1.Scale(2, 3);
8374 scale_transform_child2.Scale(4, 5);
8375
awoloszyne83f28c2014-12-22 15:40:008376 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
8377 gfx::PointF(), gfx::Size(1, 1), true, false,
8378 true);
8379 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
8380 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8381 false, false);
[email protected]18e69652014-06-13 12:50:588382
8383 child1_layer->SetMaskLayer(
8384 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
8385
8386 scoped_ptr<LayerImpl> replica_layer =
8387 LayerImpl::Create(host_impl.active_tree(), 5);
awoloszyne83f28c2014-12-22 15:40:008388 replica_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588389 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
8390 child1_layer->SetReplicaLayer(replica_layer.Pass());
awoloszyne83f28c2014-12-22 15:40:008391 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588392
8393 ExecuteCalculateDrawProperties(root_layer);
8394
8395 TransformOperations scale;
8396 scale.AppendScale(5.f, 8.f, 3.f);
8397
8398 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
awoloszyne83f28c2014-12-22 15:40:008399 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
8400 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8401 false, false);
[email protected]18e69652014-06-13 12:50:588402
8403 ExecuteCalculateDrawProperties(root_layer);
8404
8405 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8406 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale);
8407 EXPECT_FLOAT_EQ(
8408 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8409 EXPECT_FLOAT_EQ(3.f,
8410 child1_layer->replica_layer()
8411 ->mask_layer()
8412 ->draw_properties()
8413 .ideal_contents_scale);
8414 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale);
8415
8416 EXPECT_FLOAT_EQ(
8417 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8418 EXPECT_FLOAT_EQ(
8419 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8420 EXPECT_FLOAT_EQ(0.f,
8421 child1_layer->mask_layer()
8422 ->draw_properties()
8423 .maximum_animation_contents_scale);
8424 EXPECT_FLOAT_EQ(0.f,
8425 child1_layer->replica_layer()
8426 ->mask_layer()
8427 ->draw_properties()
8428 .maximum_animation_contents_scale);
8429 EXPECT_FLOAT_EQ(
8430 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8431
8432 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8433 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor);
8434 EXPECT_FLOAT_EQ(
8435 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8436 EXPECT_FLOAT_EQ(1.f,
8437 child1_layer->replica_layer()
8438 ->mask_layer()
8439 ->draw_properties()
8440 .page_scale_factor);
8441 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor);
8442
8443 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8444 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8445 EXPECT_FLOAT_EQ(
8446 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8447 EXPECT_FLOAT_EQ(1.f,
8448 child1_layer->replica_layer()
8449 ->mask_layer()
8450 ->draw_properties()
8451 .device_scale_factor);
8452 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8453
8454 // Changing page-scale would affect ideal_contents_scale and
8455 // maximum_animation_contents_scale.
8456
8457 float page_scale_factor = 3.f;
8458 float device_scale_factor = 1.0f;
8459 std::vector<LayerImpl*> render_surface_layer_list;
8460 gfx::Size device_viewport_size =
8461 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8462 root_layer->bounds().height() * device_scale_factor);
8463 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8464 root_layer, device_viewport_size, &render_surface_layer_list);
8465
8466 inputs.page_scale_factor = page_scale_factor;
8467 inputs.can_adjust_raster_scales = true;
8468 inputs.page_scale_application_layer = root_layer;
8469 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8470
8471 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8472 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale);
8473 EXPECT_FLOAT_EQ(
8474 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8475 EXPECT_FLOAT_EQ(9.f,
8476 child1_layer->replica_layer()
8477 ->mask_layer()
8478 ->draw_properties()
8479 .ideal_contents_scale);
8480 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale);
8481
8482 EXPECT_FLOAT_EQ(
8483 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8484 EXPECT_FLOAT_EQ(
8485 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8486 EXPECT_FLOAT_EQ(0.f,
8487 child1_layer->mask_layer()
8488 ->draw_properties()
8489 .maximum_animation_contents_scale);
8490 EXPECT_FLOAT_EQ(0.f,
8491 child1_layer->replica_layer()
8492 ->mask_layer()
8493 ->draw_properties()
8494 .maximum_animation_contents_scale);
8495 EXPECT_FLOAT_EQ(
8496 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8497
8498 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8499 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8500 EXPECT_FLOAT_EQ(
8501 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8502 EXPECT_FLOAT_EQ(3.f,
8503 child1_layer->replica_layer()
8504 ->mask_layer()
8505 ->draw_properties()
8506 .page_scale_factor);
8507 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8508
8509 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8510 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8511 EXPECT_FLOAT_EQ(
8512 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8513 EXPECT_FLOAT_EQ(1.f,
8514 child1_layer->replica_layer()
8515 ->mask_layer()
8516 ->draw_properties()
8517 .device_scale_factor);
8518 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8519
8520 // Changing device-scale would affect ideal_contents_scale and
8521 // maximum_animation_contents_scale.
8522
8523 device_scale_factor = 4.0f;
8524 inputs.device_scale_factor = device_scale_factor;
8525 inputs.can_adjust_raster_scales = true;
8526 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8527
8528 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale);
8529 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale);
8530 EXPECT_FLOAT_EQ(
8531 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8532 EXPECT_FLOAT_EQ(36.f,
8533 child1_layer->replica_layer()
8534 ->mask_layer()
8535 ->draw_properties()
8536 .ideal_contents_scale);
8537 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale);
8538
8539 EXPECT_FLOAT_EQ(
8540 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8541 EXPECT_FLOAT_EQ(
8542 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8543 EXPECT_FLOAT_EQ(0.f,
8544 child1_layer->mask_layer()
8545 ->draw_properties()
8546 .maximum_animation_contents_scale);
8547 EXPECT_FLOAT_EQ(0.f,
8548 child1_layer->replica_layer()
8549 ->mask_layer()
8550 ->draw_properties()
8551 .maximum_animation_contents_scale);
8552 EXPECT_FLOAT_EQ(
8553 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8554
8555 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8556 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8557 EXPECT_FLOAT_EQ(
8558 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8559 EXPECT_FLOAT_EQ(3.f,
8560 child1_layer->replica_layer()
8561 ->mask_layer()
8562 ->draw_properties()
8563 .page_scale_factor);
8564 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8565
8566 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor);
8567 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor);
8568 EXPECT_FLOAT_EQ(
8569 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8570 EXPECT_FLOAT_EQ(4.f,
8571 child1_layer->replica_layer()
8572 ->mask_layer()
8573 ->draw_properties()
8574 .device_scale_factor);
8575 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8576}
8577
danakjf6069db2014-09-13 00:46:478578TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
8579 scoped_refptr<Layer> root = Layer::Create();
8580 SetLayerPropertiesForTesting(root.get(),
8581 gfx::Transform(),
8582 gfx::Point3F(),
8583 gfx::PointF(),
8584 gfx::Size(768 / 2, 3000),
8585 true,
8586 false);
8587 root->SetIsDrawable(true);
8588
8589 scoped_refptr<Layer> clip = Layer::Create();
8590 SetLayerPropertiesForTesting(clip.get(),
8591 gfx::Transform(),
8592 gfx::Point3F(),
8593 gfx::PointF(),
8594 gfx::Size(768 / 2, 10000),
8595 true,
8596 false);
8597 clip->SetMasksToBounds(true);
8598
8599 scoped_refptr<Layer> content = Layer::Create();
8600 SetLayerPropertiesForTesting(content.get(),
8601 gfx::Transform(),
8602 gfx::Point3F(),
8603 gfx::PointF(),
8604 gfx::Size(768 / 2, 10000),
8605 true,
8606 false);
8607 content->SetIsDrawable(true);
8608 content->SetForceRenderSurface(true);
8609
8610 root->AddChild(clip);
8611 clip->AddChild(content);
8612
enne2097cab2014-09-25 20:16:318613 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
8614 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
danakjf6069db2014-09-13 00:46:478615 host->SetRootLayer(root);
8616
8617 gfx::Size device_viewport_size(768, 582);
8618 RenderSurfaceLayerList render_surface_layer_list;
8619 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8620 host->root_layer(), device_viewport_size, &render_surface_layer_list);
8621 inputs.device_scale_factor = 2.f;
8622 inputs.page_scale_factor = 1.f;
8623 inputs.page_scale_application_layer = NULL;
8624 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8625
8626 // Layers in the root render surface have their visible content rect clipped
8627 // by the viewport.
8628 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8629
8630 // Layers drawing to a child render surface should still have their visible
8631 // content rect clipped by the viewport.
8632 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8633}
8634
timav599f4359d2014-12-05 00:12:228635TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
8636 FakeImplProxy proxy;
8637 TestSharedBitmapManager shared_bitmap_manager;
8638 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8639
8640 // Set two layers: the root layer clips it's child,
8641 // the child draws its content.
8642
8643 gfx::Size root_size = gfx::Size(300, 500);
8644
8645 // Sublayer should be bigger than the root enlarged by bounds_delta.
8646 gfx::Size sublayer_size = gfx::Size(300, 1000);
8647
8648 // Device viewport accomidated the root and the top controls.
8649 gfx::Size device_viewport_size = gfx::Size(300, 600);
8650 gfx::Transform identity_matrix;
8651
8652 host_impl.active_tree()->SetRootLayer(
8653 LayerImpl::Create(host_impl.active_tree(), 1));
8654
8655 LayerImpl* root = host_impl.active_tree()->root_layer();
8656 SetLayerPropertiesForTesting(root,
8657 identity_matrix,
8658 gfx::Point3F(),
8659 gfx::PointF(),
8660 root_size,
8661 false,
awoloszyne83f28c2014-12-22 15:40:008662 false,
8663 true);
timav599f4359d2014-12-05 00:12:228664
8665 root->SetContentBounds(root_size);
8666 root->SetMasksToBounds(true);
8667
8668 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8669
8670 LayerImpl* sublayer = root->child_at(0);
8671 SetLayerPropertiesForTesting(sublayer,
8672 identity_matrix,
8673 gfx::Point3F(),
8674 gfx::PointF(),
8675 sublayer_size,
8676 false,
awoloszyne83f28c2014-12-22 15:40:008677 false,
timav599f4359d2014-12-05 00:12:228678 false);
8679
8680 sublayer->SetContentBounds(sublayer_size);
8681 sublayer->SetDrawsContent(true);
8682
8683 LayerImplList layer_impl_list;
8684 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8685 root, device_viewport_size, &layer_impl_list);
8686
8687 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8688
8689 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect());
8690
8691 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8692
8693 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8694
8695 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8696 root_size.height() + 50);
8697 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect());
8698}
8699
vollick7d83b452015-02-24 20:18:068700TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8701 const gfx::Transform identity_matrix;
8702 scoped_refptr<Layer> root = Layer::Create();
8703 scoped_refptr<LayerWithForcedDrawsContent> animated =
8704 make_scoped_refptr(new LayerWithForcedDrawsContent());
8705
8706 root->AddChild(animated);
8707
8708 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8709 host->SetRootLayer(root);
8710
8711 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8712 gfx::PointF(), gfx::Size(100, 100), true, false);
8713 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8714 gfx::PointF(), gfx::Size(20, 20), true, false);
8715
8716 root->SetMasksToBounds(true);
8717 root->SetForceRenderSurface(true);
8718 animated->SetOpacity(0.f);
8719
8720 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
8721 0.f, 1.f, false);
8722
8723 ExecuteCalculateDrawProperties(root.get());
8724
8725 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
8726}
8727
enne92f2f6d92015-02-25 23:13:318728// Verify that having an animated filter (but no current filter, as these
8729// are mutually exclusive) correctly creates a render surface.
8730TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
8731 scoped_refptr<Layer> root = Layer::Create();
8732 scoped_refptr<Layer> child = Layer::Create();
8733 scoped_refptr<Layer> grandchild = Layer::Create();
8734 root->AddChild(child);
8735 child->AddChild(grandchild);
8736
8737 gfx::Transform identity_transform;
8738 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8739 gfx::PointF(), gfx::Size(50, 50), true, false);
8740 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8741 gfx::PointF(), gfx::Size(50, 50), true, false);
8742 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8743 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8744 true, false);
8745 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8746 host->SetRootLayer(root);
8747
8748 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
8749
8750 ExecuteCalculateDrawProperties(root.get());
8751
8752 EXPECT_TRUE(root->render_surface());
8753 EXPECT_TRUE(child->render_surface());
8754 EXPECT_FALSE(grandchild->render_surface());
8755
8756 EXPECT_TRUE(root->filters().IsEmpty());
8757 EXPECT_TRUE(child->filters().IsEmpty());
8758 EXPECT_TRUE(grandchild->filters().IsEmpty());
8759
8760 EXPECT_FALSE(root->FilterIsAnimating());
8761 EXPECT_TRUE(child->FilterIsAnimating());
8762 EXPECT_FALSE(grandchild->FilterIsAnimating());
8763}
8764
vollick0120eb22015-03-02 03:07:348765// Ensures that the property tree code accounts for offsets between fixed
8766// position layers and their respective containers.
8767TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
8768 scoped_refptr<Layer> root = Layer::Create();
8769 scoped_refptr<Layer> child = Layer::Create();
8770 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8771 make_scoped_refptr(new LayerWithForcedDrawsContent());
8772
8773 root->AddChild(child);
8774 child->AddChild(grandchild);
8775
8776 gfx::Transform identity_transform;
8777 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8778 gfx::PointF(), gfx::Size(50, 50), true, false);
8779 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8780 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8781 false);
8782 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8783 gfx::Point3F(), gfx::PointF(-1000, -1000),
8784 gfx::Size(50, 50), true, false);
8785
8786 root->SetMasksToBounds(true);
8787 root->SetIsContainerForFixedPositionLayers(true);
8788 LayerPositionConstraint constraint;
8789 constraint.set_is_fixed_position(true);
8790 grandchild->SetPositionConstraint(constraint);
8791
8792 root->SetIsContainerForFixedPositionLayers(true);
8793
8794 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8795 host->SetRootLayer(root);
8796
8797 ExecuteCalculateDrawProperties(root.get());
8798
8799 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8800 grandchild->visible_rect_from_property_trees());
8801}
8802
vollick67394b42015-03-10 00:22:308803TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8804 // In the following layer tree, the layer |box|'s render target is |surface|.
8805 // |surface| also creates a transform node. We want to combine clips for |box|
8806 // in the space of its target (i.e., |surface|), not its target's target. This
8807 // test ensures that happens.
8808
8809 gfx::Transform rotate;
8810 rotate.Rotate(5);
8811 gfx::Transform identity;
8812
8813 scoped_refptr<Layer> root = Layer::Create();
8814 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8815 gfx::PointF(), gfx::Size(2500, 1500), true,
8816 false);
8817
8818 scoped_refptr<Layer> frame_clip = Layer::Create();
8819 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8820 gfx::PointF(), gfx::Size(2500, 1500), true,
8821 false);
8822 frame_clip->SetMasksToBounds(true);
8823
8824 scoped_refptr<Layer> rotated = Layer::Create();
8825 SetLayerPropertiesForTesting(rotated.get(), rotate,
8826 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8827 gfx::Size(2500, 500), true, false);
8828
8829 scoped_refptr<Layer> surface = Layer::Create();
8830 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8831 gfx::PointF(), gfx::Size(2500, 500), true,
8832 false);
8833 surface->SetOpacity(0.5);
8834
8835 scoped_refptr<LayerWithForcedDrawsContent> container =
8836 make_scoped_refptr(new LayerWithForcedDrawsContent());
8837 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8838 gfx::PointF(), gfx::Size(300, 300), true, false);
8839
8840 scoped_refptr<LayerWithForcedDrawsContent> box =
8841 make_scoped_refptr(new LayerWithForcedDrawsContent());
8842 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8843 gfx::PointF(), gfx::Size(100, 100), true, false);
8844
8845 root->AddChild(frame_clip);
8846 frame_clip->AddChild(rotated);
8847 rotated->AddChild(surface);
8848 surface->AddChild(container);
8849 surface->AddChild(box);
8850
8851 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8852 host->SetRootLayer(root);
8853
8854 ExecuteCalculateDrawProperties(root.get());
8855}
8856
vollick8c824742015-03-20 22:21:088857TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
8858 gfx::Transform identity;
8859 gfx::Transform translate_z;
8860 translate_z.Translate3d(0, 0, 10);
8861
8862 scoped_refptr<Layer> root = Layer::Create();
8863 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8864 gfx::PointF(), gfx::Size(800, 800), true, false);
8865 root->SetIsContainerForFixedPositionLayers(true);
8866
8867 scoped_refptr<Layer> frame_clip = Layer::Create();
8868 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8869 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8870 false);
8871 frame_clip->SetMasksToBounds(true);
8872
8873 scoped_refptr<LayerWithForcedDrawsContent> fixed =
8874 make_scoped_refptr(new LayerWithForcedDrawsContent());
8875 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8876 gfx::PointF(), gfx::Size(1000, 1000), true,
8877 false);
8878
8879 LayerPositionConstraint constraint;
8880 constraint.set_is_fixed_position(true);
8881 fixed->SetPositionConstraint(constraint);
8882
8883 root->AddChild(frame_clip);
8884 frame_clip->AddChild(fixed);
8885
8886 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8887 host->SetRootLayer(root);
8888
8889 ExecuteCalculateDrawProperties(root.get());
8890
8891 gfx::Rect expected(0, 0, 100, 100);
8892 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8893}
8894
[email protected]ba565742012-11-10 09:29:488895} // namespace
8896} // namespace cc